2004-08-09 17:04:08 +00:00
|
|
|
#ifndef ENGINE_H
|
|
|
|
#define ENGINE_H
|
|
|
|
|
2004-11-14 16:42:08 +00:00
|
|
|
#include "sprite.h"
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct RailVehicleInfo {
|
|
|
|
byte image_index;
|
|
|
|
byte flags; /* 1=multihead engine, 2=wagon */
|
|
|
|
byte base_cost;
|
|
|
|
uint16 max_speed;
|
|
|
|
uint16 power;
|
|
|
|
byte weight;
|
|
|
|
byte running_cost_base;
|
|
|
|
byte engclass; // 0: steam, 1: diesel, 2: electric
|
|
|
|
byte capacity;
|
|
|
|
byte cargo_type;
|
2005-06-03 10:39:30 +00:00
|
|
|
byte callbackmask; // see CallbackMask enum
|
2005-06-06 00:19:24 +00:00
|
|
|
uint16 pow_wag_power;
|
|
|
|
byte pow_wag_weight;
|
|
|
|
byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value
|
|
|
|
// for when the 'powered wagon' callback fails. But it should really also determine what
|
|
|
|
// kind of visual effect to generate for a vehicle (default, steam, diesel, electric).
|
|
|
|
// Same goes for the callback result, which atm is only used to check if a wagon is powered.
|
2005-06-06 22:44:11 +00:00
|
|
|
byte shorten_factor; // length on main map for this type is 8 - shorten_factor
|
2004-08-09 17:04:08 +00:00
|
|
|
} RailVehicleInfo;
|
|
|
|
|
2004-11-13 16:28:50 +00:00
|
|
|
typedef struct ShipVehicleInfo {
|
2004-11-13 15:15:41 +00:00
|
|
|
byte image_index;
|
|
|
|
byte base_cost;
|
|
|
|
uint16 max_speed;
|
|
|
|
byte cargo_type;
|
|
|
|
uint16 capacity;
|
|
|
|
byte running_cost;
|
|
|
|
byte sfx;
|
2004-11-13 16:28:50 +00:00
|
|
|
byte refittable;
|
|
|
|
} ShipVehicleInfo;
|
2004-11-13 15:15:41 +00:00
|
|
|
|
2004-11-13 16:28:50 +00:00
|
|
|
typedef struct AircraftVehicleInfo {
|
2004-08-09 17:04:08 +00:00
|
|
|
byte image_index;
|
|
|
|
byte base_cost;
|
|
|
|
byte running_cost;
|
2004-11-13 16:28:50 +00:00
|
|
|
byte subtype;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte sfx;
|
2004-11-13 16:28:50 +00:00
|
|
|
byte acceleration;
|
|
|
|
byte max_speed;
|
|
|
|
byte mail_capacity;
|
2005-01-07 08:38:27 +00:00
|
|
|
uint16 passenger_capacity;
|
2004-11-13 16:28:50 +00:00
|
|
|
} AircraftVehicleInfo;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 16:28:50 +00:00
|
|
|
typedef struct RoadVehicleInfo {
|
|
|
|
byte image_index;
|
|
|
|
byte base_cost;
|
|
|
|
byte running_cost;
|
|
|
|
byte sfx;
|
|
|
|
byte max_speed;
|
|
|
|
byte capacity;
|
|
|
|
byte cargo_type;
|
|
|
|
} RoadVehicleInfo;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
typedef struct EngineInfo {
|
|
|
|
uint16 base_intro;
|
|
|
|
byte unk2;
|
|
|
|
byte lifelength;
|
|
|
|
byte base_life;
|
|
|
|
byte railtype_climates;
|
|
|
|
} EngineInfo;
|
|
|
|
|
|
|
|
typedef struct Engine {
|
|
|
|
uint16 intro_date;
|
|
|
|
uint16 age;
|
|
|
|
uint16 reliability;
|
|
|
|
uint16 reliability_spd_dec;
|
|
|
|
uint16 reliability_start, reliability_max, reliability_final;
|
|
|
|
uint16 duration_phase_1, duration_phase_2, duration_phase_3;
|
|
|
|
byte lifelength;
|
|
|
|
byte flags;
|
2005-05-11 00:00:27 +00:00
|
|
|
PlayerID preview_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte preview_wait;
|
|
|
|
byte railtype;
|
2005-05-11 00:00:27 +00:00
|
|
|
PlayerID player_avail;
|
2004-12-28 17:18:46 +00:00
|
|
|
byte type; // type, ie VEH_Road, VEH_Train, etc. Same as in vehicle.h
|
2004-08-09 17:04:08 +00:00
|
|
|
} Engine;
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
RVI_MULTIHEAD = 1,
|
|
|
|
RVI_WAGON = 2,
|
|
|
|
};
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
enum {
|
|
|
|
NUM_VEHICLE_TYPES = 6
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void AddTypeToEngines(void);
|
|
|
|
void StartupEngines(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
enum GlobalCargo {
|
|
|
|
GC_PASSENGERS = 0,
|
|
|
|
GC_COAL = 1,
|
|
|
|
GC_MAIL = 2,
|
|
|
|
GC_OIL = 3,
|
|
|
|
GC_LIVESTOCK = 4,
|
|
|
|
GC_GOODS = 5,
|
|
|
|
GC_GRAIN = 6, // GC_WHEAT / GC_MAIZE
|
|
|
|
GC_WOOD = 7,
|
|
|
|
GC_IRON_ORE = 8,
|
|
|
|
GC_STEEL = 9,
|
|
|
|
GC_VALUABLES = 10, // GC_GOLD / GC_DIAMONDS
|
|
|
|
GC_PAPER = 11,
|
|
|
|
GC_FOOD = 12,
|
|
|
|
GC_FRUIT = 13,
|
|
|
|
GC_COPPER_ORE = 14,
|
|
|
|
GC_WATER = 15,
|
|
|
|
GC_RUBBER = 16,
|
|
|
|
GC_SUGAR = 17,
|
|
|
|
GC_TOYS = 18,
|
|
|
|
GC_BATTERIES = 19,
|
|
|
|
GC_CANDY = 20,
|
|
|
|
GC_TOFFEE = 21,
|
|
|
|
GC_COLA = 22,
|
|
|
|
GC_COTTON_CANDY = 23,
|
|
|
|
GC_BUBBLES = 24,
|
|
|
|
GC_PLASTIC = 25,
|
|
|
|
GC_FIZZY_DRINKS = 26,
|
|
|
|
GC_PAPER_TEMP = 27,
|
|
|
|
GC_UNDEFINED = 28, // undefined; unused slot in arctic climate
|
|
|
|
GC_DEFAULT = 29,
|
|
|
|
GC_PURCHASE = 30,
|
|
|
|
GC_INVALID = 255,
|
|
|
|
NUM_GLOBAL_CID = 31
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-06-03 10:39:30 +00:00
|
|
|
// This enum lists the implemented callbacks
|
|
|
|
// Use as argument for the GetCallBackResult function (see comments there)
|
2005-06-01 11:34:37 +00:00
|
|
|
enum CallbackID {
|
2005-06-06 00:19:24 +00:00
|
|
|
// Powered wagons, if the result is lower as 0x40 then the wagon is powered
|
|
|
|
// TODO: interpret the rest of the result, aka "visual effects"
|
|
|
|
CBID_WAGON_POWER = 0x10,
|
|
|
|
|
2005-06-06 22:44:11 +00:00
|
|
|
// Vehicle length, returns the amount of 1/8's the vehicle is shorter
|
|
|
|
// only for train vehicles
|
|
|
|
CBID_VEH_LENGTH = 0x11,
|
|
|
|
|
2005-06-01 11:34:37 +00:00
|
|
|
// Refit capacity, the passed vehicle needs to have its ->cargo_type set to
|
|
|
|
// the cargo we are refitting to, returns the new cargo capacity
|
2005-06-03 10:39:30 +00:00
|
|
|
CBID_REFIT_CAP = 0x15,
|
|
|
|
};
|
|
|
|
|
|
|
|
// bit positions for rvi->callbackmask, indicates which callbacks are used by an engine
|
|
|
|
// (some callbacks are always used, and dont appear here)
|
|
|
|
enum CallbackMask {
|
2005-06-06 01:31:36 +00:00
|
|
|
CBM_WAGON_POWER = 0,
|
2005-06-06 22:44:11 +00:00
|
|
|
CBM_VEH_LENGTH = 1,
|
2005-06-03 10:39:30 +00:00
|
|
|
CBM_REFIT_CAP = 3,
|
2005-06-01 11:34:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CALLBACK_FAILED = 0xFFFF
|
|
|
|
};
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
VARDEF const uint32 _default_refitmasks[NUM_VEHICLE_TYPES];
|
|
|
|
VARDEF const CargoID _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO];
|
|
|
|
VARDEF const uint32 _landscape_global_cargo_mask[NUM_LANDSCAPE];
|
|
|
|
VARDEF const CargoID _local_cargo_id_ctype[NUM_GLOBAL_CID];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
VARDEF uint32 _engine_refit_masks[256];
|
|
|
|
VARDEF byte _engine_original_sprites[256];
|
2004-11-12 23:59:51 +00:00
|
|
|
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, byte *train_id, int trains);
|
|
|
|
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group);
|
2004-08-09 17:04:08 +00:00
|
|
|
// loaded is in percents, overriding_engine 0xffff is none
|
2005-03-09 21:54:52 +00:00
|
|
|
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction);
|
2005-06-01 11:34:37 +00:00
|
|
|
uint16 GetCallBackResult(uint16 callback_info, byte engine, const Vehicle *v);
|
2005-06-06 00:19:24 +00:00
|
|
|
bool UsesWagonOverride(const Vehicle *v);
|
2004-11-14 20:53:34 +00:00
|
|
|
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
|
|
|
|
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
typedef enum VehicleTrigger {
|
2004-11-17 08:52:47 +00:00
|
|
|
VEHICLE_TRIGGER_NEW_CARGO = 1,
|
|
|
|
// Externally triggered only for the first vehicle in chain
|
|
|
|
VEHICLE_TRIGGER_DEPOT = 2,
|
|
|
|
// Externally triggered only for the first vehicle in chain, only if whole chain is empty
|
|
|
|
VEHICLE_TRIGGER_EMPTY = 4,
|
|
|
|
// Not triggered externally (called for the whole chain if we got NEW_CARGO)
|
|
|
|
VEHICLE_TRIGGER_ANY_NEW_CARGO = 8,
|
2005-03-10 07:01:43 +00:00
|
|
|
} VehicleTrigger;
|
|
|
|
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2005-02-06 22:25:27 +00:00
|
|
|
void SetCustomEngineName(int engine, const char *name);
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID GetCustomEngineName(int engine);
|
|
|
|
|
|
|
|
|
|
|
|
void DrawTrainEngine(int x, int y, int engine, uint32 image_ormod);
|
|
|
|
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod);
|
|
|
|
void DrawShipEngine(int x, int y, int engine, uint32 image_ormod);
|
|
|
|
void DrawAircraftEngine(int x, int y, int engine, uint32 image_ormod);
|
|
|
|
|
|
|
|
void DrawTrainEngineInfo(int engine, int x, int y, int maxw);
|
|
|
|
void DrawRoadVehEngineInfo(int engine, int x, int y, int maxw);
|
|
|
|
void DrawShipEngineInfo(int engine, int x, int y, int maxw);
|
|
|
|
void DrawAircraftEngineInfo(int engine, int x, int y, int maxw);
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
void AcceptEnginePreview(Engine *e, PlayerID player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void LoadCustomEngineNames(void);
|
|
|
|
void DeleteCustomEngineNames(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-27 21:18:03 +00:00
|
|
|
bool IsEngineBuildable(uint engine, byte type);
|
2005-03-09 19:48:20 +00:00
|
|
|
void UnInitNewgrEngines(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
NUM_NORMAL_RAIL_ENGINES = 54,
|
|
|
|
NUM_MONORAIL_ENGINES = 30,
|
|
|
|
NUM_MAGLEV_ENGINES = 32,
|
|
|
|
NUM_TRAIN_ENGINES = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
|
|
|
|
NUM_ROAD_ENGINES = 88,
|
|
|
|
NUM_SHIP_ENGINES = 11,
|
|
|
|
NUM_AIRCRAFT_ENGINES = 41,
|
2004-11-13 16:28:50 +00:00
|
|
|
TOTAL_NUM_ENGINES = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
|
2004-08-09 17:04:08 +00:00
|
|
|
AIRCRAFT_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
|
|
|
|
SHIP_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
|
|
|
|
ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES,
|
|
|
|
};
|
|
|
|
VARDEF Engine _engines[TOTAL_NUM_ENGINES];
|
2005-05-11 00:00:27 +00:00
|
|
|
#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
|
2005-06-07 18:13:49 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
static inline Engine* GetEngine(uint i)
|
|
|
|
{
|
|
|
|
assert(i < lengthof(_engines));
|
|
|
|
return &_engines[i];
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
VARDEF StringID _engine_name_strings[TOTAL_NUM_ENGINES];
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
static inline bool IsEngineIndex(uint index)
|
|
|
|
{
|
|
|
|
return index < TOTAL_NUM_ENGINES;
|
|
|
|
}
|
|
|
|
|
2004-11-13 16:28:50 +00:00
|
|
|
/* Access Vehicle Data */
|
|
|
|
//#include "table/engines.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
|
2004-11-13 16:28:50 +00:00
|
|
|
extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
|
|
|
|
extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
|
|
|
|
extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
|
|
|
|
extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
|
2004-12-03 21:57:05 +00:00
|
|
|
|
2004-12-04 00:34:20 +00:00
|
|
|
static inline RailVehicleInfo *RailVehInfo(uint e)
|
2004-12-03 21:57:05 +00:00
|
|
|
{
|
|
|
|
assert(e < lengthof(_rail_vehicle_info));
|
|
|
|
return &_rail_vehicle_info[e];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ShipVehicleInfo *ShipVehInfo(uint e)
|
|
|
|
{
|
|
|
|
assert(e - SHIP_ENGINES_INDEX < lengthof(_ship_vehicle_info));
|
|
|
|
return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline AircraftVehicleInfo *AircraftVehInfo(uint e)
|
|
|
|
{
|
|
|
|
assert(e - AIRCRAFT_ENGINES_INDEX < lengthof(_aircraft_vehicle_info));
|
|
|
|
return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline RoadVehicleInfo *RoadVehInfo(uint e)
|
|
|
|
{
|
|
|
|
assert(e - ROAD_ENGINES_INDEX < lengthof(_road_vehicle_info));
|
|
|
|
return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
|
|
|
|
}
|
2004-11-14 16:42:08 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif
|