OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
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 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
119 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
120 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
121
137 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
138
143 struct TileTypeProcs {
144 DrawTileProc *draw_tile_proc;
145 GetSlopeZProc *get_slope_z_proc;
146 ClearTileProc *clear_tile_proc;
147 AddAcceptedCargoProc *add_accepted_cargo_proc;
148 GetTileDescProc *get_tile_desc_proc;
149 GetTileTrackStatusProc *get_tile_track_status_proc;
150 ClickTileProc *click_tile_proc;
151 AnimateTileProc *animate_tile_proc;
152 TileLoopProc *tile_loop_proc;
153 ChangeTileOwnerProc *change_tile_owner_proc;
154 AddProducedCargoProc *add_produced_cargo_proc;
155 VehicleEnterTileProc *vehicle_enter_tile_proc;
156 GetFoundationProc *get_foundation_proc;
157 TerraformTileProc *terraform_tile_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);
163 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
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 */