OpenTTD
tile_cmd.h
Go to the documentation of this file.
1 /* $Id$ */
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 
26 
33  VETS_STATION_MASK = 0xFFFF << VETS_STATION_ID_OFFSET,
34 
40 };
42 
43 
44 struct TileInfo {
45  uint x;
46  uint y;
49  int z;
50 };
51 
53 struct TileDesc {
55  Owner owner[4];
63  const char *grf;
64  uint64 dparam[2];
66  uint16 rail_speed;
68  uint16 road_speed;
70  uint16 tram_speed;
71 };
72 
77 typedef void DrawTileProc(TileInfo *ti);
78 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y);
79 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
80 
87 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted);
88 
94 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
95 
109 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
110 
116 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
117 typedef bool ClickTileProc(TileIndex tile);
118 typedef void AnimateTileProc(TileIndex tile);
119 typedef void TileLoopProc(TileIndex tile);
120 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
121 
124 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
125 
141 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
142 
149  GetSlopeZProc *get_slope_z_proc;
150  ClearTileProc *clear_tile_proc;
154  ClickTileProc *click_tile_proc;
155  AnimateTileProc *animate_tile_proc;
156  TileLoopProc *tile_loop_proc;
157  ChangeTileOwnerProc *change_tile_owner_proc;
160  GetFoundationProc *get_foundation_proc;
162 };
163 
164 extern const TileTypeProcs * const _tile_type_procs[16];
165 
166 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
168 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
169 void GetTileDesc(TileIndex tile, TileDesc *td);
170 
171 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
172 {
173  AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
174  if (proc == nullptr) return;
175  CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
176  proc(tile, acceptance, always_accepted == nullptr ? &dummy : always_accepted);
177 }
178 
179 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
180 {
181  AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
182  if (proc == nullptr) return;
183  proc(tile, produced);
184 }
185 
186 static inline void AnimateTile(TileIndex tile)
187 {
188  AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
189  assert(proc != nullptr);
190  proc(tile);
191 }
192 
193 static inline bool ClickTile(TileIndex tile)
194 {
195  ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
196  if (proc == nullptr) return false;
197  return proc(tile);
198 }
199 
200 #endif /* TILE_CMD_H */
All types related to tracks.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:98
Owner
Enum for all companies/owners.
Definition: company_type.h:20
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition: landscape.cpp:62
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:63
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:47
StringID tramtype
Type of tram on the tile.
Definition: tile_cmd.h:69
Vehicle data structure.
Definition: vehicle_base.h:212
void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
Tile callback function signature for obtaining cargo acceptance of a tile.
Definition: tile_cmd.h:87
Tile description for the &#39;land area information&#39; tool.
Definition: tile_cmd.h:53
Flag for an invalid DiagDirection.
Common return value for all commands.
Definition: command_type.h:25
Types related to cargoes...
The vehicle entered a station.
Definition: tile_cmd.h:37
uint16 rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:66
int z
Height.
Definition: tile_cmd.h:49
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:55
Types related to commands.
AddAcceptedCargoProc * add_accepted_cargo_proc
Adds accepted cargo of the tile to cargo array supplied as parameter.
Definition: tile_cmd.h:151
GetTileTrackStatusProc * get_tile_track_status_proc
Get available tracks and status of a tile.
Definition: tile_cmd.h:153
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
Definition: tile_cmd.h:159
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:45
Foundation
Enumeration for Foundations.
Definition: slope_type.h:95
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition: landscape.cpp:602
TileIndex tile
Tile index.
Definition: tile_cmd.h:48
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:56
ClickTileProc * click_tile_proc
Called when tile is clicked.
Definition: tile_cmd.h:154
DoCommandFlag
List of flags for a command.
Definition: command_type.h:344
uint16 tram_speed
Speed limit of tram (bridges and track)
Definition: tile_cmd.h:70
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:38
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:24
AddProducedCargoProc * add_produced_cargo_proc
Adds produced cargo of the tile to cargo array supplied as parameter.
Definition: tile_cmd.h:158
Shift the VehicleEnterTileStatus this many bits to the right to get the station ID when VETS_ENTERED_...
Definition: tile_cmd.h:32
The vehicle cannot enter the tile.
Definition: tile_cmd.h:39
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:46
void DrawTileProc(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
Definition: tile_cmd.h:77
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:109
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition: vehicle.cpp:1679
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition: tile_cmd.h:161
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:65
StringID airport_tile_name
Name of the airport tile.
Definition: tile_cmd.h:62
void AddProducedCargoProc(TileIndex tile, CargoArray &produced)
Tile callback function signature for obtaining the produced cargo of a tile.
Definition: tile_cmd.h:116
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
StringID station_name
Type of station within the class.
Definition: tile_cmd.h:59
uint64 dparam[2]
Parameters of the str string.
Definition: tile_cmd.h:64
Class for storing amounts of cargo.
Definition: cargo_type.h:83
uint16 road_speed
Speed limit of road (bridges and track)
Definition: tile_cmd.h:68
VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y)
Definition: tile_cmd.h:123
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:147
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
The vehicle entered a station.
Definition: tile_cmd.h:23
Bit sets of the above specified bits.
Definition: tile_cmd.h:36
Types related to vehicles.
TransportType
Available types of transport.
StringID airport_name
Name of the airport.
Definition: tile_cmd.h:61
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:57
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side=INVALID_DIAGDIR)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:591
int32 Date
The type to store our dates in.
Definition: date_type.h:16
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
Definition: tile_cmd.h:148
StringID str
Description of the tile.
Definition: tile_cmd.h:54
DiagDirection
Enumeration for diagonal directions.
StringID station_class
Class of station.
Definition: tile_cmd.h:58
StringID roadtype
Type of road on the tile.
Definition: tile_cmd.h:67
CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
Definition: tile_cmd.h:141
The vehicle cannot enter the tile.
Definition: tile_cmd.h:25
Map writing/reading functions for tiles.
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:22
void GetTileDescProc(TileIndex tile, TileDesc *td)
Tile callback function signature for obtaining a tile description.
Definition: tile_cmd.h:94
StringID airport_class
Name of the airport class.
Definition: tile_cmd.h:60
GetTileDescProc * get_tile_desc_proc
Get a description of a tile (for the &#39;land area information&#39; tool)
Definition: tile_cmd.h:152