class LuDiAIAfterFix extends AIController { MAX_TOWN_VEHICLES = AIGameSettings.GetValue("max_roadveh"); MIN_DISTANCE = 40; MAX_DISTANCE = 115; MAX_DISTANCE_INCREASE = 1.2; townManager = null; routeManager = null; buildManager = null; scheduledRemoves = AIList(); cargoClass = null; bestRoutesBuilt = null; allRoutesBuilt = null; wrightAI = null; loading = null; loadData = 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, MIN_DISTANCE, MAX_DISTANCE); loading = true; } function Start(); (…) function Save() { // while(loading) { // AILog.Warning("Still loading, can't save yet...") // } AILog.Warning("Saving..."); local table = {}; table.rawset("town_manager", townManager.saveTownManager()); table.rawset("route_manager", routeManager.saveRouteManager()); table.rawset("build_manager", buildManager.saveBuildManager()); local scheduledRemovesTable = {}; for (local tile = scheduledRemoves.Begin(), i = 0; scheduledRemoves.HasNext(); tile = scheduledRemoves.Next(), ++i) { scheduledRemovesTable.rawset(i, [tile, scheduledRemoves.GetValue(tile)]); } table.rawset("scheduled_removes", scheduledRemovesTable); table.rawset("best_routes_built", bestRoutesBuilt); table.rawset("all_routes_built", allRoutesBuilt); table.rawset("wrightai", wrightAI.save()); AILog.Warning("Saved!"); return table; } function Load(version, data) { loading = true; loadData = data; AILog.Info("Loading..."); } } function LuDiAIAfterFix::Start() { local cargoId = Utils.getCargoId(cargoClass); local cargostr = AICargo.GetCargoLabel(cargoId); if (!AICompany.SetName("LuDiAI AfterFix " + cargostr)) { local i = 2; while (!AICompany.SetName("LuDiAI AfterFix " + cargostr + " #" + i)) { ++i; } } 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 scheduledRemovesTable = loadData.rawget("scheduled_removes"); local i = 0; while(scheduledRemovesTable.rawin(i)) { local tile = scheduledRemovesTable.rawget(i); scheduledRemoves.AddItem(tile[0], tile[1]); ++i; } } AILog.Info("Loaded " + scheduledRemoves.Count() + " scheduled removals."); if(loadData.rawin("best_routes_built")) { bestRoutesBuilt = loadData.rawget("best_routes_built"); } AILog.Info("Loaded " + bestRoutesBuilt + " best routes build."); if(loadData.rawin("all_routes_built")) { allRoutesBuilt = loadData.rawget("all_routes_built"); } AILog.Info("Loaded " + allRoutesBuilt + " all routes built."); if(buildManager.hasUnfinishedRoute()) { AILog.Warning("Unfinished route between " + AITown.GetName(buildManager.m_cityFrom) + " and " + AITown.GetName(buildManager.m_cityTo) + " detected!"); } AILog.Info("Loaded " + buildManager.hasUnfinishedRoute() + " has unfinished route."); if(loadData.rawin("wrightai")) { wrightAI.load(loadData.rawget("wrightai")); } AILog.Info("Loaded " + wrightAI + " wrightAI."); AILog.Warning("Game loaded."); loadData = null; } loading = false; } (…)