OpenTTD Source 20260621-master-g720d10536d
tile_cmd.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef TILE_CMD_H
11#define TILE_CMD_H
12
13#include "core/enum_type.hpp"
15#include "command_type.h"
16#include "road_type.h"
17#include "vehicle_type.h"
18#include "cargo_type.h"
19#include "track_type.h"
20#include "tile_map.h"
22
29
32
34struct TileInfo : Coord3D<int> {
37};
38
40struct TileDesc {
42 uint64_t dparam = 0;
43 std::array<Owner, 4> owner{};
44 std::array<StringID, 4> owner_type{};
51 std::optional<std::string> grf = std::nullopt;
53 uint16_t rail_speed = 0;
55 uint16_t road_speed = 0;
57 uint16_t tram_speed = 0;
58 std::optional<bool> town_can_upgrade = std::nullopt;
59};
60
65using DrawTileProc = void(TileInfo *ti);
66
78using GetSlopePixelZProc = int(TileIndex tile, uint x, uint y, bool ground_vehicle);
79
88
96using AddAcceptedCargoProc = void(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted);
97
104using GetTileDescProc = void(TileIndex tile, TileDesc &td);
105
122
129using AddProducedCargoProc = void(TileIndex tile, CargoArray &produced);
130
137using ClickTileProc = bool(TileIndex tile);
138
144using AnimateTileProc = void(TileIndex tile);
145
151using TileLoopProc = void(TileIndex tile);
152
160using ChangeTileOwnerProc = void(TileIndex tile, Owner old_owner, Owner new_owner);
161
172
180
197using TerraformTileProc = CommandCost(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new);
198
208using CheckBuildAboveProc = CommandCost(TileIndex tile, DoCommandFlags flags, Axis axis, int height);
209
231
233
236void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
237void GetTileDesc(TileIndex tile, TileDesc &td);
238
245inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
246{
247 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
248 if (proc == nullptr) return;
249 proc(tile, acceptance, always_accepted);
250}
251
257inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
258{
259 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
260 if (proc == nullptr) return;
261 proc(tile, produced);
262}
263
269inline bool MayAnimateTile(TileIndex tile)
270{
271 return _tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr;
272}
273
274inline void AnimateTile(TileIndex tile)
275{
276 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
277 assert(proc != nullptr);
278 proc(tile);
279}
280
281inline bool ClickTile(TileIndex tile)
282{
283 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
284 if (proc == nullptr) return false;
285 return proc(tile);
286}
287
288#endif /* TILE_CMD_H */
Types related to cargoes...
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
Definition cargo_type.h:113
Common return value for all commands.
Enum-as-bit-set wrapper.
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
Types related to commands.
EnumBitSet< DoCommandFlag, uint16_t > DoCommandFlags
Bitset of DoCommandFlag elements.
Axis
Enumeration for the two axis X and Y.
DiagDirection
Enumeration for diagonal directions.
@ Invalid
Flag for an invalid DiagDirection.
Type (helpers) for enums.
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
All geometry types in OpenTTD.
const EnumIndexArray< const TileTypeProcs *, TileType, TileType::MaxSize > _tile_type_procs
Tile callback functions for each type of tile.
Definition landscape.cpp:69
Enums and other types related to roads.
RoadTramType
The different types of road type.
Definition road_type.h:37
Slope
Enumeration for the slope-type.
Definition slope_type.h:53
Foundation
Enumeration for Foundations.
Definition slope_type.h:98
@ None
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:99
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class for storing amounts of cargo.
Definition cargo_type.h:118
Tile description for the 'land area information' tool.
Definition tile_cmd.h:40
uint16_t rail_speed
Speed limit of rail (bridges and track).
Definition tile_cmd.h:53
std::optional< std::string > grf
newGRF used for the tile contents
Definition tile_cmd.h:51
StringID station_name
Type of station within the class.
Definition tile_cmd.h:47
StringID str
Description of the tile.
Definition tile_cmd.h:41
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:45
std::array< Owner, 4 > owner
Name of the owner(s).
Definition tile_cmd.h:43
uint64_t dparam
Parameter of the str string.
Definition tile_cmd.h:42
StringID airport_class
Name of the airport class.
Definition tile_cmd.h:48
StringID airport_name
Name of the airport.
Definition tile_cmd.h:49
uint16_t tram_speed
Speed limit of tram (bridges and track).
Definition tile_cmd.h:57
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:54
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:56
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:52
uint16_t road_speed
Speed limit of road (bridges and track).
Definition tile_cmd.h:55
std::array< StringID, 4 > owner_type
Type of each owner.
Definition tile_cmd.h:44
std::optional< bool > town_can_upgrade
Whether the town can upgrade this house during town growth.
Definition tile_cmd.h:58
StringID airport_tile_name
Name of the airport tile.
Definition tile_cmd.h:50
StringID station_class
Class of station.
Definition tile_cmd.h:46
Tile information, used while rendering the tile.
Definition tile_cmd.h:34
Slope tileh
Slope of the tile.
Definition tile_cmd.h:35
TileIndex tile
Tile index.
Definition tile_cmd.h:36
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:214
TileLoopProc * tile_loop_proc
Called to periodically update the tile.
Definition tile_cmd.h:223
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition tile_cmd.h:226
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition tile_cmd.h:215
AddAcceptedCargoProc * add_accepted_cargo_proc
Adds accepted cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:218
GetSlopePixelZProc * get_slope_pixel_z_proc
Called to get the world Z coordinate for a given location within the tile.
Definition tile_cmd.h:216
ChangeTileOwnerProc * change_tile_owner_proc
Called to change the ownership of elements on a tile.
Definition tile_cmd.h:224
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the 'land area information' tool).
Definition tile_cmd.h:219
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition tile_cmd.h:228
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition tile_cmd.h:220
CheckBuildAboveProc * check_build_above_proc
Called to check whether a bridge can be build above.
Definition tile_cmd.h:229
AddProducedCargoProc * add_produced_cargo_proc
Adds produced cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:225
GetFoundationProc * get_foundation_proc
Called to get the foundation.
Definition tile_cmd.h:227
AnimateTileProc * animate_tile_proc
Called to animate a tile.
Definition tile_cmd.h:222
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition tile_cmd.h:221
Track status of a tile.
Definition track_type.h:105
Vehicle data structure.
void(TileIndex tile) TileLoopProc
Tile callback function signature for running periodic tile updates.
Definition tile_cmd.h:151
bool(TileIndex tile) ClickTileProc
Tile callback function signature for clicking a tile.
Definition tile_cmd.h:137
VehicleEnterTileState
Flags to describe several special states upon entering a tile.
Definition tile_cmd.h:24
@ EnteredStation
The vehicle entered a station.
Definition tile_cmd.h:25
@ CannotEnter
The vehicle cannot enter the tile.
Definition tile_cmd.h:27
@ EnteredWormhole
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition tile_cmd.h:26
Foundation(TileIndex tile, Slope tileh) GetFoundationProc
Tile callback function signature for getting the foundation of a tile.
Definition tile_cmd.h:179
VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition vehicle.cpp:1863
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, RoadTramType sub_mode, DiagDirection side=DiagDirection::Invalid)
Returns information about trackdirs and signal states.
void AddProducedCargo(TileIndex tile, CargoArray &produced)
Obtain the produced cargo of a tile.
Definition tile_cmd.h:257
CommandCost(TileIndex tile, DoCommandFlags flags) ClearTileProc
Tile callback function signature for clearing a tile.
Definition tile_cmd.h:87
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
void(TileInfo *ti) DrawTileProc
Tile callback function signature for drawing a tile and its contents to the screen.
Definition tile_cmd.h:65
void(TileIndex tile, CargoArray &produced) AddProducedCargoProc
Tile callback function signature for obtaining the produced cargo of a tile.
Definition tile_cmd.h:129
CommandCost(TileIndex tile, DoCommandFlags flags, Axis axis, int height) CheckBuildAboveProc
Tile callback function signature to test if a bridge can be built above a tile.
Definition tile_cmd.h:208
void(TileIndex tile) AnimateTileProc
Tile callback function signature for animating a tile.
Definition tile_cmd.h:144
void(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted) AddAcceptedCargoProc
Tile callback function signature for obtaining cargo acceptance of a tile.
Definition tile_cmd.h:96
void(TileIndex tile, TileDesc &td) GetTileDescProc
Tile callback function signature for obtaining a tile description.
Definition tile_cmd.h:104
void(TileIndex tile, Owner old_owner, Owner new_owner) ChangeTileOwnerProc
Tile callback function signature for changing the owner of a tile.
Definition tile_cmd.h:160
EnumBitSet< VehicleEnterTileState, uint8_t > VehicleEnterTileStates
Bitset of VehicleEnterTileState elements.
Definition tile_cmd.h:31
VehicleEnterTileStates(Vehicle *v, TileIndex tile, int x, int y) VehicleEnterTileProc
Tile callback function for a vehicle entering a tile.
Definition tile_cmd.h:171
bool MayAnimateTile(TileIndex tile)
Test if a tile may be animated.
Definition tile_cmd.h:269
TrackStatus(TileIndex tile, TransportType mode, RoadTramType sub_mode, DiagDirection side) GetTileTrackStatusProc
Tile callback function signature for getting the possible tracks that can be taken on a given tile by...
Definition tile_cmd.h:121
void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Obtain cargo acceptance of a tile.
Definition tile_cmd.h:245
int(TileIndex tile, uint x, uint y, bool ground_vehicle) GetSlopePixelZProc
Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
Definition tile_cmd.h:78
CommandCost(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new) TerraformTileProc
Tile callback function signature of the terraforming callback.
Definition tile_cmd.h:197
Map writing/reading functions for tiles.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
Definition of the game-calendar-timer.
All types related to tracks.
TransportType
Available types of transport.
Types related to vehicles.