Loading

Paste #pgzotajof

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

Version history

Revision # Author Created at
p4rtxmvyh Anonymous 19 Aug 2018, 13:34:39 UTC Diff

Comments