Loading

Paste #p4rtxmvyh

  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. };

Comments