Fix ICU iterators on leading/trailing whitespace
[openttd/fttd.git] / src / tile_cmd.h
blob20661217d4b178659ce45b6db0a8b4842e347316
1 /* $Id$ */
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 */
10 /** @file tile_cmd.h Generic 'commands' that can be performed on all tiles. */
12 #ifndef TILE_CMD_H
13 #define TILE_CMD_H
15 #include "command_type.h"
16 #include "vehicle_type.h"
17 #include "cargo_type.h"
18 #include "track_type.h"
19 #include "slope_type.h"
20 #include "map/class.h"
22 /** Tile information, used while rendering the tile */
23 struct TileInfo {
24 uint x; ///< X position of the tile in unit coordinates
25 uint y; ///< Y position of the tile in unit coordinates
26 Slope tileh; ///< Slope of the tile
27 TileIndex tile; ///< Tile index
28 int z; ///< Height
31 /** Tile description for the 'land area information' tool */
32 struct TileDesc {
33 StringID str; ///< Description of the tile
34 Owner owner[4]; ///< Name of the owner(s)
35 StringID owner_type[4]; ///< Type of each owner
36 Date build_date; ///< Date of construction of tile contents
37 StringID station_class; ///< Class of station
38 StringID station_name; ///< Type of station within the class
39 StringID airport_class; ///< Name of the airport class
40 StringID airport_name; ///< Name of the airport
41 StringID airport_tile_name; ///< Name of the airport tile
42 const char *grf; ///< newGRF used for the tile contents
43 uint64 dparam[2]; ///< Parameters of the \a str string
44 uint16 rail_speed; ///< Speed limit of rail (bridges and track)
45 uint16 road_speed; ///< Speed limit of road (bridges)
48 /**
49 * Tile callback function signature for drawing a tile and its contents to the screen
50 * @param ti Information about the tile to draw
52 typedef void DrawTileProc(TileInfo *ti);
53 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y);
54 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
56 /**
57 * Tile callback function signature for obtaining cargo acceptance of a tile
58 * @param tile Tile queried for its accepted cargo
59 * @param acceptance Storage destination of the cargo acceptance in 1/8
60 * @param always_accepted Bitmask of always accepted cargo types
62 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
64 /**
65 * Tile callback function signature for obtaining a tile description
66 * @param tile Tile being queried
67 * @param td Storage pointer for returned tile description
69 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
71 /**
72 * Tile callback function signature for getting the possible tracks
73 * that can be taken on a given tile by a train.
75 * The return value contains the existing trackdirs and signal states.
77 * see track_func.h for usage of TrackStatus.
79 * @param tile the tile to get the track status from
80 * @return the track status information
82 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, DiagDirection side);
84 /**
85 * Tile callback function signature for getting the possible tracks
86 * that can be taken on a given tile by a road vehicle.
88 * The return value contains the existing trackdirs and signal states.
90 * see track_func.h for usage of TrackStatus.
92 * @param tile the tile to get the track status from
93 * @param sub_mode used to differentiate between different kinds of transport
94 * @return the track status information
96 typedef TrackStatus GetTileRoadStatusProc(TileIndex tile, uint sub_mode, DiagDirection side);
98 /**
99 * Tile callback function signature for getting the possible tracks
100 * that can be taken on a given tile by a ship.
102 * The return value contains the existing trackdirs.
104 * @param tile the tile to get the track status from
105 * @return the track status information
107 typedef TrackdirBits GetTileWaterStatusProc(TileIndex tile, DiagDirection side);
110 * Tile callback function signature for obtaining the produced cargo of a tile.
111 * @param tile Tile being queried
112 * @param produced Destination array for produced cargo
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 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
122 * Tile callback function signature of the terraforming callback.
124 * The function is called when a tile is affected by a terraforming operation.
125 * It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype.
126 * With DC_EXEC in \a flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).
128 * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
130 * @param tile The involved tile.
131 * @param flags Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.).
132 * @param z_new TileZ after terraforming.
133 * @param tileh_new Slope after terraforming.
134 * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
136 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
139 * Set of callback functions for performing tile operations of a given tile type.
140 * @see TileType
142 struct TileTypeProcs {
143 DrawTileProc *draw_tile_proc; ///< Called to render the tile and its contents to the screen
144 GetSlopeZProc *get_slope_z_proc;
145 ClearTileProc *clear_tile_proc;
146 AddAcceptedCargoProc *add_accepted_cargo_proc; ///< Adds accepted cargo of the tile to cargo array supplied as parameter
147 GetTileDescProc *get_tile_desc_proc; ///< Get a description of a tile (for the 'land area information' tool)
148 GetTileTrackStatusProc *get_tile_railway_status_proc; ///< Get available railway tracks and status of a tile
149 GetTileRoadStatusProc *get_tile_road_status_proc; ///< Get available road tracks and status of a tile
150 GetTileWaterStatusProc *get_tile_waterway_status_proc; ///< Get available waterway tracks and status of a tile
151 ClickTileProc *click_tile_proc; ///< Called when tile is clicked
152 AnimateTileProc *animate_tile_proc;
153 TileLoopProc *tile_loop_proc;
154 ChangeTileOwnerProc *change_tile_owner_proc;
155 AddProducedCargoProc *add_produced_cargo_proc; ///< Adds produced cargo of the tile to cargo array supplied as parameter
156 GetFoundationProc *get_foundation_proc;
157 TerraformTileProc *terraform_tile_proc; ///< Called when a terraforming operation is about to take place
160 static inline const TileTypeProcs *GetTileProcs(TileIndex tile)
162 extern const TileTypeProcs * const _tile_type_procs[16];
164 return _tile_type_procs[GetTileType(tile)];
167 TrackStatus GetTileRailwayStatus(TileIndex tile, DiagDirection side = INVALID_DIAGDIR);
168 TrackStatus GetTileRoadStatus(TileIndex tile, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
169 TrackdirBits GetTileWaterwayStatus(TileIndex tile, DiagDirection side = INVALID_DIAGDIR);
171 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
172 void GetTileDesc(TileIndex tile, TileDesc *td);
174 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
176 AddAcceptedCargoProc *proc = GetTileProcs(tile)->add_accepted_cargo_proc;
177 if (proc == NULL) return;
178 uint32 dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
179 proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
182 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
184 AddProducedCargoProc *proc = GetTileProcs(tile)->add_produced_cargo_proc;
185 if (proc == NULL) return;
186 proc(tile, produced);
189 static inline void AnimateTile(TileIndex tile)
191 AnimateTileProc *proc = GetTileProcs(tile)->animate_tile_proc;
192 assert(proc != NULL);
193 proc(tile);
196 static inline bool ClickTile(TileIndex tile)
198 ClickTileProc *proc = GetTileProcs(tile)->click_tile_proc;
199 if (proc == NULL) return false;
200 return proc(tile);
203 #endif /* TILE_CMD_H */