2008-04-29 22:31:29 +01:00
/* $Id$ */
/** @file engine_base.h Base class for engines. */
# ifndef ENGINE_BASE_H
# define ENGINE_BASE_H
# include "engine_type.h"
2009-01-24 20:14:15 +00:00
# include "economy_type.h"
2008-04-29 22:31:29 +01:00
# include "oldpool.h"
2009-03-08 16:51:08 +00:00
# include "core/smallvec_type.hpp"
2008-04-29 22:31:29 +01:00
DECLARE_OLD_POOL ( Engine , Engine , 6 , 10000 )
struct Engine : PoolItem < Engine , EngineID , & _Engine_pool > {
char * name ; ///< Custom name of engine
Date intro_date ;
Date age ;
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 ;
2008-09-30 21:39:50 +01:00
uint8 preview_company_rank ;
2008-04-29 22:31:29 +01:00
byte preview_wait ;
2008-09-30 21:39:50 +01:00
CompanyMask company_avail ;
2008-04-29 22:31:29 +01:00
uint8 image_index ; ///< Original vehicle image index
VehicleType type ; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
EngineInfo info ;
union {
RailVehicleInfo rail ;
RoadVehicleInfo road ;
ShipVehicleInfo ship ;
AircraftVehicleInfo air ;
} u ;
/* NewGRF related data */
const struct GRFFile * grffile ;
const struct SpriteGroup * group [ NUM_CARGO + 2 ] ;
uint16 internal_id ; ///< ID within the GRF file
uint16 overrides_count ;
struct WagonOverride * overrides ;
uint16 list_position ;
Engine ( ) ;
Engine ( VehicleType type , EngineID base ) ;
~ Engine ( ) ;
inline bool IsValid ( ) const { return this - > info . climates ! = 0 ; }
2009-01-24 20:14:15 +00:00
2009-02-21 12:52:41 +00:00
CargoID GetDefaultCargoType ( ) const ;
bool CanCarryCargo ( ) const ;
2009-03-18 19:32:13 +00:00
uint GetDisplayDefaultCapacity ( ) const ;
2009-01-24 20:14:15 +00:00
Money GetRunningCost ( ) const ;
2009-01-25 00:57:03 +00:00
Money GetCost ( ) const ;
2009-02-01 16:10:06 +00:00
uint GetDisplayMaxSpeed ( ) const ;
uint GetPower ( ) const ;
uint GetDisplayWeight ( ) const ;
2009-02-19 09:45:44 +00:00
uint GetDisplayMaxTractiveEffort ( ) const ;
2008-04-29 22:31:29 +01:00
} ;
2009-03-08 16:51:08 +00:00
struct EngineIDMapping {
uint32 grfid ; ///< The GRF ID of the file the entity belongs to
uint16 internal_id ; ///< The internal ID within the GRF file
VehicleTypeByte type ; ///< The engine type
uint8 substitute_id ; ///< The (original) entity ID to use if this GRF is not available (currently not used)
} ;
/**
* Stores the mapping of EngineID to the internal id of newgrfs .
* Note : This is not part of Engine , as the data in the EngineOverrideManager and the engine pool get resetted in different cases .
*/
struct EngineOverrideManager : SmallVector < EngineIDMapping , 256 > {
static const uint NUM_DEFAULT_ENGINES ; ///< Number of default entries
void ResetToDefaultMapping ( ) ;
EngineID GetID ( VehicleType type , uint16 grf_local_id , uint32 grfid ) ;
} ;
extern EngineOverrideManager _engine_mngr ;
2009-05-17 00:44:36 +01:00
# define FOR_ALL_ENGINES_FROM(e, start) for (e = Engine::Get(start); e != NULL; e = (e->index + 1U < Engine::GetPoolSize()) ? Engine::Get(e->index + 1U) : NULL) if (e->IsValid())
2008-04-29 22:31:29 +01:00
# define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
# define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
static inline const EngineInfo * EngInfo ( EngineID e )
{
2009-05-17 00:34:14 +01:00
return & Engine : : Get ( e ) - > info ;
2008-04-29 22:31:29 +01:00
}
static inline const RailVehicleInfo * RailVehInfo ( EngineID e )
{
2009-05-17 00:34:14 +01:00
return & Engine : : Get ( e ) - > u . rail ;
2008-04-29 22:31:29 +01:00
}
static inline const RoadVehicleInfo * RoadVehInfo ( EngineID e )
{
2009-05-17 00:34:14 +01:00
return & Engine : : Get ( e ) - > u . road ;
2008-04-29 22:31:29 +01:00
}
static inline const ShipVehicleInfo * ShipVehInfo ( EngineID e )
{
2009-05-17 00:34:14 +01:00
return & Engine : : Get ( e ) - > u . ship ;
2008-04-29 22:31:29 +01:00
}
static inline const AircraftVehicleInfo * AircraftVehInfo ( EngineID e )
{
2009-05-17 00:34:14 +01:00
return & Engine : : Get ( e ) - > u . air ;
2008-04-29 22:31:29 +01:00
}
# endif /* ENGINE_TYPE_H */