2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file tile_cmd.h Generic 'commands' that can be performed on all tiles. */
13 #include "command_type.h"
14 #include "vehicle_type.h"
15 #include "cargo_type.h"
16 #include "track_type.h"
18 #include "timer/timer_game_calendar.h"
20 /** The returned bits of VehicleEnterTile. */
21 enum VehicleEnterTileStatus
{
22 VETS_ENTERED_STATION
= 1, ///< The vehicle entered a station
23 VETS_ENTERED_WORMHOLE
= 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
24 VETS_CANNOT_ENTER
= 3, ///< The vehicle cannot enter the tile
27 * Shift the VehicleEnterTileStatus this many bits
28 * to the right to get the station ID when
29 * VETS_ENTERED_STATION is set
31 VETS_STATION_ID_OFFSET
= 8,
32 VETS_STATION_MASK
= 0xFFFF << VETS_STATION_ID_OFFSET
,
34 /** Bit sets of the above specified bits */
35 VETSB_CONTINUE
= 0, ///< The vehicle can continue normally
36 VETSB_ENTERED_STATION
= 1 << VETS_ENTERED_STATION
, ///< The vehicle entered a station
37 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)
38 VETSB_CANNOT_ENTER
= 1 << VETS_CANNOT_ENTER
, ///< The vehicle cannot enter the tile
40 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus
)
42 /** Tile information, used while rendering the tile */
44 int x
; ///< X position of the tile in unit coordinates
45 int y
; ///< Y position of the tile in unit coordinates
46 Slope tileh
; ///< Slope of the tile
47 TileIndex tile
; ///< Tile index
51 /** Tile description for the 'land area information' tool */
53 StringID str
; ///< Description of the tile
54 uint64_t dparam
; ///< Parameter of the \a str string
55 Owner owner
[4]; ///< Name of the owner(s)
56 StringID owner_type
[4]; ///< Type of each owner
57 TimerGameCalendar::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 StringID railtype
; ///< Type of rail on the tile.
65 uint16_t rail_speed
; ///< Speed limit of rail (bridges and track)
66 StringID roadtype
; ///< Type of road on the tile.
67 uint16_t road_speed
; ///< Speed limit of road (bridges and track)
68 StringID tramtype
; ///< Type of tram on the tile.
69 uint16_t tram_speed
; ///< Speed limit of tram (bridges and track)
73 * Tile callback function signature for drawing a tile and its contents to the screen
74 * @param ti Information about the tile to draw
76 typedef void DrawTileProc(TileInfo
*ti
);
79 * Tile callback function signature for obtaining the world \c Z coordinate of a given
82 * @param tile The queries tile for the Z coordinate.
83 * @param x World X coordinate in tile "units".
84 * @param y World Y coordinate in tile "units".
85 * @param ground_vehicle Whether to get the Z coordinate of the ground vehicle, or the ground.
86 * @return World Z coordinate at tile ground (vehicle) level, including slopes and foundations.
89 typedef int GetSlopeZProc(TileIndex tile
, uint x
, uint y
, bool ground_vehicle
);
90 typedef CommandCost
ClearTileProc(TileIndex tile
, DoCommandFlag flags
);
93 * Tile callback function signature for obtaining cargo acceptance of a tile
94 * @param tile Tile queried for its accepted cargo
95 * @param acceptance Storage destination of the cargo acceptance in 1/8
96 * @param always_accepted Bitmask of always accepted cargo types
98 typedef void AddAcceptedCargoProc(TileIndex tile
, CargoArray
&acceptance
, CargoTypes
&always_accepted
);
101 * Tile callback function signature for obtaining a tile description
102 * @param tile Tile being queried
103 * @param td Storage pointer for returned tile description
105 typedef void GetTileDescProc(TileIndex tile
, TileDesc
*td
);
108 * Tile callback function signature for getting the possible tracks
109 * that can be taken on a given tile by a given transport.
111 * The return value contains the existing trackdirs and signal states.
113 * see track_func.h for usage of TrackStatus.
115 * @param tile the tile to get the track status from
116 * @param mode the mode of transportation
117 * @param sub_mode used to differentiate between different kinds within the mode
118 * @return the track status information
120 typedef TrackStatus
GetTileTrackStatusProc(TileIndex tile
, TransportType mode
, uint sub_mode
, DiagDirection side
);
123 * Tile callback function signature for obtaining the produced cargo of a tile.
124 * @param tile Tile being queried
125 * @param produced Destination array for produced cargo
127 typedef void AddProducedCargoProc(TileIndex tile
, CargoArray
&produced
);
128 typedef bool ClickTileProc(TileIndex tile
);
129 typedef void AnimateTileProc(TileIndex tile
);
130 typedef void TileLoopProc(TileIndex tile
);
131 typedef void ChangeTileOwnerProc(TileIndex tile
, Owner old_owner
, Owner new_owner
);
133 /** @see VehicleEnterTileStatus to see what the return values mean */
134 typedef VehicleEnterTileStatus
VehicleEnterTileProc(Vehicle
*v
, TileIndex tile
, int x
, int y
);
135 typedef Foundation
GetFoundationProc(TileIndex tile
, Slope tileh
);
138 * Tile callback function signature of the terraforming callback.
140 * The function is called when a tile is affected by a terraforming operation.
141 * It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype.
142 * With DC_EXEC in \a flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).
144 * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
146 * @param tile The involved tile.
147 * @param flags Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.).
148 * @param z_new TileZ after terraforming.
149 * @param tileh_new Slope after terraforming.
150 * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
152 typedef CommandCost
TerraformTileProc(TileIndex tile
, DoCommandFlag flags
, int z_new
, Slope tileh_new
);
155 * Set of callback functions for performing tile operations of a given tile type.
158 struct TileTypeProcs
{
159 DrawTileProc
*draw_tile_proc
; ///< Called to render the tile and its contents to the screen
160 GetSlopeZProc
*get_slope_z_proc
;
161 ClearTileProc
*clear_tile_proc
;
162 AddAcceptedCargoProc
*add_accepted_cargo_proc
; ///< Adds accepted cargo of the tile to cargo array supplied as parameter
163 GetTileDescProc
*get_tile_desc_proc
; ///< Get a description of a tile (for the 'land area information' tool)
164 GetTileTrackStatusProc
*get_tile_track_status_proc
; ///< Get available tracks and status of a tile
165 ClickTileProc
*click_tile_proc
; ///< Called when tile is clicked
166 AnimateTileProc
*animate_tile_proc
;
167 TileLoopProc
*tile_loop_proc
;
168 ChangeTileOwnerProc
*change_tile_owner_proc
;
169 AddProducedCargoProc
*add_produced_cargo_proc
; ///< Adds produced cargo of the tile to cargo array supplied as parameter
170 VehicleEnterTileProc
*vehicle_enter_tile_proc
; ///< Called when a vehicle enters a tile
171 GetFoundationProc
*get_foundation_proc
;
172 TerraformTileProc
*terraform_tile_proc
; ///< Called when a terraforming operation is about to take place
175 extern const TileTypeProcs
* const _tile_type_procs
[16];
177 TrackStatus
GetTileTrackStatus(TileIndex tile
, TransportType mode
, uint sub_mode
, DiagDirection side
= INVALID_DIAGDIR
);
178 VehicleEnterTileStatus
VehicleEnterTile(Vehicle
*v
, TileIndex tile
, int x
, int y
);
179 void ChangeTileOwner(TileIndex tile
, Owner old_owner
, Owner new_owner
);
180 void GetTileDesc(TileIndex tile
, TileDesc
*td
);
182 inline void AddAcceptedCargo(TileIndex tile
, CargoArray
&acceptance
, CargoTypes
*always_accepted
)
184 AddAcceptedCargoProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->add_accepted_cargo_proc
;
185 if (proc
== nullptr) return;
186 CargoTypes dummy
= 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
187 proc(tile
, acceptance
, always_accepted
== nullptr ? dummy
: *always_accepted
);
190 inline void AddProducedCargo(TileIndex tile
, CargoArray
&produced
)
192 AddProducedCargoProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->add_produced_cargo_proc
;
193 if (proc
== nullptr) return;
194 proc(tile
, produced
);
197 inline void AnimateTile(TileIndex tile
)
199 AnimateTileProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->animate_tile_proc
;
200 assert(proc
!= nullptr);
204 inline bool ClickTile(TileIndex tile
)
206 ClickTileProc
*proc
= _tile_type_procs
[GetTileType(tile
)]->click_tile_proc
;
207 if (proc
== nullptr) return false;
211 #endif /* TILE_CMD_H */