OpenTTD

tile_cmd.h
Go to the documentation of this file.
1 /* $Id: tile_cmd.h 27686 2016-12-09 21:27:22Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef TILE_CMD_H
13 #define TILE_CMD_H
14
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"
20
22 enum VehicleEnterTileStatus {
23 VETS_ENTERED_STATION = 1,
24 VETS_ENTERED_WORMHOLE = 2,
25 VETS_CANNOT_ENTER = 3,
26
32 VETS_STATION_ID_OFFSET = 8,
33 VETS_STATION_MASK = 0xFFFF << VETS_STATION_ID_OFFSET,
34
36 VETSB_CONTINUE = 0,
37 VETSB_ENTERED_STATION = 1 << VETS_ENTERED_STATION,
38 VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE,
39 VETSB_CANNOT_ENTER = 1 << VETS_CANNOT_ENTER,
40 };
41 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus)
42
43
44 struct TileInfo {
45 uint x;
46 uint y;
47 Slope tileh;
48 TileIndex tile;
49 int z;
50 };
51
53 struct TileDesc {
54 StringID str;
55 Owner owner[4];
56 StringID owner_type[4];
57 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 uint64 dparam[2];
65 StringID railtype;
66 uint16 rail_speed;
67 uint16 road_speed;
68 };
69
74 typedef void DrawTileProc(TileInfo *ti);
75 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y);
76 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
77
84 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
85
91 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
92
106 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
107
113 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
114 typedef bool ClickTileProc(TileIndex tile);
115 typedef void AnimateTileProc(TileIndex tile);
116 typedef void TileLoopProc(TileIndex tile);
117 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
118
120 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
121 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
122
138 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
139
144 struct TileTypeProcs {
145 DrawTileProc *draw_tile_proc;
146 GetSlopeZProc *get_slope_z_proc;
147 ClearTileProc *clear_tile_proc;
148 AddAcceptedCargoProc *add_accepted_cargo_proc;
149 GetTileDescProc *get_tile_desc_proc;
150 GetTileTrackStatusProc *get_tile_track_status_proc;
151 ClickTileProc *click_tile_proc;
152 AnimateTileProc *animate_tile_proc;
153 TileLoopProc *tile_loop_proc;
154 ChangeTileOwnerProc *change_tile_owner_proc;
155 AddProducedCargoProc *add_produced_cargo_proc;
156 VehicleEnterTileProc *vehicle_enter_tile_proc;
157 GetFoundationProc *get_foundation_proc;
158 TerraformTileProc *terraform_tile_proc;
159 };
160
161 extern const TileTypeProcs * const _tile_type_procs[16];
162
163 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
164 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
165 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
166 void GetTileDesc(TileIndex tile, TileDesc *td);
167
168 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
169 {
170 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
171 if (proc == NULL) return;
172 uint32 dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
173 proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
174 }
175
176 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
177 {
178 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
179 if (proc == NULL) return;
180 proc(tile, produced);
181 }
182
183 static inline void AnimateTile(TileIndex tile)
184 {
185 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
186 assert(proc != NULL);
187 proc(tile);
188 }
189
190 static inline bool ClickTile(TileIndex tile)
191 {
192 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
193 if (proc == NULL) return false;
194 return proc(tile);
195 }
196
197 #endif /* TILE_CMD_H */
track_type.h
All types related to tracks.
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:89
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:31
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
_tile_type_procs
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition: landscape.cpp:61
INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:87
TileDesc::grf
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:63
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:47
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:212
TileDesc
Tile description for the &#39;land area information&#39; tool.
Definition: tile_cmd.h:53
CommandCost
Common return value for all commands.
Definition: command_type.h:25
cargo_type.h
Types related to cargoes...
VETSB_ENTERED_STATION
The vehicle entered a station.
Definition: tile_cmd.h:37
TileDesc::rail_speed
uint16 rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:66
TileInfo::z
int z
Height.
Definition: tile_cmd.h:49
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:55
command_type.h
Types related to commands.
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:148
TileTypeProcs::get_tile_track_status_proc
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition: tile_cmd.h:150
TileTypeProcs::vehicle_enter_tile_proc
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition: tile_cmd.h:156
TileInfo::x
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:45
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:95
ChangeTileOwner
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition: landscape.cpp:520
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:48
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:56
TileTypeProcs::click_tile_proc
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition: tile_cmd.h:151
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
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:38
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:24
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:155
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:32
VETSB_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition: tile_cmd.h:39
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:46
DrawTileProc
void DrawTileProc(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
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:106
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:1662
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:80
TileTypeProcs::terraform_tile_proc
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition: tile_cmd.h:158
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:65
TileDesc::airport_tile_name
StringID airport_tile_name
Name of the airport tile.
Definition: tile_cmd.h:62
AddProducedCargoProc
void AddProducedCargoProc(TileIndex tile, CargoArray &produced)
Tile callback function signature for obtaining the produced cargo of a tile.
Definition: tile_cmd.h:113
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
TileDesc::station_name
StringID station_name
Type of station within the class.
Definition: tile_cmd.h:59
TileDesc::dparam
uint64 dparam[2]
Parameters of the str string.
Definition: tile_cmd.h:64
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:74
TileDesc::road_speed
uint16 road_speed
Speed limit of road (bridges)
Definition: tile_cmd.h:67
VehicleEnterTileProc
VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y)
Definition: tile_cmd.h:120
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:144
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
VETS_ENTERED_STATION
The vehicle entered a station.
Definition: tile_cmd.h:23
VETSB_CONTINUE
Bit sets of the above specified bits.
Definition: tile_cmd.h:36
vehicle_type.h
Types related to vehicles.
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:21
TileDesc::airport_name
StringID airport_name
Name of the airport.
Definition: tile_cmd.h:61
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
TileDesc::build_date
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:57
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:509
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:16
TileTypeProcs::draw_tile_proc
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition: tile_cmd.h:145
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:54
TileDesc::station_class
StringID station_class
Class of station.
Definition: tile_cmd.h:58
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:138
VETS_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition: tile_cmd.h:25
tile_map.h
Map writing/reading functions for tiles.
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
AddAcceptedCargoProc
void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
Tile callback function signature for obtaining cargo acceptance of a tile.
Definition: tile_cmd.h:84
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:22
GetTileDescProc
void GetTileDescProc(TileIndex tile, TileDesc *td)
Tile callback function signature for obtaining a tile description.
Definition: tile_cmd.h:91
TileDesc::airport_class
StringID airport_class
Name of the airport class.
Definition: tile_cmd.h:60
TileTypeProcs::get_tile_desc_proc
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the &#39;land area information&#39; tool)
Definition: tile_cmd.h:149