63 if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
63 if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
64 |
64 |
65 if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
65 if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
66 return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
66 return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
67 |
67 |
68 if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
|
69 |
|
70 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
68 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
71 if (CmdFailed(ret)) return CMD_ERROR; |
69 if (CmdFailed(ret)) return CMD_ERROR; |
72 ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
70 ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
73 if (CmdFailed(ret)) return CMD_ERROR; |
71 if (CmdFailed(ret)) return CMD_ERROR; |
74 |
72 |
139 if (CmdFailed(ret)) return CMD_ERROR; |
137 if (CmdFailed(ret)) return CMD_ERROR; |
140 if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) { |
138 if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) { |
141 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
139 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
142 } |
140 } |
143 |
141 |
144 if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) || |
|
145 (MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) || |
|
146 (MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) { |
|
147 return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
|
148 } |
|
149 |
|
150 if (flags & DC_EXEC) { |
142 if (flags & DC_EXEC) { |
151 MakeLock(tile, _current_player, dir); |
143 MakeLock(tile, _current_player, dir); |
152 MarkTileDirtyByTile(tile); |
144 MarkTileDirtyByTile(tile); |
153 MarkTileDirtyByTile(tile - delta); |
145 MarkTileDirtyByTile(tile - delta); |
154 MarkTileDirtyByTile(tile + delta); |
146 MarkTileDirtyByTile(tile + delta); |
235 /* Outside the editor you can only drag canals, and not areas */ |
227 /* Outside the editor you can only drag canals, and not areas */ |
236 if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR; |
228 if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR; |
237 |
229 |
238 cost = 0; |
230 cost = 0; |
239 BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) { |
231 BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) { |
240 int32 ret; |
|
241 |
|
242 if (GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
232 if (GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
243 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
233 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
244 } |
234 } |
245 |
235 |
246 // can't make water of water! |
236 // can't make water of water! |
247 if (IsTileType(tile, MP_WATER)) continue; |
237 if (IsTileType(tile, MP_WATER)) continue; |
248 |
238 |
249 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
239 /* is middle piece of a bridge? */ |
250 if (CmdFailed(ret)) return ret; |
240 if (IsBridgeTile(tile) && IsBridgeMiddle(tile)) { |
251 cost += ret; |
241 if (IsTransportUnderBridge(tile)) { |
|
242 return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
|
243 } |
|
244 |
|
245 if (IsWaterUnderBridge(tile)) return_cmd_error(STR_1007_ALREADY_BUILT); |
|
246 |
|
247 if (flags & DC_EXEC) { |
|
248 if (TileHeight(tile) == 0) { |
|
249 SetWaterUnderBridge(tile); |
|
250 } else { |
|
251 SetCanalUnderBridge(tile, _current_player); |
|
252 } |
|
253 } |
|
254 } else { |
|
255 /* no bridge, try to clear it. */ |
|
256 int32 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
257 |
|
258 if (CmdFailed(ret)) return ret; |
|
259 cost += ret; |
|
260 |
|
261 if (flags & DC_EXEC) { |
|
262 if (TileHeight(tile) == 0) { |
|
263 MakeWater(tile); |
|
264 } else { |
|
265 MakeCanal(tile, _current_player); |
|
266 } |
|
267 } |
|
268 } |
252 |
269 |
253 if (flags & DC_EXEC) { |
270 if (flags & DC_EXEC) { |
254 if (TileHeight(tile) == 0) { |
|
255 MakeWater(tile); |
|
256 } else { |
|
257 MakeCanal(tile, _current_player); |
|
258 } |
|
259 MarkTileDirtyByTile(tile); |
271 MarkTileDirtyByTile(tile); |
260 MarkTilesAroundDirty(tile); |
272 MarkTilesAroundDirty(tile); |
261 } |
273 } |
262 |
274 |
263 cost += _price.clear_water; |
275 cost += _price.clear_water; |
338 |
350 |
339 // return true if a tile is a water tile. |
351 // return true if a tile is a water tile. |
340 static bool IsWateredTile(TileIndex tile) |
352 static bool IsWateredTile(TileIndex tile) |
341 { |
353 { |
342 switch (GetTileType(tile)) { |
354 switch (GetTileType(tile)) { |
343 case MP_WATER: return !IsCoast(tile); |
355 case MP_WATER: |
344 case MP_STATION: return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile); |
356 return !IsCoast(tile); |
345 default: return false; |
357 |
|
358 case MP_STATION: |
|
359 return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile); |
|
360 |
|
361 case MP_TUNNELBRIDGE: |
|
362 return IsBridge(tile) && IsBridgeMiddle(tile) && IsWaterUnderBridge(tile); |
|
363 |
|
364 default: |
|
365 return false; |
346 } |
366 } |
347 } |
367 } |
348 |
368 |
349 // draw a canal styled water tile with dikes around |
369 // draw a canal styled water tile with dikes around |
350 void DrawCanalWater(TileIndex tile) |
370 void DrawCanalWater(TileIndex tile) |
416 { |
436 { |
417 switch (GetWaterTileType(ti->tile)) { |
437 switch (GetWaterTileType(ti->tile)) { |
418 case WATER_CLEAR: |
438 case WATER_CLEAR: |
419 DrawGroundSprite(SPR_FLAT_WATER_TILE); |
439 DrawGroundSprite(SPR_FLAT_WATER_TILE); |
420 if (ti->z != 0) DrawCanalWater(ti->tile); |
440 if (ti->z != 0) DrawCanalWater(ti->tile); |
421 DrawBridgeMiddle(ti); |
|
422 break; |
441 break; |
423 |
442 |
424 case WATER_COAST: |
443 case WATER_COAST: |
425 assert(!IsSteepSlope(ti->tileh)); |
444 assert(!IsSteepSlope(ti->tileh)); |
426 DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
445 DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
427 DrawBridgeMiddle(ti); |
|
428 break; |
446 break; |
429 |
447 |
430 case WATER_LOCK: { |
448 case WATER_LOCK: { |
431 const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)]; |
449 const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)]; |
432 DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0); |
450 DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0); |
532 MakeShore(target); |
550 MakeShore(target); |
533 MarkTileDirtyByTile(target); |
551 MarkTileDirtyByTile(target); |
534 } |
552 } |
535 break; |
553 break; |
536 |
554 |
|
555 case MP_TUNNELBRIDGE: |
|
556 if (IsBridge(target) && IsBridgeMiddle(target) && IsClearUnderBridge(target)) { |
|
557 SetWaterUnderBridge(target); |
|
558 MarkTileDirtyByTile(target); |
|
559 } |
|
560 break; |
|
561 |
537 default: |
562 default: |
538 break; |
563 break; |
539 } |
564 } |
540 } else { |
565 } else { |
|
566 if (IsBridgeTile(target) && IsBridgeMiddle(target)) { |
|
567 if (IsWaterUnderBridge(target) || |
|
568 (IsTransportUnderBridge(target) && GetTransportTypeUnderBridge(target) == TRANSPORT_WATER)) { // XXX does this happen at all? |
|
569 return; |
|
570 } |
|
571 SetWaterUnderBridge(target); |
|
572 MarkTileDirtyByTile(target); |
|
573 return; |
|
574 } |
|
575 |
541 _current_player = OWNER_WATER; |
576 _current_player = OWNER_WATER; |
542 { |
577 { |
543 Vehicle *v = FindVehicleOnTileZ(target, 0); |
578 Vehicle *v = FindVehicleOnTileZ(target, 0); |
544 if (v != NULL) FloodVehicle(v); |
579 if (v != NULL) FloodVehicle(v); |
545 } |
580 } |