2005-07-24 14:12:37 +00:00
/* $Id$ */
2007-04-04 04:08:47 +00:00
/** @vehicle.h */
2004-08-09 17:04:08 +00:00
# ifndef VEHICLE_H
# define VEHICLE_H
2006-12-03 17:27:43 +00:00
# include "oldpool.h"
2005-01-15 19:06:22 +00:00
# include "order.h"
2005-06-17 00:22:46 +00:00
# include "rail.h"
2004-12-09 18:18:21 +00:00
2007-02-13 10:26:53 +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 ,
/** 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
} ;
2007-02-13 22:27:27 +00:00
/** Road vehicle states */
enum RoadVehicleStates {
/*
* Lower 4 bits are used for vehicle track direction . ( Trackdirs )
2007-02-26 22:25:18 +00:00
* When in a road stop ( bit 5 or bit 6 set ) these bits give the
2007-02-13 22:27:27 +00:00
* track direction of the entry to the road stop .
* As the entry direction will always be a diagonal
* direction ( X_NE , Y_SE , X_SW or Y_NW ) only bits 0 and 3
* are needed to hold this direction . Bit 1 is then used to show
* that the vehicle is using the second road stop bay .
2007-02-26 22:25:18 +00:00
* Bit 2 is then used for drive - through stops to show the vehicle
* is stopping at this road stop .
2007-02-13 22:27:27 +00:00
*/
/* Numeric values */
RVSB_IN_DEPOT = 0xFE , ///< The vehicle is in a depot
RVSB_WORMHOLE = 0xFF , ///< The vehicle is in a tunnel and/or bridge
/* Bit numbers */
RVS_USING_SECOND_BAY = 1 , ///< Only used while in a road stop
2007-02-14 16:37:16 +00:00
RVS_IS_STOPPING = 2 , ///< Only used for drive-through stops. Vehicle will stop here
2007-02-26 22:25:18 +00:00
RVS_DRIVE_SIDE = 4 , ///< Only used when retrieving move data
2007-02-13 22:27:27 +00:00
RVS_IN_ROAD_STOP = 5 , ///< The vehicle is in a road stop
2007-02-14 16:37:16 +00:00
RVS_IN_DT_ROAD_STOP = 6 , ///< The vehicle is in a drive-through road stop
2007-02-13 22:27:27 +00:00
/* Bit sets of the above specified bits */
RVSB_IN_ROAD_STOP = 1 < < RVS_IN_ROAD_STOP , ///< The vehicle is in a road stop
RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END ,
2007-02-14 16:37:16 +00:00
RVSB_IN_DT_ROAD_STOP = 1 < < RVS_IN_DT_ROAD_STOP , ///< The vehicle is in a drive-through road stop
RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END ,
2007-02-13 22:27:27 +00:00
RVSB_TRACKDIR_MASK = 0x0F , ///< The mask used to extract track dirs
RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09 ///< Only bits 0 and 3 are used to encode the trackdir for road stops
} ;
2005-05-04 22:13:07 +00:00
enum {
2007-03-08 16:27:54 +00:00
VEH_TRAIN ,
VEH_ROAD ,
VEH_SHIP ,
VEH_AIRCRAFT ,
VEH_SPECIAL ,
VEH_DISASTER ,
VEH_INVALID = 0xFF ,
2005-05-04 22:13:07 +00:00
} ;
2005-05-02 23:59:11 +00:00
enum VehStatus {
2006-08-22 14:38:37 +00:00
VS_HIDDEN = 0x01 ,
VS_STOPPED = 0x02 ,
VS_UNCLICKABLE = 0x04 ,
VS_DEFPAL = 0x08 ,
VS_TRAIN_SLOWING = 0x10 ,
VS_SHADOW = 0x20 ,
2005-05-02 23:59:11 +00:00
VS_AIRCRAFT_BROKEN = 0x40 ,
2006-08-22 14:38:37 +00:00
VS_CRASHED = 0x80 ,
2005-05-02 23:59:11 +00:00
} ;
2007-02-28 17:18:36 +00:00
enum VehicleFlags {
VF_LOADING_FINISHED ,
VF_CARGO_UNLOADING ,
2007-02-28 17:59:05 +00:00
VF_BUILT_AS_PROTOTYPE ,
2006-12-02 16:56:32 +00:00
} ;
2005-05-02 23:59:11 +00:00
/* Effect vehicle types */
2007-03-07 12:11:48 +00:00
enum EffectVehicle {
2005-05-02 23:59:11 +00:00
EV_CHIMNEY_SMOKE = 0 ,
EV_STEAM_SMOKE = 1 ,
EV_DIESEL_SMOKE = 2 ,
EV_ELECTRIC_SPARK = 3 ,
EV_SMOKE = 4 ,
EV_EXPLOSION_LARGE = 5 ,
EV_BREAKDOWN_SMOKE = 6 ,
EV_EXPLOSION_SMALL = 7 ,
EV_BULLDOZER = 8 ,
EV_BUBBLE = 9
2007-03-07 12:11:48 +00:00
} ;
2005-05-02 23:59:11 +00:00
2007-03-07 12:11:48 +00:00
struct VehicleRail {
2006-08-28 18:53:03 +00:00
uint16 last_speed ; // NOSAVE: only used in UI
2004-08-09 17:04:08 +00:00
uint16 crash_anim_pos ;
2004-09-10 19:02:27 +00:00
uint16 days_since_order_progr ;
2007-04-04 04:08:47 +00:00
/* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
2005-06-05 15:37:00 +00:00
uint16 cached_max_speed ; // max speed of the consist. (minimum of the max speed of all vehicles in the consist)
uint32 cached_power ; // total power of the consist.
2005-06-06 22:44:11 +00:00
uint8 cached_veh_length ; // length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
2005-11-03 09:22:24 +00:00
uint16 cached_total_length ; ///< Length of the whole train, valid only for first engine.
2007-04-04 04:08:47 +00:00
/* cached values, recalculated when the cargo on a train changes (in addition to the conditions above) */
2006-11-27 21:14:19 +00:00
uint32 cached_weight ; // total weight of the consist.
uint32 cached_veh_weight ; // weight of the vehicle.
2006-12-28 13:18:07 +00:00
uint32 cached_max_te ; // max tractive effort of consist
2005-11-04 12:58:18 +00:00
/**
* Position / type of visual effect .
* bit 0 - 3 = position of effect relative to vehicle . ( 0 = front , 8 = centre , 15 = rear )
* bit 4 - 5 = type of effect . ( 0 = default for engine class , 1 = steam , 2 = diesel , 3 = electric )
* bit 6 = disable visual effect .
* bit 7 = disable powered wagons .
*/
byte cached_vis_effect ;
2004-08-09 17:04:08 +00:00
2007-04-04 04:08:47 +00:00
/* NOSAVE: for wagon override - id of the first engine in train
* 0xffff = = not in train */
2005-05-12 23:46:01 +00:00
EngineID first_engine ;
2004-08-09 17:04:08 +00:00
2007-01-10 18:56:51 +00:00
TrackBitsByte track ;
2004-08-09 17:04:08 +00:00
byte force_proceed ;
2007-01-10 18:56:51 +00:00
RailTypeByte railtype ;
2006-03-29 16:30:26 +00:00
RailTypeMask compatible_railtypes ;
2004-08-09 17:04:08 +00:00
byte flags ;
2005-07-04 14:58:55 +00:00
2007-04-04 04:08:47 +00:00
/* Link between the two ends of a multiheaded engine */
2005-11-18 23:41:03 +00:00
Vehicle * other_multiheaded_part ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
enum {
2006-08-22 14:38:37 +00:00
VRF_REVERSING = 0 ,
2004-08-09 17:04:08 +00:00
2007-04-04 04:08:47 +00:00
/* used to calculate if train is going up or down */
2006-08-22 14:38:37 +00:00
VRF_GOINGUP = 1 ,
VRF_GOINGDOWN = 2 ,
2005-06-06 00:19:24 +00:00
2007-04-04 04:08:47 +00:00
/* used to store if a wagon is powered or not */
2006-08-22 14:38:37 +00:00
VRF_POWEREDWAGON = 3 ,
2006-03-18 13:00:32 +00:00
2007-04-04 04:08:47 +00:00
/* used to reverse the visible direction of the vehicle */
2006-03-18 13:00:32 +00:00
VRF_REVERSE_DIRECTION = 4 ,
2006-10-17 16:16:19 +00:00
2007-04-04 04:08:47 +00:00
/* used to mark train as lost because PF can't find the route */
2006-10-17 16:16:19 +00:00
VRF_NO_PATH_TO_DESTINATION = 5 ,
2006-11-17 19:31:44 +00:00
2007-04-04 04:08:47 +00:00
/* used to mark that electric train engine is allowed to run on normal rail */
2006-11-17 19:31:44 +00:00
VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6 ,
2004-08-09 17:04:08 +00:00
} ;
2007-03-07 12:11:48 +00:00
struct VehicleAir {
2004-08-09 17:04:08 +00:00
uint16 crashed_counter ;
2007-04-18 18:37:40 +00:00
uint16 cached_max_speed ;
2004-08-09 17:04:08 +00:00
byte pos ;
2006-06-27 21:25:53 +00:00
byte previous_pos ;
2006-03-26 22:55:27 +00:00
StationID targetairport ;
2004-08-09 17:04:08 +00:00
byte state ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct VehicleRoad {
2007-04-04 04:08:47 +00:00
byte state ; ///< @see RoadVehicleStates
2004-08-09 17:04:08 +00:00
byte frame ;
2006-02-11 10:45:20 +00:00
uint16 blocked_ctr ;
2004-08-09 17:04:08 +00:00
byte overtaking ;
byte overtaking_ctr ;
uint16 crashed_ctr ;
byte reverse_ctr ;
2005-01-29 19:41:44 +00:00
struct RoadStop * slot ;
byte slot_age ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct VehicleSpecial {
2004-08-09 17:04:08 +00:00
uint16 unk0 ;
byte unk2 ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct VehicleDisaster {
2004-08-09 17:04:08 +00:00
uint16 image_override ;
uint16 unk2 ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct VehicleShip {
2007-01-10 18:56:51 +00:00
TrackBitsByte state ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
struct Vehicle {
2006-08-22 14:38:37 +00:00
byte type ; // type, ie roadven,train,ship,aircraft,special
2007-01-27 12:29:55 +00:00
byte subtype ; // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
VehicleID index ; // NOSAVE: Index in vehicle array
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
Vehicle * next ; // next
Vehicle * first ; // NOSAVE: pointer to the first vehicle in the chain
Vehicle * depot_list ; //NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
StringID string_id ; // Displayed string
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
UnitID unitnumber ; // unit number, for display purposes only
2007-04-04 04:08:47 +00:00
PlayerByte owner ; // which player owns the vehicle?
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
TileIndex tile ; // Current tile index
TileIndex dest_tile ; // Heading for this tile
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
int32 x_pos ; // coordinates
2005-01-25 21:43:57 +00:00
int32 y_pos ;
2004-08-09 17:04:08 +00:00
byte z_pos ;
2007-01-10 18:56:51 +00:00
DirectionByte direction ; // facing
2006-08-22 14:38:37 +00:00
byte spritenum ; // currently displayed sprite index
// 0xfd == custom sprite, 0xfe == custom second head sprite
// 0xff == reserved for another custom sprite
uint16 cur_image ; // sprite number for this vehicle
byte sprite_width ; // width of vehicle sprite
byte sprite_height ; // height of vehicle sprite
byte z_height ; // z-height of vehicle sprite
int8 x_offs ; // x offset for vehicle sprite
int8 y_offs ; // y offset for vehicle sprite
2005-05-06 16:13:44 +00:00
EngineID engine_type ;
2004-08-09 17:04:08 +00:00
2007-04-04 04:08:47 +00:00
/* for randomized variational spritegroups
* bitmask used to resolve them ; parts of it get reseeded when triggers
* of corresponding spritegroups get matched */
2004-11-17 08:52:47 +00:00
byte random_bits ;
2006-08-22 14:38:37 +00:00
byte waiting_triggers ; // triggers to be yet matched
2004-11-17 08:52:47 +00:00
2006-08-22 14:38:37 +00:00
uint16 max_speed ; // maximum speed
uint16 cur_speed ; // current speed
byte subspeed ; // fractional speed
byte acceleration ; // used by train & aircraft
2004-08-09 17:04:08 +00:00
byte progress ;
2006-09-27 18:17:01 +00:00
uint32 motion_counter ;
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
byte vehstatus ; // Status
2006-03-26 22:55:27 +00:00
StationID last_station_visited ;
2004-09-10 19:02:27 +00:00
2006-08-22 14:38:37 +00:00
CargoID cargo_type ; // type of cargo this vehicle is carrying
byte cargo_days ; // how many days have the pieces been in transit
StationID cargo_source ; // source of cargo
2007-01-15 14:42:24 +00:00
TileIndex cargo_source_xy ; //< stores the Tile where the source station is located, in case it is removed
2006-08-22 14:38:37 +00:00
uint16 cargo_cap ; // total capacity
uint16 cargo_count ; // how many pieces are used
2006-05-19 10:04:03 +00:00
byte cargo_subtype ; ///< Used for livery refits (NewGRF variations)
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
byte day_counter ; // increased by one for each day
byte tick_counter ; // increased by one for each tick
2004-08-09 17:04:08 +00:00
2005-01-15 19:06:22 +00:00
/* Begin Order-stuff */
2006-03-09 20:37:51 +00:00
Order current_order ; ///< The current order (+ status, like: loading)
2006-08-26 17:12:24 +00:00
VehicleOrderID cur_order_index ; ///< The index to the current order
2005-01-15 19:06:22 +00:00
2006-03-09 20:37:51 +00:00
Order * orders ; ///< Pointer to the first order for this vehicle
2006-08-26 17:12:24 +00:00
VehicleOrderID num_orders ; ///< How many orders there are in the list
2005-01-15 19:06:22 +00:00
2006-03-09 20:37:51 +00:00
Vehicle * next_shared ; ///< If not NULL, this points to the next vehicle that shared the order
Vehicle * prev_shared ; ///< If not NULL, this points to the prev vehicle that shared the order
2005-01-15 19:06:22 +00:00
/* End Order-stuff */
2004-08-09 17:04:08 +00:00
2007-04-04 04:08:47 +00:00
/* Boundaries for the current position in the world and a next hash link.
* NOSAVE : All of those can be updated with VehiclePositionChanged ( ) */
2005-01-03 08:50:44 +00:00
int32 left_coord ;
int32 top_coord ;
int32 right_coord ;
int32 bottom_coord ;
2007-01-09 16:27:25 +00:00
Vehicle * next_hash ;
2004-08-09 17:04:08 +00:00
2007-04-04 04:08:47 +00:00
/* Related to age and service time */
2006-08-20 18:40:57 +00:00
Date age ; // Age in days
Date max_age ; // Maximum age
2006-08-15 16:55:40 +00:00
Date date_of_last_service ;
Date service_interval ;
2004-08-09 17:04:08 +00:00
uint16 reliability ;
uint16 reliability_spd_dec ;
byte breakdown_ctr ;
byte breakdown_delay ;
byte breakdowns_since_last_service ;
byte breakdown_chance ;
2006-08-20 18:40:57 +00:00
Year build_year ;
2004-08-09 17:04:08 +00:00
2006-08-22 14:38:37 +00:00
bool leave_depot_instantly ; // NOSAVE: stores if the vehicle needs to leave the depot it just entered. Used by autoreplace
2005-11-07 23:20:47 +00:00
2004-08-09 17:04:08 +00:00
uint16 load_unload_time_rem ;
2007-01-31 22:33:24 +00:00
uint16 cargo_paid_for ; // How much of the cargo currently on board has been paid for.
2007-02-28 17:18:36 +00:00
byte vehicle_flags ; // Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
2004-09-10 19:02:27 +00:00
2004-08-09 17:04:08 +00:00
int32 profit_this_year ;
int32 profit_last_year ;
2007-03-02 18:49:11 +00:00
int32 cargo_feeder_share ; ///< value of feeder pickup to be paid for on delivery of cargo
TileIndex cargo_loaded_at_xy ; ///< tile index where feeder cargo was loaded
2004-08-09 17:04:08 +00:00
uint32 value ;
union {
VehicleRail rail ;
VehicleAir air ;
VehicleRoad road ;
VehicleSpecial special ;
VehicleDisaster disaster ;
VehicleShip ship ;
} u ;
2007-01-13 18:55:54 +00:00
void BeginLoading ( ) ;
void LeaveStation ( ) ;
2007-04-29 21:24:08 +00:00
/**
* An overriden version of new , so you can use the vehicle instance
* instead of a newly allocated piece of memory .
* @ param size the size of the variable ( unused )
* @ param v the vehicle to use as ' storage ' backend
* @ return the memory that is ' allocated '
*/
void * operator new ( size_t size , Vehicle * v ) { return v ; }
/**
* ' Free ' the memory allocated by the overriden new .
* @ param p the memory to ' free '
* @ param v the vehicle that was given to ' new ' on creation .
* @ note This function isn ' t used ( at the moment ) and only added
* to please some compiler .
*/
void operator delete ( void * p , Vehicle * v ) { }
/**
* ' Free ' the memory allocated by the overriden new .
* @ param p the memory to ' free '
* @ note This function isn ' t used ( at the moment ) and only added
* as the above function was needed to please some compiler
* which made it necessary to add this to please yet
* another compiler . . .
*/
void operator delete ( void * p ) { }
/** We want to 'destruct' the right class. */
virtual ~ Vehicle ( ) { }
/**
* Get a string ' representation ' of the vehicle type .
* @ return the string representation .
*/
virtual const char * GetTypeString ( ) = 0 ;
} ;
/**
* This class ' wraps ' Vehicle ; you do not actually instantiate this class .
* You create a Vehicle using AllocateVehicle , so it is added to the pool
* and you reinitialize that to a Train using :
* v = new ( v ) Train ( ) ;
*
* As side - effect the vehicle type is set correctly .
*
* A special vehicle is one of the following :
* - smoke
* - electric sparks for trains
* - explosions
* - bulldozer ( road works )
* - bubbles ( industry )
*/
struct SpecialVehicle : public Vehicle {
/** Initializes the Vehicle to a special vehicle */
SpecialVehicle ( ) { this - > type = VEH_SPECIAL ; }
/** We want to 'destruct' the right class. */
virtual ~ SpecialVehicle ( ) { }
const char * GetTypeString ( ) { return " special vehicle " ; }
} ;
/**
* This class ' wraps ' Vehicle ; you do not actually instantiate this class .
* You create a Vehicle using AllocateVehicle , so it is added to the pool
* and you reinitialize that to a Train using :
* v = new ( v ) Train ( ) ;
*
* As side - effect the vehicle type is set correctly .
*/
struct DisasterVehicle : public Vehicle {
/** Initializes the Vehicle to a disaster vehicle */
DisasterVehicle ( ) { this - > type = VEH_DISASTER ; }
/** We want to 'destruct' the right class. */
virtual ~ DisasterVehicle ( ) { }
const char * GetTypeString ( ) { return " disaster vehicle " ; }
} ;
/**
* This class ' wraps ' Vehicle ; you do not actually instantiate this class .
* You create a Vehicle using AllocateVehicle , so it is added to the pool
* and you reinitialize that to a Train using :
* v = new ( v ) Train ( ) ;
*
* As side - effect the vehicle type is set correctly .
*
* An invalid vehicle must never be used ; all ( virtual ) functions from
* Vehicle should assert ( NOT_REACHED ) .
*/
struct InvalidVehicle : public Vehicle {
/** Initializes the Vehicle to a invalid vehicle */
InvalidVehicle ( ) { this - > type = VEH_INVALID ; }
/** We want to 'destruct' the right class. */
virtual ~ InvalidVehicle ( ) { }
const char * GetTypeString ( ) { return " invalid vehicle " ; }
2004-08-09 17:04:08 +00:00
} ;
2005-05-05 20:44:52 +00:00
# define is_custom_sprite(x) (x >= 0xFD)
# define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
# define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
2004-08-09 17:04:08 +00:00
typedef void * VehicleFromPosProc ( Vehicle * v , void * data ) ;
2004-12-09 21:46:56 +00:00
void VehicleServiceInDepot ( Vehicle * v ) ;
2007-03-07 11:47:46 +00:00
Vehicle * AllocateVehicle ( ) ;
2005-11-05 14:01:00 +00:00
bool AllocateVehicles ( Vehicle * * vl , int num ) ;
2007-03-07 11:47:46 +00:00
Vehicle * ForceAllocateVehicle ( ) ;
Vehicle * ForceAllocateSpecialVehicle ( ) ;
2004-08-09 17:04:08 +00:00
void VehiclePositionChanged ( Vehicle * v ) ;
2007-03-07 11:47:46 +00:00
void AfterLoadVehicles ( ) ;
2004-08-09 17:04:08 +00:00
Vehicle * GetLastVehicleInChain ( Vehicle * v ) ;
2005-03-09 21:54:52 +00:00
Vehicle * GetPrevVehicleInChain ( const Vehicle * v ) ;
Vehicle * GetFirstVehicleInChain ( const Vehicle * v ) ;
2005-11-13 13:43:55 +00:00
uint CountVehiclesInChain ( const Vehicle * v ) ;
2006-09-08 10:47:39 +00:00
bool IsEngineCountable ( const Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
void DeleteVehicleChain ( Vehicle * v ) ;
void * VehicleFromPos ( TileIndex tile , void * data , VehicleFromPosProc * proc ) ;
2007-03-07 11:47:46 +00:00
void CallVehicleTicks ( ) ;
2005-03-30 09:25:20 +00:00
Vehicle * FindVehicleOnTileZ ( TileIndex tile , byte z ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 11:47:46 +00:00
void InitializeTrains ( ) ;
byte VehicleRandomBits ( ) ;
void ResetVehiclePosHash ( ) ;
2004-08-09 17:04:08 +00:00
bool CanFillVehicle ( Vehicle * v ) ;
2005-11-29 22:29:59 +00:00
bool CanRefitTo ( EngineID engine_type , CargoID cid_to ) ;
2006-06-07 07:20:28 +00:00
CargoID FindFirstRefittableCargo ( EngineID engine_type ) ;
2006-09-04 09:07:52 +00:00
int32 GetRefitCost ( EngineID engine_type ) ;
2004-08-09 17:04:08 +00:00
void ViewportAddVehicles ( DrawPixelInfo * dpi ) ;
/* train_cmd.h */
2006-03-08 06:55:33 +00:00
int GetTrainImage ( const Vehicle * v , Direction direction ) ;
int GetAircraftImage ( const Vehicle * v , Direction direction ) ;
int GetRoadVehImage ( const Vehicle * v , Direction direction ) ;
int GetShipImage ( const Vehicle * v , Direction direction ) ;
2007-01-28 21:53:13 +00:00
SpriteID GetRotorImage ( const Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
2005-02-12 15:53:32 +00:00
Vehicle * CreateEffectVehicle ( int x , int y , int z , EffectVehicle type ) ;
Vehicle * CreateEffectVehicleAbove ( int x , int y , int z , EffectVehicle type ) ;
Vehicle * CreateEffectVehicleRel ( const Vehicle * v , int x , int y , int z , EffectVehicle type ) ;
2004-08-09 17:04:08 +00:00
2005-06-24 12:38:35 +00:00
uint32 VehicleEnterTile ( Vehicle * v , TileIndex tile , int x , int y ) ;
2004-08-09 17:04:08 +00:00
2006-05-21 11:34:08 +00:00
StringID VehicleInTheWayErrMsg ( const Vehicle * v ) ;
2007-02-05 14:00:32 +00:00
Vehicle * FindVehicleBetween ( TileIndex from , TileIndex to , byte z , bool without_crashed = false ) ;
2004-08-09 17:04:08 +00:00
2006-03-09 12:32:25 +00:00
bool UpdateSignalsOnSegment ( TileIndex tile , DiagDirection direction ) ;
2005-06-24 12:38:35 +00:00
void SetSignalsOnBothDir ( TileIndex tile , byte track ) ;
2004-08-09 17:04:08 +00:00
2005-07-17 20:14:58 +00:00
Vehicle * CheckClickOnVehicle ( const ViewPort * vp , int x , int y ) ;
2004-08-09 17:04:08 +00:00
void DecreaseVehicleValue ( Vehicle * v ) ;
void CheckVehicleBreakdown ( Vehicle * v ) ;
void AgeVehicle ( Vehicle * v ) ;
2005-10-31 12:59:47 +00:00
void VehicleEnteredDepotThisTick ( Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
void BeginVehicleMove ( Vehicle * v ) ;
void EndVehicleMove ( Vehicle * v ) ;
2005-10-28 20:04:54 +00:00
void ShowAircraftViewWindow ( const Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
2005-02-04 14:24:23 +00:00
UnitID GetFreeUnitNumber ( byte type ) ;
2004-08-09 17:04:08 +00:00
2006-12-02 16:56:32 +00:00
int LoadUnloadVehicle ( Vehicle * v , bool just_arrived ) ;
2004-08-09 17:04:08 +00:00
2005-06-05 15:37:00 +00:00
void TrainConsistChanged ( Vehicle * v ) ;
2006-03-29 16:30:26 +00:00
void TrainPowerChanged ( Vehicle * v ) ;
2005-05-11 16:17:03 +00:00
int32 GetTrainRunningCost ( const Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
2005-03-09 19:09:04 +00:00
int CheckTrainStoppedInDepot ( const Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
2004-12-11 10:17:10 +00:00
bool VehicleNeedsService ( const Vehicle * v ) ;
2007-01-21 01:25:59 +00:00
uint GenerateVehicleSortList ( const Vehicle * * * sort_list , uint16 * length_of_array , byte type , PlayerID owner , uint32 index , uint16 window_type ) ;
2006-09-24 15:01:02 +00:00
void BuildDepotVehicleList ( byte type , TileIndex tile , Vehicle * * * engine_list , uint16 * engine_list_length , uint16 * engine_count , Vehicle * * * wagon_list , uint16 * wagon_list_length , uint16 * wagon_count ) ;
2006-09-01 10:24:15 +00:00
int32 SendAllVehiclesToDepot ( byte type , uint32 flags , bool service , PlayerID owner , uint16 vlw_flag , uint32 id ) ;
2006-10-05 08:15:51 +00:00
bool IsVehicleInDepot ( const Vehicle * v ) ;
2006-10-04 12:01:59 +00:00
void VehicleEnterDepot ( Vehicle * v ) ;
2006-09-01 10:24:15 +00:00
2007-02-06 11:11:12 +00:00
void InvalidateAutoreplaceWindow ( EngineID e ) ;
2007-03-08 23:05:05 +00:00
int32 MaybeReplaceVehicle ( Vehicle * v , bool check , bool display_costs ) ;
2006-09-01 10:24:15 +00:00
/* Flags to add to p2 for goto depot commands */
/* Note: bits 8-10 are used for VLW flags */
enum {
2007-04-18 22:41:53 +00:00
DEPOT_SERVICE = ( 1 < < 0 ) , // The vehicle will leave the depot right after arrival (serivce only)
2006-09-01 10:24:15 +00:00
DEPOT_MASS_SEND = ( 1 < < 1 ) , // Tells that it's a mass send to depot command (type in VLW flag)
DEPOT_DONT_CANCEL = ( 1 < < 2 ) , // Don't cancel current goto depot command if any
DEPOT_LOCATE_HANGAR = ( 1 < < 3 ) , // Find another airport if the target one lacks a hangar
} ;
2006-08-30 21:39:01 +00:00
2007-03-07 12:11:48 +00:00
struct GetNewVehiclePosResult {
2004-08-09 17:04:08 +00:00
int x , y ;
2005-06-24 12:38:35 +00:00
TileIndex old_tile ;
TileIndex new_tile ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2005-05-02 23:59:11 +00:00
/**
* Returns the Trackdir on which the vehicle is currently located .
* Works for trains and ships .
* Currently works only sortof for road vehicles , since they have a fuzzy
* concept of being " on " a trackdir . Dunno really what it returns for a road
* vehicle that is halfway a tile , never really understood that part . For road
* vehicles that are at the beginning or end of the tile , should just return
* the diagonal trackdir on which they are driving . I _think_ .
* For other vehicles types , or vehicles with no clear trackdir ( such as those
* in depots ) , returns 0xFF .
*/
2005-06-17 00:22:46 +00:00
Trackdir GetVehicleTrackdir ( const Vehicle * v ) ;
2005-05-02 23:59:11 +00:00
2004-08-09 17:04:08 +00:00
/* returns true if staying in the same tile */
2007-02-25 10:49:13 +00:00
GetNewVehiclePosResult GetNewVehiclePos ( const Vehicle * v ) ;
2006-03-08 06:55:33 +00:00
Direction GetDirectionTowards ( const Vehicle * v , int x , int y ) ;
2004-08-09 17:04:08 +00:00
# define BEGIN_ENUM_WAGONS(v) do {
# define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL);
2006-12-03 17:27:43 +00:00
DECLARE_OLD_POOL ( Vehicle , Vehicle , 9 , 125 )
2005-01-06 22:31:58 +00:00
2007-03-07 11:47:46 +00:00
static inline VehicleID GetMaxVehicleIndex ( )
2006-08-22 20:41:26 +00:00
{
/* TODO - This isn't the real content of the function, but
* with the new pool - system this will be replaced with one that
2006-12-05 13:58:20 +00:00
* _really_ returns the highest index . Now it just returns
2006-08-22 20:41:26 +00:00
* the next safe value we are sure about everything is below .
*/
2006-12-05 13:58:20 +00:00
return GetVehiclePoolSize ( ) - 1 ;
}
2007-03-07 11:47:46 +00:00
static inline uint GetNumVehicles ( )
2006-12-05 13:58:20 +00:00
{
2006-08-22 20:41:26 +00:00
return GetVehiclePoolSize ( ) ;
}
2005-02-06 22:36:08 +00:00
/**
* Check if a Vehicle really exists .
*/
2005-05-06 16:13:44 +00:00
static inline bool IsValidVehicle ( const Vehicle * v )
2005-02-06 22:36:08 +00:00
{
2007-03-08 16:27:54 +00:00
return v - > type ! = VEH_INVALID ;
2005-02-06 22:36:08 +00:00
}
2006-08-26 20:09:25 +00:00
void DestroyVehicle ( Vehicle * v ) ;
static inline void DeleteVehicle ( Vehicle * v )
{
DestroyVehicle ( v ) ;
2007-04-29 21:24:08 +00:00
v = new ( v ) InvalidVehicle ( ) ;
2006-08-26 20:09:25 +00:00
}
2007-01-21 20:08:00 +00:00
static inline bool IsPlayerBuildableVehicleType ( byte type )
2007-01-21 00:13:39 +00:00
{
2007-01-21 20:08:00 +00:00
switch ( type ) {
2007-03-08 16:27:54 +00:00
case VEH_TRAIN :
case VEH_ROAD :
case VEH_SHIP :
case VEH_AIRCRAFT :
2007-01-21 00:13:39 +00:00
return true ;
}
return false ;
}
2007-01-21 20:08:00 +00:00
static inline bool IsPlayerBuildableVehicleType ( const Vehicle * v )
{
return IsPlayerBuildableVehicleType ( v - > type ) ;
}
2006-10-28 10:55:59 +00:00
# define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
2006-08-22 15:33:35 +00:00
# define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
2005-02-04 13:23:29 +00:00
/**
* Check if an index is a vehicle - index ( so between 0 and max - vehicles )
2007-04-04 04:08:47 +00:00
* @ param index of the vehicle to query
2005-02-04 13:23:29 +00:00
* @ return Returns true if the vehicle - id is in range
*/
2006-08-22 18:15:17 +00:00
static inline bool IsValidVehicleID ( uint index )
2005-01-30 20:50:06 +00:00
{
2006-08-22 18:15:17 +00:00
return index < GetVehiclePoolSize ( ) & & IsValidVehicle ( GetVehicle ( index ) ) ;
2005-02-04 13:23:29 +00:00
}
2004-08-09 17:04:08 +00:00
2005-01-15 19:06:22 +00:00
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
static inline Order * GetVehicleOrder ( const Vehicle * v , int index )
{
Order * order = v - > orders ;
2005-05-05 20:44:52 +00:00
if ( index < 0 ) return NULL ;
2005-01-15 19:06:22 +00:00
while ( order ! = NULL & & index - - > 0 )
order = order - > next ;
return order ;
}
2007-04-04 04:08:47 +00:00
/**
* Returns the last order of a vehicle , or NULL if it doesn ' t exists
* @ param v Vehicle to query
* @ return last order of a vehicle , if available
*/
2005-01-15 19:06:22 +00:00
static inline Order * GetLastVehicleOrder ( const Vehicle * v )
{
Order * order = v - > orders ;
2005-05-05 20:44:52 +00:00
if ( order = = NULL ) return NULL ;
2005-01-15 19:06:22 +00:00
while ( order - > next ! = NULL )
order = order - > next ;
return order ;
}
2007-04-04 04:08:47 +00:00
/** Get the first vehicle of a shared-list, so we only have to walk forwards
* @ param v Vehicle to query
* @ return first vehicle of a shared - list
*/
2006-08-31 15:28:11 +00:00
static inline Vehicle * GetFirstVehicleFromSharedList ( const Vehicle * v )
2005-01-15 19:06:22 +00:00
{
2006-08-31 15:28:11 +00:00
Vehicle * u = ( Vehicle * ) v ;
while ( u - > prev_shared ! = NULL ) u = u - > prev_shared ;
2005-01-15 19:06:22 +00:00
return u ;
}
2004-08-09 17:04:08 +00:00
2007-04-04 04:08:47 +00:00
/* NOSAVE: Return values from various commands. */
2005-10-29 21:54:28 +00:00
VARDEF VehicleID _new_vehicle_id ;
2006-02-11 09:24:51 +00:00
VARDEF uint16 _returned_refit_capacity ;
2004-08-09 17:04:08 +00:00
2007-01-10 18:56:51 +00:00
static const VehicleID INVALID_VEHICLE = 0xFFFF ;
2004-08-09 17:04:08 +00:00
2007-04-20 21:21:47 +00:00
const struct Livery * GetEngineLivery ( EngineID engine_type , PlayerID player , EngineID parent_engine_type , const Vehicle * v ) ;
2006-03-01 17:35:01 +00:00
/**
* Get the colour map for an engine . This used for unbuilt engines in the user interface .
* @ param engine_type ID of engine
* @ param player ID of player
* @ return A ready - to - use palette modifier
*/
2007-01-14 19:57:49 +00:00
SpriteID GetEnginePalette ( EngineID engine_type , PlayerID player ) ;
2006-02-20 09:26:07 +00:00
2006-03-01 17:35:01 +00:00
/**
* Get the colour map for a vehicle .
* @ param v Vehicle to get colour map for
* @ return A ready - to - use palette modifier
*/
2007-01-14 19:57:49 +00:00
SpriteID GetVehiclePalette ( const Vehicle * v ) ;
2006-02-20 09:26:07 +00:00
2004-12-21 23:27:58 +00:00
/* A lot of code calls for the invalidation of the status bar, which is widget 5.
* Best is to have a virtual value for it when it needs to change again */
# define STATUS_BAR 5
2007-01-22 16:16:52 +00:00
extern const uint32 _veh_build_proc_table [ ] ;
extern const uint32 _veh_sell_proc_table [ ] ;
extern const uint32 _veh_refit_proc_table [ ] ;
2006-08-29 23:39:57 +00:00
extern const uint32 _send_to_depot_proc_table [ ] ;
2007-01-22 16:16:52 +00:00
/* Functions to find the right command for certain vehicle type */
static inline uint32 GetCmdBuildVeh ( byte type )
{
2007-02-07 19:10:19 +00:00
return _veh_build_proc_table [ type ] ;
2007-01-22 16:16:52 +00:00
}
static inline uint32 GetCmdBuildVeh ( const Vehicle * v )
{
return GetCmdBuildVeh ( v - > type ) ;
}
static inline uint32 GetCmdSellVeh ( byte type )
{
2007-02-07 19:10:19 +00:00
return _veh_sell_proc_table [ type ] ;
2007-01-22 16:16:52 +00:00
}
static inline uint32 GetCmdSellVeh ( const Vehicle * v )
{
return GetCmdSellVeh ( v - > type ) ;
}
static inline uint32 GetCmdRefitVeh ( byte type )
{
2007-02-07 19:10:19 +00:00
return _veh_refit_proc_table [ type ] ;
2007-01-22 16:16:52 +00:00
}
static inline uint32 GetCmdRefitVeh ( const Vehicle * v )
{
return GetCmdRefitVeh ( v - > type ) ;
}
static inline uint32 GetCmdSendToDepot ( byte type )
{
2007-02-07 19:10:19 +00:00
return _send_to_depot_proc_table [ type ] ;
2007-01-22 16:16:52 +00:00
}
static inline uint32 GetCmdSendToDepot ( const Vehicle * v )
{
return GetCmdSendToDepot ( v - > type ) ;
}
2006-08-29 23:39:57 +00:00
2004-08-09 17:04:08 +00:00
# endif /* VEHICLE_H */