src/engine.h
branchnoai
changeset 9723 eee46cb39750
parent 9701 d1ac22c62f64
child 9724 b39bc69bb2f2
equal deleted inserted replaced
9722:ebf0ece7d8f6 9723:eee46cb39750
     4 
     4 
     5 #ifndef ENGINE_H
     5 #ifndef ENGINE_H
     6 #define ENGINE_H
     6 #define ENGINE_H
     7 
     7 
     8 #include "oldpool.h"
     8 #include "oldpool.h"
     9 #include "rail.h"
     9 #include "rail_type.h"
    10 #include "sound.h"
    10 #include "cargo_type.h"
    11 #include "vehicle.h"
    11 #include "vehicle_type.h"
       
    12 #include "command_type.h"
       
    13 #include "gfx_type.h"
       
    14 #include "date_type.h"
       
    15 #include "sound_type.h"
    12 
    16 
    13 enum RailVehicleTypes {
    17 enum RailVehicleTypes {
    14 	RAILVEH_SINGLEHEAD,  ///< indicates a "standalone" locomotive
    18 	RAILVEH_SINGLEHEAD,  ///< indicates a "standalone" locomotive
    15 	RAILVEH_MULTIHEAD,   ///< indicates a combination of two locomotives
    19 	RAILVEH_MULTIHEAD,   ///< indicates a combination of two locomotives
    16 	RAILVEH_WAGON,       ///< simple wagon, not motorized
    20 	RAILVEH_WAGON,       ///< simple wagon, not motorized
   118 	byte lifelength;
   122 	byte lifelength;
   119 	byte flags;
   123 	byte flags;
   120 	PlayerByte preview_player;
   124 	PlayerByte preview_player;
   121 	byte preview_wait;
   125 	byte preview_wait;
   122 	byte player_avail;
   126 	byte player_avail;
   123 	VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc. Same as in vehicle.h
   127 	VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
   124 };
   128 };
   125 
   129 
   126 /**
   130 /**
   127  * EngineInfo.misc_flags is a bitmask, with the following values
   131  * EngineInfo.misc_flags is a bitmask, with the following values
   128  */
   132  */
   147 };
   151 };
   148 
   152 
   149 static const EngineID INVALID_ENGINE = 0xFFFF;
   153 static const EngineID INVALID_ENGINE = 0xFFFF;
   150 
   154 
   151 
   155 
   152 void AddTypeToEngines();
   156 void SetupEngines();
   153 void StartupEngines();
   157 void StartupEngines();
   154 
   158 
   155 
   159 
   156 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
   160 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
   157 void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
   161 void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
   213 {
   217 {
   214 	return index < TOTAL_NUM_ENGINES;
   218 	return index < TOTAL_NUM_ENGINES;
   215 }
   219 }
   216 
   220 
   217 /* Access Vehicle Data */
   221 /* Access Vehicle Data */
   218 //#include "table/engines.h"
   222 extern const EngineInfo _orig_engine_info[TOTAL_NUM_ENGINES];
   219 extern const EngineInfo orig_engine_info[TOTAL_NUM_ENGINES];
   223 extern const RailVehicleInfo _orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
   220 extern const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
   224 extern const ShipVehicleInfo _orig_ship_vehicle_info[NUM_SHIP_ENGINES];
   221 extern const ShipVehicleInfo orig_ship_vehicle_info[NUM_SHIP_ENGINES];
   225 extern const AircraftVehicleInfo _orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
   222 extern const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
   226 extern const RoadVehicleInfo _orig_road_vehicle_info[NUM_ROAD_ENGINES];
   223 extern const RoadVehicleInfo orig_road_vehicle_info[NUM_ROAD_ENGINES];
       
   224 
   227 
   225 extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
   228 extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
   226 extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
   229 extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
   227 extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
   230 extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
   228 extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
   231 extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
   255 static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
   258 static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
   256 {
   259 {
   257 	assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
   260 	assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
   258 	return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
   261 	return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
   259 }
   262 }
   260 
       
   261 /************************************************************************
       
   262  * Engine Replacement stuff
       
   263  ************************************************************************/
       
   264 
       
   265 struct EngineRenew;
       
   266 /**
       
   267  * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is
       
   268  * placed here so the only exception to this rule, the saveload code, can use
       
   269  * it.
       
   270  */
       
   271 DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000)
       
   272 
       
   273 /**
       
   274  * Struct to store engine replacements. DO NOT USE outside of engine.c. Is
       
   275  * placed here so the only exception to this rule, the saveload code, can use
       
   276  * it.
       
   277  */
       
   278 struct EngineRenew : PoolItem<EngineRenew, EngineRenewID, &_EngineRenew_pool> {
       
   279 	EngineID from;
       
   280 	EngineID to;
       
   281 	EngineRenew *next;
       
   282 	GroupID group_id;
       
   283 
       
   284 	EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {}
       
   285 	~EngineRenew() { this->from = INVALID_ENGINE; }
       
   286 
       
   287 	inline bool IsValid() const { return this->from != INVALID_ENGINE; }
       
   288 };
       
   289 
       
   290 #define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) if (er->IsValid())
       
   291 #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0)
       
   292 
       
   293 
       
   294 /**
       
   295  * A list to group EngineRenew directives together (such as per-player).
       
   296  */
       
   297 typedef EngineRenew* EngineRenewList;
       
   298 
       
   299 /**
       
   300  * Remove all engine replacement settings for the player.
       
   301  * @param  erl The renewlist for a given player.
       
   302  * @return The new renewlist for the player.
       
   303  */
       
   304 void RemoveAllEngineReplacement(EngineRenewList *erl);
       
   305 
       
   306 /**
       
   307  * Retrieve the engine replacement in a given renewlist for an original engine type.
       
   308  * @param  erl The renewlist to search in.
       
   309  * @param  engine Engine type to be replaced.
       
   310  * @return The engine type to replace with, or INVALID_ENGINE if no
       
   311  * replacement is in the list.
       
   312  */
       
   313 EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group);
       
   314 
       
   315 /**
       
   316  * Add an engine replacement to the given renewlist.
       
   317  * @param erl The renewlist to add to.
       
   318  * @param old_engine The original engine type.
       
   319  * @param new_engine The replacement engine type.
       
   320  * @param flags The calling command flags.
       
   321  * @return 0 on success, CMD_ERROR on failure.
       
   322  */
       
   323 CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags);
       
   324 
       
   325 /**
       
   326  * Remove an engine replacement from a given renewlist.
       
   327  * @param erl The renewlist from which to remove the replacement
       
   328  * @param engine The original engine type.
       
   329  * @param flags The calling command flags.
       
   330  * @return 0 on success, CMD_ERROR on failure.
       
   331  */
       
   332 CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags);
       
   333 
       
   334 /** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
       
   335  * @param type The type of engine
       
   336  */
       
   337 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type);
       
   338 
   263 
   339 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
   264 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
   340 void EngList_Create(EngineList *el);            ///< Creates engine list
   265 void EngList_Create(EngineList *el);            ///< Creates engine list
   341 void EngList_Destroy(EngineList *el);           ///< Deallocate and destroy engine list
   266 void EngList_Destroy(EngineList *el);           ///< Deallocate and destroy engine list
   342 uint EngList_Count(const EngineList *el);       ///< Returns number of items in the engine list
   267 uint EngList_Count(const EngineList *el);       ///< Returns number of items in the engine list