2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/** @file engine.h */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef ENGINE_H
|
|
|
|
#define ENGINE_H
|
|
|
|
|
2007-12-18 20:58:12 +00:00
|
|
|
#include "rail_type.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "cargo_type.h"
|
|
|
|
#include "vehicle_type.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_type.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_type.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_type.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "player_type.h"
|
2004-11-14 16:42:08 +00:00
|
|
|
|
2007-01-30 11:53:35 +00:00
|
|
|
enum RailVehicleTypes {
|
2007-02-23 18:55:07 +00:00
|
|
|
RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive
|
|
|
|
RAILVEH_MULTIHEAD, ///< indicates a combination of two locomotives
|
|
|
|
RAILVEH_WAGON, ///< simple wagon, not motorized
|
2007-01-30 11:53:35 +00:00
|
|
|
};
|
|
|
|
|
2007-05-06 15:01:44 +00:00
|
|
|
enum EngineClass {
|
|
|
|
EC_STEAM,
|
|
|
|
EC_DIESEL,
|
|
|
|
EC_ELECTRIC,
|
2007-05-06 19:44:22 +00:00
|
|
|
EC_MONORAIL,
|
|
|
|
EC_MAGLEV,
|
2007-05-06 15:01:44 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct RailVehicleInfo {
|
2004-08-09 17:04:08 +00:00
|
|
|
byte image_index;
|
2007-01-30 11:53:35 +00:00
|
|
|
RailVehicleTypes railveh_type;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte base_cost;
|
2007-01-24 07:14:09 +00:00
|
|
|
RailTypeByte railtype;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 max_speed;
|
|
|
|
uint16 power;
|
2005-10-20 15:15:58 +00:00
|
|
|
uint16 weight;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte running_cost_base;
|
2006-01-07 16:47:59 +00:00
|
|
|
byte running_cost_class;
|
2007-05-06 15:01:44 +00:00
|
|
|
EngineClass engclass; ///< Class of engine for this vehicle
|
2004-08-09 17:04:08 +00:00
|
|
|
byte capacity;
|
2006-03-26 22:23:32 +00:00
|
|
|
CargoID cargo_type;
|
2006-02-13 22:13:02 +00:00
|
|
|
byte ai_rank;
|
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.
|
2007-02-23 18:55:07 +00:00
|
|
|
byte shorten_factor; ///< length on main map for this type is 8 - shorten_factor
|
2007-07-24 17:01:23 +00:00
|
|
|
byte tractive_effort; ///< Tractive effort coefficient
|
2007-02-23 18:55:07 +00:00
|
|
|
byte user_def_data; ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles
|
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 ShipVehicleInfo {
|
2004-11-13 15:15:41 +00:00
|
|
|
byte image_index;
|
|
|
|
byte base_cost;
|
|
|
|
uint16 max_speed;
|
2006-03-26 22:23:32 +00:00
|
|
|
CargoID cargo_type;
|
2004-11-13 15:15:41 +00:00
|
|
|
uint16 capacity;
|
|
|
|
byte running_cost;
|
2007-01-10 18:56:51 +00:00
|
|
|
SoundFxByte sfx;
|
|
|
|
bool refittable;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-11-13 15:15:41 +00:00
|
|
|
|
2007-01-27 12:45:55 +00:00
|
|
|
/* AircraftVehicleInfo subtypes, bitmask type.
|
|
|
|
* If bit 0 is 0 then it is a helicopter, otherwise it is a plane
|
|
|
|
* in which case bit 1 tells us whether it's a big(fast) plane or not */
|
2006-06-14 11:05:30 +00:00
|
|
|
enum {
|
2007-01-27 12:45:55 +00:00
|
|
|
AIR_HELI = 0,
|
2007-02-23 18:55:07 +00:00
|
|
|
AIR_CTOL = 1, ///< Conventional Take Off and Landing, i.e. planes
|
2006-06-14 11:05:30 +00:00
|
|
|
AIR_FAST = 2
|
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
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;
|
2007-01-10 18:56:51 +00:00
|
|
|
SoundFxByte sfx;
|
2004-11-13 16:28:50 +00:00
|
|
|
byte acceleration;
|
2007-03-02 12:01:24 +00:00
|
|
|
uint16 max_speed;
|
2004-11-13 16:28:50 +00:00
|
|
|
byte mail_capacity;
|
2005-01-07 08:38:27 +00:00
|
|
|
uint16 passenger_capacity;
|
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 RoadVehicleInfo {
|
2004-11-13 16:28:50 +00:00
|
|
|
byte image_index;
|
|
|
|
byte base_cost;
|
|
|
|
byte running_cost;
|
2007-01-10 18:56:51 +00:00
|
|
|
SoundFxByte sfx;
|
2004-11-13 16:28:50 +00:00
|
|
|
byte max_speed;
|
|
|
|
byte capacity;
|
2006-03-26 22:23:32 +00:00
|
|
|
CargoID cargo_type;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-19 20:45:47 +00:00
|
|
|
/** Information about a vehicle
|
2006-09-04 20:40:33 +00:00
|
|
|
* @see table/engines.h
|
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
struct EngineInfo {
|
2006-08-15 16:55:40 +00:00
|
|
|
Date base_intro;
|
2006-08-20 18:40:57 +00:00
|
|
|
Year lifelength;
|
|
|
|
Year base_life;
|
2007-04-18 18:00:33 +00:00
|
|
|
byte unk2; ///< flag for carriage(bit 7) and decay speed(bits0..6)
|
2006-12-02 16:56:32 +00:00
|
|
|
byte load_amount;
|
2007-01-21 16:08:18 +00:00
|
|
|
byte climates;
|
2005-11-06 13:42:26 +00:00
|
|
|
uint32 refit_mask;
|
2006-06-09 16:35:07 +00:00
|
|
|
byte refit_cost;
|
2006-02-28 08:13:15 +00:00
|
|
|
byte misc_flags;
|
2006-06-04 18:22:32 +00:00
|
|
|
byte callbackmask;
|
2007-05-10 23:10:23 +00:00
|
|
|
byte retire_early; ///< Number of years early to retire vehicle
|
2008-01-12 19:58:06 +00:00
|
|
|
StringID string_id; ///< Default name of engine
|
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 Engine {
|
2008-01-12 19:58:06 +00:00
|
|
|
char *name; ///< Custom name of engine
|
2006-08-15 16:55:40 +00:00
|
|
|
Date intro_date;
|
|
|
|
Date age;
|
2004-08-09 17:04:08 +00:00
|
|
|
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;
|
2007-01-10 18:56:51 +00:00
|
|
|
PlayerByte preview_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte preview_wait;
|
2005-08-11 19:21:46 +00:00
|
|
|
byte player_avail;
|
2007-12-26 11:45:43 +00:00
|
|
|
VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-01 23:14:03 +00:00
|
|
|
/**
|
|
|
|
* EngineInfo.misc_flags is a bitmask, with the following values
|
|
|
|
*/
|
|
|
|
enum {
|
2007-05-25 08:13:01 +00:00
|
|
|
EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves
|
|
|
|
EF_ROAD_TRAM = 0, ///< Road vehicle is a tram/light rail vehicle
|
2006-03-01 23:14:03 +00:00
|
|
|
EF_USES_2CC = 1, ///< Vehicle uses two company colours
|
|
|
|
EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU)
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-28 17:06:22 +00:00
|
|
|
/**
|
|
|
|
* Engine.flags is a bitmask, with the following values.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
ENGINE_AVAILABLE = 1, ///< This vehicle is available to everyone.
|
|
|
|
ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a player.
|
|
|
|
ENGINE_OFFER_WINDOW_OPEN = 4, ///< The exclusive offer window is currently open for a player.
|
|
|
|
};
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
enum {
|
|
|
|
NUM_VEHICLE_TYPES = 6
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
static const EngineID INVALID_ENGINE = 0xFFFF;
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
|
2008-01-08 18:25:51 +00:00
|
|
|
void SetupEngines();
|
2007-03-07 11:47:46 +00:00
|
|
|
void StartupEngines();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
|
|
|
|
void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
|
|
|
|
void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal);
|
|
|
|
void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void LoadCustomEngineNames();
|
|
|
|
void DeleteCustomEngineNames();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-03 15:48:21 +00:00
|
|
|
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player);
|
2007-04-20 16:56:55 +00:00
|
|
|
CargoID GetEngineCargoType(EngineID engine);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
NUM_NORMAL_RAIL_ENGINES = 54,
|
2006-08-22 14:38:37 +00:00
|
|
|
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,
|
|
|
|
TOTAL_NUM_ENGINES = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
|
|
|
|
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,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
2007-02-06 11:11:12 +00:00
|
|
|
|
|
|
|
static inline EngineID GetFirstEngineOfType(byte type)
|
|
|
|
{
|
|
|
|
const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
|
|
|
|
|
2007-02-07 19:10:19 +00:00
|
|
|
return start[type];
|
2007-02-06 11:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline EngineID GetLastEngineOfType(byte type)
|
|
|
|
{
|
|
|
|
const EngineID end[] = {
|
|
|
|
NUM_TRAIN_ENGINES,
|
|
|
|
ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES,
|
|
|
|
SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
|
|
|
|
AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
|
|
|
|
|
2007-02-07 19:10:19 +00:00
|
|
|
return end[type];
|
2007-02-06 11:11:12 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
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++)
|
2007-02-06 11:11:12 +00:00
|
|
|
#define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
|
|
|
|
|
2005-06-07 18:13:49 +00:00
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static inline Engine* GetEngine(EngineID i)
|
2005-05-11 00:00:27 +00:00
|
|
|
{
|
2006-06-27 21:25:53 +00:00
|
|
|
assert(i < lengthof(_engines));
|
|
|
|
return &_engines[i];
|
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 */
|
2008-01-09 10:15:20 +00:00
|
|
|
extern const EngineInfo _orig_engine_info[TOTAL_NUM_ENGINES];
|
|
|
|
extern const RailVehicleInfo _orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
|
|
|
|
extern const ShipVehicleInfo _orig_ship_vehicle_info[NUM_SHIP_ENGINES];
|
|
|
|
extern const AircraftVehicleInfo _orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
|
|
|
|
extern const RoadVehicleInfo _orig_road_vehicle_info[NUM_ROAD_ENGINES];
|
2005-09-26 18:43:58 +00:00
|
|
|
|
2005-12-15 17:55:59 +00:00
|
|
|
extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
|
|
|
|
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];
|
2005-09-26 18:43:58 +00:00
|
|
|
|
2006-03-31 12:59:43 +00:00
|
|
|
static inline const EngineInfo *EngInfo(EngineID e)
|
|
|
|
{
|
|
|
|
assert(e < lengthof(_engine_info));
|
|
|
|
return &_engine_info[e];
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static inline const RailVehicleInfo* RailVehInfo(EngineID e)
|
2004-12-03 21:57:05 +00:00
|
|
|
{
|
|
|
|
assert(e < lengthof(_rail_vehicle_info));
|
|
|
|
return &_rail_vehicle_info[e];
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static inline const ShipVehicleInfo* ShipVehInfo(EngineID e)
|
2004-12-03 21:57:05 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info));
|
2004-12-03 21:57:05 +00:00
|
|
|
return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e)
|
2004-12-03 21:57:05 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info));
|
2004-12-03 21:57:05 +00:00
|
|
|
return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
|
2004-12-03 21:57:05 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
|
2004-12-03 21:57:05 +00:00
|
|
|
return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
|
|
|
|
}
|
2004-11-14 16:42:08 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
/* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
|
|
|
|
void EngList_Create(EngineList *el); ///< Creates engine list
|
|
|
|
void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list
|
|
|
|
uint EngList_Count(const EngineList *el); ///< Returns number of items in the engine list
|
|
|
|
void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list
|
|
|
|
EngineID* EngList_Items(EngineList *el); ///< Returns engine list items as C array
|
|
|
|
void EngList_RemoveAll(EngineList *el); ///< Removes all items from engine list
|
|
|
|
typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort()
|
|
|
|
void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list
|
|
|
|
void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* ENGINE_H */
|