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