class MyNewAI extends AIController
{
function Start()
{
//This function is inside the class declaration.
}
//These are optional prototypes. Notice the ; at the end rather than {}.
//Squirrel doesn't require it, but some programmers like to use them.
function Save();
function Load(version, data);
}
function MyNewAI::Save()
{
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.")
return {};
}
function MyNewAI::Load(version, data)
{
AILog.Info("Load")
}
function MyNewAI::Start()
{
if (!AICompany.SetName("MyNewAI")) {
local i = 2;
while (!AICompany.SetName("MyNewAI #" + i)) {
i = i + 1;
}
}
// local some_integer = 2;
// AILog.Info(some_integer + "");
while (true) {
while (AIEventController.IsEventWaiting()) {
local e = AIEventController.GetNextEvent();
switch (e.GetEventType()) {
case AIEvent.ET_INVALID:
AILog.Info("Event: ET_INVALID")
break
case AIEvent.ET_TEST:
AILog.Info("Event: ET_TEST")
break
case AIEvent.ET_SUBSIDY_OFFER:
local ec = AIEventSubsidyOffer.Convert(e)
local s = ec.GetSubsidyID()
AILog.Info("Event: ET_SUBSIDY_OFFER (" + s + ")")
break
case AIEvent.ET_SUBSIDY_OFFER_EXPIRED:
local ec = AIEventSubsidyOfferExpired.Convert(e)
local s = ec.GetSubsidyID()
AILog.Info("Event: ET_SUBSIDY_OFFER_EXPIRED (" + s + ")")
break
case AIEvent.ET_SUBSIDY_AWARDED:
local ec = AIEventSubsidyAwarded.Convert(e)
local s = ec.GetSubsidyID()
AILog.Info("Event: ET_SUBSIDY_AWARDED (" + s + ")")
break
// ET_SUBSIDY_AWARDED,
// ET_SUBSIDY_EXPIRED,
// ET_ENGINE_PREVIEW,
// ET_COMPANY_NEW,
// ET_COMPANY_IN_TROUBLE,
// ET_COMPANY_ASK_MERGER,
// ET_COMPANY_MERGER,
// ET_COMPANY_BANKRUPT,
// ET_VEHICLE_CRASHED,
// ET_VEHICLE_LOST,
// ET_VEHICLE_WAITING_IN_DEPOT,
// ET_VEHICLE_UNPROFITABLE,
// ET_INDUSTRY_OPEN,
// ET_INDUSTRY_CLOSE,
// ET_ENGINE_AVAILABLE,
// ET_STATION_FIRST_VEHICLE,
// ET_DISASTER_ZEPPELINER_CRASHED,
// ET_DISASTER_ZEPPELINER_CLEARED,
// ET_TOWN_FOUNDED,
// ET_AIRCRAFT_DEST_TOO_FAR,
// ET_ADMIN_PORT,
// ET_WINDOW_WIDGET_CLICK,
// ET_GOAL_QUESTION_ANSWER,
// ET_EXCLUSIVE_TRANSPORT_RIGHTS,
// ET_ROAD_RECONSTRUCTION
case AIEvent.ET_VEHICLE_CRASHED:
local ec = AIEventVehicleCrashed.Convert(e);
local v = ec.GetVehicleID();
local c = ec.GetCrashSite();
local r = ec.GetCrashReason();
AILog.Info("Event: ET_VEHICLE_CRASHED (" + v + ") (" + c + ") (" + r + ")");
/* Handle the crashed vehicle */
break;
}
}
// AILog.Info("I am a very new AI with a ticker called MyNewAI and I am at tick " + this.GetTick());
}
}