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 
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;
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 
121 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
122 
138 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
139 
146  GetSlopeZProc *get_slope_z_proc;
147  ClearTileProc *clear_tile_proc;
151  ClickTileProc *click_tile_proc;
152  AnimateTileProc *animate_tile_proc;
153  TileLoopProc *tile_loop_proc;
154  ChangeTileOwnerProc *change_tile_owner_proc;
157  GetFoundationProc *get_foundation_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);
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 */