2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-04-19 15:05:05 +02:00
|
|
|
/** @file engine_func.h */
|
2007-02-23 19:55:07 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#ifndef ENGINE_H
|
|
|
|
#define ENGINE_H
|
|
|
|
|
2008-03-28 19:00:38 +01:00
|
|
|
#include "engine_type.h"
|
2006-01-12 16:52:18 +01:00
|
|
|
|
2008-01-08 19:25:51 +01:00
|
|
|
void SetupEngines();
|
2007-03-07 12:47:46 +01:00
|
|
|
void StartupEngines();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
|
2007-01-14 20:57:49 +01: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 19:04:08 +02:00
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void LoadCustomEngineNames();
|
|
|
|
void DeleteCustomEngineNames();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-02-04 12:28:12 +01:00
|
|
|
bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player);
|
2007-04-20 18:56:55 +02:00
|
|
|
CargoID GetEngineCargoType(EngineID engine);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-02-04 12:28:12 +01:00
|
|
|
static inline EngineID GetFirstEngineOfType(VehicleType type)
|
2007-02-06 12:11:12 +01:00
|
|
|
{
|
|
|
|
const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
|
|
|
|
|
2007-02-07 20:10:19 +01:00
|
|
|
return start[type];
|
2007-02-06 12:11:12 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 12:28:12 +01:00
|
|
|
static inline EngineID GetLastEngineOfType(VehicleType type)
|
2007-02-06 12:11:12 +01:00
|
|
|
{
|
|
|
|
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 20:10:19 +01:00
|
|
|
return end[type];
|
2007-02-06 12:11:12 +01:00
|
|
|
}
|
|
|
|
|
2008-01-13 14:36:01 +01:00
|
|
|
extern Engine _engines[TOTAL_NUM_ENGINES];
|
2005-05-11 02:00:27 +02:00
|
|
|
#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
|
2007-02-06 12:11:12 +01:00
|
|
|
#define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
|
|
|
|
|
2005-06-07 20:13:49 +02:00
|
|
|
|
2005-10-01 14:43:34 +02:00
|
|
|
static inline Engine* GetEngine(EngineID i)
|
2005-05-11 02:00:27 +02:00
|
|
|
{
|
2006-06-27 23:25:53 +02:00
|
|
|
assert(i < lengthof(_engines));
|
|
|
|
return &_engines[i];
|
2005-05-11 02:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsEngineIndex(uint index)
|
|
|
|
{
|
|
|
|
return index < TOTAL_NUM_ENGINES;
|
|
|
|
}
|
|
|
|
|
2004-11-13 17:28:50 +01:00
|
|
|
/* Access Vehicle Data */
|
2008-01-09 11:15:20 +01: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 20:43:58 +02:00
|
|
|
|
2005-12-15 18:55:59 +01: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 20:43:58 +02:00
|
|
|
|
2006-03-31 14:59:43 +02:00
|
|
|
static inline const EngineInfo *EngInfo(EngineID e)
|
|
|
|
{
|
|
|
|
assert(e < lengthof(_engine_info));
|
|
|
|
return &_engine_info[e];
|
|
|
|
}
|
|
|
|
|
2005-10-01 14:43:34 +02:00
|
|
|
static inline const RailVehicleInfo* RailVehInfo(EngineID e)
|
2004-12-03 22:57:05 +01:00
|
|
|
{
|
|
|
|
assert(e < lengthof(_rail_vehicle_info));
|
|
|
|
return &_rail_vehicle_info[e];
|
|
|
|
}
|
|
|
|
|
2005-10-01 14:43:34 +02:00
|
|
|
static inline const ShipVehicleInfo* ShipVehInfo(EngineID e)
|
2004-12-03 22:57:05 +01:00
|
|
|
{
|
2005-10-01 14:43:34 +02:00
|
|
|
assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info));
|
2004-12-03 22:57:05 +01:00
|
|
|
return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
|
|
|
|
}
|
|
|
|
|
2005-10-01 14:43:34 +02:00
|
|
|
static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e)
|
2004-12-03 22:57:05 +01:00
|
|
|
{
|
2005-10-01 14:43:34 +02:00
|
|
|
assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info));
|
2004-12-03 22:57:05 +01:00
|
|
|
return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
|
|
|
|
}
|
|
|
|
|
2005-10-01 14:43:34 +02:00
|
|
|
static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
|
2004-12-03 22:57:05 +01:00
|
|
|
{
|
2005-10-01 14:43:34 +02:00
|
|
|
assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
|
2004-12-03 22:57:05 +01:00
|
|
|
return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
|
|
|
|
}
|
2004-11-14 17:42:08 +01:00
|
|
|
|
2006-11-30 17:03:12 +01: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 22:56:44 +02:00
|
|
|
#endif /* ENGINE_H */
|