Loading

Paste #phtxvttpa

  1. function Utils::AreOtherStationsNearby(tile, cargoClass, stationId) {
  2.     local stationType = cargoClass == AICargo.CC_PASSENGERS ? AIStation.STATION_BUS_STOP : AIStation.STATION_TRUCK_STOP;
  3.    
  4.     //check if there are other stations squareSize squares nearby
  5.     local squareSize = AIStation.GetCoverageRadius(stationType);
  6.     if (stationId == null) {
  7.         squareSize = squareSize * 2;
  8.     }
  9.  
  10.     local square = AITileList();
  11.     if(!AIController.GetSetting("is_friendly")) {
  12.         //dont care about enemy stations when is_friendly is off
  13.         square.AddRectangle(Utils.getValidOffsetTile(tile, (-1) * squareSize, (-1) * squareSize),
  14.             Utils.getValidOffsetTile(tile, squareSize, squareSize));
  15.  
  16.         //if another road station of mine is nearby return true
  17.         for(local tile = square.Begin(); square.HasNext(); tile = square.Next()) {
  18.             if(Utils.isTileMyRoadStation(tile, cargoClass)) { //negate second expression to merge your stations
  19.                 return true;
  20.             }
  21.         }
  22.     }
  23.     else {
  24.         square.AddRectangle(Utils.getValidOffsetTile(tile, (-1) * squareSize, (-1) * squareSize),
  25.             Utils.getValidOffsetTile(tile, squareSize, squareSize));
  26.  
  27.         //if any other station is nearby, except my own airports, return true
  28.         for (local tile = square.Begin(); square.HasNext(); tile = square.Next()) {
  29.             if(AITile.IsStationTile(tile)) {
  30.                 if (AITile.GetOwner(tile) != AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) {
  31.                     return true;
  32.                 } else {
  33.                     local stationTiles = AITileList_StationType(AIStation.GetStationID(tile), stationType);
  34.                     if (stationTiles.HasItem(tile)) {
  35.                         return true;
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.     }
  41.  
  42.     if(!((AITile.IsBuildable(tile) || AIRoad.IsRoadTile(tile)) && AITile.GetSlope(tile) == AITile.SLOPE_FLAT)) {
  43.         return true;
  44.     }
  45.    
  46.     return false;
  47. };

Comments