tron@2186: /* $Id$ */ tron@2186: belugas@6432: /** @file water_cmd.cpp */ belugas@6432: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@3189: #include "bridge_map.h" rubidium@6160: #include "bridge.h" tron@6134: #include "cmd_helper.h" tron@3338: #include "station_map.h" rubidium@8119: #include "tile_cmd.h" maedhros@6453: #include "landscape.h" rubidium@8224: #include "viewport_func.h" rubidium@8116: #include "command_func.h" truelight@0: #include "town.h" darkvater@149: #include "news.h" truelight@1313: #include "depot.h" matthijs@1752: #include "vehicle_gui.h" bjarni@2676: #include "train.h" maedhros@6857: #include "roadveh.h" rubidium@8108: #include "water.h" tron@3111: #include "water_map.h" rubidium@7507: #include "industry_map.h" peter1138@5210: #include "newgrf.h" peter1138@6583: #include "newgrf_canal.h" rubidium@7389: #include "misc/autoptr.hpp" belugas@7849: #include "transparency.h" rubidium@8114: #include "strings_func.h" rubidium@8131: #include "functions.h" rubidium@8131: #include "window_func.h" rubidium@8144: #include "vehicle_func.h" rubidium@8157: #include "sound_func.h" rubidium@8211: #include "variables.h" rubidium@8254: #include "player_func.h" rubidium@8270: #include "settings_type.h" frosch@8380: #include "clear_map.h" darkvater@149: rubidium@8264: #include "table/sprites.h" rubidium@8264: #include "table/strings.h" ludde@2261: frosch@8380: /** frosch@8380: * Describes the behaviour of a tile during flooding. frosch@8380: */ frosch@8380: enum FloodingBehaviour { frosch@8380: FLOOD_NONE, ///< The tile does not flood neighboured tiles. frosch@8380: FLOOD_ACTIVE, ///< The tile floods neighboured tiles. frosch@8380: FLOOD_PASSIVE, ///< The tile does not actively flood neighboured tiles, but it prevents them from drying up. frosch@8380: FLOOD_DRYUP, ///< The tile drys up if it is not constantly flooded from neighboured tiles. frosch@8380: }; frosch@8380: frosch@8380: /** frosch@8380: * Describes from which directions a specific slope can be flooded (if the tile is floodable at all). frosch@8380: */ frosch@8380: static const uint8 _flood_from_dirs[] = { frosch@8380: (1 << DIR_NW) | (1 << DIR_SW) | (1 << DIR_SE) | (1 << DIR_NE), // SLOPE_FLAT frosch@8380: (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_W frosch@8380: (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_S frosch@8380: (1 << DIR_NE), // SLOPE_SW frosch@8380: (1 << DIR_NW) | (1 << DIR_SW), // SLOPE_E frosch@8380: 0, // SLOPE_EW frosch@8380: (1 << DIR_NW), // SLOPE_SE frosch@8380: (1 << DIR_N ) | (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_WSE, SLOPE_STEEP_S frosch@8380: (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_N frosch@8380: (1 << DIR_SE), // SLOPE_NW frosch@8380: 0, // SLOPE_NS frosch@8380: (1 << DIR_E ) | (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_NWS, SLOPE_STEEP_W frosch@8380: (1 << DIR_SW), // SLOPE_NE frosch@8380: (1 << DIR_S ) | (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_ENW, SLOPE_STEEP_N frosch@8380: (1 << DIR_W ) | (1 << DIR_SW) | (1 << DIR_NW), // SLOPE_SEN, SLOPE_STEEP_E frosch@8380: }; frosch@8380: frosch@8380: /** frosch@8380: * Slopes that contain flat water and not only shore. frosch@8380: */ frosch@8380: static const uint32 _active_water_slopes = (1 << SLOPE_FLAT) | (1 << SLOPE_W) | (1 << SLOPE_S) | (1 << SLOPE_E) | (1 << SLOPE_N); truelight@0: rubidium@7948: /** rubidium@7948: * Makes a tile canal or water depending on the surroundings. rubidium@7948: * This as for example docks and shipdepots do not store rubidium@7948: * whether the tile used to be canal or 'normal' water. rubidium@7948: * @param t the tile to change. rubidium@7948: * @param o the owner of the new tile. rubidium@7948: */ rubidium@7948: void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o) rubidium@7948: { rubidium@7948: assert(GetTileSlope(t, NULL) == SLOPE_FLAT); rubidium@7948: smatz@8022: /* Mark tile dirty in all cases */ smatz@8022: MarkTileDirtyByTile(t); smatz@8022: rubidium@7948: /* Non-sealevel -> canal */ rubidium@7948: if (TileHeight(t) != 0) { peter1138@8368: MakeCanal(t, o, Random()); rubidium@7948: return; rubidium@7948: } rubidium@7948: rubidium@7948: bool has_water = false; rubidium@7948: bool has_canal = false; rubidium@7948: rubidium@7948: for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { rubidium@7948: TileIndex neighbour = TileAddByDiagDir(t, dir); rubidium@7948: if (IsTileType(neighbour, MP_WATER)) { rubidium@8029: has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER); rubidium@8029: has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER); rubidium@7948: } rubidium@7948: } rubidium@7948: if (has_canal || !has_water) { peter1138@8368: MakeCanal(t, o, Random()); rubidium@7948: } else { rubidium@7948: MakeWater(t); rubidium@7948: } rubidium@7948: } rubidium@7948: rubidium@7948: Darkvater@1784: /** Build a ship depot. tron@3491: * @param tile tile where ship depot is built belugas@6432: * @param flags type of operation tron@6134: * @param p1 bit 0 depot orientation (Axis) Darkvater@1784: * @param p2 unused truelight@0: */ rubidium@6943: CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { tron@3491: TileIndex tile2; truelight@193: rubidium@8230: CommandCost ret; truelight@0: tron@6134: Axis axis = Extract(p1); tron@6134: tron@6134: tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); truelight@0: rubidium@7739: if (!IsWaterTile(tile) || !IsWaterTile(tile2)) truelight@0: return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); truelight@0: celestar@5385: if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); celestar@5385: rubidium@8029: Owner o1 = GetTileOwner(tile); rubidium@8029: Owner o2 = GetTileOwner(tile2); tron@3491: ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); Darkvater@1784: if (CmdFailed(ret)) return CMD_ERROR; tron@3491: ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); Darkvater@1784: if (CmdFailed(ret)) return CMD_ERROR; truelight@193: rubidium@7389: Depot *depot = new Depot(tile); Darkvater@1784: if (depot == NULL) return CMD_ERROR; rubidium@7389: AutoPtrT d_auto_delete = depot; truelight@0: truelight@0: if (flags & DC_EXEC) { truelight@1313: depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index; truelight@0: rubidium@8029: MakeShipDepot(tile, _current_player, DEPOT_NORTH, axis, o1); rubidium@8029: MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, o2); celestar@3372: MarkTileDirtyByTile(tile); celestar@3372: MarkTileDirtyByTile(tile2); rubidium@7389: d_auto_delete.Detach(); truelight@0: } truelight@0: rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot); truelight@0: } truelight@0: glx@8105: void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o) rubidium@8029: { rubidium@8029: if (o == OWNER_WATER) { rubidium@8029: MakeWater(tile); rubidium@8029: } else { peter1138@8368: MakeCanal(tile, o, Random()); rubidium@8029: } rubidium@8029: } rubidium@8029: rubidium@6943: static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags) truelight@0: { tron@1977: TileIndex tile2; truelight@0: celestar@3373: if (!IsShipDepot(tile)) return CMD_ERROR; tron@2951: if (!CheckTileOwnership(tile)) return CMD_ERROR; rubidium@7758: if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; truelight@0: celestar@3373: tile2 = GetOtherShipDepotTile(tile); truelight@0: rubidium@7758: if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR; truelight@0: truelight@0: if (flags & DC_EXEC) { celestar@3373: /* Kill the depot, which is registered at the northernmost tile. Use that one */ rubidium@7389: delete GetDepotByTile(tile2 < tile ? tile2 : tile); truelight@0: rubidium@8029: MakeWaterOrCanalDependingOnOwner(tile, GetShipDepotWaterOwner(tile)); rubidium@8029: MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2)); tron@3111: MarkTileDirtyByTile(tile); tron@3111: MarkTileDirtyByTile(tile2); truelight@0: } truelight@0: rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot); truelight@0: } truelight@0: belugas@6432: /** build a shiplift */ rubidium@6943: static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags) truelight@0: { rubidium@6943: CommandCost ret; truelight@0: int delta; truelight@0: belugas@6432: /* middle tile */ tron@3491: ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); peter1138@2737: if (CmdFailed(ret)) return CMD_ERROR; truelight@193: Darkvater@4559: delta = TileOffsByDiagDir(dir); belugas@6432: /* lower tile */ tron@3491: ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); peter1138@2737: if (CmdFailed(ret)) return CMD_ERROR; tron@3636: if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) { tron@3636: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); tron@3636: } truelight@0: belugas@6432: /* upper tile */ tron@3491: ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); peter1138@2737: if (CmdFailed(ret)) return CMD_ERROR; tron@3636: if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) { tron@3636: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); tron@3636: } truelight@0: celestar@5385: if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) || celestar@5385: (MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) || celestar@5385: (MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) { celestar@5385: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); celestar@5385: } celestar@5385: truelight@0: if (flags & DC_EXEC) { peter1138@3940: MakeLock(tile, _current_player, dir); celestar@3372: MarkTileDirtyByTile(tile); celestar@3372: MarkTileDirtyByTile(tile - delta); celestar@3372: MarkTileDirtyByTile(tile + delta); truelight@0: } truelight@0: rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3); truelight@0: } truelight@0: rubidium@6943: static CommandCost RemoveShiplift(TileIndex tile, uint32 flags) truelight@0: { Darkvater@4559: TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile)); truelight@0: rubidium@7270: if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR; peter1138@3940: belugas@6432: /* make sure no vehicle is on the tile. */ rubidium@7758: if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta)) truelight@0: return CMD_ERROR; truelight@0: truelight@0: if (flags & DC_EXEC) { truelight@0: DoClearSquare(tile); rubidium@7948: MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player); rubidium@7948: MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player); truelight@0: } truelight@193: rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2); truelight@0: } truelight@0: rubidium@7545: /** rubidium@7545: * Marks the tiles around a tile as dirty. rubidium@7545: * rubidium@7545: * This functions marks the tiles around a given tile as dirty for repaint. rubidium@7545: * rubidium@7545: * @param tile The center of the tile where all other tiles are marked as dirty rubidium@7545: * @ingroup dirty rubidium@7545: * @see TerraformAddDirtyTileAround rubidium@7545: */ tron@1977: static void MarkTilesAroundDirty(TileIndex tile) truelight@0: { truelight@0: MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); truelight@0: MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); truelight@0: MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); truelight@0: MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); truelight@0: } truelight@0: Darkvater@1796: /** Builds a lock (ship-lift) tron@3491: * @param tile tile where to place the lock belugas@6432: * @param flags type of operation Darkvater@1796: * @param p1 unused Darkvater@1796: * @param p2 unused Darkvater@1796: */ rubidium@6943: CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { tron@3157: DiagDirection dir; darkvater@889: tron@3157: switch (GetTileSlope(tile, NULL)) { tron@3636: case SLOPE_SW: dir = DIAGDIR_SW; break; tron@3636: case SLOPE_SE: dir = DIAGDIR_SE; break; tron@3636: case SLOPE_NW: dir = DIAGDIR_NW; break; tron@3636: case SLOPE_NE: dir = DIAGDIR_NE; break; tron@3157: default: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); Darkvater@1796: } peter1138@8386: peter1138@8386: /* Disallow building of locks on river rapids */ peter1138@8386: if (IsRiverTile(tile)) return_cmd_error(STR_0239_SITE_UNSUITABLE); peter1138@8386: tron@3157: return DoBuildShiplift(tile, dir, flags); truelight@0: } truelight@0: Darkvater@1796: /** Build a piece of canal. tron@3491: * @param tile end tile of stretch-dragging belugas@6432: * @param flags type of operation Darkvater@1796: * @param p1 start tile of stretch-dragging rubidium@6286: * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor) Darkvater@1796: */ rubidium@6943: CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { rubidium@8230: CommandCost cost(EXPENSES_CONSTRUCTION); Darkvater@1632: int size_x, size_y; tron@3491: int x; tron@3491: int y; Darkvater@1796: int sx, sy; Darkvater@1796: tron@2934: if (p1 >= MapSize()) return CMD_ERROR; peter1138@8360: rubidium@6286: /* Outside of the editor you can only build canals, not oceans */ peter1138@8361: if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR; Darkvater@1796: tron@3491: x = TileX(tile); tron@3491: y = TileY(tile); Darkvater@1796: sx = TileX(p1); Darkvater@1796: sy = TileY(p1); Darkvater@1632: tron@6106: if (x < sx) Swap(x, sx); tron@6106: if (y < sy) Swap(y, sy); Darkvater@1632: size_x = (x - sx) + 1; Darkvater@1632: size_y = (y - sy) + 1; truelight@193: Darkvater@1796: /* Outside the editor you can only drag canals, and not areas */ Darkvater@1796: if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR; Darkvater@1796: tron@1981: BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) { rubidium@6943: CommandCost ret; celestar@5385: peter1138@8360: Slope slope = GetTileSlope(tile, NULL); peter1138@8360: if (slope != SLOPE_FLAT && (p2 != 2 || (slope != SLOPE_NW && slope != SLOPE_NE && slope != SLOPE_SW && slope != SLOPE_SE))) { tron@3636: return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); tron@3636: } truelight@0: belugas@6432: /* can't make water of water! */ peter1138@8360: if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue; Darkvater@1632: celestar@5385: ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); celestar@5385: if (CmdFailed(ret)) return ret; rubidium@6950: cost.AddCost(ret); tron@3183: tron@3189: if (flags & DC_EXEC) { peter1138@8360: if (TileHeight(tile) == 0 && p2 == 1) { celestar@5385: MakeWater(tile); peter1138@8360: } else if (p2 == 2) { peter1138@8368: MakeRiver(tile, Random()); celestar@5385: } else { peter1138@8368: MakeCanal(tile, _current_player, Random()); celestar@5385: } tron@3189: MarkTileDirtyByTile(tile); tron@3189: MarkTilesAroundDirty(tile); tron@3189: } tron@3183: rubidium@6950: cost.AddCost(_price.clear_water); Darkvater@1632: } END_TILE_LOOP(tile, size_x, size_y, 0); truelight@0: rubidium@6950: if (cost.GetCost() == 0) { tron@3183: return_cmd_error(STR_1007_ALREADY_BUILT); tron@3183: } else { tron@3183: return cost; tron@3183: } truelight@0: } truelight@0: rubidium@6943: static CommandCost ClearTile_Water(TileIndex tile, byte flags) tron@1977: { celestar@3425: switch (GetWaterTileType(tile)) { rubidium@6181: case WATER_TILE_CLEAR: peter1138@8360: case WATER_TILE_RIVER: celestar@3425: if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); truelight@0: belugas@6432: /* Make sure it's not an edge tile. */ skidd13@7954: if (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) || skidd13@7954: !IsInsideMM(TileY(tile), 1, MapMaxY() - 1)) { celestar@3425: return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); celestar@3425: } tron@3017: rubidium@7509: /* Make sure no vehicle is on the tile */ rubidium@7758: if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; rubidium@7509: rubidium@7270: if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR; peter1138@3940: tron@3017: if (flags & DC_EXEC) DoClearSquare(tile); rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water); truelight@0: rubidium@6181: case WATER_TILE_COAST: { tron@3636: Slope slope = GetTileSlope(tile, NULL); tron@3439: belugas@6432: /* Make sure no vehicle is on the tile */ rubidium@7758: if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; tron@3439: tron@3439: if (flags & DC_EXEC) DoClearSquare(tile); tron@3636: if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) { rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water); tron@3439: } else { rubidium@8230: return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_roughland); celestar@3425: } tron@3439: } tron@3439: rubidium@6181: case WATER_TILE_LOCK: { tron@3439: static const TileIndexDiffC _shiplift_tomiddle_offs[] = { tron@3439: { 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle tron@3439: {-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower tron@3439: { 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper tron@3439: }; tron@3439: tron@3439: if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); tron@3439: if (_current_player == OWNER_WATER) return CMD_ERROR; belugas@6432: /* move to the middle tile.. */ tron@3439: return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags); tron@3439: } tron@3439: rubidium@6181: case WATER_TILE_DEPOT: celestar@3425: if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); celestar@3425: return RemoveShipDepot(tile, flags); tron@3439: tron@3439: default: tron@3439: NOT_REACHED(); truelight@0: } truelight@0: } truelight@0: belugas@6432: /** return true if a tile is a water tile. */ tron@1048: static bool IsWateredTile(TileIndex tile) truelight@0: { tron@1214: switch (GetTileType(tile)) { tron@3977: case MP_WATER: peter1138@4087: if (!IsCoast(tile)) return true; peter1138@4087: peter1138@4087: switch (GetTileSlope(tile, NULL)) { peter1138@4087: case SLOPE_W: peter1138@4087: case SLOPE_S: peter1138@4087: case SLOPE_E: peter1138@4087: case SLOPE_N: peter1138@4087: return true; peter1138@4087: peter1138@4087: default: peter1138@4087: return false; peter1138@4087: } tron@3977: smatz@8274: case MP_RAILWAY: return GetRailGroundType(tile) == RAIL_GROUND_WATER; rubidium@7507: case MP_STATION: return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile); rubidium@7507: case MP_INDUSTRY: return (GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0; rubidium@7507: default: return false; tron@1048: } truelight@0: } truelight@0: peter1138@8360: static void DrawWaterEdges(SpriteID base, TileIndex tile) truelight@0: { truelight@0: uint wa; truelight@193: belugas@6432: /* determine the edges around with water. */ rubidium@7507: wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0; rubidium@7507: wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1; rubidium@7507: wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2; rubidium@7507: wa += IsWateredTile(TILE_ADDXY(tile, 0, -1)) << 3; truelight@193: peter1138@8360: if (!(wa & 1)) DrawGroundSprite(base, PAL_NONE); peter1138@8360: if (!(wa & 2)) DrawGroundSprite(base + 1, PAL_NONE); peter1138@8360: if (!(wa & 4)) DrawGroundSprite(base + 2, PAL_NONE); peter1138@8360: if (!(wa & 8)) DrawGroundSprite(base + 3, PAL_NONE); truelight@0: belugas@6432: /* right corner */ tron@2989: switch (wa & 0x03) { peter1138@8360: case 0: DrawGroundSprite(base + 4, PAL_NONE); break; peter1138@8360: case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(base + 8, PAL_NONE); break; tron@2989: } truelight@0: belugas@6432: /* bottom corner */ tron@2989: switch (wa & 0x06) { peter1138@8360: case 0: DrawGroundSprite(base + 5, PAL_NONE); break; peter1138@8360: case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(base + 9, PAL_NONE); break; tron@2989: } truelight@0: belugas@6432: /* left corner */ tron@2989: switch (wa & 0x0C) { peter1138@8360: case 0: DrawGroundSprite(base + 6, PAL_NONE); break; peter1138@8360: case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(base + 10, PAL_NONE); break; tron@2989: } truelight@0: belugas@6432: /* upper corner */ tron@2989: switch (wa & 0x09) { peter1138@8360: case 0: DrawGroundSprite(base + 7, PAL_NONE); break; peter1138@8360: case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(base + 11, PAL_NONE); break; tron@2989: } truelight@0: } truelight@0: peter1138@8360: /** draw a canal styled water tile with dikes around */ peter1138@8360: void DrawCanalWater(TileIndex tile) peter1138@8360: { peter1138@8360: /* Test for custom graphics, else use the default */ peter1138@8360: SpriteID dikes_base = GetCanalSprite(CF_DIKES, tile); peter1138@8360: if (dikes_base == 0) dikes_base = SPR_CANAL_DIKES_BASE; peter1138@8360: peter1138@8360: DrawWaterEdges(dikes_base, tile); peter1138@8360: } peter1138@8360: rubidium@6248: struct LocksDrawTileStruct { truelight@0: int8 delta_x, delta_y, delta_z; truelight@0: byte width, height, depth; truelight@0: SpriteID image; rubidium@6248: }; truelight@0: truelight@0: #include "table/water_land.h" truelight@0: Darkvater@2436: static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts, peter1138@5668: SpriteID palette, uint base tron@1399: ) truelight@0: { peter1138@6583: SpriteID image; peter1138@6583: SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile); peter1138@6583: SpriteID locks_base = GetCanalSprite(CF_LOCKS, ti->tile); peter1138@6583: peter1138@6583: /* If no custom graphics, use defaults */ rubidium@7882: if (water_base == 0) water_base = SPR_CANALS_BASE; peter1138@6583: if (locks_base == 0) { rubidium@7882: locks_base = SPR_SHIPLIFT_BASE; peter1138@6583: } else { peter1138@6583: /* If using custom graphics, ignore the variation on height */ peter1138@6583: base = 0; peter1138@6583: } peter1138@6583: peter1138@6583: image = wdts++->image; peter1138@6583: if (image < 4) image += water_base; peter1138@6583: DrawGroundSprite(image, PAL_NONE); truelight@193: tron@1399: for (; wdts->delta_x != 0x80; wdts++) { rubidium@7333: AddSortableSpriteToDraw(wdts->image + base + ((wdts->image < 24) ? locks_base : 0), palette, peter1138@5668: ti->x + wdts->delta_x, ti->y + wdts->delta_y, peter1138@5668: wdts->width, wdts->height, rubidium@7333: wdts->unk, ti->z + wdts->delta_z, belugas@7849: IsTransparencySet(TO_BUILDINGS)); truelight@0: } truelight@0: } truelight@0: peter1138@8360: static void DrawRiverWater(const TileInfo *ti) peter1138@8360: { peter1138@8360: SpriteID image = SPR_FLAT_WATER_TILE; peter1138@8360: SpriteID edges_base = GetCanalSprite(CF_RIVER_EDGE, ti->tile); peter1138@8360: peter1138@8360: if (ti->tileh != SLOPE_FLAT) { peter1138@8360: image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile); peter1138@8360: if (image == 0) { peter1138@8360: image = SPR_FLAT_WATER_TILE; peter1138@8360: } else { peter1138@8360: switch (ti->tileh) { peter1138@8360: default: NOT_REACHED(); peter1138@8360: case SLOPE_SE: edges_base += 12; break; peter1138@8360: case SLOPE_NE: image += 1; edges_base += 24; break; peter1138@8360: case SLOPE_SW: image += 2; edges_base += 36; break; peter1138@8360: case SLOPE_NW: image += 3; edges_base += 48; break; peter1138@8360: } peter1138@8360: } peter1138@8360: } peter1138@8360: peter1138@8360: DrawGroundSprite(image, PAL_NONE); peter1138@8360: peter1138@8360: /* Draw canal dikes if there are no river edges to draw. */ peter1138@8360: if (edges_base <= 48) edges_base = SPR_CANAL_DIKES_BASE; peter1138@8360: DrawWaterEdges(edges_base, ti->tile); peter1138@8360: } peter1138@8360: frosch@8380: void DrawShoreTile(Slope tileh) frosch@8380: { frosch@8380: /* Converts the enum Slope into an offset based on SPR_SHORE_BASE. frosch@8380: * This allows to calculate the proper sprite to display for this Slope */ frosch@8380: static const byte tileh_to_shoresprite[32] = { frosch@8380: 0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0, frosch@8380: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10, 15, 0, frosch@8380: }; frosch@8380: frosch@8380: assert(!IsHalftileSlope(tileh)); // Halftile slopes need to get handled earlier. frosch@8380: assert(tileh != SLOPE_FLAT); // Shore is never flat frosch@8380: frosch@8380: assert((tileh != SLOPE_EW) && (tileh != SLOPE_NS)); // No suitable sprites for current flooding behaviour frosch@8380: frosch@8380: DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[tileh], PAL_NONE); frosch@8380: } frosch@8380: truelight@0: static void DrawTile_Water(TileInfo *ti) truelight@0: { celestar@3402: switch (GetWaterTileType(ti->tile)) { rubidium@6181: case WATER_TILE_CLEAR: peter1138@5668: DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE); rubidium@7739: if (IsCanal(ti->tile)) DrawCanalWater(ti->tile); celestar@5385: DrawBridgeMiddle(ti); celestar@3402: break; truelight@0: belugas@8164: case WATER_TILE_COAST: { frosch@8380: DrawShoreTile(ti->tileh); celestar@5385: DrawBridgeMiddle(ti); belugas@8164: } break; truelight@0: rubidium@6181: case WATER_TILE_LOCK: { celestar@3425: const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)]; celestar@3402: DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0); celestar@3402: } break; celestar@3402: rubidium@6181: case WATER_TILE_DEPOT: celestar@3425: DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0); celestar@3402: break; peter1138@8360: peter1138@8360: case WATER_TILE_RIVER: peter1138@8360: DrawRiverWater(ti); peter1138@8360: DrawBridgeMiddle(ti); peter1138@8360: break; truelight@0: } truelight@0: } truelight@0: truelight@0: void DrawShipDepotSprite(int x, int y, int image) truelight@0: { tron@1399: const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image]; truelight@0: peter1138@5668: DrawSprite(wdts++->image, PAL_NONE, x, y); truelight@193: tron@1399: for (; wdts->delta_x != 0x80; wdts++) { truelight@0: Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z); peter1138@5668: DrawSprite(wdts->image, PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y); truelight@0: } truelight@0: } truelight@0: truelight@0: tron@4231: static uint GetSlopeZ_Water(TileIndex tile, uint x, uint y) truelight@193: { tron@4231: uint z; rubidium@5587: Slope tileh = GetTileSlope(tile, &z); tron@4231: tron@4231: return z + GetPartialZ(x & 0xF, y & 0xF, tileh); truelight@0: } truelight@0: rubidium@7335: static Foundation GetFoundation_Water(TileIndex tile, Slope tileh) truelight@193: { rubidium@7335: return FOUNDATION_NONE; dominik@39: } dominik@39: tron@1977: static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac) truelight@0: { truelight@0: /* not used */ truelight@0: } truelight@0: tron@1977: static void GetTileDesc_Water(TileIndex tile, TileDesc *td) truelight@0: { celestar@3402: switch (GetWaterTileType(tile)) { rubidium@6181: case WATER_TILE_CLEAR: peter1138@8360: case WATER_TILE_RIVER: rubidium@7739: if (!IsCanal(tile)) { celestar@3402: td->str = STR_3804_WATER; celestar@3402: } else { celestar@3402: td->str = STR_LANDINFO_CANAL; celestar@3402: } celestar@3402: break; rubidium@6181: case WATER_TILE_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break; rubidium@6181: case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK; break; rubidium@6181: case WATER_TILE_DEPOT: td->str = STR_3806_SHIP_DEPOT; break; celestar@3402: default: assert(0); break; tron@2951: } truelight@0: tron@1901: td->owner = GetTileOwner(tile); truelight@0: } truelight@0: tron@1977: static void AnimateTile_Water(TileIndex tile) truelight@0: { truelight@0: /* not used */ truelight@0: } truelight@0: rubidium@7771: /** smatz@8044: * Marks tile dirty if it is a canal tile. smatz@8044: * Called to avoid glitches when flooding tiles next to canal tile. smatz@8044: * smatz@8044: * @param tile tile to check smatz@8044: */ frosch@8331: static inline void MarkTileDirtyIfCanal(TileIndex tile) frosch@8331: { smatz@8044: if (IsTileType(tile, MP_WATER) && IsCanal(tile)) MarkTileDirtyByTile(tile); smatz@8044: } smatz@8044: truelight@0: rubidium@5940: /** rubidium@5940: * Finds a vehicle to flood. rubidium@5940: * It does not find vehicles that are already crashed on bridges, i.e. flooded. rubidium@5940: * @param tile the tile where to find a vehicle to flood rubidium@5940: * @return a vehicle too flood or NULL when there is no vehicle too flood. rubidium@5940: */ rubidium@5940: static Vehicle *FindFloodableVehicleOnTile(TileIndex tile) rubidium@5940: { rubidium@6906: if (IsTileType(tile, MP_STATION) && IsAirport(tile)) { rubidium@6906: const Station *st = GetStationByTile(tile); rubidium@6906: const AirportFTAClass *airport = st->Airport(); rubidium@6906: for (uint x = 0; x < airport->size_x; x++) { rubidium@6906: for (uint y = 0; y < airport->size_y; y++) { rubidium@6906: tile = TILE_ADDXY(st->airport_tile, x, y); rubidium@6906: Vehicle *v = FindVehicleOnTileZ(tile, 1 + airport->delta_z); rubidium@6906: if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v; rubidium@6906: } rubidium@6906: } rubidium@6906: rubidium@6906: /* No vehicle could be flooded on this airport anymore */ rubidium@6906: return NULL; rubidium@6906: } rubidium@6906: smatz@8014: /* if non-uniform stations are disabled, flood some train in this train station (if there is any) */ smatz@8014: if (!_patches.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) { smatz@8014: const Station *st = GetStationByTile(tile); smatz@8014: smatz@8014: BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) smatz@8014: if (st->TileBelongsToRailStation(t)) { smatz@8014: Vehicle *v = FindVehicleOnTileZ(t, 0); smatz@8014: if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v; smatz@8014: } smatz@8014: END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) smatz@8014: smatz@8014: return NULL; smatz@8014: } smatz@8014: rubidium@5940: if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0); rubidium@5940: rubidium@5940: TileIndex end = GetOtherBridgeEnd(tile); rubidium@5940: byte z = GetBridgeHeight(tile); rubidium@5940: Vehicle *v; rubidium@5940: rubidium@5940: /* check the start tile first since as this is closest to the water */ rubidium@5940: v = FindVehicleOnTileZ(tile, z); rubidium@5940: if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v; rubidium@5940: rubidium@5940: /* check a vehicle in between both bridge heads */ rubidium@5940: v = FindVehicleBetween(tile, end, z, true); rubidium@5940: if (v != NULL) return v; rubidium@5940: rubidium@5940: /* check the end tile last to give fleeing vehicles a chance to escape */ rubidium@5940: v = FindVehicleOnTileZ(end, z); rubidium@5940: return (v != NULL && (v->vehstatus & VS_CRASHED) == 0) ? v : NULL; rubidium@5940: } rubidium@5940: darkvater@149: static void FloodVehicle(Vehicle *v) darkvater@149: { darkvater@149: if (!(v->vehstatus & VS_CRASHED)) { darkvater@168: uint16 pass = 0; darkvater@149: rubidium@6906: if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) { rubidium@6906: if (v->type == VEH_AIRCRAFT) { rubidium@6906: /* Crashing aircraft are always at z_pos == 1, never on z_pos == 0, rubidium@6906: * because that's always the shadow. Except for the heliport, because rubidium@6906: * that station has a big z_offset for the aircraft. */ rubidium@6906: if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return; rubidium@6906: const Station *st = GetStationByTile(v->tile); rubidium@6906: const AirportFTAClass *airport = st->Airport(); rubidium@6906: rubidium@6906: if (v->z_pos != airport->delta_z + 1) return; rubidium@6906: } belugas@4171: Vehicle *u; truelight@193: rubidium@7497: if (v->type != VEH_AIRCRAFT) v = v->First(); darkvater@149: u = v; darkvater@149: maedhros@6857: /* crash all wagons, and count passengers */ darkvater@149: BEGIN_ENUM_WAGONS(v) rubidium@7010: if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count(); darkvater@149: v->vehstatus |= VS_CRASHED; smatz@8317: MarkSingleVehicleDirty(v); darkvater@149: END_ENUM_WAGONS(v) darkvater@149: darkvater@149: v = u; maedhros@6857: rubidium@6906: switch (v->type) { rubidium@6906: default: NOT_REACHED(); rubidium@6906: case VEH_TRAIN: rubidium@6906: if (IsFrontEngine(v)) pass += 4; // driver rubidium@6906: v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast rubidium@6906: break; rubidium@6906: rubidium@6906: case VEH_ROAD: rubidium@6906: if (IsRoadVehFront(v)) pass += 1; // driver rubidium@6906: v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast rubidium@6906: break; rubidium@6906: rubidium@6906: case VEH_AIRCRAFT: rubidium@6906: pass += 2; // driver rubidium@6906: v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast rubidium@6906: break; maedhros@6857: } maedhros@6857: tron@588: RebuildVehicleLists(); tron@2549: } else { darkvater@168: return; tron@2549: } darkvater@149: smatz@8350: InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); darkvater@149: InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); truelight@193: tron@534: SetDParam(0, pass); darkvater@149: AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED, rubidium@6491: NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0), darkvater@149: v->index, darkvater@149: 0); tron@2549: CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); tron@2549: SndPlayVehicleFx(SND_12_EXPLOSION, v); dominik@714: } darkvater@149: } darkvater@149: belugas@7731: /** frosch@8380: * Returns the behaviour of a tile during flooding. frosch@8380: * frosch@8380: * @return Behaviour of the tile frosch@8380: */ frosch@8380: static FloodingBehaviour GetFloodingBehaviour(TileIndex tile) frosch@8380: { frosch@8380: /* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, rail with flooded halftile frosch@8380: * FLOOD_DRYUP: coast with more than one corner raised frosch@8380: * FLOOD_PASSIVE: oilrig, dock, water-industries frosch@8380: * FLOOD_NONE: canals, rivers, everything else frosch@8380: */ frosch@8380: switch (GetTileType(tile)) { frosch@8380: case MP_WATER: frosch@8380: if (IsCoast(tile)) { frosch@8380: Slope tileh = GetTileSlope(tile, NULL); frosch@8380: return (HasBit(_active_water_slopes, tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP); frosch@8380: } else { frosch@8380: return ((IsSea(tile) || (IsShipDepot(tile) && (GetShipDepotWaterOwner(tile) == OWNER_WATER))) ? FLOOD_ACTIVE : FLOOD_NONE); frosch@8380: } frosch@8380: frosch@8380: case MP_RAILWAY: frosch@8380: return ((GetRailGroundType(tile) == RAIL_GROUND_WATER) ? FLOOD_ACTIVE : FLOOD_NONE); frosch@8380: frosch@8380: case MP_STATION: frosch@8380: if (IsSeaBuoyTile(tile)) return FLOOD_ACTIVE; frosch@8380: if (IsOilRig(tile) || IsDock(tile)) return FLOOD_PASSIVE; frosch@8380: return FLOOD_NONE; frosch@8380: frosch@8380: case MP_INDUSTRY: frosch@8380: return ((GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0 ? FLOOD_PASSIVE : FLOOD_NONE); frosch@8380: frosch@8380: default: frosch@8380: return FLOOD_NONE; frosch@8380: } frosch@8380: } frosch@8380: frosch@8380: /** frosch@8380: * Floods a tile. frosch@8380: */ frosch@8380: static void DoFloodTile(TileIndex target) frosch@8380: { frosch@8380: if (IsTileType(target, MP_WATER)) return; frosch@8380: frosch@8380: bool flooded = false; // Will be set to true if something is changed. frosch@8380: frosch@8380: _current_player = OWNER_WATER; frosch@8380: frosch@8380: if (GetTileSlope(target, NULL) != SLOPE_FLAT) { frosch@8380: /* make coast.. */ frosch@8380: switch (GetTileType(target)) { frosch@8380: case MP_RAILWAY: { frosch@8380: if (!IsPlainRailTile(target)) break; frosch@8380: frosch@8380: flooded = FloodHalftile(target); frosch@8380: frosch@8380: Vehicle *v = FindFloodableVehicleOnTile(target); frosch@8380: if (v != NULL) FloodVehicle(v); frosch@8380: frosch@8380: break; frosch@8380: } frosch@8380: frosch@8380: case MP_CLEAR: frosch@8380: case MP_TREES: frosch@8380: if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { frosch@8380: MakeShore(target); frosch@8380: MarkTileDirtyByTile(target); frosch@8380: flooded = true; frosch@8380: } frosch@8380: break; frosch@8380: frosch@8380: default: frosch@8380: break; frosch@8380: } frosch@8380: } else { frosch@8380: /* Flood vehicles */ frosch@8380: Vehicle *v = FindFloodableVehicleOnTile(target); frosch@8380: if (v != NULL) FloodVehicle(v); frosch@8380: frosch@8380: /* flood flat tile */ frosch@8380: if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { frosch@8380: MakeWater(target); frosch@8380: MarkTileDirtyByTile(target); frosch@8380: flooded = true; frosch@8380: } frosch@8380: } frosch@8380: frosch@8380: if (flooded) { frosch@8380: /* Mark surrounding canal tiles dirty too to avoid glitches */ frosch@8380: for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) { frosch@8380: MarkTileDirtyIfCanal(target + TileOffsByDir(dir)); frosch@8380: } frosch@8380: frosch@8380: /* update signals if needed */ frosch@8380: UpdateSignalsInBuffer(); frosch@8380: } frosch@8380: frosch@8380: _current_player = OWNER_NONE; frosch@8380: } frosch@8380: frosch@8380: /** frosch@8380: * Drys a tile up. frosch@8380: */ frosch@8380: static void DoDryUp(TileIndex tile) frosch@8380: { frosch@8380: assert(IsTileType(tile, MP_WATER) && IsCoast(tile)); frosch@8380: _current_player = OWNER_WATER; frosch@8380: frosch@8380: if (CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { frosch@8380: MakeClear(tile, CLEAR_GRASS, 3); frosch@8380: MarkTileDirtyByTile(tile); frosch@8380: } frosch@8380: frosch@8380: _current_player = OWNER_NONE; frosch@8380: } frosch@8380: frosch@8380: /** belugas@7731: * Let a water tile floods its diagonal adjoining tiles rubidium@7771: * called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track() belugas@7731: * belugas@7731: * @param tile the water/shore tile that floods belugas@7731: */ tron@1977: void TileLoop_Water(TileIndex tile) truelight@0: { frosch@8380: switch (GetFloodingBehaviour(tile)) { frosch@8380: case FLOOD_ACTIVE: frosch@8380: for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) { frosch@8380: TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(dir)); frosch@8380: if (dest == INVALID_TILE) continue; tron@2989: frosch@8380: uint z_dest; frosch@8380: Slope slope_dest = (Slope)(GetFoundationSlope(dest, &z_dest) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP); frosch@8380: if (z_dest > 0) continue; dominik@43: frosch@8380: if (!HasBit(_flood_from_dirs[slope_dest], ReverseDir(dir))) continue; dominik@43: frosch@8380: DoFloodTile(dest); frosch@8380: } frosch@8380: break; dominik@43: frosch@8380: case FLOOD_DRYUP: { frosch@8380: Slope slope_here = (Slope)(GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP); frosch@8380: uint check_dirs = _flood_from_dirs[slope_here]; frosch@8380: uint dir; frosch@8380: FOR_EACH_SET_BIT(dir, check_dirs) { frosch@8380: TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir((Direction)dir)); frosch@8380: if (dest == INVALID_TILE) continue; frosch@8380: frosch@8380: FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest); frosch@8380: if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return; frosch@8380: } frosch@8380: DoDryUp(tile); frosch@8380: break; frosch@8380: } frosch@8380: frosch@8380: default: return; tron@2639: } frosch@8380: } dominik@43: frosch@8380: void ConvertGroundTilesIntoWaterTiles() frosch@8380: { frosch@8380: TileIndex tile; frosch@8380: uint z; frosch@8380: Slope slope; frosch@8380: frosch@8380: for (tile = 0; tile < MapSize(); ++tile) { frosch@8380: slope = GetTileSlope(tile, &z); frosch@8380: if (IsTileType(tile, MP_CLEAR) && z == 0) { frosch@8380: /* Make both water for tiles at level 0 frosch@8380: * and make shore, as that looks much better frosch@8380: * during the generation. */ frosch@8380: switch (slope) { frosch@8380: case SLOPE_FLAT: frosch@8380: MakeWater(tile); frosch@8380: break; frosch@8380: frosch@8380: case SLOPE_N: frosch@8380: case SLOPE_E: frosch@8380: case SLOPE_S: frosch@8380: case SLOPE_W: frosch@8380: MakeShore(tile); frosch@8380: break; frosch@8380: frosch@8380: default: frosch@8380: uint check_dirs = _flood_from_dirs[slope & ~SLOPE_STEEP]; frosch@8380: uint dir; frosch@8380: FOR_EACH_SET_BIT(dir, check_dirs) { frosch@8380: TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir)); frosch@8380: Slope slope_dest = (Slope)(GetTileSlope(dest, NULL) & ~SLOPE_STEEP); frosch@8380: if (HasBit(_active_water_slopes, slope_dest)) { frosch@8380: MakeShore(tile); frosch@8380: break; frosch@8380: } frosch@8380: } frosch@8380: break; frosch@8380: } frosch@8380: } tron@2639: } truelight@0: } truelight@0: rubidium@6683: static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode) truelight@0: { celestar@3423: static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0}; tron@4169: tron@4169: TrackBits ts; tron@4169: tron@2951: if (mode != TRANSPORT_WATER) return 0; truelight@0: celestar@3423: switch (GetWaterTileType(tile)) { rubidium@6181: case WATER_TILE_CLEAR: ts = TRACK_BIT_ALL; break; rubidium@6181: case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break; rubidium@6181: case WATER_TILE_LOCK: ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break; rubidium@6181: case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break; peter1138@8360: case WATER_TILE_RIVER: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break; celestar@3423: default: return 0; truelight@0: } KUDr@3900: if (TileX(tile) == 0) { belugas@6432: /* NE border: remove tracks that connects NE tile edge */ KUDr@3900: ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT); KUDr@3900: } KUDr@3900: if (TileY(tile) == 0) { belugas@6432: /* NW border: remove tracks that connects NW tile edge */ KUDr@3900: ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER); KUDr@3900: } KUDr@3900: return ts * 0x101; truelight@0: } truelight@0: tron@1977: static void ClickTile_Water(TileIndex tile) truelight@0: { rubidium@6181: if (GetWaterTileType(tile) == WATER_TILE_DEPOT) { celestar@3423: TileIndex tile2 = GetOtherShipDepotTile(tile); truelight@193: rubidium@6259: ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP); truelight@0: } truelight@0: } truelight@0: Darkvater@2436: static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player) truelight@0: { tron@1901: if (!IsTileOwner(tile, old_player)) return; truelight@0: Darkvater@4848: if (new_player != PLAYER_SPECTATOR) { tron@1902: SetTileOwner(tile, new_player); rubidium@7270: } else if (IsShipDepot(tile)) { rubidium@7270: DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); truelight@0: } else { rubidium@7270: SetTileOwner(tile, OWNER_NONE); truelight@0: } truelight@0: } truelight@0: rubidium@8119: static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) truelight@0: { rubidium@5991: return VETSB_CONTINUE; truelight@0: } truelight@0: rubidium@7494: static CommandCost TerraformTile_Water(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) rubidium@7494: { rubidium@7494: /* Canals can't be terraformed */ rubidium@7739: if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST); rubidium@7494: rubidium@7494: return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); rubidium@7494: } rubidium@7494: truelight@0: rubidium@5587: extern const TileTypeProcs _tile_type_water_procs = { rubidium@4344: DrawTile_Water, /* draw_tile_proc */ rubidium@4344: GetSlopeZ_Water, /* get_slope_z_proc */ rubidium@4344: ClearTile_Water, /* clear_tile_proc */ rubidium@4344: GetAcceptedCargo_Water, /* get_accepted_cargo_proc */ rubidium@4344: GetTileDesc_Water, /* get_tile_desc_proc */ rubidium@4344: GetTileTrackStatus_Water, /* get_tile_track_status_proc */ rubidium@4344: ClickTile_Water, /* click_tile_proc */ rubidium@4344: AnimateTile_Water, /* animate_tile_proc */ rubidium@4344: TileLoop_Water, /* tile_loop_clear */ rubidium@4344: ChangeTileOwner_Water, /* change_tile_owner_clear */ rubidium@4344: NULL, /* get_produced_cargo_proc */ rubidium@4344: VehicleEnter_Water, /* vehicle_enter_tile_proc */ rubidium@7335: GetFoundation_Water, /* get_foundation_proc */ rubidium@7494: TerraformTile_Water, /* terraform_tile_proc */ truelight@0: };