2009-08-21 20:21:05 +00:00
/*
* This file is part of OpenTTD .
* 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.
* 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 .
* 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/>.
*/
2007-12-21 22:50:51 +00:00
/** @file tile_cmd.h Generic 'commands' that can be performed on all tiles. */
# ifndef TILE_CMD_H
# define TILE_CMD_H
# include "command_type.h"
# include "vehicle_type.h"
# include "cargo_type.h"
2008-02-20 17:49:50 +00:00
# include "track_type.h"
2009-06-25 19:23:09 +00:00
# include "tile_map.h"
2023-04-24 18:33:18 +00:00
# include "timer/timer_game_calendar.h"
2007-12-21 22:50:51 +00:00
/** The returned bits of VehicleEnterTile. */
enum VehicleEnterTileStatus {
VETS_ENTERED_STATION = 1 , ///< The vehicle entered a station
VETS_ENTERED_WORMHOLE = 2 , ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
VETS_CANNOT_ENTER = 3 , ///< The vehicle cannot enter the tile
/**
* Shift the VehicleEnterTileStatus this many bits
* to the right to get the station ID when
* VETS_ENTERED_STATION is set
*/
VETS_STATION_ID_OFFSET = 8 ,
2008-01-21 23:55:57 +00:00
VETS_STATION_MASK = 0xFFFF < < VETS_STATION_ID_OFFSET ,
2007-12-21 22:50:51 +00:00
/** Bit sets of the above specified bits */
VETSB_CONTINUE = 0 , ///< The vehicle can continue normally
VETSB_ENTERED_STATION = 1 < < VETS_ENTERED_STATION , ///< The vehicle entered a station
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)
VETSB_CANNOT_ENTER = 1 < < VETS_CANNOT_ENTER , ///< The vehicle cannot enter the tile
} ;
2010-03-23 22:25:43 +00:00
DECLARE_ENUM_AS_BIT_SET ( VehicleEnterTileStatus )
2007-12-21 22:50:51 +00:00
2008-10-19 15:39:12 +00:00
/** Tile information, used while rendering the tile */
2007-12-25 23:42:52 +00:00
struct TileInfo {
2023-01-28 09:53:42 +00:00
int x ; ///< X position of the tile in unit coordinates
int y ; ///< Y position of the tile in unit coordinates
2008-10-19 15:39:12 +00:00
Slope tileh ; ///< Slope of the tile
TileIndex tile ; ///< Tile index
2011-11-04 11:30:37 +00:00
int z ; ///< Height
2007-12-25 23:42:52 +00:00
} ;
2008-10-19 15:39:12 +00:00
/** Tile description for the 'land area information' tool */
2007-12-25 23:42:52 +00:00
struct TileDesc {
2010-02-22 14:17:17 +00:00
StringID str ; ///< Description of the tile
2023-06-11 19:16:16 +00:00
uint64_t dparam ; ///< Parameter of the \a str string
2010-02-22 14:17:17 +00:00
Owner owner [ 4 ] ; ///< Name of the owner(s)
StringID owner_type [ 4 ] ; ///< Type of each owner
2023-04-24 18:33:18 +00:00
TimerGameCalendar : : Date build_date ; ///< Date of construction of tile contents
2010-02-22 14:17:17 +00:00
StringID station_class ; ///< Class of station
StringID station_name ; ///< Type of station within the class
2010-09-01 23:14:15 +00:00
StringID airport_class ; ///< Name of the airport class
StringID airport_name ; ///< Name of the airport
2010-02-22 14:17:17 +00:00
StringID airport_tile_name ; ///< Name of the airport tile
const char * grf ; ///< newGRF used for the tile contents
2016-12-09 21:27:22 +00:00
StringID railtype ; ///< Type of rail on the tile.
2023-05-08 17:01:06 +00:00
uint16_t rail_speed ; ///< Speed limit of rail (bridges and track)
2019-04-06 06:46:15 +00:00
StringID roadtype ; ///< Type of road on the tile.
2023-05-08 17:01:06 +00:00
uint16_t road_speed ; ///< Speed limit of road (bridges and track)
2019-04-06 06:46:15 +00:00
StringID tramtype ; ///< Type of tram on the tile.
2023-05-08 17:01:06 +00:00
uint16_t tram_speed ; ///< Speed limit of tram (bridges and track)
2007-12-25 23:42:52 +00:00
} ;
2008-10-19 15:39:12 +00:00
/**
* Tile callback function signature for drawing a tile and its contents to the screen
* @ param ti Information about the tile to draw
*/
2007-12-21 22:50:51 +00:00
typedef void DrawTileProc ( TileInfo * ti ) ;
2023-03-12 17:14:44 +00:00
/**
* Tile callback function signature for obtaining the world \ c Z coordinate of a given
* point of a tile .
*
* @ param tile The queries tile for the Z coordinate .
* @ param x World X coordinate in tile " units " .
* @ param y World Y coordinate in tile " units " .
* @ param ground_vehicle Whether to get the Z coordinate of the ground vehicle , or the ground .
* @ return World Z coordinate at tile ground ( vehicle ) level , including slopes and foundations .
* @ see GetSlopePixelZ
*/
typedef int GetSlopeZProc ( TileIndex tile , uint x , uint y , bool ground_vehicle ) ;
2009-02-09 21:20:05 +00:00
typedef CommandCost ClearTileProc ( TileIndex tile , DoCommandFlag flags ) ;
2008-10-19 15:39:12 +00:00
/**
2009-06-27 18:26:50 +00:00
* Tile callback function signature for obtaining cargo acceptance of a tile
2009-09-20 17:44:33 +00:00
* @ param tile Tile queried for its accepted cargo
* @ param acceptance Storage destination of the cargo acceptance in 1 / 8
2009-09-20 18:52:12 +00:00
* @ param always_accepted Bitmask of always accepted cargo types
2008-10-19 15:39:12 +00:00
*/
2018-05-21 21:08:39 +00:00
typedef void AddAcceptedCargoProc ( TileIndex tile , CargoArray & acceptance , CargoTypes * always_accepted ) ;
2008-10-19 15:39:12 +00:00
/**
* Tile callback function signature for obtaining a tile description
* @ param tile Tile being queried
* @ param td Storage pointer for returned tile description
*/
2007-12-21 22:50:51 +00:00
typedef void GetTileDescProc ( TileIndex tile , TileDesc * td ) ;
/**
2008-10-19 15:39:12 +00:00
* Tile callback function signature for getting the possible tracks
2008-02-20 17:49:50 +00:00
* that can be taken on a given tile by a given transport .
2008-10-19 15:39:12 +00:00
*
2008-02-20 17:49:50 +00:00
* The return value contains the existing trackdirs and signal states .
2007-12-21 22:50:51 +00:00
*
2008-02-20 17:49:50 +00:00
* see track_func . h for usage of TrackStatus .
2007-12-21 22:50:51 +00:00
*
* @ param tile the tile to get the track status from
* @ param mode the mode of transportation
* @ param sub_mode used to differentiate between different kinds within the mode
2008-02-20 17:49:50 +00:00
* @ return the track status information
2007-12-21 22:50:51 +00:00
*/
2008-02-20 17:49:50 +00:00
typedef TrackStatus GetTileTrackStatusProc ( TileIndex tile , TransportType mode , uint sub_mode , DiagDirection side ) ;
2008-10-19 15:39:12 +00:00
/**
* Tile callback function signature for obtaining the produced cargo of a tile .
2009-06-27 18:26:50 +00:00
* @ param tile Tile being queried
* @ param produced Destination array for produced cargo
2008-10-19 15:39:12 +00:00
*/
2009-06-27 21:06:58 +00:00
typedef void AddProducedCargoProc ( TileIndex tile , CargoArray & produced ) ;
2009-01-02 22:42:05 +00:00
typedef bool ClickTileProc ( TileIndex tile ) ;
2007-12-21 22:50:51 +00:00
typedef void AnimateTileProc ( TileIndex tile ) ;
typedef void TileLoopProc ( TileIndex tile ) ;
2008-09-30 20:39:50 +00:00
typedef void ChangeTileOwnerProc ( TileIndex tile , Owner old_owner , Owner new_owner ) ;
2007-12-21 22:50:51 +00:00
/** @see VehicleEnterTileStatus to see what the return values mean */
typedef VehicleEnterTileStatus VehicleEnterTileProc ( Vehicle * v , TileIndex tile , int x , int y ) ;
typedef Foundation GetFoundationProc ( TileIndex tile , Slope tileh ) ;
/**
2008-10-19 15:39:12 +00:00
* Tile callback function signature of the terraforming callback .
*
* The function is called when a tile is affected by a terraforming operation .
* It has to check if terraforming of the tile is allowed and return extra terraform - cost that depend on the tiletype .
* With DC_EXEC in \ a flags it has to perform tiletype - specific actions ( like clearing land etc . , but not the terraforming itself ) .
2007-12-21 22:50:51 +00:00
*
* @ note The terraforming has not yet taken place . So GetTileZ ( ) and GetTileSlope ( ) refer to the landscape before the terraforming operation .
*
* @ param tile The involved tile .
* @ param flags Command flags passed to the terraform command ( DC_EXEC , DC_QUERY_COST , etc . ) .
* @ param z_new TileZ after terraforming .
* @ param tileh_new Slope after terraforming .
* @ return Error code or extra cost for terraforming ( like clearing land , building foundations , etc . , but not the terraforming itself . )
*/
2011-11-04 11:36:10 +00:00
typedef CommandCost TerraformTileProc ( TileIndex tile , DoCommandFlag flags , int z_new , Slope tileh_new ) ;
2007-12-21 22:50:51 +00:00
2008-10-13 03:26:48 +00:00
/**
* Set of callback functions for performing tile operations of a given tile type .
2010-08-01 19:44:49 +00:00
* @ see TileType
*/
2007-12-21 22:50:51 +00:00
struct TileTypeProcs {
2008-10-19 15:39:12 +00:00
DrawTileProc * draw_tile_proc ; ///< Called to render the tile and its contents to the screen
2007-12-21 22:50:51 +00:00
GetSlopeZProc * get_slope_z_proc ;
ClearTileProc * clear_tile_proc ;
2009-06-25 19:23:09 +00:00
AddAcceptedCargoProc * add_accepted_cargo_proc ; ///< Adds accepted cargo of the tile to cargo array supplied as parameter
2008-10-19 15:39:12 +00:00
GetTileDescProc * get_tile_desc_proc ; ///< Get a description of a tile (for the 'land area information' tool)
GetTileTrackStatusProc * get_tile_track_status_proc ; ///< Get available tracks and status of a tile
ClickTileProc * click_tile_proc ; ///< Called when tile is clicked
2007-12-21 22:50:51 +00:00
AnimateTileProc * animate_tile_proc ;
TileLoopProc * tile_loop_proc ;
ChangeTileOwnerProc * change_tile_owner_proc ;
2009-06-27 17:05:20 +00:00
AddProducedCargoProc * add_produced_cargo_proc ; ///< Adds produced cargo of the tile to cargo array supplied as parameter
2008-10-19 15:39:12 +00:00
VehicleEnterTileProc * vehicle_enter_tile_proc ; ///< Called when a vehicle enters a tile
2007-12-21 22:50:51 +00:00
GetFoundationProc * get_foundation_proc ;
2008-10-19 15:39:12 +00:00
TerraformTileProc * terraform_tile_proc ; ///< Called when a terraforming operation is about to take place
2007-12-21 22:50:51 +00:00
} ;
extern const TileTypeProcs * const _tile_type_procs [ 16 ] ;
2008-02-20 17:49:50 +00:00
TrackStatus GetTileTrackStatus ( TileIndex tile , TransportType mode , uint sub_mode , DiagDirection side = INVALID_DIAGDIR ) ;
2008-12-26 22:44:13 +00:00
VehicleEnterTileStatus VehicleEnterTile ( Vehicle * v , TileIndex tile , int x , int y ) ;
2008-09-30 20:39:50 +00:00
void ChangeTileOwner ( TileIndex tile , Owner old_owner , Owner new_owner ) ;
2007-12-21 22:50:51 +00:00
void GetTileDesc ( TileIndex tile , TileDesc * td ) ;
2024-01-06 11:19:27 +00:00
inline void AddAcceptedCargo ( TileIndex tile , CargoArray & acceptance , CargoTypes * always_accepted )
2009-06-25 19:23:09 +00:00
{
AddAcceptedCargoProc * proc = _tile_type_procs [ GetTileType ( tile ) ] - > add_accepted_cargo_proc ;
2019-04-10 21:07:06 +00:00
if ( proc = = nullptr ) return ;
CargoTypes dummy = 0 ; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks
proc ( tile , acceptance , always_accepted = = nullptr ? & dummy : always_accepted ) ;
2009-06-25 19:23:09 +00:00
}
2024-01-06 11:19:27 +00:00
inline void AddProducedCargo ( TileIndex tile , CargoArray & produced )
2009-06-27 17:05:20 +00:00
{
AddProducedCargoProc * proc = _tile_type_procs [ GetTileType ( tile ) ] - > add_produced_cargo_proc ;
2019-04-10 21:07:06 +00:00
if ( proc = = nullptr ) return ;
2009-06-27 18:26:50 +00:00
proc ( tile , produced ) ;
2009-06-27 17:05:20 +00:00
}
2024-01-06 11:19:27 +00:00
inline void AnimateTile ( TileIndex tile )
2009-06-25 20:08:59 +00:00
{
AnimateTileProc * proc = _tile_type_procs [ GetTileType ( tile ) ] - > animate_tile_proc ;
2019-04-10 21:07:06 +00:00
assert ( proc ! = nullptr ) ;
2009-06-25 20:08:59 +00:00
proc ( tile ) ;
}
2024-01-06 11:19:27 +00:00
inline bool ClickTile ( TileIndex tile )
2009-06-25 20:08:59 +00:00
{
ClickTileProc * proc = _tile_type_procs [ GetTileType ( tile ) ] - > click_tile_proc ;
2019-04-10 21:07:06 +00:00
if ( proc = = nullptr ) return false ;
2009-06-25 20:08:59 +00:00
return proc ( tile ) ;
}
2007-12-21 22:50:51 +00:00
# endif /* TILE_CMD_H */