| Old revision #pizkc23g9 | New revision #pqpkz9ykh | ||
|---|---|---|---|
| 13 | 13 | ||
| 14 | /* Modified code */ | 14 | /* Modified code */ |
| 15 | class BuildVehicleMoneyTest { | 15 | class BuildVehicleMoneyTest { |
| 16 | function DoMoneyTest(engine) { | 16 | function DoMoneyTest() { |
| 17 | local price = AIEngine.GetPrice(engine); | 17 | if (WrightAI.HasMoney(GetPrice())) WrightAI.GetMoney(GetPrice()); |
| 18 | if (WrightAI.HasMoney(price)) WrightAI.GetMoney(price); | 18 | if (DoBuildVehicle()) { |
| 19 | local vehicle = DoBuildVehicle(); | 19 | WrightAI.RepayLoan(); |
| 20 | return true; | ||
| 21 | } | ||
| 20 | WrightAI.RepayLoan(); | 22 | WrightAI.RepayLoan(); |
| 21 | if (!AIVehicle.IsValidVehicle(vehicle)) { | 21 | return false; |
| 22 | // if (!silent_mode) AILog.Error("Couldn't build the aircraft"); | ||
| 23 | return null; | ||
| 24 | } | ||
| 25 | return vehicle; | ||
| 26 | } | 24 | } |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | class TestBuildVehicle extends BuildVehicleMoneyTest { | 27 | class TestBuildVehicle extends BuildVehicleMoneyTest { |
| 30 | h = null; | 28 | h = null; |
| 31 | e = null; | 29 | e = null; |
| 30 | v = null; | ||
| 31 | p = null; | ||
| 32 | 32 | ||
| 33 | function DoBuildVehicle() { | 33 | function DoBuildVehicle() { |
| 34 | return AIVehicle.BuildVehicle(h, e); | 34 | v = AIVehicle.BuildVehicle(h, e); |
| 35 | if (!AIVehicle.IsValidVehicle(v)) { | ||
| 36 | // if (!silent_mode) AILog.Error("Couldn't build the aircraft"); | ||
| 37 | return false; | ||
| 38 | } | ||
| 39 | return true; | ||
| 40 | } | ||
| 41 | |||
| 42 | function GetPrice() { | ||
| 43 | return AIEngine.GetPrice(e); | ||
| 35 | } | 44 | } |
| 36 | 45 | ||
| 37 | function TryBuild(best_hangar, engine) { | 46 | function TryBuild(best_hangar, engine) { |
| 38 | h = best_hangar; | 47 | h = best_hangar; |
| 39 | e = engine; | 48 | e = engine; |
| 40 | return DoMoneyTest(e); | 49 | p = GetPrice(); |
| 50 | if (DoMoneyTest()) { | ||
| 51 | return v; | ||
| 52 | } | ||
| 53 | return null; | ||
| 41 | } | 54 | } |
| 42 | } | 55 | } |
| 43 | 56 | ||