OpenTTD Source 20250312-master-gcdcc6b491d
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 <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef TILE_CMD_H
11#define TILE_CMD_H
12
13#include "command_type.h"
14#include "vehicle_type.h"
15#include "cargo_type.h"
16#include "track_type.h"
17#include "tile_map.h"
19
41
42
43struct TileInfo {
44 int x;
45 int y;
48 int z;
49};
50
52struct TileDesc {
54 uint64_t dparam = 0;
55 std::array<Owner, 4> owner{};
56 std::array<StringID, 4> owner_type{};
63 const char *grf = nullptr;
65 uint16_t rail_speed = 0;
67 uint16_t road_speed = 0;
69 uint16_t tram_speed = 0;
70 std::optional<bool> town_can_upgrade = std::nullopt;
71};
72
77typedef void DrawTileProc(TileInfo *ti);
78
90typedef int GetSlopeZProc(TileIndex tile, uint x, uint y, bool ground_vehicle);
91typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlags flags);
92
99typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted);
100
106typedef void GetTileDescProc(TileIndex tile, TileDesc &td);
107
121typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
122
128typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
129typedef bool ClickTileProc(TileIndex tile);
130typedef void AnimateTileProc(TileIndex tile);
131typedef void TileLoopProc(TileIndex tile);
132typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
133
136typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
137
153typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new);
154
161 GetSlopeZProc *get_slope_z_proc;
162 ClearTileProc *clear_tile_proc;
166 ClickTileProc *click_tile_proc;
167 AnimateTileProc *animate_tile_proc;
168 TileLoopProc *tile_loop_proc;
169 ChangeTileOwnerProc *change_tile_owner_proc;
172 GetFoundationProc *get_foundation_proc;
174};
175
176extern const TileTypeProcs * const _tile_type_procs[16];
177
178TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
180void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
181void GetTileDesc(TileIndex tile, TileDesc &td);
182
183inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
184{
186 if (proc == nullptr) return;
187 CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
188 proc(tile, acceptance, always_accepted == nullptr ? dummy : *always_accepted);
189}
190
191inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
192{
194 if (proc == nullptr) return;
195 proc(tile, produced);
196}
197
203inline bool MayAnimateTile(TileIndex tile)
204{
205 return _tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr;
206}
207
208inline void AnimateTile(TileIndex tile)
209{
210 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
211 assert(proc != nullptr);
212 proc(tile);
213}
214
215inline bool ClickTile(TileIndex tile)
216{
217 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
218 if (proc == nullptr) return false;
219 return proc(tile);
220}
221
222#endif /* TILE_CMD_H */
Types related to cargoes...
Common return value for all commands.
Enum-as-bit-set wrapper.
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
Representation of an invalid date.
Types related to commands.
DiagDirection
Enumeration for diagonal directions.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:70
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Enumeration for Foundations.
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:113
Tile description for the 'land area information' tool.
Definition tile_cmd.h:52
uint16_t rail_speed
Speed limit of rail (bridges and track)
Definition tile_cmd.h:65
StringID station_name
Type of station within the class.
Definition tile_cmd.h:59
StringID str
Description of the tile.
Definition tile_cmd.h:53
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:57
std::array< Owner, 4 > owner
Name of the owner(s)
Definition tile_cmd.h:55
uint64_t dparam
Parameter of the str string.
Definition tile_cmd.h:54
StringID airport_class
Name of the airport class.
Definition tile_cmd.h:60
StringID airport_name
Name of the airport.
Definition tile_cmd.h:61
uint16_t tram_speed
Speed limit of tram (bridges and track)
Definition tile_cmd.h:69
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:66
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:68
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:64
uint16_t road_speed
Speed limit of road (bridges and track)
Definition tile_cmd.h:67
const char * grf
newGRF used for the tile contents
Definition tile_cmd.h:63
std::array< StringID, 4 > owner_type
Type of each owner.
Definition tile_cmd.h:56
std::optional< bool > town_can_upgrade
Whether the town can upgrade this house during town growth.
Definition tile_cmd.h:70
StringID airport_tile_name
Name of the airport tile.
Definition tile_cmd.h:62
StringID station_class
Class of station.
Definition tile_cmd.h:58
Tile information, used while rendering the tile.
Definition tile_cmd.h:43
int z
Height.
Definition tile_cmd.h:48
int x
X position of the tile in unit coordinates.
Definition tile_cmd.h:44
Slope tileh
Slope of the tile.
Definition tile_cmd.h:46
TileIndex tile
Tile index.
Definition tile_cmd.h:47
int y
Y position of the tile in unit coordinates.
Definition tile_cmd.h:45
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:159
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition tile_cmd.h:171
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition tile_cmd.h:160
AddAcceptedCargoProc * add_accepted_cargo_proc
Adds accepted cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:163
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the 'land area information' tool)
Definition tile_cmd.h:164
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition tile_cmd.h:173
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition tile_cmd.h:165
AddProducedCargoProc * add_produced_cargo_proc
Adds produced cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:170
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition tile_cmd.h:166
Vehicle data structure.
void AddProducedCargoProc(TileIndex tile, CargoArray &produced)
Tile callback function signature for obtaining the produced cargo of a tile.
Definition tile_cmd.h:128
void DrawTileProc(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
Definition tile_cmd.h:77
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Tile callback function signature for obtaining cargo acceptance of a tile.
Definition tile_cmd.h:99
VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y)
Definition tile_cmd.h:135
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition vehicle.cpp:1829
int GetSlopeZProc(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.
Definition tile_cmd.h:90
TrackStatus GetTileTrackStatusProc(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...
Definition tile_cmd.h:121
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition landscape.cpp:65
CommandCost TerraformTileProc(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
Definition tile_cmd.h:153
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition tile_cmd.h:21
@ VETS_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition tile_cmd.h:24
@ VETS_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition tile_cmd.h:23
@ VETS_ENTERED_STATION
The vehicle entered a station.
Definition tile_cmd.h:22
@ VETSB_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition tile_cmd.h:37
@ VETSB_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition tile_cmd.h:38
@ VETS_STATION_ID_OFFSET
Shift the VehicleEnterTileStatus this many bits to the right to get the station ID when VETS_ENTERED_...
Definition tile_cmd.h:31
@ VETSB_ENTERED_STATION
The vehicle entered a station.
Definition tile_cmd.h:36
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition tile_cmd.h:35
void GetTileDescProc(TileIndex tile, TileDesc &td)
Tile callback function signature for obtaining a tile description.
Definition tile_cmd.h:106
bool MayAnimateTile(TileIndex tile)
Test if a tile may be animated.
Definition tile_cmd.h:203
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
Returns information about trackdirs and signal states.
Map writing/reading functions for tiles.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
Definition of the game-calendar-timer.
All types related to tracks.
TransportType
Available types of transport.
Types related to vehicles.