| Old revision #pqpkz9ykh | New revision #pkii1nhhh | ||
|---|---|---|---|
| 1 | /* Original code */ | 1 | class MoneyTest { |
| 2 | (…) | 2 | function DoMoneyTest() { |
| 3 | // local price = AIEngine.GetPrice(engine); | 3 | local price = GetPrice(); |
| 4 | // if (HasMoney(price)) GetMoney(price); | 4 | if (WrightAI.HasMoney(price)) { |
| 5 | // local vehicle = AIVehicle.BuildVehicle(best_hangar, engine); | 5 | WrightAI.GetMoney(price); |
| 6 | // RepayLoan(); | 6 | } |
| 7 | // if (!AIVehicle.IsValidVehicle(vehicle)) { | 7 | if (DoBuild()) { |
| 8 | // if (!silent_mode) AILog.Error("Couldn't build the aircraft"); | 8 | WrightAI.RepayLoan(); |
| 9 | // return -1; | 9 | return true; |
| 10 | // } | 10 | } |
| 11 | (…) | 11 | WrightAI.RepayLoan(); |
| 12 | return false; | ||
| 13 | } | ||
| 14 | } | ||
| 12 | 15 | ||
| 16 | class TestBuildAirport extends MoneyTest { | ||
| 17 | loc = null; | ||
| 18 | tp = null; | ||
| 19 | id = null; | ||
| 13 | 20 | ||
| 14 | /* Modified code */ | 21 | function DoBuild() { |
| 15 | class BuildVehicleMoneyTest { | 22 | return AIExecMode() && AIAirport.BuildAirport(loc, tp, id); |
| 16 | function DoMoneyTest() { | 23 | } |
| 17 | if (WrightAI.HasMoney(GetPrice())) WrightAI.GetMoney(GetPrice()); | 24 | |
| 18 | if (DoBuildVehicle()) { | 25 | function GetPrice() { |
| 19 | WrightAI.RepayLoan(); | 26 | local last_cost = AIAccounting(); |
| 27 | AITestMode() && AIAirport.BuildAirport(loc, tp, id); | ||
| 28 | return last_cost.GetCosts(); | ||
| 29 | } | ||
| 30 | |||
| 31 | function TryBuild(location, type, theid) { | ||
| 32 | loc = location; | ||
| 33 | tp = type; | ||
| 34 | id = theid; | ||
| 35 | if (DoMoneyTest()) { | ||
| 20 | return true; | 36 | return true; |
| 37 | } else { | ||
| 38 | assert(AIError.GetLastError() != AIError.ERR_STATION_TOO_SPREAD_OUT); | ||
| 39 | return false; | ||
| 21 | } | 40 | } |
| 22 | |||
| 23 | |||
| 24 | } | 41 | } |
| 25 | } | 42 | } |
| 26 | 43 | ||
| 27 | class TestBuildVehicle extends | 27 | class TestBuildVehicle extends MoneyTest { |
| 28 | h = null; | 45 | h = null; |
| 29 | e = null; | 46 | e = null; |
| 30 | v = null; | 47 | v = null; |
| 31 | |||
| 32 | 48 | ||
| 33 | function DoBuild | 33 | function DoBuild() { |
| 34 | v = AIVehicle.BuildVehicle(h, e); | 50 | v = AIVehicle.BuildVehicle(h, e); |
| 35 | if (!AIVehicle.IsValidVehicle(v)) { | 51 | if (!AIVehicle.IsValidVehicle(v)) { |
| 36 | |||
| 37 | return false; | 52 | return false; |
| 38 | } | 53 | } |
| 39 | return true; | 54 | return true; | … | … |
| 46 | function TryBuild(best_hangar, engine) { | 61 | function TryBuild(best_hangar, engine) { |
| 47 | h = best_hangar; | 62 | h = best_hangar; |
| 48 | e = engine; | 63 | e = engine; |
| 49 | |||
| 50 | if (DoMoneyTest()) { | 64 | if (DoMoneyTest()) { |
| 51 | return v; | 65 | return v; |
| 52 | } | 66 | } |
| 53 | return null; | 67 | return null; |
| 54 | } | 68 | } |
| 55 | } | 55 | } |
| 56 | |||
| 57 | /* Somewhere else */ | ||
| 58 | (…) | ||
| 59 | local tvb = TestBuildVehicle(); | ||
| 60 | local vehicle = tvb.TryBuild(best_hangar, engine); | ||
| 61 | if (vehicle == null) { | ||
| 62 | if (!silent_mode) AILog.Error("Couldn't build the aircraft"); | ||
| 63 | return -1; | ||
| 64 | } | ||
| 65 | (…) | ||