Loading

Paste #pk6kvijmi

  1. //////////
  2. main.nut
  3. //////////
  4.  
  5. class LuDiAIAfterFix extends AIController {
  6.     MAX_TOWN_VEHICLES = AIGameSettings.GetValue("max_roadveh");
  7.     MIN_DISTANCE = AIController.GetSetting("road_min_dist");
  8.     MAX_DISTANCE = 115;
  9.     MAX_DISTANCE_INCREASE = 25;
  10.     MAX_MANAGEMENT_TICKS = 2220; // 30 days
  11.  
  12.     townManager = null;
  13.     routeManager = null;
  14.     buildManager = null;
  15.     scheduledRemovals = AIList();
  16.    
  17.     lastManaged = 0;
  18.  
  19.     cargoClass = null;
  20.  
  21.     bestRoutesBuilt = null;
  22.     allRoutesBuilt = null;
  23.  
  24.     wrightAI = null;
  25.    
  26.     sentToDepotAirGroup = AIGroup.GROUP_INVALID;
  27.     sentToDepotRoadGroup = AIGroup.GROUP_INVALID;
  28.    
  29.     loading = null;
  30.     loadData = null;
  31.     buildTimer = 0;
  32.    
  33.     scp = null;
  34.     cvgs = null;
  35.     ncg = null;
  36.  
  37.     constructor() {
  38.         townManager = TownManager();
  39.         routeManager = RouteManager();
  40.         buildManager = BuildManager();
  41.  
  42.         if (!AIController.GetSetting("select_town_cargo")) {
  43.             cargoClass = AICargo.CC_PASSENGERS;
  44.         }
  45.         else {
  46.             cargoClass = AICargo.CC_MAIL;
  47.         }
  48.  
  49.         bestRoutesBuilt = false;
  50.         allRoutesBuilt = false;
  51.  
  52.         wrightAI = WrightAI(cargoClass);
  53.        
  54.         loading = true;
  55.     }
  56.  
  57.     function Start();
  58. }
  59.  
  60.  
  61. // etc.. etc..
  62.  
  63. function LuDiAIAfterFix::Start() {
  64.     local cargoId = Utils.getCargoId(cargoClass);
  65.     local cargostr = AICargo.GetCargoLabel(cargoId);
  66.  
  67.     AICompany.SetAutoRenewMonths(-12);
  68.     AICompany.SetAutoRenewMoney(0);
  69.  
  70.     if (loading) {
  71.         if (loadData != null) {
  72.             if (loadData.rawin("town_manager")) {
  73.                 townManager.loadTownManager(loadData.rawget("town_manager"));
  74.             }
  75.  
  76.             if (loadData.rawin("route_manager")) {
  77.                 routeManager.loadRouteManager(loadData.rawget("route_manager"));
  78.             }
  79.  
  80.             if (loadData.rawin("build_manager")) {
  81.                 buildManager.loadBuildManager(loadData.rawget("build_manager"));
  82.             }
  83.  
  84.             if (loadData.rawin("scheduled_removes")) {
  85.                 local scheduledRemovalsTable = loadData.rawget("scheduled_removes");
  86.                 local i = 0;
  87.                 while(scheduledRemovalsTable.rawin(i)) {
  88.                     local tile = scheduledRemovalsTable.rawget(i);
  89.                     scheduledRemovals.AddItem(tile[0], tile[1]);
  90.                     ++i;
  91.                 }
  92.             }
  93.             AILog.Info("Loaded " + scheduledRemovals.Count() + " scheduled removals.");
  94.  
  95.             if (loadData.rawin("best_routes_built")) {
  96.                 bestRoutesBuilt = loadData.rawget("best_routes_built");
  97.             }
  98.  
  99.             if (loadData.rawin("all_routes_built")) {
  100.                 allRoutesBuilt = loadData.rawget("all_routes_built");
  101.             }
  102.  
  103.             if (loadData.rawin("wrightai")) {
  104.                 wrightAI.load(loadData.rawget("wrightai"));
  105.             }
  106.            
  107.             if (loadData.rawin("sent_to_depot_air_group")) {
  108.                 sentToDepotAirGroup = loadData.rawget("sent_to_depot_air_group");
  109.             }
  110.            
  111.             if (loadData.rawin("sent_to_depot_road_group")) {
  112.                 sentToDepotRoadGroup = loadData.rawget("sent_to_depot_road_group");
  113.             }
  114.  
  115.             AILog.Warning("Game loaded.");
  116.             loadData = null;
  117.         } else {
  118.             /* Name company */
  119.             if (!AICompany.SetName("LuDiAI AfterFix " + cargostr)) {
  120.                 local i = 2;
  121.                 while (!AICompany.SetName("LuDiAI AfterFix " + cargostr + " #" + i)) {
  122.                     ++i;
  123.                 }
  124.             }
  125.         }
  126.         loading = false;
  127.  
  128.         if (!AIGroup.IsValidGroup(sentToDepotAirGroup)) {
  129.             sentToDepotAirGroup = AIGroup.CreateGroup(AIVehicle.VT_AIR);
  130.         }
  131.         if (!AIGroup.IsValidGroup(sentToDepotRoadGroup)) {
  132.             sentToDepotRoadGroup = AIGroup.CreateGroup(AIVehicle.VT_ROAD);
  133.         }
  134.         if (AIGroup.IsValidGroup(sentToDepotAirGroup) && AIGroup.IsValidGroup(sentToDepotRoadGroup)) {
  135.             AILog.Info("Enabled AutoRenew");
  136.             AICompany.SetAutoRenewStatus(true);
  137.         }
  138.  
  139. etc... etc...
  140.  
  141. /////////////
  142. somewhere in route.nut
  143. /////////////
  144. etc... etc..
  145.  
  146.                             if (!AIGroup.MoveVehicle(LuDiAIAfterFix.sentToDepotRoadGroup, vehicle)) {
  147.                                 AILog.Error("Failed to move vehicle " + vehicle + " to group " + LuDiAIAfterFix.sentToDepotRoadGroup);
  148.                             }

Comments