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/>.
10 /** @file tile_cmd.h Generic 'commands' that can be performed on all tiles. */
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 */
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
31 /** Tile description for the 'land area information' tool */
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
48 * Tile callback function signature for drawing a tile and its contents to the screen
49 * @param ti Information about the tile to draw
51 typedef void DrawTileProc(TileInfo
*ti
);
52 typedef int GetSlopeZProc(TileIndex tile
, uint x
, uint y
);
53 typedef CommandCost
ClearTileProc(TileIndex tile
, DoCommandFlag flags
);
56 * Tile callback function signature for obtaining cargo acceptance of a tile
57 * @param tile Tile queried for its accepted cargo
58 * @param acceptance Storage destination of the cargo acceptance in 1/8
59 * @param always_accepted Bitmask of always accepted cargo types
61 typedef void AddAcceptedCargoProc(TileIndex tile
, CargoArray
&acceptance
, uint32
*always_accepted
);
64 * Tile callback function signature for obtaining a tile description
65 * @param tile Tile being queried
66 * @param td Storage pointer for returned tile description
68 typedef void GetTileDescProc(TileIndex tile
, TileDesc
*td
);
71 * Tile callback function signature for getting the possible tracks
72 * that can be taken on a given tile by a train.
74 * The return value contains the existing trackdirs and signal states.
76 * see track_func.h for usage of TrackStatus.
78 * @param tile the tile to get the track status from
79 * @return the track status information
81 typedef TrackStatus
GetTileTrackStatusProc(TileIndex tile
, DiagDirection side
);
84 * Tile callback function signature for getting the possible tracks
85 * that can be taken on a given tile by a road vehicle.
87 * The return value contains the existing trackdirs and signal states.
89 * see track_func.h for usage of TrackStatus.
91 * @param tile the tile to get the track status from
92 * @param sub_mode used to differentiate between different kinds of transport
93 * @return the track status information
95 typedef TrackStatus
GetTileRoadStatusProc(TileIndex tile
, uint sub_mode
, DiagDirection side
);
98 * Tile callback function signature for getting the possible tracks
99 * that can be taken on a given tile by a ship.
101 * The return value contains the existing trackdirs.
103 * @param tile the tile to get the track status from
104 * @return the track status information
106 typedef TrackdirBits
GetTileWaterStatusProc(TileIndex tile
, DiagDirection side
);
109 * Tile callback function signature for obtaining the produced cargo of a tile.
110 * @param tile Tile being queried
111 * @param produced Destination array for produced cargo
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 typedef Foundation
GetFoundationProc(TileIndex tile
, Slope tileh
);
121 * Tile callback function signature of the terraforming callback.
123 * The function is called when a tile is affected by a terraforming operation.
124 * It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype.
125 * With DC_EXEC in \a flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).
127 * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
129 * @param tile The involved tile.
130 * @param flags Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.).
131 * @param z_new TileZ after terraforming.
132 * @param tileh_new Slope after terraforming.
133 * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
135 typedef CommandCost
TerraformTileProc(TileIndex tile
, DoCommandFlag flags
, int z_new
, Slope tileh_new
);
138 * Set of callback functions for performing tile operations of a given tile type.
141 struct TileTypeProcs
{
142 DrawTileProc
*draw_tile_proc
; ///< Called to render the tile and its contents to the screen
143 GetSlopeZProc
*get_slope_z_proc
;
144 ClearTileProc
*clear_tile_proc
;
145 AddAcceptedCargoProc
*add_accepted_cargo_proc
; ///< Adds accepted cargo of the tile to cargo array supplied as parameter
146 GetTileDescProc
*get_tile_desc_proc
; ///< Get a description of a tile (for the 'land area information' tool)
147 GetTileTrackStatusProc
*get_tile_railway_status_proc
; ///< Get available railway tracks and status of a tile
148 GetTileRoadStatusProc
*get_tile_road_status_proc
; ///< Get available road tracks and status of a tile
149 GetTileWaterStatusProc
*get_tile_waterway_status_proc
; ///< Get available waterway tracks and status of a tile
150 ClickTileProc
*click_tile_proc
; ///< Called when tile is clicked
151 AnimateTileProc
*animate_tile_proc
;
152 TileLoopProc
*tile_loop_proc
;
153 ChangeTileOwnerProc
*change_tile_owner_proc
;
154 AddProducedCargoProc
*add_produced_cargo_proc
; ///< Adds produced cargo of the tile to cargo array supplied as parameter
155 GetFoundationProc
*get_foundation_proc
;
156 TerraformTileProc
*terraform_tile_proc
; ///< Called when a terraforming operation is about to take place
159 static inline const TileTypeProcs
*GetTileProcs(TileIndex tile
)
161 extern const TileTypeProcs
* const _tile_type_procs
[16];
163 return _tile_type_procs
[GetTileType(tile
)];
166 TrackStatus
GetTileRailwayStatus(TileIndex tile
, DiagDirection side
= INVALID_DIAGDIR
);
167 TrackStatus
GetTileRoadStatus(TileIndex tile
, uint sub_mode
, DiagDirection side
= INVALID_DIAGDIR
);
168 TrackdirBits
GetTileWaterwayStatus(TileIndex tile
, DiagDirection side
= INVALID_DIAGDIR
);
170 void ChangeTileOwner(TileIndex tile
, Owner old_owner
, Owner new_owner
);
171 void GetTileDesc(TileIndex tile
, TileDesc
*td
);
173 static inline void AddAcceptedCargo(TileIndex tile
, CargoArray
&acceptance
, uint32
*always_accepted
)
175 AddAcceptedCargoProc
*proc
= GetTileProcs(tile
)->add_accepted_cargo_proc
;
176 if (proc
== NULL
) return;
177 uint32 dummy
= 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
178 proc(tile
, acceptance
, always_accepted
== NULL
? &dummy
: always_accepted
);
181 static inline void AddProducedCargo(TileIndex tile
, CargoArray
&produced
)
183 AddProducedCargoProc
*proc
= GetTileProcs(tile
)->add_produced_cargo_proc
;
184 if (proc
== NULL
) return;
185 proc(tile
, produced
);
188 static inline void AnimateTile(TileIndex tile
)
190 AnimateTileProc
*proc
= GetTileProcs(tile
)->animate_tile_proc
;
191 assert(proc
!= NULL
);
195 static inline bool ClickTile(TileIndex tile
)
197 ClickTileProc
*proc
= GetTileProcs(tile
)->click_tile_proc
;
198 if (proc
== NULL
) return false;
202 #endif /* TILE_CMD_H */