//////////
main.nut
//////////
class LuDiAIAfterFix extends AIController {
MAX_TOWN_VEHICLES = AIGameSettings.GetValue("max_roadveh");
MIN_DISTANCE = AIController.GetSetting("road_min_dist");
MAX_DISTANCE = 115;
MAX_DISTANCE_INCREASE = 25;
MAX_MANAGEMENT_TICKS = 2220; // 30 days
townManager = null;
routeManager = null;
buildManager = null;
scheduledRemovals = AIList();
lastManaged = 0;
cargoClass = null;
bestRoutesBuilt = null;
allRoutesBuilt = null;
wrightAI = null;
sentToDepotAirGroup = AIGroup.GROUP_INVALID;
sentToDepotRoadGroup = AIGroup.GROUP_INVALID;
loading = null;
loadData = null;
buildTimer = 0;
scp = null;
cvgs = null;
ncg = null;
constructor() {
townManager = TownManager();
routeManager = RouteManager();
buildManager = BuildManager();
if (!AIController.GetSetting("select_town_cargo")) {
cargoClass = AICargo.CC_PASSENGERS;
}
else {
cargoClass = AICargo.CC_MAIL;
}
bestRoutesBuilt = false;
allRoutesBuilt = false;
wrightAI = WrightAI(cargoClass);
loading = true;
}
function Start();
}
// etc.. etc..
function LuDiAIAfterFix::Start() {
local cargoId = Utils.getCargoId(cargoClass);
local cargostr = AICargo.GetCargoLabel(cargoId);
AICompany.SetAutoRenewMonths(-12);
AICompany.SetAutoRenewMoney(0);
if (loading) {
if (loadData != null) {
if (loadData.rawin("town_manager")) {
townManager.loadTownManager(loadData.rawget("town_manager"));
}
if (loadData.rawin("route_manager")) {
routeManager.loadRouteManager(loadData.rawget("route_manager"));
}
if (loadData.rawin("build_manager")) {
buildManager.loadBuildManager(loadData.rawget("build_manager"));
}
if (loadData.rawin("scheduled_removes")) {
local scheduledRemovalsTable = loadData.rawget("scheduled_removes");
local i = 0;
while(scheduledRemovalsTable.rawin(i)) {
local tile = scheduledRemovalsTable.rawget(i);
scheduledRemovals.AddItem(tile[0], tile[1]);
++i;
}
}
AILog.Info("Loaded " + scheduledRemovals.Count() + " scheduled removals.");
if (loadData.rawin("best_routes_built")) {
bestRoutesBuilt = loadData.rawget("best_routes_built");
}
if (loadData.rawin("all_routes_built")) {
allRoutesBuilt = loadData.rawget("all_routes_built");
}
if (loadData.rawin("wrightai")) {
wrightAI.load(loadData.rawget("wrightai"));
}
if (loadData.rawin("sent_to_depot_air_group")) {
sentToDepotAirGroup = loadData.rawget("sent_to_depot_air_group");
}
if (loadData.rawin("sent_to_depot_road_group")) {
sentToDepotRoadGroup = loadData.rawget("sent_to_depot_road_group");
}
AILog.Warning("Game loaded.");
loadData = null;
} else {
/* Name company */
if (!AICompany.SetName("LuDiAI AfterFix " + cargostr)) {
local i = 2;
while (!AICompany.SetName("LuDiAI AfterFix " + cargostr + " #" + i)) {
++i;
}
}
}
loading = false;
if (!AIGroup.IsValidGroup(sentToDepotAirGroup)) {
sentToDepotAirGroup = AIGroup.CreateGroup(AIVehicle.VT_AIR);
}
if (!AIGroup.IsValidGroup(sentToDepotRoadGroup)) {
sentToDepotRoadGroup = AIGroup.CreateGroup(AIVehicle.VT_ROAD);
}
if (AIGroup.IsValidGroup(sentToDepotAirGroup) && AIGroup.IsValidGroup(sentToDepotRoadGroup)) {
AILog.Info("Enabled AutoRenew");
AICompany.SetAutoRenewStatus(true);
}
etc... etc...
/////////////
somewhere in route.nut
/////////////
etc... etc..
if (!AIGroup.MoveVehicle(LuDiAIAfterFix.sentToDepotRoadGroup, vehicle)) {
AILog.Error("Failed to move vehicle " + vehicle + " to group " + LuDiAIAfterFix.sentToDepotRoadGroup);
}