function PerformTownActions() {
if (!cvgs.IsCompanyValueGSGame() || cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1) {
local cargoId = Utils.getCargoId(cargoClass);
local stationList = AIStationList(AIStation.STATION_ANY);
stationList.Valuate(AIStation.HasCargoRating, cargoId);
stationList.KeepValue(1);
stationList.Valuate(AIStation.GetCargoRating, cargoId);
stationList.KeepBelowValue(50);
local stationTowns = AIList();
for (local st = stationList.Begin(); !stationList.IsEnd(); st = stationList.Next()) {
if (AIVehicleList_Station(st).Count()) {
local neartown = AIStation.GetNearestTown(st);
if (!stationTowns.HasItem(neartown)) {
stationTowns.AddItem(neartown, st);
} else {
// AILog.Info(AITown.GetName(neartown) + " to existing station " + AIBaseStation.GetName(stationTowns.GetValue(neartown)) + " (" + AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(stationTowns.GetValue(neartown))) + " manhattan tiles)");
// AILog.Info(AITown.GetName(neartown) + " to checking station " + AIBaseStation.GetName(st) + " (" + AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(st)) + " manhattan tiles)");
if (AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(stationTowns.GetValue(neartown))) < AITown.GetDistanceManhattanToTile(neartown, AIBaseStation.GetLocation(st))) {
stationTowns.SetValue(neartown, st);
}
}
}
}
for (local town = stationTowns.Begin(); !stationTowns.IsEnd(); town = stationTowns.Next()) {
if (!AITown.HasStatue(town)) {
if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_BUILD_STATUE)) {
local perform_action = true;
local action_price = AIAccounting();
AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_BUILD_STATUE);
AIExecMode();
if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
perform_action = false;
}
}
if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_BUILD_STATUE)) {
AILog.Warning("Built a statue in " + AITown.GetName(town) + ".");
}
}
} else if (!AIController.GetSetting("is_friendly")) {
local station_location = AIBaseStation.GetLocation(stationTowns.GetValue(town));
local distance = AITown.GetDistanceManhattanToTile(town, station_location);
if (distance <= 10) {
if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_ADVERTISE_SMALL)) {
local perform_action = true;
local action_price = AIAccounting();
AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_ADVERTISE_SMALL);
AIExecMode();
if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
perform_action = false;
}
}
if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_ADVERTISE_SMALL)) {
AILog.Warning("Initiated a small advertising campaign in " + AITown.GetName(town) + ".");
}
}
} else if (distance <= 15) {
if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_ADVERTISE_MEDIUM)) {
local perform_action = true;
local action_price = AIAccounting();
AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_ADVERTISE_MEDIUM);
AIExecMode();
if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
perform_action = false;
}
}
if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_ADVERTISE_MEDIUM)) {
AILog.Warning("Initiated a medium advertising campaign in " + AITown.GetName(town) + ".");
}
}
} else if (distance <= 20) {
if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_ADVERTISE_LARGE)) {
local perform_action = true;
local action_price = AIAccounting();
AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_ADVERTISE_LARGE);
AIExecMode();
if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
perform_action = false;
}
}
if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_ADVERTISE_LARGE)) {
AILog.Warning("Initiated a large advertising campaign in " + AITown.GetName(town) + ".");
}
}
}
}
if (AITown.GetLastMonthProduction(town, cargoId) <= (cargoClass == AICargo.CC_PASSENGERS ? 70 : 35)) {
if (AITown.IsActionAvailable(town, AITown.TOWN_ACTION_FUND_BUILDINGS)) {
if (AITown.GetFundBuildingsDuration(town) == 0) {
local perform_action = true;
local action_price = AIAccounting();
AITestMode() && AITown.PerformTownAction(town, AITown.TOWN_ACTION_FUND_BUILDINGS);
AIExecMode();
if (cvgs.IsCompanyValueGSGame() && cvgs.GetCompanyIDRank(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) == 1 && cvgs.RankingList().Count() > 1) {
AILog.Info("Cost of perfoming action: " + action_price.GetCosts() + " ; Value difference to company behind: " + cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false));
if (action_price.GetCosts() > cvgs.GetCompanyIDDiffToNext(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), false)) {
perform_action = false;
}
}
if (perform_action && TestPerformTownAction().TryPerform(town, AITown.TOWN_ACTION_FUND_BUILDINGS)) {
AILog.Warning("Funded the construction of new buildings in " + AITown.GetName(town) + ".");
}
}
}
}
}
}
}