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
2007-12-19 23:26:02 +00:00
# include "vehicle_type.h"
2006-12-03 17:27:43 +00:00
# include "oldpool.h"
2005-01-15 19:06:22 +00:00
# include "order.h"
2007-12-18 20:38:16 +00:00
# include "track_type.h"
# include "rail_type.h"
# include "road_type.h"
2007-12-21 22:50:51 +00:00
# include "cargo_type.h"
2007-12-19 19:44:29 +00:00
# include "window_type.h"
2007-06-22 11:58:59 +00:00
# include "cargopacket.h"
2007-06-21 16:17:47 +00:00
# include "texteff.hpp"
2007-12-21 22:50:51 +00:00
# include "command_type.h"
2007-02-13 10:26:53 +00:00
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-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 ,
2007-06-25 20:55:43 +00:00
VF_TIMETABLE_STARTED , ///< Whether the vehicle has started running on the timetable yet.
VF_AUTOFILL_TIMETABLE , ///< Whether the vehicle should fill in the timetable automatically.
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
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 ;
2007-11-15 00:13:12 +00:00
byte user_def_data ;
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-05-10 06:42:43 +00:00
/* Cached wagon override spritegroup */
const struct SpriteGroup * cached_override ;
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-06-11 14:00:16 +00:00
EngineID first_engine ;
byte cached_veh_length ;
2007-05-24 22:41:50 +00:00
RoadType roadtype ;
RoadTypes compatible_roadtypes ;
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 {
2007-07-26 15:37:19 +00:00
uint16 animation_state ;
byte animation_substate ;
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 ;
2007-07-26 15:37:19 +00:00
VehicleID big_ufo_destroyer_target ;
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
2007-08-03 19:36:00 +00:00
DECLARE_OLD_POOL ( Vehicle , Vehicle , 9 , 125 )
2004-08-09 17:04:08 +00:00
2007-09-07 22:06:52 +00:00
/* Some declarations of functions, so we can make them friendly */
2007-08-30 13:09:44 +00:00
struct SaveLoad ;
2007-09-07 22:06:52 +00:00
extern const SaveLoad * GetVehicleDescription ( VehicleType vt ) ;
extern void AfterLoadVehicles ( ) ;
struct LoadgameState ;
extern bool LoadOldVehicle ( LoadgameState * ls , int num ) ;
2007-08-30 13:09:44 +00:00
2007-08-03 19:36:00 +00:00
struct Vehicle : PoolItem < Vehicle , VehicleID , & _Vehicle_pool > {
2007-05-15 11:28:22 +00:00
VehicleTypeByte type ; ///< Type of vehicle
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
2007-08-30 13:09:44 +00:00
private :
2007-08-30 13:03:56 +00:00
Vehicle * next ; // pointer to the next vehicle in the chain
2007-08-30 21:11:12 +00:00
Vehicle * previous ; // NOSAVE: pointer to the previous vehicle in the chain
Vehicle * first ; // NOSAVE: pointer to the first vehicle in the chain
2007-08-30 13:09:44 +00:00
public :
friend const SaveLoad * GetVehicleDescription ( VehicleType vt ) ; // So we can use private/protected variables in the saveload code
2007-09-07 22:06:52 +00:00
friend void AfterLoadVehicles ( ) ; // So we can set the previous and first pointers while loading
friend bool LoadOldVehicle ( LoadgameState * ls , int num ) ; // So we can set the proper next pointer while loading
2007-08-30 13:09:44 +00:00
2007-08-30 13:03:56 +00:00
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-06-21 16:17:47 +00:00
TextEffectID fill_percent_te_id ; // a text-effect id to a loading indicator object
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
uint16 cargo_cap ; // total capacity
2006-05-19 10:04:03 +00:00
byte cargo_subtype ; ///< Used for livery refits (NewGRF variations)
2007-06-22 11:58:59 +00:00
CargoList cargo ; ///< The cargo this vehicle is carrying
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 ;
2007-06-12 11:22:32 +00:00
Vehicle * next_new_hash ;
Vehicle * * old_new_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-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
2007-06-18 21:44:47 +00:00
Money profit_this_year ;
Money profit_last_year ;
Money value ;
2004-08-09 17:04:08 +00:00
2007-05-19 09:40:18 +00:00
GroupID group_id ; ///< Index of group Pool array
2007-06-20 19:17:22 +00:00
/* Used for timetabling. */
uint32 current_order_time ; ///< How many ticks have passed since this order started.
int32 lateness_counter ; ///< How many ticks late (or early if negative) this vehicle is.
2007-10-28 15:40:18 +00:00
SpriteID colormap ; // NOSAVE: cached color mapping
2004-08-09 17:04:08 +00:00
union {
VehicleRail rail ;
VehicleAir air ;
VehicleRoad road ;
VehicleSpecial special ;
VehicleDisaster disaster ;
VehicleShip ship ;
} u ;
2007-01-13 18:55:54 +00:00
2007-08-03 19:36:00 +00:00
/**
* Allocates a lot of vehicles .
* @ param vl pointer to an array of vehicles to get allocated . Can be NULL if the vehicles aren ' t needed ( makes it test only )
* @ param num number of vehicles to allocate room for
* @ return true if there is room to allocate all the vehicles
*/
static bool AllocateList ( Vehicle * * vl , int num ) ;
/** Create a new vehicle */
Vehicle ( ) ;
2007-08-05 17:43:04 +00:00
/** Destroy all stuff that (still) needs the virtual functions to work properly */
void PreDestructor ( ) ;
2007-08-03 19:36:00 +00:00
/** We want to 'destruct' the right class. */
virtual ~ Vehicle ( ) ;
2007-01-13 18:55:54 +00:00
void BeginLoading ( ) ;
void LeaveStation ( ) ;
2007-04-29 21:24:08 +00:00
2007-05-07 16:21:34 +00:00
/**
* Handle the loading of the vehicle ; when not it skips through dummy
* orders and does nothing in all other cases .
* @ param mode is the non - first call for this vehicle in this tick ?
*/
void HandleLoading ( bool mode = false ) ;
2007-04-29 21:24:08 +00:00
/**
* Get a string ' representation ' of the vehicle type .
* @ return the string representation .
*/
2007-08-03 20:17:26 +00:00
virtual const char * GetTypeString ( ) const { return " base vehicle " ; }
2007-04-29 22:33:51 +00:00
/**
* Marks the vehicles to be redrawn and updates cached variables
2007-09-09 10:13:17 +00:00
*
* This method marks the area of the vehicle on the screen as dirty .
* It can be use to repaint the vehicle .
*
* @ ingroup dirty
2007-04-29 22:33:51 +00:00
*/
virtual void MarkDirty ( ) { }
2007-05-01 16:35:14 +00:00
/**
* Updates the x and y offsets and the size of the sprite used
* for this vehicle .
* @ param direction the direction the vehicle is facing
*/
virtual void UpdateDeltaXY ( Direction direction ) { }
2007-05-02 09:29:41 +00:00
/**
* Sets the expense type associated to this vehicle type
* @ param income whether this is income or ( running ) expenses of the vehicle
*/
2007-05-02 09:39:11 +00:00
virtual ExpensesType GetExpenseType ( bool income ) const { return EXPENSES_OTHER ; }
2007-05-02 09:29:41 +00:00
/**
* Invalidates the vehicle list window of this type of vehicle
*/
2007-05-02 09:39:11 +00:00
virtual WindowClass GetVehicleListWindowClass ( ) const { return WC_NONE ; }
2007-05-07 15:58:05 +00:00
/**
* Play the sound associated with leaving the station
*/
virtual void PlayLeaveStationSound ( ) const { }
2007-06-01 12:03:10 +00:00
/**
* Whether this is the primary vehicle in the chain .
*/
virtual bool IsPrimaryVehicle ( ) const { return false ; }
2007-07-01 19:11:47 +00:00
/**
* Gets the sprite to show for the given direction
* @ param direction the direction the vehicle is facing
* @ return the sprite for the given vehicle in the given direction
*/
virtual int GetImage ( Direction direction ) const { return 0 ; }
2007-07-01 19:24:54 +00:00
2007-08-26 20:43:22 +00:00
/**
* Gets the speed in mph that can be sent into SetDParam for string processing .
* @ return the vehicle ' s speed
*/
virtual int GetDisplaySpeed ( ) const { return 0 ; }
2007-08-28 06:46:33 +00:00
/**
* Gets the maximum speed in mph that can be sent into SetDParam for string processing .
* @ return the vehicle ' s maximum speed
*/
virtual int GetDisplayMaxSpeed ( ) const { return 0 ; }
2007-08-29 21:27:16 +00:00
/**
* Gets the running cost of a vehicle
* @ return the vehicle ' s running cost
*/
virtual Money GetRunningCost ( ) const { return 0 ; }
2007-08-29 21:49:08 +00:00
/**
* Check whether the vehicle is in the depot .
* @ return true if and only if the vehicle is in the depot .
*/
virtual bool IsInDepot ( ) const { return false ; }
/**
* Check whether the vehicle is in the depot * and * stopped .
* @ return true if and only if the vehicle is in the depot and stopped .
*/
virtual bool IsStoppedInDepot ( ) const { return this - > IsInDepot ( ) & & ( this - > vehstatus & VS_STOPPED ) ! = 0 ; }
2007-07-01 19:24:54 +00:00
/**
* Calls the tick handler of the vehicle
*/
2007-08-03 20:17:26 +00:00
virtual void Tick ( ) { } ;
2007-08-02 21:19:07 +00:00
2007-08-29 21:27:16 +00:00
/**
* Gets the running cost of a vehicle that can be sent into SetDParam for string processing .
* @ return the vehicle ' s running cost
*/
Money GetDisplayRunningCost ( ) const { return ( this - > GetRunningCost ( ) > > 8 ) ; }
2007-08-30 13:03:56 +00:00
/**
* Is this vehicle a valid vehicle ?
* @ return true if and only if the vehicle is valid .
*/
inline bool IsValid ( ) const { return this - > type ! = VEH_INVALID ; }
/**
* Set the next vehicle of this vehicle .
* @ param next the next vehicle . NULL removes the next vehicle .
*/
2007-08-30 21:11:12 +00:00
void SetNext ( Vehicle * next ) ;
2007-08-30 13:03:56 +00:00
/**
* Get the next vehicle of this vehicle .
* @ note articulated parts are also counted as vehicles .
* @ return the next vehicle or NULL when there isn ' t a next vehicle .
*/
inline Vehicle * Next ( ) const { return this - > next ; }
2007-08-30 21:11:12 +00:00
/**
* Get the previous vehicle of this vehicle .
* @ note articulated parts are also counted as vehicles .
* @ return the previous vehicle or NULL when there isn ' t a previous vehicle .
*/
inline Vehicle * Previous ( ) const { return this - > previous ; }
/**
* Get the first vehicle of this vehicle chain .
* @ return the first vehicle of the chain .
*/
inline Vehicle * First ( ) const { return this - > first ; }
2007-04-29 21:24:08 +00:00
} ;
/**
* 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 ( ) { }
2007-05-02 09:39:11 +00:00
const char * GetTypeString ( ) const { return " special vehicle " ; }
2007-05-01 16:35:14 +00:00
void UpdateDeltaXY ( Direction direction ) ;
2007-07-01 19:24:54 +00:00
void Tick ( ) ;
2007-04-29 21:24:08 +00:00
} ;
/**
* 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 ( ) { }
2007-05-02 09:39:11 +00:00
const char * GetTypeString ( ) const { return " disaster vehicle " ; }
2007-05-01 16:35:14 +00:00
void UpdateDeltaXY ( Direction direction ) ;
2007-07-01 19:24:54 +00:00
void Tick ( ) ;
2007-04-29 21:24:08 +00:00
} ;
/**
* 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 InvalidVehicle : public Vehicle {
/** Initializes the Vehicle to a invalid vehicle */
InvalidVehicle ( ) { this - > type = VEH_INVALID ; }
/** We want to 'destruct' the right class. */
virtual ~ InvalidVehicle ( ) { }
2007-05-02 09:39:11 +00:00
const char * GetTypeString ( ) const { return " invalid vehicle " ; }
2007-07-01 19:24:54 +00:00
void Tick ( ) { }
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 ) ;
2004-08-09 17:04:08 +00:00
void VehiclePositionChanged ( Vehicle * v ) ;
Vehicle * GetLastVehicleInChain ( Vehicle * v ) ;
2007-07-24 17:01:23 +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-06-12 11:22:32 +00:00
void * VehicleFromPosXY ( int x , int y , 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 ) ;
2007-06-22 18:28:44 +00:00
uint8 CalcPercentVehicleFilled ( Vehicle * v , StringID * color ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 11:47:46 +00:00
void InitializeTrains ( ) ;
byte VehicleRandomBits ( ) ;
void ResetVehiclePosHash ( ) ;
2007-10-28 15:40:18 +00:00
void ResetVehicleColorMap ( ) ;
2007-10-28 16:00:51 +00:00
void CheckVehicle32Day ( Vehicle * v ) ;
2004-08-09 17:04:08 +00:00
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 ) ;
2007-06-18 10:48:15 +00:00
CommandCost GetRefitCost ( EngineID engine_type ) ;
2004-08-09 17:04:08 +00:00
void ViewportAddVehicles ( DrawPixelInfo * dpi ) ;
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 ) ;
2007-12-14 23:21:20 +00:00
Vehicle * GetVehicleTunnelBridge ( TileIndex tile , TileIndex endtile ) ;
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 ) ;
2007-05-18 23:38:29 +00:00
UnitID GetFreeUnitNumber ( VehicleType type ) ;
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 ) ;
2007-06-18 21:44:47 +00:00
Money GetTrainRunningCost ( 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-05-18 23:38:29 +00:00
uint GenerateVehicleSortList ( const Vehicle * * * sort_list , uint16 * length_of_array , VehicleType type , PlayerID owner , uint32 index , uint16 window_type ) ;
void BuildDepotVehicleList ( VehicleType type , TileIndex tile , Vehicle * * * engine_list , uint16 * engine_list_length , uint16 * engine_count , Vehicle * * * wagon_list , uint16 * wagon_list_length , uint16 * wagon_count ) ;
2007-06-18 10:48:15 +00:00
CommandCost SendAllVehiclesToDepot ( VehicleType type , uint32 flags , bool service , PlayerID owner , uint16 vlw_flag , uint32 id ) ;
2006-10-04 12:01:59 +00:00
void VehicleEnterDepot ( Vehicle * v ) ;
2006-09-01 10:24:15 +00:00
2007-06-27 20:40:20 +00:00
void InvalidateAutoreplaceWindow ( EngineID e , GroupID id_g ) ;
2007-02-06 11:11:12 +00:00
2007-06-18 10:48:15 +00:00
CommandCost MaybeReplaceVehicle ( Vehicle * v , bool check , bool display_costs ) ;
2007-06-27 14:15:48 +00:00
bool CanBuildVehicleInfrastructure ( VehicleType type ) ;
2007-03-08 23:05:05 +00:00
2007-08-26 21:21:59 +00:00
void CcCloneVehicle ( bool success , TileIndex tile , uint32 p1 , uint32 p2 ) ;
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 {
2007-07-24 17:01:23 +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 ) ;
2007-07-24 17:01:23 +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 {
2007-08-30 13:03:56 +00:00
# define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL);
2004-08-09 17:04:08 +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 ( ) ;
}
2007-05-18 23:38:29 +00:00
static inline bool IsPlayerBuildableVehicleType ( VehicleType 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 ;
2007-05-18 23:38:29 +00:00
default : return false ;
2007-01-21 00:13:39 +00:00
}
}
2007-01-21 20:08:00 +00:00
static inline bool IsPlayerBuildableVehicleType ( const Vehicle * v )
{
return IsPlayerBuildableVehicleType ( v - > type ) ;
}
2007-08-02 21:19:07 +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 (v->IsValid())
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
{
2007-08-02 21:19:07 +00:00
return index < GetVehiclePoolSize ( ) & & GetVehicle ( index ) - > IsValid ( ) ;
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 */
2007-05-18 23:38:29 +00:00
static inline uint32 GetCmdBuildVeh ( VehicleType type )
2007-01-22 16:16:52 +00:00
{
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 ) ;
}
2007-05-18 23:38:29 +00:00
static inline uint32 GetCmdSellVeh ( VehicleType type )
2007-01-22 16:16:52 +00:00
{
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 ) ;
}
2007-05-18 23:38:29 +00:00
static inline uint32 GetCmdRefitVeh ( VehicleType type )
2007-01-22 16:16:52 +00:00
{
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 ) ;
}
2007-05-18 23:38:29 +00:00
static inline uint32 GetCmdSendToDepot ( VehicleType type )
2007-01-22 16:16:52 +00:00
{
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
2007-12-21 22:50:51 +00:00
/* This one is not used anymore. */
VARDEF VehicleID _vehicle_id_ctr_day ;
VARDEF Vehicle * _place_clicked_vehicle ;
2004-08-09 17:04:08 +00:00
# endif /* VEHICLE_H */