Functions | Variables

# water_cmd.cpp File Reference

Handling of water tiles. More...

`#include "stdafx.h"`
`#include "cmd_helper.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "town.h"`
`#include "news_func.h"`
`#include "depot_base.h"`
`#include "depot_func.h"`
`#include "water.h"`
`#include "industry_map.h"`
`#include "newgrf_canal.h"`
`#include "strings_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "company_func.h"`
`#include "clear_map.h"`
`#include "tree_map.h"`
`#include "aircraft.h"`
`#include "effectvehicle_func.h"`
`#include "tunnelbridge_map.h"`
`#include "station_base.h"`
`#include "ai/ai.hpp"`
`#include "game/game.hpp"`
`#include "core/random_func.hpp"`
`#include "core/backup_type.hpp"`
`#include "date_func.h"`
`#include "company_base.h"`
`#include "company_gui.h"`
`#include "newgrf_generic.h"`
`#include "table/strings.h"`
`#include "table/water_land.h"`

Go to the source code of this file.

## 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.
CommandCost | CmdBuildShipDepot (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build a ship depot.
void | MakeWaterKeepingClass (TileIndex tile, Owner o)
static CommandCost | RemoveShipDepot (TileIndex tile, DoCommandFlag flags)
static CommandCost | DoBuildLock (TileIndex tile, DiagDirection dir, DoCommandFlag flags)
| Builds a lock.
static CommandCost | RemoveLock (TileIndex tile, DoCommandFlag flags)
| Remove a lock.
CommandCost | CmdBuildLock (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Builds a lock.
bool | RiverModifyDesertZone (TileIndex tile, void *)
| Callback to create non-desert around a river tile.
CommandCost | CmdBuildCanal (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build a piece of canal.
static CommandCost | ClearTile_Water (TileIndex tile, DoCommandFlag flags)
static bool | IsWateredTile (TileIndex tile, Direction from)
| return true if a tile is a water tile wrt.
static void | DrawWaterSprite (SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
| Draw a water sprite, potentially with a NewGRF-modified sprite offset.
static void | DrawWaterEdges (bool canal, uint offset, TileIndex tile)
| Draw canal or river edges.
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 | DrawWaterTileStruct (const TileInfo *ti, const DrawTileSeqStruct *dtss, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
| Draw a build sprite sequence for water tiles.
static void | DrawWaterLock (const TileInfo *ti)
| Draw a lock tile.
static void | DrawWaterDepot (const TileInfo *ti)
| Draw a ship depot tile.
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, Axis axis, DepotPart part)
static int | GetSlopePixelZ_Water (TileIndex tile, uint x, uint y)
static Foundation | GetFoundation_Water (TileIndex tile, Slope tileh)
static void | GetTileDesc_Water (TileIndex tile, TileDesc *td)
static void | FloodVehicle (Vehicle *v)
| Handle the flooding of a vehicle.
static Vehicle * | 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.
FloodingBehaviour | GetFloodingBehaviour (TileIndex tile)
| Returns the behaviour of a tile during flooding.
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 bool | ClickTile_Water (TileIndex tile)
static void | ChangeTileOwner_Water (TileIndex tile, Owner old_owner, Owner new_owner)
static VehicleEnterTileStatus | VehicleEnter_Water (Vehicle *v, TileIndex tile, int x, int y)
static CommandCost | TerraformTile_Water (TileIndex tile, DoCommandFlag flags, int 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

Handling of water tiles.

Definition in file water_cmd.cpp.

## Function Documentation

CommandCost CmdBuildCanal | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Build a piece of canal.

Parameters:

  | tile | end tile of stretch-dragging
  | flags | type of operation
  | p1 | start tile of stretch-dragging
  | p2 | waterclass to build. sea and river can only be built in scenario editor
  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 389 of file water_cmd.cpp.

References _current_company, CommandCost::AddCost(), CircularTileSearch(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, DC_FORCE_CLEAR_TILE, DirtyCompanyInfrastructureWindows(), DoCommand(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), CommandCost::GetCost(), GetTileSlope(), TileArea::h, IsInclinedSlope(), IsTileOwner(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MakeCanal(), MakeRiver(), MakeSea(), MapSize(), MarkCanalsAndRiversAroundDirty(), MarkTileDirtyByTile(), MP_WATER, OWNER_WATER, return_cmd_error, RiverModifyDesertZone(), SLOPE_FLAT, TILE_AREA_LOOP, TileHeight(), TileArea::w, WATER_CLASS_CANAL, WATER_CLASS_RIVER, and WATER_CLASS_SEA.

CommandCost CmdBuildLock | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Builds a lock.

Parameters:

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

Returns:
  the cost of this operation or an error

Definition at line 365 of file water_cmd.cpp.

References DoBuildLock(), GetInclinedSlopeDirection(), GetTileSlope(), INVALID_DIAGDIR, and return_cmd_error.

CommandCost CmdBuildShipDepot | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Build a ship depot.

Parameters:

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

Returns:
  the cost of this operation or an error

Definition at line 100 of file water_cmd.cpp.

References _current_company, _date, CommandCost::AddCost(), AXIS_X, Depot::build_date, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::CanAllocateItem(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, DC_AUTO, DC_EXEC, DEPOT_PART_NORTH, DEPOT_PART_SOUTH, DirtyCompanyInfrastructureWindows(), DoCommand(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetTileSlope(), GetWaterClass(), HasTileWaterGround(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsBridgeAbove(), IsWaterTile(), LOCK_DEPOT_TILE_FACTOR, MakeDefaultName(), MakeShipDepot(), MarkTileDirtyByTile(), MayHaveBridgeAbove(), return_cmd_error, SLOPE_FLAT, TileDiffXY(), and WATER_CLASS_CANAL.

static CommandCost DoBuildLock | ( | TileIndex | tile,
|  | DiagDirection | dir,
|  | DoCommandFlag | flags |
| ) |  |  | `[static]`

Builds a lock.

Parameters:

  | tile | Central tile of the lock.
  | dir | Uphill direction.
  | flags | Operation to perform.

Returns:
  The cost in case of success, or an error code if it failed.

Definition at line 240 of file water_cmd.cpp.

References _current_company, CommandCost::AddCost(), CMD_LANDSCAPE_CLEAR, DirtyCompanyInfrastructureWindows(), DoCommand(), EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetTileSlope(), GetWaterClass(), Company::infrastructure, IsBridgeAbove(), IsWaterTile(), LOCK_DEPOT_TILE_FACTOR, MakeLock(), MarkCanalsAndRiversAroundDirty(), MarkTileDirtyByTile(), MayHaveBridgeAbove(), return_cmd_error, SLOPE_FLAT, CommandCost::Succeeded(), TileOffsByDiagDir(), and CompanyInfrastructure::water.

Referenced by CmdBuildLock().

static void DrawWaterDepot | ( | const TileInfo * | ti | ) | `[static]`

Draw a ship depot tile.

Definition at line 764 of file water_cmd.cpp.

References DrawWaterTileStruct(), GetShipDepotAxis(), GetShipDepotPart(), GetTileOwner(), and TileInfo::tile.

static void DrawWaterEdges | ( | bool | canal,
|  | uint | offset,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Draw canal or river edges.

Parameters:

  | canal | True if canal edges should be drawn, false for river edges.
  | offset | Sprite offset.
  | tile | Tile to draw.

Definition at line 625 of file water_cmd.cpp.

References DIR_E, DIR_N, DIR_NE, DIR_NW, DIR_S, DIR_SE, DIR_SW, DIR_W, DrawWaterSprite(), GetCanalSprite(), IsWateredTile(), and TILE_ADDXY.

Referenced by DrawCanalWater().

static void DrawWaterLock | ( | const TileInfo * | ti | ) | `[static]`

Draw a lock tile.

Definition at line 725 of file water_cmd.cpp.

References _water_feature, CFF_HAS_FLAT_SPRITE, DrawGroundSprite(), DrawWaterTileStruct(), GetCanalSprite(), GetLockDirection(), GetLockPart(), DrawTileSprites::ground, HasBit(), LOCK_PART_UPPER, DrawTileSprites::seq, PalSpriteID::sprite, TileInfo::tile, and TileInfo::z.

static void DrawWaterSprite | ( | SpriteID | base,
|  | uint | offset,
|  | CanalFeature | feature,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Draw a water sprite, potentially with a NewGRF-modified sprite offset.

Parameters:

  | base | Sprite base.
  | offset | Sprite offset.
  | feature | The type of sprite that is drawn.
  | tile | Tile index to draw.

Definition at line 610 of file water_cmd.cpp.

References DrawGroundSprite(), and GetCanalSpriteOffset().

Referenced by DrawCanalWater(), and DrawWaterEdges().

static void DrawWaterTileStruct | ( | const TileInfo * | ti,
|  | const DrawTileSeqStruct * | dtss,
|  | SpriteID | base,
|  | uint | offset,
|  | PaletteID | palette,
|  | CanalFeature | feature |
| ) |  |  | `[static]`

Draw a build sprite sequence for water tiles.

If buildings are invisible, nothing will be drawn.

Parameters:

  | ti | Tile info.
  | dtss | Sprite sequence to draw.
  | base | Base sprite.
  | offset | Additional sprite offset.
  | palette | Palette to use.

Definition at line 708 of file water_cmd.cpp.

References AddSortableSpriteToDraw(), DrawTileSeqStruct::delta_x, DrawTileSeqStruct::delta_z, GetCanalSpriteOffset(), IsInvisibilitySet(), DrawTileSeqStruct::IsTerminator(), IsTransparencySet(), PalSpriteID::sprite, TileInfo::tile, TO_BUILDINGS, TileInfo::x, TileInfo::y, and TileInfo::z.

Referenced by DrawWaterDepot(), and DrawWaterLock().

static void FloodVehicle | ( | Vehicle * | v | ) | `[static]`

Handle the flooding of a vehicle.

This sets the vehicle state to crashed, creates a newsitem and dirties the necessary windows.

Parameters:

  | v | The vehicle to flood.

Definition at line 909 of file water_cmd.cpp.

References AddVehicleNewsItem(), Vehicle::Crash(), CreateEffectVehicleRel(), EV_EXPLOSION_LARGE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Game::NewEvent(), AI::NewEvent(), NT_ACCIDENT, Vehicle::owner, SetDParam(), and Vehicle::tile.

Referenced by FloodVehicleProc().

static Vehicle* 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 927 of file water_cmd.cpp.

References AIR_SHADOW, Station::airport, AirportFTAClass::delta_z, Vehicle::First(), FloodVehicle(), SpecializedStation< Station, false >::GetByTile(), Airport::GetFTA(), GetTileMaxZ(), IsAirportTile(), Vehicle::subtype, Vehicle::tile, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_TRAIN, Vehicle::vehstatus, VS_CRASHED, and Vehicle::z_pos.

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 965 of file water_cmd.cpp.

References Station::airport, FindVehicleOnPos(), FloodVehicleProc(), GetBridgePixelHeight(), SpecializedStation< Station, false >::GetByTile(), GetOtherBridgeEnd(), IsAirportTile(), IsBridgeTile(), and TILE_AREA_LOOP.

Referenced by DoFloodTile().

FloodingBehaviour GetFloodingBehaviour | ( | TileIndex | tile | ) |

Returns the behaviour of a tile during flooding.

Returns:
  Behaviour of the tile

Definition at line 996 of file water_cmd.cpp.

References FLOOD_ACTIVE, FLOOD_DRYUP, FLOOD_NONE, GetTileSlope(), GetTileType(), GetTreeGround(), GetWaterClass(), IsCoast(), IsSlopeWithOneCornerRaised(), MP_INDUSTRY, MP_OBJECT, MP_RAILWAY, MP_STATION, MP_TREES, MP_WATER, RAIL_GROUND_WATER, TREE_GROUND_SHORE, and WATER_CLASS_SEA.

Referenced by CheckRailSlope(), and 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 541 of file water_cmd.cpp.

References DiagDirToAxis(), DIR_NE, DIR_NW, DIR_SE, DIR_SW, DirToDiagDir(), GetIndustryIndex(), GetLockDirection(), GetTileSlope(), GetTileType(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), GetWaterTileType(), IsBuoy(), IsDock(), IsOilRig(), IsPlainRail(), IsTileOnWater(), IsTileType(), MP_INDUSTRY, MP_OBJECT, MP_RAILWAY, MP_STATION, MP_TUNNELBRIDGE, MP_WATER, ReverseDiagDir(), SLOPE_E, SLOPE_FLAT, SLOPE_N, SLOPE_S, SLOPE_W, TileOffsByDir(), TRANSPORT_WATER, WATER_TILE_CLEAR, WATER_TILE_COAST, WATER_TILE_DEPOT, and WATER_TILE_LOCK.

Referenced by DrawWaterEdges().

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 72 of file water_cmd.cpp.

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

Referenced by MarkCanalsAndRiversAroundDirty().

static CommandCost RemoveLock | ( | TileIndex | tile,
|  | DoCommandFlag | flags |
| ) |  |  | `[static]`

Remove a lock.

Parameters:

  | tile | Central tile of the lock.
  | flags | Operation to perform.

Returns:
  The cost in case of success, or an error code if it failed.

Definition at line 318 of file water_cmd.cpp.

References CheckTileOwnership(), DirtyCompanyInfrastructureWindows(), EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetLockDirection(), GetTileOwner(), GetWaterClass(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, LOCK_DEPOT_TILE_FACTOR, MakeRiver(), MarkCanalsAndRiversAroundDirty(), OWNER_NONE, CommandCost::Succeeded(), TileOffsByDiagDir(), CompanyInfrastructure::water, and WATER_CLASS_RIVER.

bool RiverModifyDesertZone | ( | TileIndex | tile,
|  | void * |  |
| ) |  |  |

Callback to create non-desert around a river tile.

Definition at line 374 of file water_cmd.cpp.

References GetTropicZone(), SetTropicZone(), TROPICZONE_DESERT, and TROPICZONE_NORMAL.

Referenced by CmdBuildCanal().

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 1144 of file water_cmd.cpp.

References _flood_from_dirs, AmbientSoundEffect(), DIR_BEGIN, DoDryUp(), DoFloodTile(), FLOOD_ACTIVE, FLOOD_DRYUP, FLOOD_PASSIVE, FOR_EACH_SET_BIT, GetFloodingBehaviour(), GetFoundationSlope(), HasBit(), IsTileType(), IsValidTile(), MP_WATER, ReverseDir(), SLOPE_HALFTILE_MASK, and TileOffsByDir().

## 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 48 of file water_cmd.cpp.

Referenced by TileLoop_Water().

const TileTypeProcs _tile_type_water_procs

Initial value:

     {
      DrawTile_Water,
      GetSlopePixelZ_Water,
      ClearTile_Water,
      NULL,
      GetTileDesc_Water,
      GetTileTrackStatus_Water,
      ClickTile_Water,
      NULL,
      TileLoop_Water,
      ChangeTileOwner_Water,
      NULL,
      VehicleEnter_Water,
      GetFoundation_Water,
      TerraformTile_Water,
    }