/// valuateTruckStopTile
///
/// @param tile - The starting tile to valuate.
/// @param cargoClass - should be either AICargo.CC_MAIL, or AICargo.CC_PASSENGERS to get correct cargo acceptance.
/// @return - The tile value.
function Utils::valuateTruckStopTile(tile, cargoClass, stationId) {
//check if there are other stations squareSize squares nearby
//if(stationId == AIStation.STATION_NEW) {
local square = AITileList();
local squareSize = 0;
if(!AIController.GetSetting("is_friendly")) {
//dont care about enemy stations when is_friendly is off
squareSize = (stationId == null) ? 5 : 2; //6 tiles distance between new stations, 3 tiles distance between adjacent stations
square.AddRectangle(Utils.getOffsetTile(tile, (-1) * squareSize, (-1) * squareSize),
Utils.getOffsetTile(tile, squareSize, squareSize));
//if another station is nearby return 0
for(local tile = square.Begin(); square.HasNext(); tile = square.Next()) {
if(AITile.IsStationTile(tile) && (AITile.GetOwner(tile) == AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) ) { //negate second expression to merge your statitions
return 0;
}
}
}
else {
squareSize = 3;
square.AddRectangle(Utils.getOffsetTile(tile, (-1) * squareSize, (-1) * squareSize),
Utils.getOffsetTile(tile, squareSize, squareSize));
//if another station is nearby return 0
for(local tile = square.Begin(); square.HasNext(); tile = square.Next()) {
if(AITile.IsStationTile(tile)) {
return 0;
}
}
}
//}
if(! ((AITile.IsBuildable(tile) || AIRoad.IsRoadTile(tile)) && AITile.GetSlope(tile) == AITile.SLOPE_FLAT)) {
return 0;
}
local cargoList = AICargoList();
cargoList.Valuate(AICargo.HasCargoClass, cargoClass);
cargoList.KeepValue(1);
local cargoType = cargoList.Begin();
local radiusType;
if(cargoClass == AICargo.CC_MAIL) {
radiusType = AIStation.STATION_TRUCK_STOP;
}
else {
radiusType = AIStation.STATION_BUS_STOP;
}
if(AITile.GetCargoAcceptance(tile,
cargoType,
1,
1,
AIStation.GetCoverageRadius(radiusType)) < 8) {
return 0;
}
local value = AITile.GetCargoProduction(tile,
cargoType,
1,
1,
AIStation.GetCoverageRadius(radiusType));
return value;
}