2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef VEHICLE_H
|
|
|
|
#define VEHICLE_H
|
|
|
|
|
2005-02-04 13:23:29 +00:00
|
|
|
#include "pool.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
|
|
|
|
2005-05-04 22:13:07 +00:00
|
|
|
enum {
|
2006-04-18 08:50:17 +00:00
|
|
|
VEH_Invalid = 0,
|
2005-05-02 23:59:11 +00:00
|
|
|
VEH_Train = 0x10,
|
|
|
|
VEH_Road = 0x11,
|
|
|
|
VEH_Ship = 0x12,
|
|
|
|
VEH_Aircraft = 0x13,
|
|
|
|
VEH_Special = 0x14,
|
|
|
|
VEH_Disaster = 0x15,
|
2005-05-04 22:13:07 +00:00
|
|
|
} ;
|
2005-05-02 23:59:11 +00:00
|
|
|
|
|
|
|
enum VehStatus {
|
|
|
|
VS_HIDDEN = 1,
|
|
|
|
VS_STOPPED = 2,
|
|
|
|
VS_UNCLICKABLE = 4,
|
|
|
|
VS_DEFPAL = 0x8,
|
|
|
|
VS_TRAIN_SLOWING = 0x10,
|
2006-07-26 08:32:20 +00:00
|
|
|
VS_SHADOW = 0x20,
|
2005-05-02 23:59:11 +00:00
|
|
|
VS_AIRCRAFT_BROKEN = 0x40,
|
|
|
|
VS_CRASHED = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Effect vehicle types */
|
|
|
|
typedef enum EffectVehicle {
|
|
|
|
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
|
|
|
|
} EffectVehicle;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct VehicleRail {
|
|
|
|
uint16 last_speed; // NOSAVE: only used in UI
|
|
|
|
uint16 crash_anim_pos;
|
2004-09-10 19:02:27 +00:00
|
|
|
uint16 days_since_order_progr;
|
|
|
|
|
2005-06-05 15:37:00 +00:00
|
|
|
// cached values, recalculated on load and each time a vehicle is added to/removed from the consist.
|
|
|
|
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.
|
|
|
|
|
2005-06-05 15:37:00 +00:00
|
|
|
// cached values, recalculated when the cargo on a train changes (in addition to the conditions above)
|
|
|
|
uint16 cached_weight; // total weight of the consist.
|
|
|
|
uint16 cached_veh_weight; // weight of the vehicle.
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
byte track;
|
|
|
|
byte force_proceed;
|
|
|
|
byte 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
|
|
|
|
2005-11-18 23:41:03 +00:00
|
|
|
// Link between the two ends of a multiheaded engine
|
|
|
|
Vehicle *other_multiheaded_part;
|
2004-08-09 17:04:08 +00:00
|
|
|
} VehicleRail;
|
|
|
|
|
|
|
|
enum {
|
2005-01-09 16:02:06 +00:00
|
|
|
VRF_REVERSING = 0,
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// used to calculate if train is going up or down
|
2005-01-09 16:02:06 +00:00
|
|
|
VRF_GOINGUP = 1,
|
|
|
|
VRF_GOINGDOWN = 2,
|
2005-06-06 00:19:24 +00:00
|
|
|
|
|
|
|
// used to store if a wagon is powered or not
|
|
|
|
VRF_POWEREDWAGON = 3,
|
2006-03-18 13:00:32 +00:00
|
|
|
|
|
|
|
// used to reverse the visible direction of the vehicle
|
|
|
|
VRF_REVERSE_DIRECTION = 4,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct VehicleAir {
|
|
|
|
uint16 crashed_counter;
|
|
|
|
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;
|
|
|
|
} VehicleAir;
|
|
|
|
|
|
|
|
typedef struct VehicleRoad {
|
|
|
|
byte state;
|
|
|
|
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;
|
2004-08-09 17:04:08 +00:00
|
|
|
} VehicleRoad;
|
|
|
|
|
|
|
|
typedef struct VehicleSpecial {
|
|
|
|
uint16 unk0;
|
|
|
|
byte unk2;
|
|
|
|
} VehicleSpecial;
|
|
|
|
|
|
|
|
typedef struct VehicleDisaster {
|
|
|
|
uint16 image_override;
|
|
|
|
uint16 unk2;
|
|
|
|
} VehicleDisaster;
|
|
|
|
|
|
|
|
typedef struct VehicleShip {
|
|
|
|
byte state;
|
|
|
|
} VehicleShip;
|
|
|
|
|
|
|
|
|
|
|
|
struct Vehicle {
|
2005-05-04 22:13:07 +00:00
|
|
|
byte type; // type, ie roadven,train,ship,aircraft,special
|
2005-11-14 19:48:04 +00:00
|
|
|
byte subtype; // subtype (Filled with values from EffectVehicles or TrainSubTypes)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-05 20:44:52 +00:00
|
|
|
VehicleID index; // NOSAVE: Index in vehicle array
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
Vehicle *next; // next
|
2005-03-29 11:19:10 +00:00
|
|
|
Vehicle *first; // NOSAVE: pointer to the first vehicle in the chain
|
2005-10-31 12:59:47 +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
|
|
|
|
|
|
|
StringID string_id; // Displayed string
|
|
|
|
|
2005-02-04 14:24:23 +00:00
|
|
|
UnitID unitnumber; // unit number, for display purposes only
|
2005-05-11 00:00:27 +00:00
|
|
|
PlayerID owner; // which player owns the vehicle?
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
TileIndex tile; // Current tile index
|
|
|
|
TileIndex dest_tile; // Heading for this tile
|
|
|
|
|
2005-01-25 21:43:57 +00:00
|
|
|
int32 x_pos; // coordinates
|
|
|
|
int32 y_pos;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte z_pos;
|
|
|
|
byte direction; // facing
|
|
|
|
|
|
|
|
byte spritenum; // currently displayed sprite index
|
|
|
|
// 0xfd == custom sprite, 0xfe == custom second head sprite
|
|
|
|
// 0xff == reserved for another custom sprite
|
2004-11-17 08:52:47 +00:00
|
|
|
uint16 cur_image; // sprite number for this vehicle
|
2004-08-09 17:04:08 +00:00
|
|
|
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
|
|
|
|
2004-11-17 08:52:47 +00:00
|
|
|
// 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
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 max_speed; // maximum speed
|
|
|
|
uint16 cur_speed; // current speed
|
|
|
|
byte subspeed; // fractional speed
|
|
|
|
byte acceleration; // used by train & aircraft
|
|
|
|
byte progress;
|
|
|
|
|
|
|
|
byte vehstatus; // Status
|
2006-03-26 22:55:27 +00:00
|
|
|
StationID last_station_visited;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-03-26 22:23:32 +00:00
|
|
|
CargoID cargo_type; // type of cargo this vehicle is carrying
|
2004-08-09 17:04:08 +00:00
|
|
|
byte cargo_days; // how many days have the pieces been in transit
|
2006-03-26 22:55:27 +00:00
|
|
|
StationID cargo_source;// source of cargo
|
2004-08-09 17:04:08 +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
|
|
|
|
|
|
|
byte day_counter; // increased by one for each day
|
|
|
|
byte tick_counter;// increased by one for each tick
|
|
|
|
|
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)
|
|
|
|
OrderID 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
|
|
|
|
OrderID 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
|
|
|
|
|
|
|
// 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;
|
2005-11-13 21:16:34 +00:00
|
|
|
VehicleID next_hash;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Related to age and service time
|
|
|
|
uint16 age; // Age in days
|
|
|
|
uint16 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;
|
|
|
|
byte build_year;
|
|
|
|
|
2005-11-07 23:20:47 +00:00
|
|
|
bool leave_depot_instantly; // NOSAVE: stores if the vehicle needs to leave the depot it just entered. Used by autoreplace
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 load_unload_time_rem;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 profit_this_year;
|
|
|
|
int32 profit_last_year;
|
|
|
|
uint32 value;
|
|
|
|
|
|
|
|
union {
|
|
|
|
VehicleRail rail;
|
|
|
|
VehicleAir air;
|
|
|
|
VehicleRoad road;
|
|
|
|
VehicleSpecial special;
|
|
|
|
VehicleDisaster disaster;
|
|
|
|
VehicleShip ship;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
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);
|
2005-01-22 20:23:18 +00:00
|
|
|
Vehicle *AllocateVehicle(void);
|
2005-11-05 14:01:00 +00:00
|
|
|
bool AllocateVehicles(Vehicle **vl, int num);
|
2005-01-22 20:23:18 +00:00
|
|
|
Vehicle *ForceAllocateVehicle(void);
|
|
|
|
Vehicle *ForceAllocateSpecialVehicle(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
void VehiclePositionChanged(Vehicle *v);
|
2005-01-22 20:23:18 +00:00
|
|
|
void AfterLoadVehicles(void);
|
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);
|
2004-08-09 17:04:08 +00:00
|
|
|
void DeleteVehicle(Vehicle *v);
|
|
|
|
void DeleteVehicleChain(Vehicle *v);
|
|
|
|
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
2005-01-22 20:23:18 +00:00
|
|
|
void CallVehicleTicks(void);
|
2005-03-30 09:25:20 +00:00
|
|
|
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeTrains(void);
|
2005-12-28 22:29:59 +00:00
|
|
|
byte VehicleRandomBits(void);
|
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);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
void TrainEnterDepot(Vehicle *v, TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* 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);
|
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);
|
2004-08-09 17:04:08 +00:00
|
|
|
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z);
|
2006-06-07 19:35:21 +00:00
|
|
|
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v);
|
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
|
|
|
|
|
|
|
int LoadUnloadVehicle(Vehicle *v);
|
|
|
|
|
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);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct GetNewVehiclePosResult {
|
|
|
|
int x,y;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex old_tile;
|
|
|
|
TileIndex new_tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
} GetNewVehiclePosResult;
|
|
|
|
|
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 */
|
2005-09-18 20:56:44 +00:00
|
|
|
bool GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp);
|
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);
|
|
|
|
|
2005-02-04 13:23:29 +00:00
|
|
|
extern MemoryPool _vehicle_pool;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2005-02-04 13:23:29 +00:00
|
|
|
/**
|
|
|
|
* Get the pointer to the vehicle with index 'index'
|
|
|
|
*/
|
|
|
|
static inline Vehicle *GetVehicle(VehicleID index)
|
|
|
|
{
|
|
|
|
return (Vehicle*)GetItemFromPool(&_vehicle_pool, index);
|
|
|
|
}
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2005-02-04 13:23:29 +00:00
|
|
|
/**
|
|
|
|
* Get the current size of the VehiclePool
|
|
|
|
*/
|
|
|
|
static inline uint16 GetVehiclePoolSize(void)
|
2005-01-06 22:31:58 +00:00
|
|
|
{
|
2005-02-04 13:23:29 +00:00
|
|
|
return _vehicle_pool.total_items;
|
2005-01-06 22:31:58 +00:00
|
|
|
}
|
|
|
|
|
2005-02-04 13:23:29 +00:00
|
|
|
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL)
|
|
|
|
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return v->type != 0;
|
|
|
|
}
|
|
|
|
|
2005-02-04 13:23:29 +00:00
|
|
|
/**
|
|
|
|
* Check if an index is a vehicle-index (so between 0 and max-vehicles)
|
|
|
|
*
|
|
|
|
* @return Returns true if the vehicle-id is in range
|
|
|
|
*/
|
2005-01-30 20:50:06 +00:00
|
|
|
static inline bool IsVehicleIndex(uint index)
|
|
|
|
{
|
2005-10-22 06:39:32 +00:00
|
|
|
return index < GetVehiclePoolSize();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the last order of a vehicle, or NULL if it doesn't exists */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the first vehicle of a shared-list, so we only have to walk forwards */
|
|
|
|
static inline Vehicle *GetFirstVehicleFromSharedList(Vehicle *v)
|
|
|
|
{
|
|
|
|
Vehicle *u = v;
|
|
|
|
while (u->prev_shared != NULL)
|
|
|
|
u = u->prev_shared;
|
|
|
|
|
|
|
|
return u;
|
|
|
|
}
|
2004-08-09 17:04:08 +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
|
|
|
|
2005-05-05 20:44:52 +00:00
|
|
|
#define INVALID_VEHICLE 0xFFFF
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
PalSpriteID 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
|
|
|
|
*/
|
|
|
|
PalSpriteID 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
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* VEHICLE_H */
|