Loading

Revision differences

Old revision #pijrjcpdkNew revision #ppl8yzr9f
14  14  
15function MyNewAI::Save()  15function MyNewAI::Save()  
16{  16{  
17   //This function is outside the class declaration and requires the name of the class so squirrel can assign it to the right place.  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 {};
18}  19}  
19  20  
20function MyNewAI::Load(version, data)  21function MyNewAI::Load(version, data)  
21{  22{  
  23  AILog.Info("Load")  
22}  24}  
23  25  
24function MyNewAI::Start()  26function MyNewAI::Start()  
25{  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   
26  while (true) {  38  while (true) {  
27    AILog.Info("I am a very new AI with a ticker called MyNewAI and I am at tick " + this.GetTick());  39    while (AIEventController.IsEventWaiting()) {
28    this.Sleep(50);  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());
29  }  105  }  
30} 106}