OpenTTD Source 20260311-master-g511d3794ce
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 "vehicle_type.h"
17#include "cargo_type.h"
18#include "track_type.h"
19#include "tile_map.h"
21
28
29using VehicleEnterTileStates = EnumBitSet<VehicleEnterTileState, uint8_t>;
30
32struct TileInfo : Coord3D<int> {
35};
36
38struct TileDesc {
40 uint64_t dparam = 0;
41 std::array<Owner, 4> owner{};
42 std::array<StringID, 4> owner_type{};
43 TimerGameCalendar::Date build_date = CalendarTime::INVALID_DATE;
49 std::optional<std::string> grf = std::nullopt;
51 uint16_t rail_speed = 0;
53 uint16_t road_speed = 0;
55 uint16_t tram_speed = 0;
56 std::optional<bool> town_can_upgrade = std::nullopt;
57};
58
63using DrawTileProc = void(TileInfo *ti);
64
76using GetSlopePixelZProc = int(TileIndex tile, uint x, uint y, bool ground_vehicle);
77
85using ClearTileProc = CommandCost(TileIndex tile, DoCommandFlags flags);
86
94using AddAcceptedCargoProc = void(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted);
95
102using GetTileDescProc = void(TileIndex tile, TileDesc &td);
103
119using GetTileTrackStatusProc = TrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
120
127using AddProducedCargoProc = void(TileIndex tile, CargoArray &produced);
128
135using ClickTileProc = bool(TileIndex tile);
136
142using AnimateTileProc = void(TileIndex tile);
143
149using TileLoopProc = void(TileIndex tile);
150
158using ChangeTileOwnerProc = void(TileIndex tile, Owner old_owner, Owner new_owner);
159
169using VehicleEnterTileProc = VehicleEnterTileStates(Vehicle *v, TileIndex tile, int x, int y);
170
178
195using TerraformTileProc = CommandCost(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new);
196
206using CheckBuildAboveProc = CommandCost(TileIndex tile, DoCommandFlags flags, Axis axis, int height);
207
229
231
232TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
233VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
234void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
235void GetTileDesc(TileIndex tile, TileDesc &td);
236
243inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
244{
245 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
246 if (proc == nullptr) return;
247 proc(tile, acceptance, always_accepted);
248}
249
255inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
256{
257 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
258 if (proc == nullptr) return;
259 proc(tile, produced);
260}
261
267inline bool MayAnimateTile(TileIndex tile)
268{
269 return _tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr;
270}
271
272inline void AnimateTile(TileIndex tile)
273{
274 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
275 assert(proc != nullptr);
276 proc(tile);
277}
278
279inline bool ClickTile(TileIndex tile)
280{
281 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
282 if (proc == nullptr) return false;
283 return proc(tile);
284}
285
286#endif /* TILE_CMD_H */
Types related to cargoes...
Common return value for all commands.
Enum-as-bit-set wrapper.
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific enum class.
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
Types related to commands.
Axis
Allow incrementing of DiagDirDiff variables.
DiagDirection
Enumeration for diagonal directions.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Type (helpers) for enums.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
All geometry types in OpenTTD.
const EnumClassIndexContainer< std::array< const TileTypeProcs *, to_underlying(TileType::MaxSize)>, TileType > _tile_type_procs
Tile callback functions for each type of tile.
Definition landscape.cpp:69
Slope
Enumeration for the slope-type.
Definition slope_type.h:47
Foundation
Enumeration for Foundations.
Definition slope_type.h:92
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:93
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class for storing amounts of cargo.
Definition cargo_type.h:115
Tile description for the 'land area information' tool.
Definition tile_cmd.h:38
uint16_t rail_speed
Speed limit of rail (bridges and track).
Definition tile_cmd.h:51
std::optional< std::string > grf
newGRF used for the tile contents
Definition tile_cmd.h:49
StringID station_name
Type of station within the class.
Definition tile_cmd.h:45
StringID str
Description of the tile.
Definition tile_cmd.h:39
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:43
std::array< Owner, 4 > owner
Name of the owner(s).
Definition tile_cmd.h:41
uint64_t dparam
Parameter of the str string.
Definition tile_cmd.h:40
StringID airport_class
Name of the airport class.
Definition tile_cmd.h:46
StringID airport_name
Name of the airport.
Definition tile_cmd.h:47
uint16_t tram_speed
Speed limit of tram (bridges and track).
Definition tile_cmd.h:55
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:52
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:54
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:50
uint16_t road_speed
Speed limit of road (bridges and track).
Definition tile_cmd.h:53
std::array< StringID, 4 > owner_type
Type of each owner.
Definition tile_cmd.h:42
std::optional< bool > town_can_upgrade
Whether the town can upgrade this house during town growth.
Definition tile_cmd.h:56
StringID airport_tile_name
Name of the airport tile.
Definition tile_cmd.h:48
StringID station_class
Class of station.
Definition tile_cmd.h:44
Tile information, used while rendering the tile.
Definition tile_cmd.h:32
Slope tileh
Slope of the tile.
Definition tile_cmd.h:33
TileIndex tile
Tile index.
Definition tile_cmd.h:34
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:212
TileLoopProc * tile_loop_proc
Called to periodically update the tile.
Definition tile_cmd.h:221
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition tile_cmd.h:224
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition tile_cmd.h:213
AddAcceptedCargoProc * add_accepted_cargo_proc
Adds accepted cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:216
GetSlopePixelZProc * get_slope_pixel_z_proc
Called to get the world Z coordinate for a given location within the tile.
Definition tile_cmd.h:214
ChangeTileOwnerProc * change_tile_owner_proc
Called to change the ownership of elements on a tile.
Definition tile_cmd.h:222
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the 'land area information' tool).
Definition tile_cmd.h:217
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition tile_cmd.h:226
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition tile_cmd.h:218
CheckBuildAboveProc * check_build_above_proc
Called to check whether a bridge can be build above.
Definition tile_cmd.h:227
AddProducedCargoProc * add_produced_cargo_proc
Adds produced cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:223
GetFoundationProc * get_foundation_proc
Called to get the foundation.
Definition tile_cmd.h:225
AnimateTileProc * animate_tile_proc
Called to animate a tile.
Definition tile_cmd.h:220
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition tile_cmd.h:219
Vehicle data structure.
void(TileIndex tile) TileLoopProc
Tile callback function signature for running periodic tile updates.
Definition tile_cmd.h:149
TrackStatus(TileIndex tile, TransportType mode, uint 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:119
bool(TileIndex tile) ClickTileProc
Tile callback function signature for clicking a tile.
Definition tile_cmd.h:135
VehicleEnterTileState
Flags to describe several special states upon entering a tile.
Definition tile_cmd.h:23
@ EnteredStation
The vehicle entered a station.
Definition tile_cmd.h:24
@ CannotEnter
The vehicle cannot enter the tile.
Definition tile_cmd.h:26
@ EnteredWormhole
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition tile_cmd.h:25
Foundation(TileIndex tile, Slope tileh) GetFoundationProc
Tile callback function signature for getting the foundation of a tile.
Definition tile_cmd.h:177
VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition vehicle.cpp:1859
void AddProducedCargo(TileIndex tile, CargoArray &produced)
Obtain the produced cargo of a tile.
Definition tile_cmd.h:255
CommandCost(TileIndex tile, DoCommandFlags flags) ClearTileProc
Tile callback function signature for clearing a tile.
Definition tile_cmd.h:85
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:63
void(TileIndex tile, CargoArray &produced) AddProducedCargoProc
Tile callback function signature for obtaining the produced cargo of a tile.
Definition tile_cmd.h:127
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:206
void(TileIndex tile) AnimateTileProc
Tile callback function signature for animating a tile.
Definition tile_cmd.h:142
void(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted) AddAcceptedCargoProc
Tile callback function signature for obtaining cargo acceptance of a tile.
Definition tile_cmd.h:94
void(TileIndex tile, TileDesc &td) GetTileDescProc
Tile callback function signature for obtaining a tile description.
Definition tile_cmd.h:102
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:158
VehicleEnterTileStates(Vehicle *v, TileIndex tile, int x, int y) VehicleEnterTileProc
Tile callback function for a vehicle entering a tile.
Definition tile_cmd.h:169
bool MayAnimateTile(TileIndex tile)
Test if a tile may be animated.
Definition tile_cmd.h:267
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
Returns information about trackdirs and signal states.
void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Obtain cargo acceptance of a tile.
Definition tile_cmd.h:243
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:76
CommandCost(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new) TerraformTileProc
Tile callback function signature of the terraforming callback.
Definition tile_cmd.h:195
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
TileType
The different types of tiles.
Definition tile_type.h:48
@ MaxSize
The maximum possible number of tile types to be stored in map.
Definition tile_type.h:61
Definition of the game-calendar-timer.
All types related to tracks.
TransportType
Available types of transport.
Types related to vehicles.