OpenTTD Source: src/tile_cmd.h Source File

OpenTTD Source 15.3

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
10#ifndef TILE_CMD_H
11#define TILE_CMD_H
12
13#include "core/geometry_type.hpp"
14#include "command_type.h"
15#include "vehicle_type.h"
16#include "cargo_type.h"
17#include "track_type.h"
18#include "tile_map.h"
19#include "timer/timer_game_calendar.h"
20
21 enum class VehicleEnterTileState : uint8_t {
22 EnteredStation,
23 EnteredWormhole,
24 CannotEnter,
25};
26
27using VehicleEnterTileStates = EnumBitSet<VehicleEnterTileState, uint8_t>;
28
30 struct TileInfo : Coord3D<int> {
31 Slope tileh;
32 TileIndex tile;
33};
34
36 struct TileDesc {
37 StringID str{};
38 uint64_t dparam = 0;
39 std::array<Owner, 4> owner{};
40 std::array<StringID, 4> owner_type{};
41 TimerGameCalendar::Date build_date = CalendarTime::INVALID_DATE;
42 StringID station_class{};
43 StringID station_name{};
44 StringID airport_class{};
45 StringID airport_name{};
46 StringID airport_tile_name{};
47 std::optional<std::string> grf = std::nullopt;
48 StringID railtype{};
49 uint16_t rail_speed = 0;
50 StringID roadtype{};
51 uint16_t road_speed = 0;
52 StringID tramtype{};
53 uint16_t tram_speed = 0;
54 std::optional<bool> town_can_upgrade = std::nullopt;
55};
56
61 typedef void DrawTileProc(TileInfo *ti);
62
74 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y, bool ground_vehicle);
75typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlags flags);
76
83 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted);
84
90 typedef void GetTileDescProc(TileIndex tile, TileDesc &td);
91
105 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
106
112 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
113typedef bool ClickTileProc(TileIndex tile);
114typedef void AnimateTileProc(TileIndex tile);
115typedef void TileLoopProc(TileIndex tile);
116typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
117
118typedef VehicleEnterTileStates VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
119typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
120
136 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new);
137
146 using CheckBuildAboveProc = CommandCost(TileIndex tile, DoCommandFlags flags, Axis axis, int height);
147
152 struct TileTypeProcs {
153 DrawTileProc *draw_tile_proc;
154 GetSlopeZProc *get_slope_z_proc;
155 ClearTileProc *clear_tile_proc;
156 AddAcceptedCargoProc *add_accepted_cargo_proc;
157 GetTileDescProc *get_tile_desc_proc;
158 GetTileTrackStatusProc *get_tile_track_status_proc;
159 ClickTileProc *click_tile_proc;
160 AnimateTileProc *animate_tile_proc;
161 TileLoopProc *tile_loop_proc;
162 ChangeTileOwnerProc *change_tile_owner_proc;
163 AddProducedCargoProc *add_produced_cargo_proc;
164 VehicleEnterTileProc *vehicle_enter_tile_proc;
165 GetFoundationProc *get_foundation_proc;
166 TerraformTileProc *terraform_tile_proc;
167 CheckBuildAboveProc *check_build_above_proc;
168};
169
170extern const TileTypeProcs * const _tile_type_procs[16];
171
172TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
173 VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
174void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
175void GetTileDesc(TileIndex tile, TileDesc &td);
176
177inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
178{
179 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
180 if (proc == nullptr) return;
181 CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
182 proc(tile, acceptance, always_accepted == nullptr ? dummy : *always_accepted);
183}
184
185inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
186{
187 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
188 if (proc == nullptr) return;
189 proc(tile, produced);
190}
191
197 inline bool MayAnimateTile(TileIndex tile)
198{
199 return _tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr;
200}
201
202inline void AnimateTile(TileIndex tile)
203{
204 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
205 assert(proc != nullptr);
206 proc(tile);
207}
208
209inline bool ClickTile(TileIndex tile)
210{
211 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
212 if (proc == nullptr) return false;
213 return proc(tile);
214}
215
216#endif /* TILE_CMD_H */
cargo_type.h
Types related to cargoes...
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
TimerGameConst< struct Calendar >::INVALID_DATE
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
Representation of an invalid date.
Definition timer_game_common.h:193
command_type.h
Types related to commands.
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition direction_type.h:85
geometry_type.hpp
All geometry types in OpenTTD.
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
Coord3D
A coordinate with three dimensions.
Definition geometry_type.hpp:43
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileDesc
Tile description for the 'land area information' tool.
Definition tile_cmd.h:36
TileDesc::rail_speed
uint16_t rail_speed
Speed limit of rail (bridges and track)
Definition tile_cmd.h:49
TileDesc::grf
std::optional< std::string > grf
newGRF used for the tile contents
Definition tile_cmd.h:47
TileDesc::station_name
StringID station_name
Type of station within the class.
Definition tile_cmd.h:43
TileDesc::str
StringID str
Description of the tile.
Definition tile_cmd.h:37
TileDesc::build_date
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:41
TileDesc::owner
std::array< Owner, 4 > owner
Name of the owner(s)
Definition tile_cmd.h:39
TileDesc::dparam
uint64_t dparam
Parameter of the str string.
Definition tile_cmd.h:38
TileDesc::airport_class
StringID airport_class
Name of the airport class.
Definition tile_cmd.h:44
TileDesc::airport_name
StringID airport_name
Name of the airport.
Definition tile_cmd.h:45
TileDesc::tram_speed
uint16_t tram_speed
Speed limit of tram (bridges and track)
Definition tile_cmd.h:53
TileDesc::roadtype
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:50
TileDesc::tramtype
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:52
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:48
TileDesc::road_speed
uint16_t road_speed
Speed limit of road (bridges and track)
Definition tile_cmd.h:51
TileDesc::owner_type
std::array< StringID, 4 > owner_type
Type of each owner.
Definition tile_cmd.h:40
TileDesc::town_can_upgrade
std::optional< bool > town_can_upgrade
Whether the town can upgrade this house during town growth.
Definition tile_cmd.h:54
TileDesc::airport_tile_name
StringID airport_tile_name
Name of the airport tile.
Definition tile_cmd.h:46
TileDesc::station_class
StringID station_class
Class of station.
Definition tile_cmd.h:42
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition tile_cmd.h:31
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:32
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:152
TileTypeProcs::vehicle_enter_tile_proc
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition tile_cmd.h:164
TileTypeProcs::draw_tile_proc
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition tile_cmd.h:153
TileTypeProcs::add_accepted_cargo_proc
AddAcceptedCargoProc * add_accepted_cargo_proc
Adds accepted cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:156
TileTypeProcs::get_tile_desc_proc
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the 'land area information' tool)
Definition tile_cmd.h:157
TileTypeProcs::terraform_tile_proc
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition tile_cmd.h:166
TileTypeProcs::get_tile_track_status_proc
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition tile_cmd.h:158
TileTypeProcs::add_produced_cargo_proc
AddProducedCargoProc * add_produced_cargo_proc
Adds produced cargo of the tile to cargo array supplied as parameter.
Definition tile_cmd.h:163
TileTypeProcs::click_tile_proc
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition tile_cmd.h:159
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
VehicleEnterTileState
VehicleEnterTileState
Definition tile_cmd.h:21
VehicleEnterTileState::EnteredStation
@ EnteredStation
The vehicle entered a station.
VehicleEnterTileState::CannotEnter
@ CannotEnter
The vehicle cannot enter the tile.
VehicleEnterTileState::EnteredWormhole
@ EnteredWormhole
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
AddProducedCargoProc
void AddProducedCargoProc(TileIndex tile, CargoArray &produced)
Tile callback function signature for obtaining the produced cargo of a tile.
Definition tile_cmd.h:112
DrawTileProc
void DrawTileProc(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
Definition tile_cmd.h:61
VehicleEnterTile
VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition vehicle.cpp:1819
ChangeTileOwner
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition landscape.cpp:571
AddAcceptedCargoProc
void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Tile callback function signature for obtaining cargo acceptance of a tile.
Definition tile_cmd.h:83
GetSlopeZProc
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:74
GetTileTrackStatusProc
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:105
_tile_type_procs
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition landscape.cpp:69
CheckBuildAboveProc
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:146
TerraformTileProc
CommandCost TerraformTileProc(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
Definition tile_cmd.h:136
GetTileDescProc
void GetTileDescProc(TileIndex tile, TileDesc &td)
Tile callback function signature for obtaining a tile description.
Definition tile_cmd.h:90
MayAnimateTile
bool MayAnimateTile(TileIndex tile)
Test if a tile may be animated.
Definition tile_cmd.h:197
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
Returns information about trackdirs and signal states.
Definition landscape.cpp:560
tile_map.h
Map writing/reading functions for tiles.
GetTileType
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
timer_game_calendar.h
Definition of the game-calendar-timer.
track_type.h
All types related to tracks.
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
vehicle_type.h
Types related to vehicles.