|
1 /* $Id$ */ |
|
2 |
|
3 /** @file engine.h */ |
|
4 |
|
5 #ifndef ENGINE_H |
|
6 #define ENGINE_H |
|
7 |
|
8 #include "engine_type.h" |
|
9 |
|
10 void SetupEngines(); |
|
11 void StartupEngines(); |
|
12 |
|
13 |
|
14 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal); |
|
15 void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal); |
|
16 void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal); |
|
17 void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal); |
|
18 |
|
19 void LoadCustomEngineNames(); |
|
20 void DeleteCustomEngineNames(); |
|
21 |
|
22 bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player); |
|
23 CargoID GetEngineCargoType(EngineID engine); |
|
24 |
|
25 static inline EngineID GetFirstEngineOfType(VehicleType type) |
|
26 { |
|
27 const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX}; |
|
28 |
|
29 return start[type]; |
|
30 } |
|
31 |
|
32 static inline EngineID GetLastEngineOfType(VehicleType type) |
|
33 { |
|
34 const EngineID end[] = { |
|
35 NUM_TRAIN_ENGINES, |
|
36 ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES, |
|
37 SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES, |
|
38 AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES}; |
|
39 |
|
40 return end[type]; |
|
41 } |
|
42 |
|
43 extern Engine _engines[TOTAL_NUM_ENGINES]; |
|
44 #define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++) |
|
45 #define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++) |
|
46 |
|
47 |
|
48 static inline Engine* GetEngine(EngineID i) |
|
49 { |
|
50 assert(i < lengthof(_engines)); |
|
51 return &_engines[i]; |
|
52 } |
|
53 |
|
54 static inline bool IsEngineIndex(uint index) |
|
55 { |
|
56 return index < TOTAL_NUM_ENGINES; |
|
57 } |
|
58 |
|
59 /* Access Vehicle Data */ |
|
60 extern const EngineInfo _orig_engine_info[TOTAL_NUM_ENGINES]; |
|
61 extern const RailVehicleInfo _orig_rail_vehicle_info[NUM_TRAIN_ENGINES]; |
|
62 extern const ShipVehicleInfo _orig_ship_vehicle_info[NUM_SHIP_ENGINES]; |
|
63 extern const AircraftVehicleInfo _orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; |
|
64 extern const RoadVehicleInfo _orig_road_vehicle_info[NUM_ROAD_ENGINES]; |
|
65 |
|
66 extern EngineInfo _engine_info[TOTAL_NUM_ENGINES]; |
|
67 extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; |
|
68 extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES]; |
|
69 extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; |
|
70 extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES]; |
|
71 |
|
72 static inline const EngineInfo *EngInfo(EngineID e) |
|
73 { |
|
74 assert(e < lengthof(_engine_info)); |
|
75 return &_engine_info[e]; |
|
76 } |
|
77 |
|
78 static inline const RailVehicleInfo* RailVehInfo(EngineID e) |
|
79 { |
|
80 assert(e < lengthof(_rail_vehicle_info)); |
|
81 return &_rail_vehicle_info[e]; |
|
82 } |
|
83 |
|
84 static inline const ShipVehicleInfo* ShipVehInfo(EngineID e) |
|
85 { |
|
86 assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info)); |
|
87 return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX]; |
|
88 } |
|
89 |
|
90 static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e) |
|
91 { |
|
92 assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info)); |
|
93 return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX]; |
|
94 } |
|
95 |
|
96 static inline const RoadVehicleInfo* RoadVehInfo(EngineID e) |
|
97 { |
|
98 assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info)); |
|
99 return &_road_vehicle_info[e - ROAD_ENGINES_INDEX]; |
|
100 } |
|
101 |
|
102 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */ |
|
103 void EngList_Create(EngineList *el); ///< Creates engine list |
|
104 void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list |
|
105 uint EngList_Count(const EngineList *el); ///< Returns number of items in the engine list |
|
106 void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list |
|
107 EngineID* EngList_Items(EngineList *el); ///< Returns engine list items as C array |
|
108 void EngList_RemoveAll(EngineList *el); ///< Removes all items from engine list |
|
109 typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort() |
|
110 void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list |
|
111 void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list |
|
112 |
|
113 #endif /* ENGINE_H */ |