# water_cmd.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "bridge_map.h"`
`#include "bridge.h"`
`#include "cmd_helper.h"`
`#include "station_map.h"`
`#include "tile_cmd.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "town.h"`
`#include "news.h"`
`#include "depot.h"`
`#include "vehicle_gui.h"`
`#include "train.h"`
`#include "roadveh.h"`
`#include "water.h"`
`#include "water_map.h"`
`#include "industry_map.h"`
`#include "newgrf.h"`
`#include "newgrf_canal.h"`
`#include "transparency.h"`
`#include "strings_func.h"`
`#include "functions.h"`
`#include "window_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "variables.h"`
`#include "player_func.h"`
`#include "settings_type.h"`
`#include "clear_map.h"`
`#include "tree_map.h"`
`#include "aircraft.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`
`#include "table/water_land.h"`

Go to the source code of this file.

## Data Structures
struct | LocksDrawTileStruct
## Enumerations
enum | FloodingBehaviour { FLOOD_NONE, FLOOD_ACTIVE, FLOOD_PASSIVE, FLOOD_DRYUP }
| Describes the behaviour of a tile during flooding. More...
## Functions
static void | MarkTileDirtyIfCanalOrRiver (TileIndex tile)
| Marks tile dirty if it is a canal or river tile.
static void | MarkCanalsAndRiversAroundDirty (TileIndex tile)
| Marks the tiles around a tile as dirty, if they are canals or rivers.
void | SetWaterClassDependingOnSurroundings (TileIndex t)
| Makes a tile canal or water depending on the surroundings.
CommandCost | CmdBuildShipDepot (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
| Build a ship depot.
void | MakeWaterKeepingClass (TileIndex tile, Owner o)
static CommandCost | RemoveShipDepot (TileIndex tile, uint32 flags)
static CommandCost | DoBuildShiplift (TileIndex tile, DiagDirection dir, uint32 flags)
| build a shiplift
static CommandCost | RemoveShiplift (TileIndex tile, uint32 flags)
CommandCost | CmdBuildLock (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
| Builds a lock (ship-lift).
CommandCost | CmdBuildCanal (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
| Build a piece of canal.
static CommandCost | ClearTile_Water (TileIndex tile, byte flags)
static bool | IsWateredTile (TileIndex tile, Direction from)
| return true if a tile is a water tile wrt.
static void | DrawWaterEdges (SpriteID base, TileIndex tile)
static void | DrawSeaWater (TileIndex tile)
| Draw a plain sea water tile with no edges.
static void | DrawCanalWater (TileIndex tile)
| draw a canal styled water tile with dikes around
static void | DrawWaterStuff (const TileInfo *ti, const WaterDrawTileStruct *wdts, SpriteID palette, uint base, bool draw_ground)
static void | DrawRiverWater (const TileInfo *ti)
void | DrawShoreTile (Slope tileh)
void | DrawWaterClassGround (const TileInfo *ti)
static void | DrawTile_Water (TileInfo *ti)
void | DrawShipDepotSprite (int x, int y, int image)
static uint | GetSlopeZ_Water (TileIndex tile, uint x, uint y)
static Foundation | GetFoundation_Water (TileIndex tile, Slope tileh)
static void | GetAcceptedCargo_Water (TileIndex tile, AcceptedCargo ac)
static void | GetTileDesc_Water (TileIndex tile, TileDesc *td)
static void | AnimateTile_Water (TileIndex tile)
static void | FloodVehicle (Vehicle *v)
static void * | FloodVehicleProc (Vehicle *v, void *data)
| Flood a vehicle if we are allowed to flood it, i.e.
static void | FloodVehicles (TileIndex tile)
| Finds a vehicle to flood.
static FloodingBehaviour | GetFloodingBehaviour (TileIndex tile)
| Returns the behaviour of a tile during flooding.
static void | DoFloodTile (TileIndex target)
| Floods a tile.
static void | DoDryUp (TileIndex tile)
| Drys a tile up.
void | TileLoop_Water (TileIndex tile)
| Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track().
void | ConvertGroundTilesIntoWaterTiles ()
static TrackStatus | GetTileTrackStatus_Water (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
static void | ClickTile_Water (TileIndex tile)
static void | ChangeTileOwner_Water (TileIndex tile, PlayerID old_player, PlayerID new_player)
static VehicleEnterTileStatus | VehicleEnter_Water (Vehicle *v, TileIndex tile, int x, int y)
static CommandCost | TerraformTile_Water (TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
## Variables
static const uint8 | _flood_from_dirs []
| Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
const TileTypeProcs | _tile_type_water_procs

## Detailed Description

Definition in file water_cmd.cpp.

## Enumeration Type Documentation

enum FloodingBehaviour

Describes the behaviour of a tile during flooding.

Enumerator:

  FLOOD_NONE | The tile does not flood neighboured tiles.
  FLOOD_ACTIVE | The tile floods neighboured tiles.
  FLOOD_PASSIVE | The tile does not actively flood neighboured tiles, but it prevents them from drying up.
  FLOOD_DRYUP | The tile drys up if it is not constantly flooded from neighboured tiles.

Definition at line 45 of file water_cmd.cpp.

## Function Documentation

CommandCost CmdBuildCanal | ( | TileIndex | tile,
|  | uint32 | flags,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

Build a piece of canal.

Parameters:

  | tile | end tile of stretch-dragging
  | flags | type of operation
  | p1 | start tile of stretch-dragging
  | p2 | specifies canal (0), water (1) or river (2); last two can only be built in scenario editor

Definition at line 343 of file water_cmd.cpp.

References CommandCost::AddCost(), BEGIN_TILE_LOOP, CMD_ERROR, CMD_LANDSCAPE_CLEAR, CmdFailed(), DoCommand(), END_TILE_LOOP, CommandCost::GetCost(), IsInclinedSlope(), IsTileOwner(), IsTileType(), MapSize(), MarkCanalsAndRiversAroundDirty(), MarkTileDirtyByTile(), MP_WATER, OWNER_WATER, return_cmd_error, SLOPE_FLAT, Swap(), TileHeight(), TileX(), TileXY(), and TileY().

CommandCost CmdBuildLock | ( | TileIndex | tile,
|  | uint32 | flags,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

Builds a lock (ship-lift).

Parameters:

  | tile | tile where to place the lock
  | flags | type of operation
  | p1 | unused
  | p2 | unused

Definition at line 326 of file water_cmd.cpp.

References DoBuildShiplift(), GetInclinedSlopeDirection(), INVALID_DIAGDIR, and return_cmd_error.

CommandCost CmdBuildShipDepot | ( | TileIndex | tile,
|  | uint32 | flags,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

Build a ship depot.

Parameters:

  | tile | tile where ship depot is built
  | flags | type of operation
  | p1 | bit 0 depot orientation (Axis)
  | p2 | unused

Definition at line 171 of file water_cmd.cpp.

References AXIS_X, CMD_ERROR, CMD_LANDSCAPE_CLEAR, CmdFailed(), DC_EXEC, DoCommand(), IsBridgeAbove(), MarkTileDirtyByTile(), return_cmd_error, SLOPE_FLAT, and TileDiffXY().

static void* FloodVehicleProc | ( | Vehicle * | v,
|  | void * | data |
| ) |  |  | `[static]`

Flood a vehicle if we are allowed to flood it, i.e.

when it is on the ground.

Parameters:

  | v | The vehicle to test for flooding.
  | data | The z of level to flood.

Returns:
  NULL as we always want to remove everything.

Definition at line 749 of file water_cmd.cpp.

References AIR_SHADOW.

Referenced by FloodVehicles().

static void FloodVehicles | ( | TileIndex | tile | ) | `[static]`

Finds a vehicle to flood.

It does not find vehicles that are already crashed on bridges, i.e. flooded.

Parameters:

  | tile | the tile where to find a vehicle to flood

Definition at line 765 of file water_cmd.cpp.

References BEGIN_TILE_LOOP, END_TILE_LOOP, FindVehicleOnPos(), FloodVehicleProc(), GetBridgeHeight(), GetOtherBridgeEnd(), IsBridgeTile(), IsTileType(), MP_STATION, and TILE_ADDXY.

Referenced by DoFloodTile().

static FloodingBehaviour GetFloodingBehaviour | ( | TileIndex | tile | ) | `[static]`

Returns the behaviour of a tile during flooding.

Returns:
  Behaviour of the tile

Definition at line 880 of file water_cmd.cpp.

References FLOOD_ACTIVE, FLOOD_DRYUP, FLOOD_NONE, FLOOD_PASSIVE, GetIndustrySpec(), GetIndustryType(), GetTileType(), GetTreeGround(), INDUSTRYBEH_BUILT_ONWATER, IsSlopeWithOneCornerRaised(), MP_INDUSTRY, MP_RAILWAY, MP_STATION, MP_TREES, MP_WATER, RAIL_GROUND_WATER, SLOPE_FLAT, and TREE_GROUND_SHORE.

Referenced by TileLoop_Water().

static bool IsWateredTile | ( | TileIndex | tile,
|  | Direction | from |
| ) |  |  | `[static]`

return true if a tile is a water tile wrt.

a certain direction.

Parameters:

  | tile | The tile of interest.
  | from | The direction of interest.

Returns:
  true iff the tile is water in the view of 'from'.

Definition at line 476 of file water_cmd.cpp.

References IndustrySpec::behaviour, DIR_E, DIR_N, DIR_NE, DIR_NW, DIR_S, DIR_SE, DIR_SW, DIR_W, GetIndustrySpec(), GetIndustryType(), GetTileType(), INDUSTRYBEH_BUILT_ONWATER, IsPlainRailTile(), MP_INDUSTRY, MP_RAILWAY, MP_STATION, MP_WATER, RAIL_GROUND_WATER, SLOPE_E, SLOPE_FLAT, SLOPE_N, SLOPE_S, and SLOPE_W.

static void MarkTileDirtyIfCanalOrRiver | ( | TileIndex | tile | ) | `[inline, static]`

Marks tile dirty if it is a canal or river tile.

Called to avoid glitches when flooding tiles next to canal tile.

Parameters:

  | tile | tile to check

Definition at line 79 of file water_cmd.cpp.

References IsTileType(), MarkTileDirtyByTile(), and MP_WATER.

Referenced by MarkCanalsAndRiversAroundDirty().

void SetWaterClassDependingOnSurroundings | ( | TileIndex | t | ) |

Makes a tile canal or water depending on the surroundings.

Must only be used for converting old savegames. Use WaterClass now.

This as for example docks and shipdepots do not store whether the tile used to be canal or 'normal' water.

Parameters:

  | t | the tile to change.
  | o | the owner of the new tile.

Definition at line 107 of file water_cmd.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, GetTileType(), GetTreeGround(), MapMaxX(), MapMaxY(), MarkTileDirtyByTile(), MP_RAILWAY, MP_TREES, MP_WATER, RAIL_GROUND_WATER, SLOPE_FLAT, TileAddByDiagDir(), TileX(), TileY(), and TREE_GROUND_SHORE.

void TileLoop_Water | ( | TileIndex | tile | ) |

Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track().

Parameters:

  | tile | the water/shore tile that floods

Definition at line 1033 of file water_cmd.cpp.

References _flood_from_dirs, AddTileIndexDiffCWrap(), DIR_BEGIN, DIR_END, DoDryUp(), DoFloodTile(), FLOOD_ACTIVE, FLOOD_DRYUP, FLOOD_PASSIVE, FOR_EACH_SET_BIT, GetFloodingBehaviour(), HasBit(), INVALID_TILE, IsTileType(), MP_WATER, ReverseDir(), SLOPE_HALFTILE_MASK, SLOPE_STEEP, and TileIndexDiffCByDir().

## Variable Documentation

const uint8 _flood_from_dirs[]`[static]`

Initial value:

     {
      (1 << DIR_NW) | (1 << DIR_SW) | (1 << DIR_SE) | (1 << DIR_NE),
      (1 << DIR_NE) | (1 << DIR_SE),
      (1 << DIR_NW) | (1 << DIR_NE),
      (1 << DIR_NE),
      (1 << DIR_NW) | (1 << DIR_SW),
      0,
      (1 << DIR_NW),
      (1 << DIR_N ) | (1 << DIR_NW) | (1 << DIR_NE),
      (1 << DIR_SW) | (1 << DIR_SE),
      (1 << DIR_SE),
      0,
      (1 << DIR_E ) | (1 << DIR_NE) | (1 << DIR_SE),
      (1 << DIR_SW),
      (1 << DIR_S ) | (1 << DIR_SW) | (1 << DIR_SE),
      (1 << DIR_W ) | (1 << DIR_SW) | (1 << DIR_NW),
    }

Describes from which directions a specific slope can be flooded (if the tile is floodable at all).

Definition at line 55 of file water_cmd.cpp.

Referenced by TileLoop_Water().

const TileTypeProcs _tile_type_water_procs

Initial value:

     {
      DrawTile_Water,
      GetSlopeZ_Water,
      ClearTile_Water,
      GetAcceptedCargo_Water,
      GetTileDesc_Water,
      GetTileTrackStatus_Water,
      ClickTile_Water,
      AnimateTile_Water,
      TileLoop_Water,
      ChangeTileOwner_Water,
      NULL,
      VehicleEnter_Water,
      GetFoundation_Water,
      TerraformTile_Water,
    }