OpenTTD
tile_cmd.h
Go to the documentation of this file.
1 /* $Id: tile_cmd.h 26277 2014-01-26 13:50:10Z 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 
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];
65  uint16 rail_speed;
66  uint16 road_speed;
67 };
68 
73 typedef void DrawTileProc(TileInfo *ti);
74 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y);
75 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
76 
83 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *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);
113 typedef bool ClickTileProc(TileIndex tile);
114 typedef void AnimateTileProc(TileIndex tile);
115 typedef void TileLoopProc(TileIndex tile);
116 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
117 
120 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
121 
137 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
138 
145  GetSlopeZProc *get_slope_z_proc;
146  ClearTileProc *clear_tile_proc;
150  ClickTileProc *click_tile_proc;
151  AnimateTileProc *animate_tile_proc;
152  TileLoopProc *tile_loop_proc;
153  ChangeTileOwnerProc *change_tile_owner_proc;
156  GetFoundationProc *get_foundation_proc;
158 };
159 
160 extern const TileTypeProcs * const _tile_type_procs[16];
161 
162 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
164 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
165 void GetTileDesc(TileIndex tile, TileDesc *td);
166 
167 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
168 {
169  AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
170  if (proc == NULL) return;
171  uint32 dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
172  proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
173 }
174 
175 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
176 {
177  AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
178  if (proc == NULL) return;
179  proc(tile, produced);
180 }
181 
182 static inline void AnimateTile(TileIndex tile)
183 {
184  AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
185  assert(proc != NULL);
186  proc(tile);
187 }
188 
189 static inline bool ClickTile(TileIndex tile)
190 {
191  ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
192  if (proc == NULL) return false;
193  return proc(tile);
194 }
195 
196 #endif /* TILE_CMD_H */