src/tile_cmd.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
child 6878 7d1ff2f621c7
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file tile_cmd.h Generic 'commands' that can be performed on all tiles. */
       
     4 
       
     5 #ifndef TILE_CMD_H
       
     6 #define TILE_CMD_H
       
     7 
       
     8 #include "slope_type.h"
       
     9 #include "tile_type.h"
       
    10 #include "command_type.h"
       
    11 #include "vehicle_type.h"
       
    12 #include "cargo_type.h"
       
    13 #include "strings_type.h"
       
    14 #include "date_type.h"
       
    15 #include "player_type.h"
       
    16 
       
    17 /** The returned bits of VehicleEnterTile. */
       
    18 enum VehicleEnterTileStatus {
       
    19 	VETS_ENTERED_STATION  = 1, ///< The vehicle entered a station
       
    20 	VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
       
    21 	VETS_CANNOT_ENTER     = 3, ///< The vehicle cannot enter the tile
       
    22 
       
    23 	/**
       
    24 	 * Shift the VehicleEnterTileStatus this many bits
       
    25 	 * to the right to get the station ID when
       
    26 	 * VETS_ENTERED_STATION is set
       
    27 	 */
       
    28 	VETS_STATION_ID_OFFSET = 8,
       
    29 	VETS_STATION_MASK      = 0xFFFF << VETS_STATION_ID_OFFSET,
       
    30 
       
    31 	/** Bit sets of the above specified bits */
       
    32 	VETSB_CONTINUE         = 0,                          ///< The vehicle can continue normally
       
    33 	VETSB_ENTERED_STATION  = 1 << VETS_ENTERED_STATION,  ///< The vehicle entered a station
       
    34 	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)
       
    35 	VETSB_CANNOT_ENTER     = 1 << VETS_CANNOT_ENTER,     ///< The vehicle cannot enter the tile
       
    36 };
       
    37 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus);
       
    38 
       
    39 struct TileInfo {
       
    40 	uint x;
       
    41 	uint y;
       
    42 	Slope tileh;
       
    43 	TileIndex tile;
       
    44 	uint z;
       
    45 };
       
    46 
       
    47 struct TileDesc {
       
    48 	StringID str;
       
    49 	Owner owner;
       
    50 	Date build_date;
       
    51 	uint64 dparam[2];
       
    52 };
       
    53 
       
    54 typedef void DrawTileProc(TileInfo *ti);
       
    55 typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
       
    56 typedef CommandCost ClearTileProc(TileIndex tile, byte flags);
       
    57 typedef void GetAcceptedCargoProc(TileIndex tile, AcceptedCargo res);
       
    58 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
       
    59 
       
    60 /**
       
    61  * GetTileTrackStatusProcs return a value that contains the possible tracks
       
    62  * that can be taken on a given tile by a given transport. The return value is
       
    63  * composed as follows: 0xaabbccdd. ccdd and aabb are bitmasks of trackdirs,
       
    64  * where bit n corresponds to trackdir n. ccdd are the trackdirs that are
       
    65  * present in the tile (1==present, 0==not present), aabb is the signal
       
    66  * status, if applicable (0==green/no signal, 1==red, note that this is
       
    67  * reversed from map3/2[tile] for railway signals).
       
    68  *
       
    69  * The result (let's call it ts) is often used as follows:
       
    70  * tracks = (byte)(ts | ts >>8)
       
    71  * This effectively converts the present part of the result (ccdd) to a
       
    72  * track bitmask, which disregards directions. Normally, this is the same as just
       
    73  * doing (byte)ts I think, although I am not really sure
       
    74  *
       
    75  * A trackdir is combination of a track and a dir, where the lower three bits
       
    76  * are a track, the fourth bit is the direction. these give 12 (or 14)
       
    77  * possible options: 0-5 and 8-13, so we need 14 bits for a trackdir bitmask
       
    78  * above.
       
    79  * @param tile     the tile to get the track status from
       
    80  * @param mode     the mode of transportation
       
    81  * @param sub_mode used to differentiate between different kinds within the mode
       
    82  * @return the above mentions track status information
       
    83  */
       
    84 typedef uint32 GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode);
       
    85 typedef void GetProducedCargoProc(TileIndex tile, CargoID *b);
       
    86 typedef void ClickTileProc(TileIndex tile);
       
    87 typedef void AnimateTileProc(TileIndex tile);
       
    88 typedef void TileLoopProc(TileIndex tile);
       
    89 typedef void ChangeTileOwnerProc(TileIndex tile, PlayerID old_player, PlayerID new_player);
       
    90 
       
    91 /** @see VehicleEnterTileStatus to see what the return values mean */
       
    92 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
       
    93 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
       
    94 
       
    95 /**
       
    96  * Called when a tile is affected by a terraforming operation.
       
    97  * The function has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype.
       
    98  * With DC_EXEC in flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).
       
    99  *
       
   100  * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
       
   101  *
       
   102  * @param tile      The involved tile.
       
   103  * @param flags     Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.).
       
   104  * @param z_new     TileZ after terraforming.
       
   105  * @param tileh_new Slope after terraforming.
       
   106  * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
       
   107  */
       
   108 typedef CommandCost TerraformTileProc(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new);
       
   109 
       
   110 struct TileTypeProcs {
       
   111 	DrawTileProc *draw_tile_proc;
       
   112 	GetSlopeZProc *get_slope_z_proc;
       
   113 	ClearTileProc *clear_tile_proc;
       
   114 	GetAcceptedCargoProc *get_accepted_cargo_proc;
       
   115 	GetTileDescProc *get_tile_desc_proc;
       
   116 	GetTileTrackStatusProc *get_tile_track_status_proc;
       
   117 	ClickTileProc *click_tile_proc;
       
   118 	AnimateTileProc *animate_tile_proc;
       
   119 	TileLoopProc *tile_loop_proc;
       
   120 	ChangeTileOwnerProc *change_tile_owner_proc;
       
   121 	GetProducedCargoProc *get_produced_cargo_proc;
       
   122 	VehicleEnterTileProc *vehicle_enter_tile_proc;
       
   123 	GetFoundationProc *get_foundation_proc;
       
   124 	TerraformTileProc *terraform_tile_proc;
       
   125 };
       
   126 
       
   127 extern const TileTypeProcs * const _tile_type_procs[16];
       
   128 
       
   129 uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode);
       
   130 void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac);
       
   131 void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player);
       
   132 void AnimateTile(TileIndex tile);
       
   133 void ClickTile(TileIndex tile);
       
   134 void GetTileDesc(TileIndex tile, TileDesc *td);
       
   135 
       
   136 #endif /* TILE_CMD_H */