Loading

Paste #pqpkz9ykh

  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() {
  17.         if (WrightAI.HasMoney(GetPrice())) WrightAI.GetMoney(GetPrice());
  18.         if (DoBuildVehicle()) {
  19.             WrightAI.RepayLoan();
  20.             return true;
  21.         }
  22.         WrightAI.RepayLoan();
  23.         return false;
  24.     }
  25. }
  26.  
  27. class TestBuildVehicle extends BuildVehicleMoneyTest {
  28.     h = null;
  29.     e = null;
  30.     v = null;
  31.     p = null;
  32.    
  33.     function DoBuildVehicle() {
  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);
  44.     }
  45.    
  46.     function TryBuild(best_hangar, engine) {
  47.         h = best_hangar;
  48.         e = engine;
  49.         p = GetPrice();
  50.         if (DoMoneyTest()) {
  51.             return v;
  52.         }
  53.         return null;
  54.     }
  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. ()

Version history

Revision # Author Created at
pizkc23g9 Anonymous 01 Sep 2018, 15:11:38 UTC Diff

Comments