Loading

Paste #pas0yab3x

  1. /**
  2.  * Are the tiles of the industry free?
  3.  * @param tile                     Position to check.
  4.  * @param it                       Industry tiles table.
  5.  * @param itspec_index             The index of the itsepc to build/fund
  6.  * @param type                     Type of the industry.
  7.  * @param initial_random_bits      The random bits the industry is going to have after construction.
  8.  * @param founder                  Industry founder
  9.  * @param creation_type            The circumstances the industry is created under.
  10.  * @param [out] custom_shape_check Perform custom check for the site.
  11.  * @return Failed or succeeded command.
  12.  */
  13. static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check = NULL)
  14. {
  15.     bool refused_slope = false;
  16.     bool custom_shape = false;
  17.  
  18.     do {
  19.         IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx);
  20.         TileIndex cur_tile = TileAddWrap(tile, it->ti.x, it->ti.y);
  21.  
  22.         if (!IsValidTile(cur_tile)) {
  23.             return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  24.         }
  25.  
  26.         if (gfx == GFX_WATERTILE_SPECIALCHECK) {
  27.             if (!IsTileType(cur_tile, MP_WATER) ||
  28.                     !IsTileFlat(cur_tile)) {
  29.                 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  30.             }
  31.         } else {
  32.             CommandCost ret = EnsureNoVehicleOnGround(cur_tile);
  33.             if (ret.Failed()) return ret;
  34.             if (IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  35.  
  36.             const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
  37.  
  38.             IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
  39.  
  40.             /* Perform land/water check if not disabled */
  41.             if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  42.  
  43.             if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) {
  44.                 custom_shape = true;
  45.                 CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index, initial_random_bits, founder, creation_type);
  46.                 if (ret.Failed()) return ret;
  47.             } else {
  48.                 Slope tileh = GetTileSlope(cur_tile);
  49.                 refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
  50.             }
  51.  
  52.             if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house
  53.                     ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house)
  54.                 if (!IsTileType(cur_tile, MP_HOUSE)) {
  55.                     return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
  56.                 }
  57.  
  58.                 /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
  59.                 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
  60.                 CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
  61.                 cur_company.Restore();
  62.  
  63.                 if (ret.Failed()) return ret;
  64.             } else {
  65.                 /* Clear the tiles, but do not affect town ratings */
  66.                 CommandCost ret = DoCommand(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
  67.  
  68.                 if (ret.Failed()) {
  69.                     if (!(ind_behav & INDUSTRYBEH_BUILT_ONWATER)) return ret;
  70.  
  71.                     if (!_settings_game.construction.build_on_competitor_canal) return ret;
  72.                     if (_settings_game.construction.build_on_competitor_canal && (ind_behav & INDUSTRYBEH_BUILT_ONWATER) && (IsTileType(cur_tile, MP_INDUSTRY) || _current_company >= MAX_COMPANIES)) return ret;
  73.                 }
  74.             }
  75.         }
  76.     } while ((++it)->ti.x != -0x80);
  77.  
  78.     if (custom_shape_check != NULL) *custom_shape_check = custom_shape;
  79.  
  80.     /* It is almost impossible to have a fully flat land in TG, so what we
  81.      *  do is that we check if we can make the land flat later on. See
  82.      *  CheckIfCanLevelIndustryPlatform(). */
  83.     if (!refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions)) {
  84.         return CommandCost();
  85.     }
  86.     return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  87. }

Version history

Revision # Author Created at
p3hueuoac Anonymous 08 Apr 2015, 17:04:14 UTC Diff

Comments