Loading

Paste #pizkc23g9

  1. /* Original code */
  2. ()
  3. //  local price = AIEngine.GetPrice(engine);
  4. //  if (HasMoney(price)) GetMoney(price);
  5. //  local vehicle = AIVehicle.BuildVehicle(best_hangar, engine);
  6. //  RepayLoan();
  7. //  if (!AIVehicle.IsValidVehicle(vehicle)) {
  8. //      if (!silent_mode) AILog.Error("Couldn't build the aircraft");
  9. //      return -1;
  10. //  }
  11. ()
  12.  
  13.  
  14. /* Modified code */
  15. class BuildVehicleMoneyTest {
  16.     function DoMoneyTest(engine) {
  17.         local price = AIEngine.GetPrice(engine);
  18.         if (WrightAI.HasMoney(price)) WrightAI.GetMoney(price);
  19.         local vehicle = DoBuildVehicle();
  20.         WrightAI.RepayLoan();
  21.         if (!AIVehicle.IsValidVehicle(vehicle)) {
  22. //          if (!silent_mode) AILog.Error("Couldn't build the aircraft");
  23.             return null;
  24.         }
  25.         return vehicle;
  26.     }
  27. }
  28.  
  29. class TestBuildVehicle extends BuildVehicleMoneyTest {
  30.     h = null;
  31.     e = null;
  32.    
  33.     function DoBuildVehicle() {
  34.         return AIVehicle.BuildVehicle(h, e);
  35.     }
  36.    
  37.     function TryBuild(best_hangar, engine) {
  38.         h = best_hangar;
  39.         e = engine;
  40.         return DoMoneyTest(e);
  41.     }
  42. }
  43.  
  44. /* Somewhere else */
  45. ()
  46.     local tvb = TestBuildVehicle();
  47.     local vehicle = tvb.TryBuild(best_hangar, engine);
  48.     if (vehicle == null) {
  49.         if (!silent_mode) AILog.Error("Couldn't build the aircraft");
  50.         return -1;
  51.     }
  52. ()

Comments