OpenTTD Source 20260311-master-g511d3794ce
tile_cmd.h File Reference

Generic 'commands' that can be performed on all tiles. More...

#include "core/enum_type.hpp"
#include "core/geometry_type.hpp"
#include "command_type.h"
#include "vehicle_type.h"
#include "cargo_type.h"
#include "track_type.h"
#include "tile_map.h"
#include "timer/timer_game_calendar.h"

Go to the source code of this file.

Data Structures

struct  TileInfo
 Tile information, used while rendering the tile. More...
struct  TileDesc
 Tile description for the 'land area information' tool. More...
struct  TileTypeProcs
 Set of callback functions for performing tile operations of a given tile type. More...

Typedefs

using VehicleEnterTileStates = EnumBitSet<VehicleEnterTileState, uint8_t>
using DrawTileProc = void(TileInfo *ti)
 Tile callback function signature for drawing a tile and its contents to the screen.
using GetSlopePixelZProc = int(TileIndex tile, uint x, uint y, bool ground_vehicle)
 Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
using ClearTileProc = CommandCost(TileIndex tile, DoCommandFlags flags)
 Tile callback function signature for clearing a tile.
using AddAcceptedCargoProc = void(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
 Tile callback function signature for obtaining cargo acceptance of a tile.
using GetTileDescProc = void(TileIndex tile, TileDesc &td)
 Tile callback function signature for obtaining a tile description.
using GetTileTrackStatusProc = TrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 Tile callback function signature for getting the possible tracks that can be taken on a given tile by a given transport.
using AddProducedCargoProc = void(TileIndex tile, CargoArray &produced)
 Tile callback function signature for obtaining the produced cargo of a tile.
using ClickTileProc = bool(TileIndex tile)
 Tile callback function signature for clicking a tile.
using AnimateTileProc = void(TileIndex tile)
 Tile callback function signature for animating a tile.
using TileLoopProc = void(TileIndex tile)
 Tile callback function signature for running periodic tile updates.
using ChangeTileOwnerProc = void(TileIndex tile, Owner old_owner, Owner new_owner)
 Tile callback function signature for changing the owner of a tile.
using VehicleEnterTileProc = VehicleEnterTileStates(Vehicle *v, TileIndex tile, int x, int y)
 Tile callback function for a vehicle entering a tile.
using GetFoundationProc = Foundation(TileIndex tile, Slope tileh)
 Tile callback function signature for getting the foundation of a tile.
using TerraformTileProc = CommandCost(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
 Tile callback function signature of the terraforming callback.
using CheckBuildAboveProc = CommandCost(TileIndex tile, DoCommandFlags flags, Axis axis, int height)
 Tile callback function signature to test if a bridge can be built above a tile.

Enumerations

enum class  VehicleEnterTileState : uint8_t { EnteredStation , EnteredWormhole , CannotEnter }
 Flags to describe several special states upon entering a tile. More...

Functions

TrackStatus GetTileTrackStatus (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
 Returns information about trackdirs and signal states.
VehicleEnterTileStates VehicleEnterTile (Vehicle *v, TileIndex tile, int x, int y)
 Call the tile callback function for a vehicle entering a tile.
void ChangeTileOwner (TileIndex tile, Owner old_owner, Owner new_owner)
 Change the owner of a tile.
void GetTileDesc (TileIndex tile, TileDesc &td)
void AddAcceptedCargo (TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
 Obtain cargo acceptance of a tile.
void AddProducedCargo (TileIndex tile, CargoArray &produced)
 Obtain the produced cargo of a tile.
bool MayAnimateTile (TileIndex tile)
 Test if a tile may be animated.
void AnimateTile (TileIndex tile)
bool ClickTile (TileIndex tile)

Variables

const EnumClassIndexContainer< std::array< const TileTypeProcs *, to_underlying(TileType::MaxSize)>, TileType_tile_type_procs
 Tile callback functions for each type of tile.

Detailed Description

Generic 'commands' that can be performed on all tiles.

Definition in file tile_cmd.h.

Typedef Documentation

◆ AddAcceptedCargoProc

using AddAcceptedCargoProc = void(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)

Tile callback function signature for obtaining cargo acceptance of a tile.

Parameters
tileTile queried for its accepted cargo
acceptanceStorage destination of the cargo acceptance in 1/8
always_acceptedBitmask of always accepted cargo types
See also
AddAcceptedCargo

Definition at line 94 of file tile_cmd.h.

◆ AddProducedCargoProc

using AddProducedCargoProc = void(TileIndex tile, CargoArray &produced)

Tile callback function signature for obtaining the produced cargo of a tile.

Parameters
tileTile being queried
producedDestination array for produced cargo
See also
AddProducedCargo

Definition at line 127 of file tile_cmd.h.

◆ AnimateTileProc

using AnimateTileProc = void(TileIndex tile)

Tile callback function signature for animating a tile.

Parameters
tileThe tile to animate.
See also
AnimateTile

Definition at line 142 of file tile_cmd.h.

◆ ChangeTileOwnerProc

using ChangeTileOwnerProc = void(TileIndex tile, Owner old_owner, Owner new_owner)

Tile callback function signature for changing the owner of a tile.

Parameters
tileThe tile to process.
old_ownerThe owner to replace.
new_ownerThe owner to replace with.
See also
ChangeTileOwner

Definition at line 158 of file tile_cmd.h.

◆ CheckBuildAboveProc

using CheckBuildAboveProc = CommandCost(TileIndex tile, DoCommandFlags flags, Axis axis, int height)

Tile callback function signature to test if a bridge can be built above a tile.

Parameters
tileThe involved tile.
flagsCommand flags passed to the build command.
axisAxis of bridge being built.
heightAbsolute height of bridge platform.
Returns
Error code or extra cost for building bridge above the tile.
See also
CheckBuildAbove

Definition at line 206 of file tile_cmd.h.

◆ ClearTileProc

using ClearTileProc = CommandCost(TileIndex tile, DoCommandFlags flags)

Tile callback function signature for clearing a tile.

Parameters
tileThe tile to clear.
flagsThe command flags.
Returns
The cost or error.
See also
ClearTile

Definition at line 85 of file tile_cmd.h.

◆ ClickTileProc

using ClickTileProc = bool(TileIndex tile)

Tile callback function signature for clicking a tile.

Parameters
tileThe tile that was clicked.
Returns
Whether any action was taken.
See also
ClickTile

Definition at line 135 of file tile_cmd.h.

◆ DrawTileProc

using DrawTileProc = void(TileInfo *ti)

Tile callback function signature for drawing a tile and its contents to the screen.

Parameters
tiInformation about the tile to draw

Definition at line 63 of file tile_cmd.h.

◆ GetFoundationProc

Tile callback function signature for getting the foundation of a tile.

Parameters
tileThe tile to check.
tilehThe current slope.
Returns
The foundation that will be used.

Definition at line 177 of file tile_cmd.h.

◆ GetSlopePixelZProc

using GetSlopePixelZProc = int(TileIndex tile, uint x, uint y, bool ground_vehicle)

Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.

Parameters
tileThe queries tile for the Z coordinate.
xWorld X coordinate in tile "units".
yWorld Y coordinate in tile "units".
ground_vehicleWhether to get the Z coordinate of the ground vehicle, or the ground.
Returns
World Z coordinate at tile ground (vehicle) level, including slopes and foundations.
See also
GetSlopePixelZ

Definition at line 76 of file tile_cmd.h.

◆ GetTileDescProc

using GetTileDescProc = void(TileIndex tile, TileDesc &td)

Tile callback function signature for obtaining a tile description.

Parameters
tileTile being queried
tdStorage pointer for returned tile description
See also
GetTileDesc

Definition at line 102 of file tile_cmd.h.

◆ GetTileTrackStatusProc

using GetTileTrackStatusProc = TrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)

Tile callback function signature for getting the possible tracks that can be taken on a given tile by a given transport.

The return value contains the existing trackdirs and signal states.

see track_func.h for usage of TrackStatus.

Parameters
tilethe tile to get the track status from
modethe mode of transportation
sub_modeused to differentiate between different kinds within the mode
sideThe side where the tile is entered.
Returns
the track status information
See also
GetTileTrackStatus

Definition at line 119 of file tile_cmd.h.

◆ TerraformTileProc

using TerraformTileProc = CommandCost(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)

Tile callback function signature of the terraforming callback.

The function is called when a tile is affected by a terraforming operation. It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype. With DoCommandFlag::Execute in flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).

Note
The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
Parameters
tileThe involved tile.
flagsCommand flags passed to the terraform command (DoCommandFlag::Execute, DoCommandFlag::QueryCost, etc.).
z_newTileZ after terraforming.
tileh_newSlope after terraforming.
Returns
Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
See also
TerraformTile

Definition at line 195 of file tile_cmd.h.

◆ TileLoopProc

using TileLoopProc = void(TileIndex tile)

Tile callback function signature for running periodic tile updates.

Parameters
tileThe tile to update.
See also
RunTileLoop

Definition at line 149 of file tile_cmd.h.

◆ VehicleEnterTileProc

using VehicleEnterTileProc = VehicleEnterTileStates(Vehicle *v, TileIndex tile, int x, int y)

Tile callback function for a vehicle entering a tile.

Parameters
vVehicle entering the tile.
tileTile entered.
xX position in world coordinates.
yY position in world coordinates.
Returns
Some meta-data over the to be entered tile.
See also
VehicleEnterTile

Definition at line 169 of file tile_cmd.h.

◆ VehicleEnterTileStates

using VehicleEnterTileStates = EnumBitSet<VehicleEnterTileState, uint8_t>

Definition at line 29 of file tile_cmd.h.

Enumeration Type Documentation

◆ VehicleEnterTileState

enum class VehicleEnterTileState : uint8_t
strong

Flags to describe several special states upon entering a tile.

Enumerator
EnteredStation 

The vehicle entered a station.

EnteredWormhole 

The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel).

CannotEnter 

The vehicle cannot enter the tile.

Definition at line 23 of file tile_cmd.h.

Function Documentation

◆ AddAcceptedCargo()

void AddAcceptedCargo ( TileIndex tile,
CargoArray & acceptance,
CargoTypes & always_accepted )
inline

Obtain cargo acceptance of a tile.

Parameters
tileTile queried for its accepted cargo.
acceptanceStorage destination of the cargo acceptance in 1/8.
always_acceptedBitmask of always accepted cargo types.

Definition at line 243 of file tile_cmd.h.

References _tile_type_procs, and GetTileType().

Referenced by FindSubsidyCargoDestination(), GetAcceptanceAroundStation(), GetAcceptanceAroundTiles(), and LandInfoWindow::OnInit().

◆ AddProducedCargo()

void AddProducedCargo ( TileIndex tile,
CargoArray & produced )
inline

Obtain the produced cargo of a tile.

Parameters
tileTile being queried.
producedDestination array for produced cargo.

Definition at line 255 of file tile_cmd.h.

References _tile_type_procs, and GetTileType().

Referenced by FindSubsidyTownCargoRoute(), and GetProductionAroundTiles().

◆ AnimateTile()

void AnimateTile ( TileIndex tile)
inline

Definition at line 272 of file tile_cmd.h.

◆ ChangeTileOwner()

void ChangeTileOwner ( TileIndex tile,
Owner old_owner,
Owner new_owner )

Change the owner of a tile.

Parameters
tileTile to change
old_ownerCurrent owner of the tile
new_ownerNew owner of the tile

Definition at line 577 of file landscape.cpp.

References _tile_type_procs, and GetTileType().

Referenced by AfterLoadGame(), ChangeOwnershipOfCompanyItems(), ChangeTileOwner_Object(), and ChangeTileOwner_Station().

◆ ClickTile()

bool ClickTile ( TileIndex tile)
inline

Definition at line 279 of file tile_cmd.h.

◆ GetTileDesc()

void GetTileDesc ( TileIndex tile,
TileDesc & td )

Definition at line 582 of file landscape.cpp.

◆ GetTileTrackStatus()

TrackStatus GetTileTrackStatus ( TileIndex tile,
TransportType mode,
uint sub_mode,
DiagDirection side )

Returns information about trackdirs and signal states.

If there is any trackbit at 'side', return all trackdirbits. For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.

Parameters
tiletile to get info about
modetransport type
sub_modefor TRANSPORT_ROAD, roadtypes to check
sideside we are entering from, INVALID_DIAGDIR to return all trackbits
Returns
trackdirbits and other info depending on 'mode'

Definition at line 566 of file landscape.cpp.

References _tile_type_procs, and GetTileType().

Referenced by AfterLoadGame(), CheckRoadBlockedForOvertaking(), CYapfFollowShipT< Types >::CheckShipReverse(), DisasterTick_Submarine(), FixOwnerOfRailTrack(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::Follow(), GenericPlaceSignals(), GetTrackdirBitsForRoad(), IsPossibleDockingTile(), MaskWireBits(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::QueryNewTileTrackStatus(), RoadFindPathToDest(), RoadVehicle::TileMayHaveSlopedTrack(), TrainCheckIfLineEnds(), TrainController(), TryPathReserve(), TryReserveRailTrack(), UnreserveRailTrack(), and UpdateSignalsInBuffer().

◆ MayAnimateTile()

bool MayAnimateTile ( TileIndex tile)
inline

Test if a tile may be animated.

Parameters
tileTile to test.
Returns
True iff the type of the tile has a handler for tile animation.

Definition at line 267 of file tile_cmd.h.

References _tile_type_procs, and GetTileType().

Referenced by AfterLoadGame().

◆ VehicleEnterTile()

VehicleEnterTileStates VehicleEnterTile ( Vehicle * v,
TileIndex tile,
int x,
int y )

Call the tile callback function for a vehicle entering a tile.

Parameters
vVehicle entering the tile
tileTile entered
xX position
yY position
Returns
Some meta-data over the to be entered tile.
See also
VehicleEnterTileStates to see what the bits in the return value mean.

Definition at line 1859 of file vehicle.cpp.

References _tile_type_procs, and GetTileType().

Referenced by TrainController(), and UpdateStatusAfterSwap().

Variable Documentation

◆ _tile_type_procs