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"
21 /** The returned bits of VehicleEnterTile. */
22 enum VehicleEnterTileStatus
{
23 VETS_ENTERED_STATION
= 1, ///< The vehicle entered a station
24 VETS_ENTERED_WORMHOLE
= 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
25 VETS_CANNOT_ENTER
= 3, ///< The vehicle cannot enter the tile
28 * Shift the VehicleEnterTileStatus this many bits
29 * to the right to get the station ID when
30 * VETS_ENTERED_STATION is set
32 VETS_STATION_ID_OFFSET
= 8,
33 VETS_STATION_MASK
= 0xFFFF << VETS_STATION_ID_OFFSET
,
35 /** Bit sets of the above specified bits */
36 VETSB_CONTINUE
= 0, ///< The vehicle can continue normally
37 VETSB_ENTERED_STATION
= 1 << VETS_ENTERED_STATION
, ///< The vehicle entered a station
38 VETSB_ENTERED_WORMHOLE
= 1 << VETS_ENTERED_WORMHOLE
, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
39 VETSB_CANNOT_ENTER
= 1 << VETS_CANNOT_ENTER
, ///< The vehicle cannot enter the tile
41 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus
)
43 /** Tile information, used while rendering the tile */
45 uint x
; ///< X position of the tile in unit coordinates
46 uint y
; ///< Y position of the tile in unit coordinates
47 Slope tileh
; ///< Slope of the tile
48 TileIndex tile
; ///< Tile index
52 /** Tile description for the 'land area information' tool */
54 StringID str
; ///< Description of the tile
55 Owner owner
[4]; ///< Name of the owner(s)
56 StringID owner_type
[4]; ///< Type of each owner
57 Date build_date
; ///< Date of construction of tile contents
58 StringID station_class
; ///< Class of station
59 StringID station_name
; ///< Type of station within the class
60 StringID airport_class
; ///< Name of the airport class
61 StringID airport_name
; ///< Name of the airport
62 StringID airport_tile_name
; ///< Name of the airport tile
63 const char *grf
; ///< newGRF used for the tile contents
64 uint64 dparam
[2]; ///< Parameters of the \a str string
65 StringID railtype
; ///< Type of rail on the tile.
66 uint16 rail_speed
; ///< Speed limit of rail (bridges and track)
67 uint16 road_speed
; ///< Speed limit of road (bridges)
71 * Tile callback function signature for drawing a tile and its contents to the screen
72 * @param ti Information about the tile to draw
74 typedef void DrawTileProc(TileInfo
*ti
);
75 typedef int GetSlopeZProc(TileIndex tile
, uint x
, uint y
);
76 typedef CommandCost
ClearTileProc(TileIndex tile
, DoCommandFlag flags
);
79 * Tile callback function signature for obtaining cargo acceptance of a tile
80 * @param tile Tile queried for its accepted cargo
81 * @param acceptance Storage destination of the cargo acceptance in 1/8
82 * @param always_accepted Bitmask of always accepted cargo types
84 typedef void AddAcceptedCargoProc(TileIndex tile
, CargoArray
&acceptance
, uint32
*always_accepted
);
87 * Tile callback function signature for obtaining a tile description
88 * @param tile Tile being queried
89 * @param td Storage pointer for returned tile description
91 typedef void GetTileDescProc(TileIndex tile
, TileDesc
*td
);
94 * Tile callback function signature for getting the possible tracks
95 * that can be taken on a given tile by a given transport.
97 * The return value contains the existing trackdirs and signal states.
99 * see track_func.h for usage of TrackStatus.
101 * @param tile the tile to get the track status from
102 * @param mode the mode of transportation
103 * @param sub_mode used to differentiate between different kinds within the mode
104 * @return the track status information
106 typedef TrackStatus
GetTileTrackStatusProc(TileIndex tile
, TransportType mode
, uint sub_mode
, 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
);
119 /** @see VehicleEnterTileStatus to see what the return values mean */
120 typedef VehicleEnterTileStatus
VehicleEnterTileProc(Vehicle
*v
, TileIndex tile
, int x
, int y
);
121 typedef Foundation
GetFoundationProc(TileIndex tile
, Slope tileh
);
124 * Tile callback function signature of the terraforming callback.
126 * The function is called when a tile is affected by a terraforming operation.
127 * It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype.
128 * With DC_EXEC in \a flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).
130 * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
132 * @param tile The involved tile.
133 * @param flags Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.).
134 * @param z_new TileZ after terraforming.
135 * @param tileh_new Slope after terraforming.
136 * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
138 typedef CommandCost
TerraformTileProc(TileIndex tile
, DoCommandFlag flags
, int z_new
, Slope tileh_new
);
141 * Set of callback functions for performing tile operations of a given tile type.
144 struct TileTypeProcs
{
145 DrawTileProc
*draw_tile_proc
; ///< Called to render the tile and its contents to the screen
146 GetSlopeZProc
*get_slope_z_proc
;
147 ClearTileProc
*clear_tile_proc
;
148 AddAcceptedCargoProc
*add_accepted_cargo_proc
; ///< Adds accepted cargo of the tile to cargo array supplied as parameter
149 GetTileDescProc
*get_tile_desc_proc
; ///< Get a description of a tile (for the 'land area information' tool)
150 GetTileTrackStatusProc
*get_tile_track_status_proc
; ///< Get available 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 VehicleEnterTileProc
*vehicle_enter_tile_proc
; ///< Called when a vehicle enters a tile
157 GetFoundationProc
*get_foundation_proc
;
158 TerraformTileProc
*terraform_tile_proc
; ///< Called when a terraforming operation is about to take place
161 extern const TileTypeProcs
* const _tile_type_procs
[16];
163 TrackStatus
GetTileTrackStatus(TileIndex tile
, TransportType mode
, uint sub_mode
, DiagDirection side
= INVALID_DIAGDIR
);
164 VehicleEnterTileStatus
VehicleEnterTile(Vehicle
*v
, TileIndex tile
, int x
, int y
);
165 void ChangeTileOwner(TileIndex tile
, Owner old_owner
, Owner new_owner
);
166 void GetTileDesc(TileIndex tile
, TileDesc
*td
);
168 static inline void AddAcceptedCargo(TileIndex tile
, CargoArray
&acceptance
, uint32
*always_accepted
)
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
);
176 static inline void AddProducedCargo(TileIndex tile
, CargoArray
&produced
)
178 AddProducedCargoProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->add_produced_cargo_proc
;
179 if (proc
== NULL
) return;
180 proc(tile
, produced
);
183 static inline void AnimateTile(TileIndex tile
)
185 AnimateTileProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->animate_tile_proc
;
186 assert(proc
!= NULL
);
190 static inline bool ClickTile(TileIndex tile
)
192 ClickTileProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->click_tile_proc
;
193 if (proc
== NULL
) return false;
197 #endif /* TILE_CMD_H */