Loading

Paste #po4hqnzmp

  1. /// valuateTruckStopTile
  2. ///
  3. /// @param tile - The starting tile to valuate.
  4. /// @param cargoClass - should be either AICargo.CC_MAIL, or AICargo.CC_PASSENGERS to get correct cargo acceptance.
  5. /// @return - The tile value.
  6. function Utils::valuateTruckStopTile(tile, cargoClass, stationId) {
  7.     //check if there are other stations squareSize squares nearby
  8.  
  9.     //if(stationId == AIStation.STATION_NEW) {
  10.         local square = AITileList();
  11.         local squareSize = 0;
  12.  
  13.         if(!AIController.GetSetting("is_friendly")) {
  14.             //dont care about enemy stations when is_friendly is off
  15.             squareSize = (stationId == null) ? 5 : 2; //6 tiles distance between new stations, 3 tiles distance between adjacent stations
  16.  
  17.             square.AddRectangle(Utils.getOffsetTile(tile, (-1) * squareSize, (-1) * squareSize),
  18.                 Utils.getOffsetTile(tile, squareSize, squareSize));
  19.  
  20.             //if another station is nearby return 0
  21.             for(local tile = square.Begin(); square.HasNext(); tile = square.Next()) {
  22.                 if(AITile.IsStationTile(tile) && (AITile.GetOwner(tile) == AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) ) { //negate second expression to merge your statitions
  23.                     return 0;
  24.                 }
  25.             }
  26.         }
  27.         else {
  28.             squareSize = 3;
  29.  
  30.             square.AddRectangle(Utils.getOffsetTile(tile, (-1) * squareSize, (-1) * squareSize),
  31.                 Utils.getOffsetTile(tile, squareSize, squareSize));
  32.  
  33.             //if another station is nearby return 0
  34.             for(local tile = square.Begin(); square.HasNext(); tile = square.Next()) {
  35.                 if(AITile.IsStationTile(tile)) {
  36.                     return 0;
  37.                 }
  38.             }
  39.         }
  40.  
  41.     //}
  42.  
  43.     if(! ((AITile.IsBuildable(tile) || AIRoad.IsRoadTile(tile)) && AITile.GetSlope(tile) == AITile.SLOPE_FLAT)) {
  44.         return 0;
  45.     }
  46.  
  47.     local cargoList = AICargoList();
  48.     cargoList.Valuate(AICargo.HasCargoClass, cargoClass);
  49.     cargoList.KeepValue(1);
  50.     local cargoType = cargoList.Begin();
  51.  
  52.     local radiusType;
  53.     if(cargoClass == AICargo.CC_MAIL) {
  54.         radiusType = AIStation.STATION_TRUCK_STOP;
  55.     }
  56.     else {
  57.         radiusType = AIStation.STATION_BUS_STOP;
  58.     }
  59.  
  60.     if(AITile.GetCargoAcceptance(tile,
  61.         cargoType,
  62.         1,
  63.         1,
  64.         AIStation.GetCoverageRadius(radiusType)) < 8) {
  65.  
  66.             return 0;
  67.     }
  68.  
  69.     local value = AITile.GetCargoProduction(tile,
  70.                 cargoType,
  71.                 1,
  72.                 1,
  73.                 AIStation.GetCoverageRadius(radiusType));
  74.  
  75.     return value;
  76. }

Comments