| | 1 | /**
|
---|
| | 2 | * Build a ship depot.
|
---|
| | 3 | * @param tile tile where ship depot is built
|
---|
| | 4 | * @param flags type of operation
|
---|
| | 5 | * @param p1 bit 0 depot orientation (Axis)
|
---|
| | 6 | * @param p2 unused
|
---|
| | 7 | * @param text unused
|
---|
| | 8 | * @return the cost of this operation or an error
|
---|
| | 9 | */
|
---|
| | 10 | CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
---|
| | 11 | {
|
---|
| | 12 | Axis axis = Extract<Axis, 0, 1>(p1);
|
---|
| | 13 |
|
---|
| | 14 | TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
---|
| | 15 |
|
---|
| | 16 | if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
---|
| | 17 |
|
---|
| | 18 | if (!Depot::CanAllocateItem()) return CMD_ERROR;
|
---|
| | 19 |
|
---|
| | 20 | CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
|
---|
| | 21 |
|
---|
| | 22 | WaterClass wc1 = IsWaterTile(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
|
---|
| | 23 | Owner oc1 = HasTileWaterGround(tile) && GetWaterClass(tile) == WATER_CLASS_CANAL ? GetCanalOwner(tile) : _current_company;
|
---|
| | 24 | bool add_cost1 = !IsWaterTile(tile);
|
---|
| | 25 |
|
---|
| | 26 | CommandCost ret;
|
---|
| | 27 | /* At this point we got a flat tile with no bridge over it. Check for ownership */
|
---|
| | 28 | if (IsWaterTile(tile) && IsCanal(tile)) {
|
---|
| | 29 | ret = EnsureNoVehicleOnGround(tile);
|
---|
| | 30 | if (ret.Failed()) return ret;
|
---|
| | 31 | if (oc1 != OWNER_NONE) {
|
---|
| | 32 | ret = CheckTileOwnership(tile);
|
---|
| | 33 | if (ret.Failed() && !_settings_game.construction.build_on_competitor_canal) return ret;
|
---|
| | 34 | }
|
---|
| | 35 | } else {
|
---|
| | 36 | ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
---|
| | 37 | if (ret.Failed()) return ret;
|
---|
| | 38 | if (add_cost1) {
|
---|
| | 39 | cost.AddCost(ret);
|
---|
| | 40 | if (wc1 == WATER_CLASS_CANAL) cost.AddCost(_price[PR_BUILD_CANAL]);
|
---|
| | 41 | }
|
---|
| | 42 | }
|
---|
| | 43 |
|
---|
| | 44 | WaterClass wc2 = IsWaterTile(tile2) ? GetWaterClass(tile2) : WATER_CLASS_CANAL;
|
---|
| | 45 | Owner oc2 = HasTileWaterGround(tile2) && GetWaterClass(tile2) == WATER_CLASS_CANAL ? GetCanalOwner(tile2) : _current_company;
|
---|
| | 46 | bool add_cost2 = !IsWaterTile(tile2);
|
---|
| | 47 |
|
---|
| | 48 | /* At this point we got a flat tile2 with no bridge over it. Check for ownership */
|
---|
| | 49 | if (IsWaterTile(tile2) && IsCanal(tile2)) {
|
---|
| | 50 | ret = EnsureNoVehicleOnGround(tile2);
|
---|
| | 51 | if (ret.Failed()) return ret;
|
---|
| | 52 | if (oc2 != OWNER_NONE) {
|
---|
| | 53 | ret = CheckTileOwnership(tile2);
|
---|
| | 54 | if (ret.Failed() && !_settings_game.construction.build_on_competitor_canal) return ret;
|
---|
| | 55 | }
|
---|
| | 56 | } else {
|
---|
| | 57 | ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
---|
| | 58 | if (ret.Failed()) return ret;
|
---|
| | 59 | if (add_cost2) {
|
---|
| | 60 | cost.AddCost(ret);
|
---|
| | 61 | if (wc2 == WATER_CLASS_CANAL) cost.AddCost(_price[PR_BUILD_CANAL]);
|
---|
| | 62 | }
|
---|
| | 63 | }
|
---|
| | 64 |
|
---|
82 | if (IsInclinedSlope(slope1) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) || IsInclinedSlope(slope2) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1))) {
| 82 | if ((IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == OtherAxis(axis) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2))) || (IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == OtherAxis(axis) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1)))) {
|
---|
83 | if ((IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == OtherAxis(axis)) || (IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == OtherAxis(axis))) {
| 83 | /* Mark the tile as already cleared for the terraform command.
|
---|
84 | if (IsInclinedSlope(slope1)) {
| 84 | * Do this for all tiles (like trees), not only objects. */
|
---|
85 | /* Mark the tile as already cleared for the terraform command.
| 85 | ClearedObjectArea *coa = FindClearedObject(IsInclinedSlope(slope1) ? tile : tile2);
|
---|
86 | * Do this for all tiles (like trees), not only objects. */
| 86 | if (coa == NULL) {
|
---|
87 | ClearedObjectArea *coa = FindClearedObject(tile);
| 87 | coa = _cleared_object_areas.Append();
|
---|
88 | if (coa == NULL) {
| 88 | coa->first_tile = IsInclinedSlope(slope1) ? tile : tile2;
|
---|
89 | coa = _cleared_object_areas.Append();
| 89 | coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
|
---|
90 | coa->first_tile = tile;
| | |
---|
91 | coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
| | |
---|
92 | }
| | |
---|
93 | /* Hide the tile from the terraforming command */
| | |
---|
94 | TileIndex tile_inclined1_before = coa->first_tile;
| | |
---|
95 | coa->first_tile = INVALID_TILE;
| | |
---|
96 | ret = DoCommand(tile, IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope1) : slope1, IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
| | |
---|
97 | coa->first_tile = tile_inclined1_before;
| | |
---|
98 | if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
| | |
---|
99 | cost.AddCost(ret);
| | |
---|
100 | } else {
| | |
---|
101 | /* Mark the tile as already cleared for the terraform command.
| | |
---|
102 | * Do this for all tiles (like trees), not only objects. */
| | |
---|
103 | ClearedObjectArea *coa = FindClearedObject(tile2);
| | |
---|
104 | if (coa == NULL) {
| | |
---|
105 | coa = _cleared_object_areas.Append();
| | |
---|
106 | coa->first_tile = tile2;
| | |
---|
107 | coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
| | |
---|
108 | }
| | |
---|
109 | /* Hide the tile from the terraforming command */
| | |
---|
110 | TileIndex tile_inclined2_before = coa->first_tile;
| | |
---|
111 | coa->first_tile = INVALID_TILE;
| | |
---|
112 | ret = DoCommand(tile2, IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope2) : slope2, IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
| | |
---|
113 | coa->first_tile = tile_inclined2_before;
| | |
---|
114 | if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
| | |
---|
115 | cost.AddCost(ret);
| | |
---|
116 | }
| | |
---|
| | 141 | /* Hide the tile from the terraforming command */
|
---|
| | 142 | TileIndex tile_inclined1_before = coa->first_tile;
|
---|
| | 143 | coa->first_tile = INVALID_TILE;
|
---|
| | 144 | ret = DoCommand(IsInclinedSlope(slope1) ? tile : tile2, IsInclinedSlope(slope1) ? IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope1) : slope1 : IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope2) : slope2, IsInclinedSlope(slope1) ? IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0 : IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
|
---|
| | 145 | coa->first_tile = tile_inclined1_before;
|
---|
| | 146 | if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
|
---|
| | 147 | cost.AddCost(ret);
|
---|
142 | } | 172 | }
|
---|
| | 173 |
|
---|
| | 174 | if (flags & DC_EXEC) {
|
---|
| | 175 | Depot *depot = new Depot(tile);
|
---|
| | 176 | depot->build_date = _date;
|
---|
| | 177 |
|
---|
| | 178 | if (add_cost1 && wc1 == WATER_CLASS_CANAL) Company::Get(_current_company)->infrastructure.water++;
|
---|
| | 179 | if (add_cost2 && wc2 == WATER_CLASS_CANAL) Company::Get(_current_company)->infrastructure.water++;
|
---|
| | 180 | Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR;
|
---|
| | 181 | DirtyCompanyInfrastructureWindows(_current_company);
|
---|
| | 182 |
|
---|
| | 183 | MakeShipDepot(tile, _current_company, oc1, depot->index, DEPOT_PART_NORTH, axis, wc1);
|
---|
| | 184 | MakeShipDepot(tile2, _current_company, oc2, depot->index, DEPOT_PART_SOUTH, axis, wc2);
|
---|
| | 185 | MarkTileDirtyByTile(tile);
|
---|
| | 186 | MarkTileDirtyByTile(tile2);
|
---|
| | 187 | MakeDefaultName(depot);
|
---|
| | 188 | }
|
---|
| | 189 |
|
---|
| | 190 | return cost;
|
---|
| | 191 | } |
---|