2008-04-29 21:31:29 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-04-29 21:31:29 +00:00
|
|
|
/** @file engine_base.h Base class for engines. */
|
|
|
|
|
|
|
|
#ifndef ENGINE_BASE_H
|
|
|
|
#define ENGINE_BASE_H
|
|
|
|
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "company_type.h"
|
2008-04-29 21:31:29 +00:00
|
|
|
#include "engine_type.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "vehicle_type.h"
|
2009-05-22 15:39:22 +00:00
|
|
|
#include "core/pool_type.hpp"
|
2009-03-08 16:51:08 +00:00
|
|
|
#include "core/smallvec_type.hpp"
|
2010-08-10 15:54:53 +00:00
|
|
|
#include "newgrf_commons.h"
|
2008-04-29 21:31:29 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
typedef Pool<Engine, EngineID, 64, 64000> EnginePool;
|
|
|
|
extern EnginePool _engine_pool;
|
2008-04-29 21:31:29 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
struct Engine : EnginePool::PoolItem<&_engine_pool> {
|
2011-03-13 16:43:00 +00:00
|
|
|
char *name; ///< Custom name of engine.
|
|
|
|
Date intro_date; ///< Date of introduction of the engine.
|
2008-04-29 21:31:29 +00:00
|
|
|
Date age;
|
2011-03-13 16:43:00 +00:00
|
|
|
uint16 reliability; ///< Current reliability of the engine.
|
|
|
|
uint16 reliability_spd_dec; ///< Speed of reliability decay between services (per day).
|
|
|
|
uint16 reliability_start; ///< Initial reliability of the engine.
|
|
|
|
uint16 reliability_max; ///< Maximal reliability of the engine.
|
|
|
|
uint16 reliability_final; ///< Final reliability of the engine.
|
|
|
|
uint16 duration_phase_1; ///< First reliability phase in months, increasing reliability from #reliability_start to #reliability_max.
|
|
|
|
uint16 duration_phase_2; ///< Second reliability phase in months, keeping #reliability_max.
|
|
|
|
uint16 duration_phase_3; ///< Third reliability phase on months, decaying to #reliability_final.
|
|
|
|
byte flags; ///< Flags of the engine. @see EngineFlags
|
|
|
|
uint8 preview_company_rank; ///< Rank of the company that is offered a preview. \c 0xFF means no company.
|
|
|
|
byte preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company_rank company.
|
|
|
|
CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company.
|
2009-06-16 13:31:06 +00:00
|
|
|
uint8 original_image_index; ///< Original vehicle image index, thus the image index of the overridden vehicle
|
2011-03-13 16:43:00 +00:00
|
|
|
VehicleType type; ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc.
|
2008-04-29 21:31:29 +00:00
|
|
|
|
|
|
|
EngineInfo info;
|
|
|
|
|
|
|
|
union {
|
|
|
|
RailVehicleInfo rail;
|
|
|
|
RoadVehicleInfo road;
|
|
|
|
ShipVehicleInfo ship;
|
|
|
|
AircraftVehicleInfo air;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
/* NewGRF related data */
|
2010-08-10 15:54:53 +00:00
|
|
|
/**
|
|
|
|
* Properties related the the grf file.
|
|
|
|
* NUM_CARGO real cargo plus two pseudo cargo sprite groups.
|
|
|
|
* Used for obtaining the sprite offset of custom sprites, and for
|
|
|
|
* evaluating callbacks.
|
|
|
|
*/
|
|
|
|
GRFFilePropsBase<NUM_CARGO + 2> grf_prop;
|
2008-04-29 21:31:29 +00:00
|
|
|
uint16 overrides_count;
|
|
|
|
struct WagonOverride *overrides;
|
|
|
|
uint16 list_position;
|
|
|
|
|
|
|
|
Engine();
|
|
|
|
Engine(VehicleType type, EngineID base);
|
|
|
|
~Engine();
|
2011-02-05 20:37:00 +00:00
|
|
|
bool IsEnabled() const;
|
2008-04-29 21:31:29 +00:00
|
|
|
|
2009-08-17 18:33:48 +00:00
|
|
|
/**
|
|
|
|
* Determines the default cargo type of an engine.
|
|
|
|
*
|
|
|
|
* Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used
|
|
|
|
* for livery selection etc..
|
|
|
|
*
|
|
|
|
* Vehicles with CT_INVALID as default cargo are usally not available, but it can appear as default cargo of articulated parts.
|
|
|
|
*
|
|
|
|
* @return The default cargo type.
|
|
|
|
* @see CanCarryCargo
|
|
|
|
*/
|
|
|
|
CargoID GetDefaultCargoType() const
|
|
|
|
{
|
|
|
|
return this->info.cargo_type;
|
|
|
|
}
|
|
|
|
|
2009-02-21 12:52:41 +00:00
|
|
|
bool CanCarryCargo() const;
|
2009-10-31 17:48:09 +00:00
|
|
|
uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) 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;
|
2009-06-16 13:52:18 +00:00
|
|
|
Date GetLifeLengthInDays() const;
|
2010-12-14 21:27:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the engine is a ground vehicle.
|
|
|
|
* @return True iff the engine is a train or a road vehicle.
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsGroundVehicle() const
|
|
|
|
{
|
|
|
|
return this->type == VEH_TRAIN || this->type == VEH_ROAD;
|
|
|
|
}
|
2011-11-01 00:23:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the NewGRF the engine is tied to.
|
|
|
|
* This is the GRF providing the Action 3.
|
|
|
|
* @return NewGRF associated to the engine.
|
|
|
|
*/
|
|
|
|
const GRFFile *GetGRF() const
|
|
|
|
{
|
|
|
|
return this->grf_prop.grffile;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 GetGRFID() const;
|
2008-04-29 21:31:29 +00: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);
|
2011-02-05 16:07:23 +00:00
|
|
|
|
|
|
|
static bool ResetToCurrentNewGRFConfig();
|
2009-03-08 16:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern EngineOverrideManager _engine_mngr;
|
|
|
|
|
2009-05-22 14:23:36 +00:00
|
|
|
#define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
|
|
|
|
#define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
|
2008-04-29 21:31:29 +00:00
|
|
|
|
|
|
|
#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-16 23:34:14 +00:00
|
|
|
return &Engine::Get(e)->info;
|
2008-04-29 21:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const RailVehicleInfo *RailVehInfo(EngineID e)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
return &Engine::Get(e)->u.rail;
|
2008-04-29 21:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
return &Engine::Get(e)->u.road;
|
2008-04-29 21:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
return &Engine::Get(e)->u.ship;
|
2008-04-29 21:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
return &Engine::Get(e)->u.air;
|
2008-04-29 21:31:29 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 10:50:32 +00:00
|
|
|
#endif /* ENGINE_BASE_H */
|