Loading

Paste #ppl8yzr9f

  1. class MyNewAI extends AIController
  2. {
  3.  
  4.   function Start()
  5.   {
  6.     //This function is inside the class declaration.
  7.   }
  8.    
  9.   //These are optional prototypes. Notice the ; at the end rather than {}.
  10.   //Squirrel doesn't require it, but some programmers like to use them.
  11.   function Save();
  12.   function Load(version, data);
  13. }
  14.  
  15. function MyNewAI::Save()
  16. {
  17.   AILog.Info("//This function is outside the class declaration and requires the name of the class so squirrel can assign it to the right place.")
  18.   return {};
  19. }
  20.  
  21. function MyNewAI::Load(version, data)
  22. {
  23.   AILog.Info("Load")
  24. }
  25.  
  26. function MyNewAI::Start()
  27. {
  28.   if (!AICompany.SetName("MyNewAI")) {
  29.     local i = 2;
  30.     while (!AICompany.SetName("MyNewAI #" + i)) {
  31.       i = i + 1;
  32.     }
  33.   }
  34.  
  35. //  local some_integer = 2;
  36. //  AILog.Info(some_integer + "");
  37.  
  38.   while (true) {
  39.     while (AIEventController.IsEventWaiting()) {
  40.       local e = AIEventController.GetNextEvent();
  41.       switch (e.GetEventType()) {
  42.         case AIEvent.ET_INVALID:
  43.           AILog.Info("Event: ET_INVALID")
  44.           break
  45.        
  46.         case AIEvent.ET_TEST:
  47.           AILog.Info("Event: ET_TEST")
  48.           break
  49.          
  50.         case AIEvent.ET_SUBSIDY_OFFER:
  51.           local ec = AIEventSubsidyOffer.Convert(e)
  52.           local s  = ec.GetSubsidyID()
  53.           AILog.Info("Event: ET_SUBSIDY_OFFER (" + s + ")")
  54.           break
  55.  
  56.         case AIEvent.ET_SUBSIDY_OFFER_EXPIRED:
  57.           local ec = AIEventSubsidyOfferExpired.Convert(e)
  58.           local s  = ec.GetSubsidyID()
  59.           AILog.Info("Event: ET_SUBSIDY_OFFER_EXPIRED (" + s + ")")
  60.           break
  61.  
  62.         case AIEvent.ET_SUBSIDY_AWARDED:
  63.           local ec = AIEventSubsidyAwarded.Convert(e)
  64.           local s  = ec.GetSubsidyID()
  65.           AILog.Info("Event: ET_SUBSIDY_AWARDED (" + s + ")")
  66.           break
  67.        
  68. //  ET_SUBSIDY_AWARDED,
  69. //  ET_SUBSIDY_EXPIRED,
  70. //  ET_ENGINE_PREVIEW,
  71. //  ET_COMPANY_NEW,
  72. //  ET_COMPANY_IN_TROUBLE,
  73. //  ET_COMPANY_ASK_MERGER,
  74. //  ET_COMPANY_MERGER,
  75. //  ET_COMPANY_BANKRUPT,
  76. //  ET_VEHICLE_CRASHED,
  77. //  ET_VEHICLE_LOST,
  78. //  ET_VEHICLE_WAITING_IN_DEPOT,
  79. //  ET_VEHICLE_UNPROFITABLE,
  80. //  ET_INDUSTRY_OPEN,
  81. //  ET_INDUSTRY_CLOSE,
  82. //  ET_ENGINE_AVAILABLE,
  83. //  ET_STATION_FIRST_VEHICLE,
  84. //  ET_DISASTER_ZEPPELINER_CRASHED,
  85. //  ET_DISASTER_ZEPPELINER_CLEARED,
  86. //  ET_TOWN_FOUNDED,
  87. //  ET_AIRCRAFT_DEST_TOO_FAR,
  88. //  ET_ADMIN_PORT,
  89. //  ET_WINDOW_WIDGET_CLICK,
  90. //  ET_GOAL_QUESTION_ANSWER,
  91. //  ET_EXCLUSIVE_TRANSPORT_RIGHTS,
  92. //  ET_ROAD_RECONSTRUCTION
  93.         case AIEvent.ET_VEHICLE_CRASHED:
  94.          local ec = AIEventVehicleCrashed.Convert(e);
  95.          local v  = ec.GetVehicleID();
  96.          local c  = ec.GetCrashSite();
  97.          local r  = ec.GetCrashReason();
  98.          AILog.Info("Event: ET_VEHICLE_CRASHED (" + v + ") (" + c + ") (" + r + ")");
  99.          /* Handle the crashed vehicle */
  100.          break;
  101.       }
  102.     }
  103.    
  104. //    AILog.Info("I am a very new AI with a ticker called MyNewAI and I am at tick " + this.GetTick());
  105.   }
  106. }

Version history

Revision # Author Created at
pijrjcpdk Anonymous 05 Feb 2018, 18:09:29 UTC Diff

Comments