OpenTTD Source  20240919-master-gdf0233f4c2
water_cmd.cpp File Reference
#include "stdafx.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 "timer/timer_game_calendar.h"
#include "company_base.h"
#include "company_gui.h"
#include "newgrf_generic.h"
#include "industry.h"
#include "water_cmd.h"
#include "landscape_cmd.h"
#include "pathfinder/water_regions.h"
#include "table/strings.h"
#include "safeguards.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. More...
 
static void MarkCanalsAndRiversAroundDirty (TileIndex tile)
 Marks the tiles around a tile as dirty, if they are canals or rivers. More...
 
CommandCost CmdBuildShipDepot (DoCommandFlag flags, TileIndex tile, Axis axis)
 Build a ship depot. More...
 
bool IsPossibleDockingTile (Tile t)
 
void CheckForDockingTile (TileIndex t)
 Mark the supplied tile as a docking tile if it is suitable for docking. More...
 
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. More...
 
static CommandCost RemoveLock (TileIndex tile, DoCommandFlag flags)
 Remove a lock. More...
 
CommandCost CmdBuildLock (DoCommandFlag flags, TileIndex tile)
 Builds a lock. More...
 
bool RiverModifyDesertZone (TileIndex tile, void *)
 Callback to create non-desert around a river tile.
 
void MakeRiverAndModifyDesertZoneAround (TileIndex tile)
 Make a river tile and remove desert directly around it. More...
 
CommandCost CmdBuildCanal (DoCommandFlag flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
 Build a piece of canal. More...
 
static CommandCost ClearTile_Water (TileIndex tile, DoCommandFlag flags)
 
bool IsWateredTile (TileIndex tile, Direction from)
 return true if a tile is a water tile wrt. More...
 
static void DrawWaterSprite (SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
 Draw a water sprite, potentially with a NewGRF-modified sprite offset. More...
 
static void DrawWaterEdges (bool canal, uint offset, TileIndex tile)
 Draw canal or river edges. More...
 
static void DrawSeaWater (TileIndex)
 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. More...
 
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, bool)
 
static Foundation GetFoundation_Water (TileIndex, Slope)
 
static void GetTileDesc_Water (TileIndex tile, TileDesc *td)
 
static void FloodVehicle (Vehicle *v)
 Handle the flooding of a vehicle. More...
 
static VehicleFloodVehicleProc (Vehicle *v, void *data)
 Flood a vehicle if we are allowed to flood it, i.e. More...
 
static void FloodVehicles (TileIndex tile)
 Finds a vehicle to flood. More...
 
FloodingBehaviour GetFloodingBehaviour (TileIndex tile)
 Returns the behaviour of a tile during flooding. More...
 
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() More...
 
void ConvertGroundTilesIntoWaterTiles ()
 
static TrackStatus GetTileTrackStatus_Water (TileIndex tile, TransportType mode, uint, DiagDirection)
 
static bool ClickTile_Water (TileIndex tile)
 
static void ChangeTileOwner_Water (TileIndex tile, Owner old_owner, Owner new_owner)
 
static VehicleEnterTileStatus VehicleEnter_Water (Vehicle *, TileIndex, int, int)
 
static CommandCost TerraformTile_Water (TileIndex tile, DoCommandFlag flags, int, Slope)
 

Variables

static const uint8_t _flood_from_dirs []
 Describes from which directions a specific slope can be flooded (if the tile is floodable at all). More...
 
const TileTypeProcs _tile_type_water_procs
 

Detailed Description

Handling of water tiles.

Definition in file water_cmd.cpp.

Function Documentation

◆ CheckForDockingTile()

void CheckForDockingTile ( TileIndex  t)

Mark the supplied tile as a docking tile if it is suitable for docking.

Tiles surrounding the tile are tested to be docks with correct orientation.

Parameters
tTile to test.

Definition at line 184 of file water_cmd.cpp.

References OrthogonalTileArea::Add(), DIAGDIR_BEGIN, DIAGDIR_END, Station::docking_station, Industry::GetByTile(), SpecializedStation< Station, false >::GetByTile(), IsDockTile(), IsDockWaterPart(), IsOilRig(), IsTileType(), IsValidTile(), MP_INDUSTRY, MP_STATION, Industry::neutral_station, SetDockingTile(), and TileOffsByDiagDir().

◆ CmdBuildCanal()

CommandCost CmdBuildCanal ( DoCommandFlag  flags,
TileIndex  tile,
TileIndex  start_tile,
WaterClass  wc,
bool  diagonal 
)

Build a piece of canal.

Parameters
flagstype of operation
tileend tile of stretch-dragging
start_tilestart tile of stretch-dragging
wcwaterclass to build. sea and river can only be built in scenario editor
diagonalWhether to use the Orthogonal (0) or Diagonal (1) iterator.
Returns
the cost of this operation or an error

Definition at line 460 of file water_cmd.cpp.

References CMD_ERROR, IsValidWaterClass(), Map::Size(), and WATER_CLASS_CANAL.

◆ CmdBuildLock()

CommandCost CmdBuildLock ( DoCommandFlag  flags,
TileIndex  tile 
)

Builds a lock.

Parameters
flagstype of operation
tiletile where to place the lock
Returns
the cost of this operation or an error

Definition at line 423 of file water_cmd.cpp.

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

◆ CmdBuildShipDepot()

CommandCost CmdBuildShipDepot ( DoCommandFlag  flags,
TileIndex  tile,
Axis  axis 
)

Build a ship depot.

Parameters
flagstype of operation
tiletile where ship depot is built
axisdepot orientation (Axis)
Returns
the cost of this operation or an error

Definition at line 101 of file water_cmd.cpp.

References AXIS_X, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::CanAllocateItem(), CMD_ERROR, EXPENSES_CONSTRUCTION, GetWaterClass(), HasTileWaterGround(), IsBridgeAbove(), IsTileFlat(), IsValidAxis(), return_cmd_error, and TileDiffXY().

◆ DoBuildLock()

static CommandCost DoBuildLock ( TileIndex  tile,
DiagDirection  dir,
DoCommandFlag  flags 
)
static

Builds a lock.

Parameters
tileCentral tile of the lock.
dirUphill direction.
flagsOperation to perform.
Returns
The cost in case of success, or an error code if it failed.

Definition at line 301 of file water_cmd.cpp.

References CommandCost::AddCost(), EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetWaterClass(), HasTileWaterGround(), IsWaterTile(), CommandCost::Succeeded(), TileOffsByDiagDir(), and WATER_CLASS_CANAL.

Referenced by CmdBuildLock().

◆ DrawWaterEdges()

static void DrawWaterEdges ( bool  canal,
uint  offset,
TileIndex  tile 
)
static

Draw canal or river edges.

Parameters
canalTrue if canal edges should be drawn, false for river edges.
offsetSprite offset.
tileTile to draw.

Definition at line 708 of file water_cmd.cpp.

◆ DrawWaterSprite()

static void DrawWaterSprite ( SpriteID  base,
uint  offset,
CanalFeature  feature,
TileIndex  tile 
)
static

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

Parameters
baseSprite base.
offsetSprite offset.
featureThe type of sprite that is drawn.
tileTile index to draw.

Definition at line 693 of file water_cmd.cpp.

◆ DrawWaterTileStruct()

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
tiTile info.
dtssSprite sequence to draw.
baseBase sprite.
offsetAdditional sprite offset.
palettePalette to use.

Definition at line 791 of file water_cmd.cpp.

References IsInvisibilitySet(), DrawTileSeqStruct::IsTerminator(), PalSpriteID::sprite, and TO_BUILDINGS.

◆ FloodVehicle()

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
vThe vehicle to flood.

Definition at line 991 of file water_cmd.cpp.

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

Referenced by FloodVehicleProc().

◆ 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
vThe vehicle to test for flooding.
dataThe z of level to flood.
Returns
nullptr as we always want to remove everything.

Definition at line 1009 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().

◆ 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
tilethe tile where to find a vehicle to flood

Definition at line 1047 of file water_cmd.cpp.

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

Referenced by DoFloodTile().

◆ GetFloodingBehaviour()

FloodingBehaviour GetFloodingBehaviour ( TileIndex  tile)

Returns the behaviour of a tile during flooding.

Returns
Behaviour of the tile

Definition at line 1078 of file water_cmd.cpp.

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

Referenced by CheckRailSlope(), and TileLoop_Water().

◆ IsWateredTile()

bool IsWateredTile ( TileIndex  tile,
Direction  from 
)

return true if a tile is a water tile wrt.

a certain direction.

Parameters
tileThe tile of interest.
fromThe direction of interest.
Returns
true iff the tile is water in the view of 'from'.

Definition at line 622 of file water_cmd.cpp.

References GetTileType(), GetWaterTileType(), and MP_WATER.

Referenced by CanalScopeResolver::GetVariable().

◆ MakeRiverAndModifyDesertZoneAround()

void MakeRiverAndModifyDesertZoneAround ( TileIndex  tile)

Make a river tile and remove desert directly around it.

Parameters
tileThe tile to change into river and create non-desert around

Definition at line 442 of file water_cmd.cpp.

References MakeRiver().

Referenced by RiverMakeWider().

◆ MarkTileDirtyIfCanalOrRiver()

static void MarkTileDirtyIfCanalOrRiver ( TileIndex  tile)
inlinestatic

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

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

Parameters
tiletile to check

Definition at line 75 of file water_cmd.cpp.

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

Referenced by MarkCanalsAndRiversAroundDirty().

◆ RemoveLock()

◆ TileLoop_Water()

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
tilethe water/shore tile that floods

Definition at line 1231 of file water_cmd.cpp.

References _flood_from_dirs, AmbientSoundEffect(), DIR_BEGIN, DIR_END, DoDryUp(), DoFloodTile(), FLOOD_ACTIVE, FLOOD_DRYUP, FLOOD_PASSIVE, GetFloodingBehaviour(), GetFoundationSlope(), GetTreeGround(), HasBit(), IsTileType(), IsValidTile(), MP_TREES, MP_WATER, ReverseDir(), Map::Size(), SLOPE_HALFTILE_MASK, SLOPE_STEEP, TileOffsByDir(), and TREE_GROUND_SHORE.

Variable Documentation

◆ _flood_from_dirs

const uint8_t _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 51 of file water_cmd.cpp.

Referenced by TileLoop_Water().

◆ _tile_type_water_procs

const TileTypeProcs _tile_type_water_procs
Initial value:
= {
DrawTile_Water,
GetSlopePixelZ_Water,
ClearTile_Water,
nullptr,
GetTileDesc_Water,
GetTileTrackStatus_Water,
ClickTile_Water,
nullptr,
ChangeTileOwner_Water,
nullptr,
VehicleEnter_Water,
GetFoundation_Water,
TerraformTile_Water,
}

Definition at line 54 of file landscape.cpp.

DIR_SW
@ DIR_SW
Southwest.
Definition: direction_type.h:31
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
DIR_S
@ DIR_S
South.
Definition: direction_type.h:30
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition: water_cmd.cpp:1231
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
DIR_SE
@ DIR_SE
Southeast.
Definition: direction_type.h:29
DIR_N
@ DIR_N
North.
Definition: direction_type.h:26