84 */ |
84 */ |
85 CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
85 CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
86 { |
86 { |
87 TileIndex tile2; |
87 TileIndex tile2; |
88 |
88 |
89 CommandCost cost, ret; |
89 CommandCost ret; |
90 |
|
91 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
92 |
90 |
93 Axis axis = Extract<Axis, 0>(p1); |
91 Axis axis = Extract<Axis, 0>(p1); |
94 |
92 |
95 tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
93 tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
96 |
94 |
118 MarkTileDirtyByTile(tile); |
116 MarkTileDirtyByTile(tile); |
119 MarkTileDirtyByTile(tile2); |
117 MarkTileDirtyByTile(tile2); |
120 d_auto_delete.Detach(); |
118 d_auto_delete.Detach(); |
121 } |
119 } |
122 |
120 |
123 return cost.AddCost(_price.build_ship_depot); |
121 return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot); |
124 } |
122 } |
125 |
123 |
126 void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o) |
124 void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o) |
127 { |
125 { |
128 if (o == OWNER_WATER) { |
126 if (o == OWNER_WATER) { |
152 MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2)); |
150 MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2)); |
153 MarkTileDirtyByTile(tile); |
151 MarkTileDirtyByTile(tile); |
154 MarkTileDirtyByTile(tile2); |
152 MarkTileDirtyByTile(tile2); |
155 } |
153 } |
156 |
154 |
157 return CommandCost(_price.remove_ship_depot); |
155 return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot); |
158 } |
156 } |
159 |
157 |
160 /** build a shiplift */ |
158 /** build a shiplift */ |
161 static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags) |
159 static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags) |
162 { |
160 { |
193 MarkTileDirtyByTile(tile); |
191 MarkTileDirtyByTile(tile); |
194 MarkTileDirtyByTile(tile - delta); |
192 MarkTileDirtyByTile(tile - delta); |
195 MarkTileDirtyByTile(tile + delta); |
193 MarkTileDirtyByTile(tile + delta); |
196 } |
194 } |
197 |
195 |
198 return CommandCost(_price.clear_water * 22 >> 3); |
196 return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3); |
199 } |
197 } |
200 |
198 |
201 static CommandCost RemoveShiplift(TileIndex tile, uint32 flags) |
199 static CommandCost RemoveShiplift(TileIndex tile, uint32 flags) |
202 { |
200 { |
203 TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile)); |
201 TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile)); |
212 DoClearSquare(tile); |
210 DoClearSquare(tile); |
213 MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player); |
211 MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player); |
214 MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player); |
212 MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player); |
215 } |
213 } |
216 |
214 |
217 return CommandCost(_price.clear_water * 2); |
215 return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2); |
218 } |
216 } |
219 |
217 |
220 /** |
218 /** |
221 * Marks the tiles around a tile as dirty. |
219 * Marks the tiles around a tile as dirty. |
222 * |
220 * |
242 */ |
240 */ |
243 CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
241 CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
244 { |
242 { |
245 DiagDirection dir; |
243 DiagDirection dir; |
246 |
244 |
247 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
248 |
|
249 switch (GetTileSlope(tile, NULL)) { |
245 switch (GetTileSlope(tile, NULL)) { |
250 case SLOPE_SW: dir = DIAGDIR_SW; break; |
246 case SLOPE_SW: dir = DIAGDIR_SW; break; |
251 case SLOPE_SE: dir = DIAGDIR_SE; break; |
247 case SLOPE_SE: dir = DIAGDIR_SE; break; |
252 case SLOPE_NW: dir = DIAGDIR_NW; break; |
248 case SLOPE_NW: dir = DIAGDIR_NW; break; |
253 case SLOPE_NE: dir = DIAGDIR_NE; break; |
249 case SLOPE_NE: dir = DIAGDIR_NE; break; |
262 * @param p1 start tile of stretch-dragging |
258 * @param p1 start tile of stretch-dragging |
263 * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor) |
259 * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor) |
264 */ |
260 */ |
265 CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
261 CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
266 { |
262 { |
267 CommandCost cost; |
263 CommandCost cost(EXPENSES_CONSTRUCTION); |
268 int size_x, size_y; |
264 int size_x, size_y; |
269 int x; |
265 int x; |
270 int y; |
266 int y; |
271 int sx, sy; |
267 int sx, sy; |
272 |
268 |
276 |
272 |
277 x = TileX(tile); |
273 x = TileX(tile); |
278 y = TileY(tile); |
274 y = TileY(tile); |
279 sx = TileX(p1); |
275 sx = TileX(p1); |
280 sy = TileY(p1); |
276 sy = TileY(p1); |
281 |
|
282 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
283 |
277 |
284 if (x < sx) Swap(x, sx); |
278 if (x < sx) Swap(x, sx); |
285 if (y < sy) Swap(y, sy); |
279 if (y < sy) Swap(y, sy); |
286 size_x = (x - sx) + 1; |
280 size_x = (x - sx) + 1; |
287 size_y = (y - sy) + 1; |
281 size_y = (y - sy) + 1; |
339 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
333 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
340 |
334 |
341 if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR; |
335 if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR; |
342 |
336 |
343 if (flags & DC_EXEC) DoClearSquare(tile); |
337 if (flags & DC_EXEC) DoClearSquare(tile); |
344 return CommandCost(_price.clear_water); |
338 return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water); |
345 |
339 |
346 case WATER_TILE_COAST: { |
340 case WATER_TILE_COAST: { |
347 Slope slope = GetTileSlope(tile, NULL); |
341 Slope slope = GetTileSlope(tile, NULL); |
348 |
342 |
349 /* Make sure no vehicle is on the tile */ |
343 /* Make sure no vehicle is on the tile */ |
350 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
344 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
351 |
345 |
352 if (flags & DC_EXEC) DoClearSquare(tile); |
346 if (flags & DC_EXEC) DoClearSquare(tile); |
353 if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) { |
347 if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) { |
354 return CommandCost(_price.clear_water); |
348 return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water); |
355 } else { |
349 } else { |
356 return CommandCost(_price.clear_roughland); |
350 return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_roughland); |
357 } |
351 } |
358 } |
352 } |
359 |
353 |
360 case WATER_TILE_LOCK: { |
354 case WATER_TILE_LOCK: { |
361 static const TileIndexDiffC _shiplift_tomiddle_offs[] = { |
355 static const TileIndexDiffC _shiplift_tomiddle_offs[] = { |