OpenTTD Source: src/tile_cmd.h Source File

OpenTTD Source 15.0-beta1

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"
18#include "timer/timer_game_calendar.h"
19
21 enum VehicleEnterTileStatus {
22 VETS_ENTERED_STATION = 1,
23 VETS_ENTERED_WORMHOLE = 2,
24 VETS_CANNOT_ENTER = 3,
25
31 VETS_STATION_ID_OFFSET = 8,
32 VETS_STATION_MASK = 0xFFFF << VETS_STATION_ID_OFFSET,
33
35 VETSB_CONTINUE = 0,
36 VETSB_ENTERED_STATION = 1 << VETS_ENTERED_STATION,
37 VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE,
38 VETSB_CANNOT_ENTER = 1 << VETS_CANNOT_ENTER,
39};
40 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus)
41
42
43struct TileInfo {
44 int x;
45 int y;
46 Slope tileh;
47 TileIndex tile;
48 int z;
49};
50
52 struct TileDesc {
53 StringID str;
54 uint64_t dparam;
55 Owner owner[4];
56 StringID owner_type[4];
57 TimerGameCalendar::Date build_date;
58 StringID station_class;
59 StringID station_name;
60 StringID airport_class;
61 StringID airport_name;
62 StringID airport_tile_name;
63 const char *grf;
64 StringID railtype;
65 uint16_t rail_speed;
66 StringID roadtype;
67 uint16_t road_speed;
68 StringID tramtype;
69 uint16_t tram_speed;
70};
71
76 typedef void DrawTileProc(TileInfo *ti);
77
89 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y, bool ground_vehicle);
90typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
91
98 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted);
99
105 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
106
120 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
121
127 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
128typedef bool ClickTileProc(TileIndex tile);
129typedef void AnimateTileProc(TileIndex tile);
130typedef void TileLoopProc(TileIndex tile);
131typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
132
134 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
135typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
136
152 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
153
158 struct TileTypeProcs {
159 DrawTileProc *draw_tile_proc;
160 GetSlopeZProc *get_slope_z_proc;
161 ClearTileProc *clear_tile_proc;
162 AddAcceptedCargoProc *add_accepted_cargo_proc;
163 GetTileDescProc *get_tile_desc_proc;
164 GetTileTrackStatusProc *get_tile_track_status_proc;
165 ClickTileProc *click_tile_proc;
166 AnimateTileProc *animate_tile_proc;
167 TileLoopProc *tile_loop_proc;
168 ChangeTileOwnerProc *change_tile_owner_proc;
169 AddProducedCargoProc *add_produced_cargo_proc;
170 VehicleEnterTileProc *vehicle_enter_tile_proc;
171 GetFoundationProc *get_foundation_proc;
172 TerraformTileProc *terraform_tile_proc;
173};
174
175extern const TileTypeProcs * const _tile_type_procs[16];
176
177TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
178 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
179void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
180void GetTileDesc(TileIndex tile, TileDesc *td);
181
182inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
183{
184 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
185 if (proc == nullptr) return;
186 CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
187 proc(tile, acceptance, always_accepted == nullptr ? dummy : *always_accepted);
188}
189
190inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
191{
192 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
193 if (proc == nullptr) return;
194 proc(tile, produced);
195}
196
202 inline bool MayAnimateTile(TileIndex tile)
203{
204 return _tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr;
205}
206
207inline void AnimateTile(TileIndex tile)
208{
209 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
210 assert(proc != nullptr);
211 proc(tile);
212}
213
214inline bool ClickTile(TileIndex tile)
215{
216 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
217 if (proc == nullptr) return false;
218 return proc(tile);
219}
220
221#endif /* TILE_CMD_H */
cargo_type.h
Types related to cargoes...
CommandCost
Common return value for all commands.
Definition command_type.h:23
command_type.h
Types related to commands.
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition command_type.h:374
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:73
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition direction_type.h:80
DECLARE_ENUM_AS_BIT_SET
#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:35
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:16
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:114
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:52
TileDesc::rail_speed
uint16_t rail_speed
Speed limit of rail (bridges and track)
Definition tile_cmd.h:65
TileDesc::station_name
StringID station_name
Type of station within the class.
Definition tile_cmd.h:59
TileDesc::str
StringID str
Description of the tile.
Definition tile_cmd.h:53
TileDesc::build_date
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:57
TileDesc::dparam
uint64_t dparam
Parameter of the str string.
Definition tile_cmd.h:54
TileDesc::airport_class
StringID airport_class
Name of the airport class.
Definition tile_cmd.h:60
TileDesc::airport_name
StringID airport_name
Name of the airport.
Definition tile_cmd.h:61
TileDesc::tram_speed
uint16_t tram_speed
Speed limit of tram (bridges and track)
Definition tile_cmd.h:69
TileDesc::roadtype
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:66
TileDesc::tramtype
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:68
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:64
TileDesc::road_speed
uint16_t road_speed
Speed limit of road (bridges and track)
Definition tile_cmd.h:67
TileDesc::grf
const char * grf
newGRF used for the tile contents
Definition tile_cmd.h:63
TileDesc::airport_tile_name
StringID airport_tile_name
Name of the airport tile.
Definition tile_cmd.h:62
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition tile_cmd.h:55
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition tile_cmd.h:56
TileDesc::station_class
StringID station_class
Class of station.
Definition tile_cmd.h:58
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:43
TileInfo::z
int z
Height.
Definition tile_cmd.h:48
TileInfo::x
int x
X position of the tile in unit coordinates.
Definition tile_cmd.h:44
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition tile_cmd.h:46
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:47
TileInfo::y
int y
Y position of the tile in unit coordinates.
Definition tile_cmd.h:45
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:158
TileTypeProcs::vehicle_enter_tile_proc
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition tile_cmd.h:170
TileTypeProcs::draw_tile_proc
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition tile_cmd.h:159
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:162
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:163
TileTypeProcs::terraform_tile_proc
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition tile_cmd.h:172
TileTypeProcs::get_tile_track_status_proc
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition tile_cmd.h:164
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:169
TileTypeProcs::click_tile_proc
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition tile_cmd.h:165
Vehicle
Vehicle data structure.
Definition vehicle_base.h:244
TerraformTileProc
CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
Definition tile_cmd.h:152
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition tile_cmd.h:21
VETS_CANNOT_ENTER
@ VETS_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition tile_cmd.h:24
VETS_ENTERED_WORMHOLE
@ 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
@ VETS_ENTERED_STATION
The vehicle entered a station.
Definition tile_cmd.h:22
VETSB_ENTERED_WORMHOLE
@ 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
@ VETSB_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition tile_cmd.h:38
VETS_STATION_ID_OFFSET
@ 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
@ VETSB_ENTERED_STATION
The vehicle entered a station.
Definition tile_cmd.h:36
VETSB_CONTINUE
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition tile_cmd.h:35
AddProducedCargoProc
void AddProducedCargoProc(TileIndex tile, CargoArray &produced)
Tile callback function signature for obtaining the produced cargo of a tile.
Definition tile_cmd.h:127
DrawTileProc
void DrawTileProc(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
Definition tile_cmd.h:76
GetTileDescProc
void GetTileDescProc(TileIndex tile, TileDesc *td)
Tile callback function signature for obtaining a tile description.
Definition tile_cmd.h:105
ChangeTileOwner
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition landscape.cpp:565
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:98
VehicleEnterTileProc
VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y)
Definition tile_cmd.h:134
VehicleEnterTile
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition vehicle.cpp:1838
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:89
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:120
_tile_type_procs
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition landscape.cpp:65
MayAnimateTile
bool MayAnimateTile(TileIndex tile)
Test if a tile may be animated.
Definition tile_cmd.h:202
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
Returns information about trackdirs and signal states.
Definition landscape.cpp:554
tile_map.h
Map writing/reading functions for tiles.
GetTileType
static debug_inline 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:19
vehicle_type.h
Types related to vehicles.