Loading

Paste #pyjz1t6cc

  1. static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
  2. {
  3.     bool canal_on_river = HasTileCanalOnRiver(tile);
  4.     switch (GetWaterTileType(tile)) {
  5.         case WATER_TILE_CLEAR: {
  6.             if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
  7.  
  8.             Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER];
  9.             if (IsRiver(tile) && _game_mode == GM_NORMAL && !_cheats.magic_bulldozer.value) base_cost = 0;
  10.  
  11.             /* Make sure freeform edges are allowed or it's not an edge tile. */
  12.             if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
  13.                     !IsInsideMM(TileY(tile), 1, MapMaxY() - 1))) {
  14.                 return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
  15.             }
  16.  
  17.             /* Make sure no vehicle is on the tile */
  18.             CommandCost ret = EnsureNoVehicleOnGround(tile);
  19.             if (ret.Failed()) return ret;
  20.  
  21.             Owner owner = GetTileOwner(tile);
  22.             if (owner != OWNER_WATER && owner != OWNER_NONE) {
  23.                 CommandCost ret = CheckTileOwnership(tile);
  24.                 if (ret.Failed()) { // Canals of OWNER_NONE or of same owner always succeed.
  25.                     /* Fail Oil Rig on random creation on canal owned by any company when the setting is on. */
  26.                     if (_settings_game.construction.build_on_competitor_canal && _current_company == OWNER_NONE) return ret;
  27.                     /* Fail Oil Rig on prospecting on canal of competitor when the setting is on. */
  28.                     if (_settings_game.construction.build_on_competitor_canal && _current_company == OWNER_TOWN && _local_company != owner) return ret;
  29.                     /* Fail for clearance check. */
  30.                     if (_settings_game.construction.build_on_competitor_canal && _current_company == _local_company && _local_company != owner) return ret;
  31.                     /* Fail for everything else when the setting is off. */
  32.                     if (!_settings_game.construction.build_on_competitor_canal) return ret;
  33.                 }
  34.             }
  35.  
  36.             if (flags & DC_EXEC) {
  37.                 if (IsCanal(tile) && Company::IsValidID(owner)) {
  38.                     Company::Get(owner)->infrastructure.water--;
  39.                     DirtyCompanyInfrastructureWindows(owner);
  40.                 }
  41.                 bool restore_river = HasTileWaterClass(tile) && GetWaterClass(tile) == WATER_CLASS_RIVER;
  42.                 uint8 same_aspect = GetWaterTileRandomBits(tile);
  43.  
  44.                 DoClearSquare(tile);
  45.                 if (canal_on_river) {
  46.                     MakeRiver(tile, Random());
  47.                 }
  48.                 if (restore_river && (_game_mode == GM_NORMAL && !_cheats.magic_bulldozer.value)) {
  49.                     MakeRiver(tile, same_aspect);
  50.                 }
  51.                 MarkCanalsAndRiversAroundDirty(tile);
  52.             }
  53.  
  54.             return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
  55.         }
  56.  
  57.         case WATER_TILE_COAST: {
  58.             Slope slope = GetTileSlope(tile);
  59.  
  60.             /* Make sure no vehicle is on the tile */
  61.             CommandCost ret = EnsureNoVehicleOnGround(tile);
  62.             if (ret.Failed()) return ret;
  63.  
  64.             if (flags & DC_EXEC) {
  65.                 DoClearSquare(tile);
  66.                 MarkCanalsAndRiversAroundDirty(tile);
  67.             }
  68.             if (IsSlopeWithOneCornerRaised(slope)) {
  69.                 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
  70.             } else {
  71.                 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]);
  72.             }
  73.         }
  74.  
  75.         case WATER_TILE_LOCK: {
  76.             static const TileIndexDiffC _lock_tomiddle_offs[][DIAGDIR_END] = {
  77.                 /*   NE       SE        SW      NW       */
  78.                 { { 0,  0}, {0,  0}, { 0, 0}, {0,  0} }, // LOCK_PART_MIDDLE
  79.                 { {-1,  0}, {0,  1}, { 1, 0}, {0, -1} }, // LOCK_PART_LOWER
  80.                 { { 1,  0}, {0, -1}, {-1, 0}, {0,  1} }, // LOCK_PART_UPPER
  81.             };
  82.  
  83.             if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
  84.             if (_current_company == OWNER_WATER) return CMD_ERROR;
  85.             /* move to the middle tile.. */
  86.             return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetLockPart(tile)][GetLockDirection(tile)]), flags);
  87.         }
  88.  
  89.         case WATER_TILE_DEPOT:
  90.             if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
  91.             return RemoveShipDepot(tile, flags);
  92.  
  93.         default:
  94.             NOT_REACHED();
  95.     }
  96. }

Comments