Loading

Paste #pwjr1knwo

  1.     function PerformTownActions() {
  2.         if (!cvgs.IsCompanyValueGSGame() || cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1) {
  3.             local cargoId = Utils.getCargoId(cargoClass);
  4.  
  5.             local stationList = AIStationList(AIStation.STATION_ANY);
  6.             stationList.Valuate(AIStation.HasCargoRating, cargoId);
  7.             stationList.KeepValue(1);
  8.             stationList.Valuate(AIStation.GetCargoRating, cargoId);
  9.             stationList.KeepBelowValue(50);
  10.             local stationTowns = AIList();
  11.             for (local st = stationList.Begin(); !stationList.IsEnd(); st = stationList.Next()) {
  12.                 if (AIVehicleList_Station(st).Count()) {
  13.                     local neartown = AIStation.GetNearestTown(st);
  14.                     if (!stationTowns.HasItem(neartown)) {
  15.                         stationTowns.AddItem(neartown, st);
  16.                     } else {
  17. //                      AILog.Info(AITown.GetName(neartown) + " to existing station " + AIBaseStation.GetName(stationTowns.GetValue(neartown)) + " (" + AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(stationTowns.GetValue(neartown))) + " manhattan tiles)");
  18. //                      AILog.Info(AITown.GetName(neartown) + " to checking station " + AIBaseStation.GetName(st) + " (" + AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(st)) + " manhattan tiles)");
  19.                         if (AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(stationTowns.GetValue(neartown))) < AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(st))) {
  20.                             stationTowns.SetValue(neartown, st);
  21.                         }
  22.                     }
  23.                 }
  24.             }
  25.             for (local town = stationTowns.Begin(); !stationTowns.IsEnd(); town = stationTowns.Next()) {
  26.                 if (!AITown.HasStatue(town)) {
  27.                     if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_BUILD_STATUE)) {
  28.                         local perform_action = true;
  29.                         local action_price = AIAccounting();
  30.                         AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_BUILD_STATUE);
  31.                         AIExecMode();
  32.                         if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
  33.                             AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
  34.                             if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
  35.                                 perform_action = false;
  36.                             }
  37.                         }
  38.                         if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_BUILD_STATUE)) {
  39.                             AILog.Warning("Built a statue in " + AITown.GetName(town) + ".");
  40.                         }
  41.                     }
  42.                 } else if (!AIController.GetSetting("is_friendly")) {
  43.                     local station_location = AIBaseStation.GetLocation(stationTowns.GetValue(town));
  44.                     local distance = AITown.GetDistanceManhattanToTile(town, station_location);
  45.                     if (distance <= 10) {
  46.                         if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_ADVERTISE_SMALL)) {
  47.                             local perform_action = true;
  48.                             local action_price = AIAccounting();
  49.                             AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_ADVERTISE_SMALL);
  50.                             AIExecMode();
  51.                             if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
  52.                                 AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
  53.                                 if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
  54.                                     perform_action = false;
  55.                                 }
  56.                             }
  57.                             if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_ADVERTISE_SMALL)) {
  58.                                 AILog.Warning("Initiated a small advertising campaign in " + AITown.GetName(town) + ".");
  59.                             }
  60.                         }
  61.                     } else if (distance <= 15) {
  62.                         if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_ADVERTISE_MEDIUM)) {
  63.                             local perform_action = true;
  64.                             local action_price = AIAccounting();
  65.                             AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_ADVERTISE_MEDIUM);
  66.                             AIExecMode();
  67.                             if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
  68.                                 AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
  69.                                 if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
  70.                                     perform_action = false;
  71.                                 }
  72.                             }
  73.                             if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_ADVERTISE_MEDIUM)) {
  74.                                 AILog.Warning("Initiated a medium advertising campaign in " + AITown.GetName(town) + ".");
  75.                             }
  76.                         }
  77.                     } else if (distance <= 20) {
  78.                         if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_ADVERTISE_LARGE)) {
  79.                             local perform_action = true;
  80.                             local action_price = AIAccounting();
  81.                             AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_ADVERTISE_LARGE);
  82.                             AIExecMode();
  83.                             if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
  84.                                 AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
  85.                                 if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
  86.                                     perform_action = false;
  87.                                 }
  88.                             }
  89.                             if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_ADVERTISE_LARGE)) {
  90.                                 AILog.Warning("Initiated a large advertising campaign in " + AITown.GetName(town) + ".");
  91.                             }
  92.                         }
  93.                     }
  94.                 }
  95.                
  96.                 if (AITown.GetLastMonthProduction(town, cargoId) <= (cargoClass == AICargo.CC_PASSENGERS ? 70 : 35)) {
  97.                     if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_FUND_BUILDINGS)) {
  98.                         if (AITown.GetFundBuildingsDuration(town) == 0) {
  99.                             local perform_action = true;
  100.                             local action_price = AIAccounting();
  101.                             AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_FUND_BUILDINGS);
  102.                             AIExecMode();
  103.                             if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
  104.                                 AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
  105.                                 if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
  106.                                     perform_action = false;
  107.                                 }
  108.                             }
  109.                             if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_FUND_BUILDINGS)) {
  110.                                 AILog.Warning("Funded the construction of new buildings in " + AITown.GetName(town) + ".");
  111.                             }
  112.                         }
  113.                     }
  114.                 }
  115.             }
  116.         }
  117.     }

Comments