src/engine.h
changeset 6195 b90cf92697b9
parent 6119 b47985557d1e
child 6206 67358999d80d
equal deleted inserted replaced
6194:3d84c2b85f3d 6195:b90cf92697b9
     6 /** @file engine.h */
     6 /** @file engine.h */
     7 
     7 
     8 #include "oldpool.h"
     8 #include "oldpool.h"
     9 #include "rail.h"
     9 #include "rail.h"
    10 #include "sound.h"
    10 #include "sound.h"
       
    11 #include "vehicle.h"
    11 
    12 
    12 enum RailVehicleTypes {
    13 enum RailVehicleTypes {
    13 	RAILVEH_SINGLEHEAD,
    14 	RAILVEH_SINGLEHEAD,
    14 	RAILVEH_MULTIHEAD,
    15 	RAILVEH_MULTIHEAD,
    15 	RAILVEH_WAGON,
    16 	RAILVEH_WAGON,
   155 	TOTAL_NUM_ENGINES       = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
   156 	TOTAL_NUM_ENGINES       = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
   156 	AIRCRAFT_ENGINES_INDEX  = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
   157 	AIRCRAFT_ENGINES_INDEX  = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
   157 	SHIP_ENGINES_INDEX      = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
   158 	SHIP_ENGINES_INDEX      = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
   158 	ROAD_ENGINES_INDEX      = NUM_TRAIN_ENGINES,
   159 	ROAD_ENGINES_INDEX      = NUM_TRAIN_ENGINES,
   159 };
   160 };
       
   161 
       
   162 static inline EngineID GetFirstEngineOfType(byte type)
       
   163 {
       
   164 	const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
       
   165 
       
   166 	return start[VehTypeToIndex(type)];
       
   167 }
       
   168 
       
   169 static inline EngineID GetLastEngineOfType(byte type)
       
   170 {
       
   171 	const EngineID end[] = {
       
   172 		NUM_TRAIN_ENGINES,
       
   173 		ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES,
       
   174 		SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
       
   175 		AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
       
   176 
       
   177 	return end[VehTypeToIndex(type)];
       
   178 }
       
   179 
   160 VARDEF Engine _engines[TOTAL_NUM_ENGINES];
   180 VARDEF Engine _engines[TOTAL_NUM_ENGINES];
   161 #define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
   181 #define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
       
   182 #define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
       
   183 
   162 
   184 
   163 static inline Engine* GetEngine(EngineID i)
   185 static inline Engine* GetEngine(EngineID i)
   164 {
   186 {
   165 	assert(i < lengthof(_engines));
   187 	assert(i < lengthof(_engines));
   166 	return &_engines[i];
   188 	return &_engines[i];
   296  * @param engine The original engine type.
   318  * @param engine The original engine type.
   297  * @param flags The calling command flags.
   319  * @param flags The calling command flags.
   298  * @return 0 on success, CMD_ERROR on failure.
   320  * @return 0 on success, CMD_ERROR on failure.
   299  */
   321  */
   300 int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags);
   322 int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags);
       
   323 
       
   324 /** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
       
   325  * @param type The type of engine
       
   326  */
       
   327 void AddRemoveEngineFromAutoreplaceAndBuildWindows(byte type);
   301 
   328 
   302 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
   329 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
   303 void EngList_Create(EngineList *el);            ///< Creates engine list
   330 void EngList_Create(EngineList *el);            ///< Creates engine list
   304 void EngList_Destroy(EngineList *el);           ///< Deallocate and destroy engine list
   331 void EngList_Destroy(EngineList *el);           ///< Deallocate and destroy engine list
   305 uint EngList_Count(const EngineList *el);       ///< Returns number of items in the engine list
   332 uint EngList_Count(const EngineList *el);       ///< Returns number of items in the engine list