/* Original code */ (…) // local price = AIEngine.GetPrice(engine); // if (HasMoney(price)) GetMoney(price); // local vehicle = AIVehicle.BuildVehicle(best_hangar, engine); // RepayLoan(); // if (!AIVehicle.IsValidVehicle(vehicle)) { // if (!silent_mode) AILog.Error("Couldn't build the aircraft"); // return -1; // } (…) /* Modified code */ class BuildVehicleMoneyTest { function DoMoneyTest(engine) { local price = AIEngine.GetPrice(engine); if (WrightAI.HasMoney(price)) WrightAI.GetMoney(price); local vehicle = DoBuildVehicle(); WrightAI.RepayLoan(); if (!AIVehicle.IsValidVehicle(vehicle)) { // if (!silent_mode) AILog.Error("Couldn't build the aircraft"); return null; } return vehicle; } } class TestBuildVehicle extends BuildVehicleMoneyTest { h = null; e = null; function DoBuildVehicle() { return AIVehicle.BuildVehicle(h, e); } function TryBuild(best_hangar, engine) { h = best_hangar; e = engine; return DoMoneyTest(e); } } /* Somewhere else */ (…) local tvb = TestBuildVehicle(); local vehicle = tvb.TryBuild(best_hangar, engine); if (vehicle == null) { if (!silent_mode) AILog.Error("Couldn't build the aircraft"); return -1; } (…)