| 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 | }
|
|---|
| 14 | /* Modified code */
| 21 | function DoBuild() {
|
|---|
| 15 | class BuildVehicleMoneyTest {
| 22 | return AIExecMode() && AIAirport.BuildAirport(loc, tp, id);
|
|---|
| 16 | function DoMoneyTest(engine) {
| 23 | }
|
|---|
| 17 | local price = AIEngine.GetPrice(engine);
| 24 |
|
|---|
| 18 | if (WrightAI.HasMoney(price)) WrightAI.GetMoney(price);
| 25 | function GetPrice() {
|
|---|
| 19 | local vehicle = DoBuildVehicle();
| 26 | local last_cost = AIAccounting();
|
|---|
| 20 | WrightAI.RepayLoan();
| 27 | AITestMode() && AIAirport.BuildAirport(loc, tp, id);
|
|---|
| 21 | if (!AIVehicle.IsValidVehicle(vehicle)) {
| 28 | return last_cost.GetCosts();
|
|---|
| 22 | // if (!silent_mode) AILog.Error("Couldn't build the aircraft");
| 29 | }
|
|---|
| 23 | return null;
| 30 |
|
|---|
| 24 | }
| 31 | function TryBuild(location, type, theid) {
|
|---|
| 25 | return vehicle;
| 32 | loc = location;
|
|---|
| | | 33 | tp = type;
|
|---|
| | | 34 | id = theid;
|
|---|
| | | 35 | if (DoMoneyTest()) {
|
|---|
| | | 36 | return true;
|
|---|
| | | 37 | } else {
|
|---|
| | | 38 | assert(AIError.GetLastError() != AIError.ERR_STATION_TOO_SPREAD_OUT);
|
|---|
| | | 39 | return false;
|
|---|
| | | 40 | }
|
|---|