|
@@ -167,195 +167,191 @@ struct VehicleRoad {
|
|
|
uint16 crashed_ctr;
|
|
|
byte reverse_ctr;
|
|
|
struct RoadStop *slot;
|
|
|
byte slot_age;
|
|
|
EngineID first_engine;
|
|
|
byte cached_veh_length;
|
|
|
|
|
|
RoadType roadtype;
|
|
|
RoadTypes compatible_roadtypes;
|
|
|
};
|
|
|
|
|
|
struct VehicleEffect {
|
|
|
uint16 animation_state;
|
|
|
byte animation_substate;
|
|
|
};
|
|
|
|
|
|
struct VehicleDisaster {
|
|
|
uint16 image_override;
|
|
|
VehicleID big_ufo_destroyer_target;
|
|
|
};
|
|
|
|
|
|
struct VehicleShip {
|
|
|
TrackBitsByte state;
|
|
|
};
|
|
|
|
|
|
DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
|
|
|
|
|
|
/* Some declarations of functions, so we can make them friendly */
|
|
|
struct SaveLoad;
|
|
|
extern const SaveLoad *GetVehicleDescription(VehicleType vt);
|
|
|
extern void AfterLoadVehicles(bool clear_te_id);
|
|
|
struct LoadgameState;
|
|
|
extern bool LoadOldVehicle(LoadgameState *ls, int num);
|
|
|
|
|
|
struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool>, BaseVehicle {
|
|
|
private:
|
|
|
Vehicle *next; ///< pointer to the next vehicle in the chain
|
|
|
Vehicle *previous; ///< NOSAVE: pointer to the previous vehicle in the chain
|
|
|
Vehicle *first; ///< NOSAVE: pointer to the first vehicle in the chain
|
|
|
|
|
|
Vehicle *next_shared; ///< pointer to the next vehicle that shares the order
|
|
|
Vehicle *previous_shared; ///< NOSAVE: pointer to the previous vehicle in the shared order chain
|
|
|
Vehicle *first_shared; ///< NOSAVE: pointer to the first vehicle in the shared order chain
|
|
|
public:
|
|
|
friend const SaveLoad *GetVehicleDescription(VehicleType vt); ///< So we can use private/protected variables in the saveload code
|
|
|
friend void AfterLoadVehicles(bool clear_te_id); ///< 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
|
|
|
|
|
|
Vehicle *depot_list; ///< NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
|
|
|
|
|
|
char *name; ///< Name of vehicle
|
|
|
|
|
|
TileIndex tile; ///< Current tile index
|
|
|
|
|
|
/**
|
|
|
* Heading for this tile.
|
|
|
* For airports and train stations this tile does not necessarily belong to the destination station,
|
|
|
* but it can be used for heuristical purposes to estimate the distance.
|
|
|
*/
|
|
|
TileIndex dest_tile;
|
|
|
|
|
|
Money profit_this_year; ///< Profit this year << 8, low 8 bits are fract
|
|
|
Money profit_last_year; ///< Profit last year << 8, low 8 bits are fract
|
|
|
Money value;
|
|
|
|
|
|
/* 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.
|
|
|
|
|
|
/* Boundaries for the current position in the world and a next hash link.
|
|
|
* NOSAVE: All of those can be updated with VehiclePositionChanged() */
|
|
|
int32 left_coord;
|
|
|
int32 top_coord;
|
|
|
int32 right_coord;
|
|
|
int32 bottom_coord;
|
|
|
Vehicle *next_hash;
|
|
|
Vehicle *next_new_hash;
|
|
|
Vehicle **old_new_hash;
|
|
|
|
|
|
SpriteID colormap; // NOSAVE: cached color mapping
|
|
|
|
|
|
/* Related to age and service time */
|
|
|
Year build_year;
|
|
|
Date age; // Age in days
|
|
|
Date max_age; // Maximum age
|
|
|
Date date_of_last_service;
|
|
|
Date service_interval;
|
|
|
uint16 reliability;
|
|
|
uint16 reliability_spd_dec;
|
|
|
byte breakdown_ctr;
|
|
|
byte breakdown_delay;
|
|
|
byte breakdowns_since_last_service;
|
|
|
byte breakdown_chance;
|
|
|
|
|
|
int32 x_pos; // coordinates
|
|
|
int32 y_pos;
|
|
|
byte z_pos;
|
|
|
DirectionByte direction; // facing
|
|
|
|
|
|
OwnerByte owner; // which company owns the vehicle?
|
|
|
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 x_extent; // x-extent of vehicle bounding box
|
|
|
byte y_extent; // y-extent of vehicle bounding box
|
|
|
byte z_extent; // z-extent of vehicle bounding box
|
|
|
int8 x_offs; // x offset for vehicle sprite
|
|
|
int8 y_offs; // y offset for vehicle sprite
|
|
|
EngineID engine_type;
|
|
|
|
|
|
TextEffectID fill_percent_te_id; // a text-effect id to a loading indicator object
|
|
|
UnitID unitnumber; // unit number, for display purposes only
|
|
|
|
|
|
uint16 max_speed; ///< maximum speed
|
|
|
uint16 cur_speed; ///< current speed
|
|
|
byte subspeed; ///< fractional speed
|
|
|
byte acceleration; ///< used by train & aircraft
|
|
|
uint32 motion_counter;
|
|
|
byte progress;
|
|
|
|
|
|
/* for randomized variational spritegroups
|
|
|
* bitmask used to resolve them; parts of it get reseeded when triggers
|
|
|
* of corresponding spritegroups get matched */
|
|
|
byte random_bits;
|
|
|
byte waiting_triggers; ///< triggers to be yet matched
|
|
|
|
|
|
StationID last_station_visited;
|
|
|
|
|
|
CargoID cargo_type; ///< type of cargo this vehicle is carrying
|
|
|
byte cargo_subtype; ///< Used for livery refits (NewGRF variations)
|
|
|
uint16 cargo_cap; ///< total capacity
|
|
|
CargoList cargo; ///< The cargo this vehicle is carrying
|
|
|
|
|
|
byte day_counter; ///< Increased by one for each day
|
|
|
byte tick_counter; ///< Increased by one for each tick
|
|
|
byte running_ticks; ///< Number of ticks this vehicle was not stopped this day
|
|
|
|
|
|
byte vehstatus; ///< Status
|
|
|
Order current_order; ///< The current order (+ status, like: loading)
|
|
|
VehicleOrderID num_orders; ///< How many orders there are in the list
|
|
|
VehicleOrderID cur_order_index; ///< The index to the current order
|
|
|
|
|
|
Order *orders; ///< Pointer to the first order for this vehicle
|
|
|
|
|
|
bool leave_depot_instantly; ///< NOSAVE: stores if the vehicle needs to leave the depot it just entered. Used by autoreplace
|
|
|
|
|
|
byte vehicle_flags; ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
|
|
|
uint16 load_unload_time_rem;
|
|
|
|
|
|
GroupID group_id; ///< Index of group Pool array
|
|
|
|
|
|
byte subtype; ///< subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
|
|
|
|
|
|
union {
|
|
|
VehicleRail rail;
|
|
|
VehicleAir air;
|
|
|
VehicleRoad road;
|
|
|
VehicleEffect effect;
|
|
|
VehicleDisaster disaster;
|
|
|
VehicleShip ship;
|
|
|
} u;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 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();
|
|
|
|
|
|
/** Destroy all stuff that (still) needs the virtual functions to work properly */
|
|
|
void PreDestructor();
|
|
|
/** We want to 'destruct' the right class. */
|
|
|
virtual ~Vehicle();
|
|
|
|
|
|
void BeginLoading();
|
|
|
void LeaveStation();
|
|
|
|
|
|
/**
|
|
|
* 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);
|
|
|
|
|
|
/**
|
|
|
* Get a string 'representation' of the vehicle type.
|
|
|
* @return the string representation.
|
|
|
*/
|
|
|
virtual const char* GetTypeString() const { return "base vehicle"; }
|