Base for all engine handling. More...
#include "stdafx.h"
#include "company_func.h"
#include "command_func.h"
#include "news_func.h"
#include "aircraft.h"
#include "newgrf.h"
#include "newgrf_engine.h"
#include "strings_func.h"
#include "core/random_func.hpp"
#include "window_func.h"
#include "date_func.h"
#include "autoreplace_gui.h"
#include "string_func.h"
#include "ai/ai.hpp"
#include "core/pool_func.hpp"
#include "engine_gui.h"
#include "engine_func.h"
#include "engine_base.h"
#include "company_base.h"
#include "vehicle_func.h"
#include "table/strings.h"
#include "table/engines.h"
Go to the source code of this file.
Functions | |
assert_compile (lengthof(_orig_rail_vehicle_info)+lengthof(_orig_road_vehicle_info)+lengthof(_orig_ship_vehicle_info)+lengthof(_orig_aircraft_vehicle_info)==lengthof(_orig_engine_info)) | |
void | SetupEngines () |
Initialise the engine pool with the data from the original vehicles. | |
static void | CheckRailIntroduction () |
Check whether the railtypes should be introduced. | |
void | ShowEnginePreviewWindow (EngineID engine) |
static bool | IsWagon (EngineID index) |
Determine whether an engine type is a wagon (and not a loco). | |
static void | CalcEngineReliability (Engine *e) |
Update reliability of engine e, (if needed) update the engine GUIs. | |
void | SetYearEngineAgingStops () |
Compute the value for _year_engine_aging_stops. | |
void | StartupOneEngine (Engine *e, Date aging_date) |
Start/initialise one engine. | |
void | StartupEngines () |
Start/initialise all our engines. | |
static void | AcceptEnginePreview (EngineID eid, CompanyID company) |
Company company accepts engine eid for preview. | |
static CompanyID | GetBestCompany (uint8 pp) |
Get the N-th best company. | |
void | EnginesDailyLoop () |
Daily check to offer an exclusive engine preview to the companies. | |
CommandCost | CmdWantEnginePreview (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Accept an engine prototype. | |
static void | NewVehicleAvailable (Engine *e) |
An engine has become available for general use. | |
void | EnginesMonthlyLoop () |
static bool | IsUniqueEngineName (const char *name) |
CommandCost | CmdRenameEngine (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Rename an engine. | |
bool | IsEngineBuildable (EngineID engine, VehicleType type, CompanyID company) |
Check if an engine is buildable. | |
bool | IsEngineRefittable (EngineID engine) |
Check if an engine is refittable. | |
Variables | |
EnginePool | _engine_pool ("Engine") |
EngineOverrideManager | _engine_mngr |
static Year | _year_engine_aging_stops |
Year that engine aging stops. | |
static uint16 | _introduced_railtypes |
The railtypes that have been or never will be introduced, or an inverse bitmap of rail types that have to be introduced. | |
const uint8 | _engine_counts [4] |
Number of engines of each vehicle type in original engine data. | |
const uint8 | _engine_offsets [4] |
Offset of the first engine of each vehicle type in original engine data. |
Base for all engine handling.
Definition in file engine.cpp.
Company company accepts engine eid for preview.
eid | Engine being accepted (is under preview). | |
company | Current company previewing the engine. |
Definition at line 730 of file engine.cpp.
References _date, _local_company, AddDateIntroducedRailTypes(), AddRemoveEngineFromAutoreplaceAndBuildWindows(), CompanyProperties::avail_railtypes, Company::avail_roadtypes, Engine::company_avail, EF_ROAD_TRAM, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetRailTypeInfo(), HasBit(), RailtypeInfo::introduces_railtypes, InvalidateWindowData(), EngineInfo::misc_flags, Engine::preview_company_rank, RAILTYPE_END, ROADTYPE_ROAD, ROADTYPE_TRAM, SetBit(), TRANSPORT_ROAD, TRANSPORT_WATER, Engine::type, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and WC_BUILD_TOOLBAR.
Referenced by CmdWantEnginePreview().
static void CalcEngineReliability | ( | Engine * | e | ) | [static] |
Update reliability of engine e, (if needed) update the engine GUIs.
e | Engine to update. |
Definition at line 583 of file engine.cpp.
References _settings_game, AddRemoveEngineFromAutoreplaceAndBuildWindows(), EngineInfo::base_life, Engine::company_avail, Engine::duration_phase_1, Engine::duration_phase_2, Engine::duration_phase_3, max(), VehicleSettings::never_expire_vehicles, Engine::reliability, Engine::reliability_final, Engine::reliability_max, Engine::reliability_start, EngineInfo::retire_early, SetWindowClassesDirty(), Engine::type, GameSettings::vehicle, WC_BUILD_VEHICLE, and WC_REPLACE_VEHICLE.
Referenced by StartupOneEngine().
CommandCost CmdRenameEngine | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Rename an engine.
tile | unused | |
flags | operation to perfom | |
p1 | engine ID to rename | |
p2 | unused | |
text | the new name or an empty string when resetting to the default |
Definition at line 955 of file engine.cpp.
References CMD_ERROR, DC_EXEC, free(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid(), MarkWholeScreenDirty(), MAX_LENGTH_ENGINE_NAME_CHARS, Engine::name, return_cmd_error, StrEmpty(), and Utf8StringLength().
CommandCost CmdWantEnginePreview | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Accept an engine prototype.
XXX - it is possible that the top-company changes while you are waiting to accept the offer? Then it becomes invalid
tile | unused | |
flags | operation to perfom | |
p1 | engine-prototype offered | |
p2 | unused | |
text | unused |
Definition at line 828 of file engine.cpp.
References _current_company, AcceptEnginePreview(), CMD_ERROR, DC_EXEC, GetBestCompany(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid(), and Engine::preview_company_rank.
void EnginesDailyLoop | ( | ) |
Daily check to offer an exclusive engine preview to the companies.
Functions used by the IncreaseDate function.
Definition at line 785 of file engine.cpp.
References _cur_year, _year_engine_aging_stops, CheckRailIntroduction(), DeleteWindowById(), ENGINE_EXCLUSIVE_PREVIEW, ENGINE_OFFER_WINDOW_OPEN, Engine::flags, GetBestCompany(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_COMPANY, IsInteractiveCompany(), AI::NewEvent(), Engine::preview_company_rank, Engine::preview_wait, and WC_ENGINE_PREVIEW.
Referenced by OnNewDay().
static CompanyID GetBestCompany | ( | uint8 | pp | ) | [static] |
Get the N-th best company.
pp | Value N, 1 means best, 2 means second best, etc. |
Definition at line 758 of file engine.cpp.
References CompanyProperties::block_preview, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_COMPANY, CompanyProperties::old_economy, CompanyEconomyEntry::performance_history, and SetBit().
Referenced by CmdWantEnginePreview(), and EnginesDailyLoop().
bool IsEngineBuildable | ( | EngineID | engine, | |
VehicleType | type, | |||
CompanyID | company | |||
) |
Check if an engine is buildable.
engine | index of the engine to check. | |
type | the type the engine should be. | |
company | index of the company. |
Definition at line 991 of file engine.cpp.
References CompanyProperties::avail_railtypes, Engine::company_avail, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid(), GetRailTypeInfo(), HasBit(), Engine::IsEnabled(), OWNER_DEITY, Engine::type, and VEH_TRAIN.
Referenced by CheckAutoreplaceValidity(), CmdBuildVehicle(), and GetNewEngineType().
bool IsEngineRefittable | ( | EngineID | engine | ) |
Check if an engine is refittable.
Note: Likely you want to use IsArticulatedVehicleRefittable().
engine | index of the engine to check. |
Definition at line 1021 of file engine.cpp.
References EngineInfo::callback_mask, Engine::CanCarryCargo(), CBM_VEHICLE_CARGO_SUFFIX, CT_INVALID, Engine::GetDefaultCargoType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid(), and HasBit().
Referenced by IsArticulatedVehicleRefittable(), and IsVehicleRefitable().
static bool IsWagon | ( | EngineID | index | ) | [static] |
Determine whether an engine type is a wagon (and not a loco).
index | Engine getting queried. |
Definition at line 573 of file engine.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::type, and VEH_TRAIN.
Referenced by NewVehicleAvailable().
static void NewVehicleAvailable | ( | Engine * | e | ) | [static] |
An engine has become available for general use.
Also handle the exclusive engine preview contract.
e | Engine generally available as of now. |
Definition at line 843 of file engine.cpp.
References _date, AddDateIntroducedRailTypes(), AddNewsItem(), AddRemoveEngineFromAutoreplaceAndBuildWindows(), CompanyProperties::avail_railtypes, Company::avail_roadtypes, CompanyProperties::block_preview, AI::BroadcastNewEvent(), Engine::company_avail, EF_ROAD_TRAM, ENGINE_AVAILABLE, ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, Engine::flags, FOR_ALL_VEHICLES, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), GetEngineCategoryName(), GetRailTypeInfo(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, RailtypeInfo::introduces_railtypes, InvalidateWindowData(), Aircraft::IsNormalAircraft(), IsWagon(), EngineInfo::misc_flags, NR_ENGINE, NS_NEW_VEHICLES, Vehicle::owner, RAILTYPE_END, ROADTYPE_ROAD, ROADTYPE_TRAM, SetBit(), SetDParam(), TRANSPORT_ROAD, TRANSPORT_WATER, Engine::type, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and WC_BUILD_TOOLBAR.
void SetYearEngineAgingStops | ( | ) |
Compute the value for _year_engine_aging_stops.
Definition at line 621 of file engine.cpp.
References _settings_game, _year_engine_aging_stops, EngineInfo::base_intro, EngineInfo::climates, ConvertDateToYMD(), DAYS_IN_LEAP_YEAR, GameSettings::game_creation, HasBit(), GameCreationSettings::landscape, EngineInfo::lifelength, max(), RAILVEH_WAGON, Engine::type, VEH_TRAIN, and YearMonthDay::year.
Referenced by AfterLoadGRFs().
void StartupEngines | ( | ) |
Start/initialise all our engines.
Must be called whenever there are changes to the NewGRF config.
Definition at line 691 of file engine.cpp.
References _date, _introduced_railtypes, _year_engine_aging_stops, CompanyProperties::avail_railtypes, Company::avail_roadtypes, CheckRailIntroduction(), ConvertYMDToDate(), GetCompanyRailtypes(), GetCompanyRoadtypes(), GetRailTypeInfo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, RailtypeInfo::introduction_date, InvalidateWindowClassesData(), IsInsideMM(), RailtypeInfo::label, MAX_DAY, min(), RAILTYPE_BEGIN, SetBit(), StartupOneEngine(), and WC_BUILD_VEHICLE.
Referenced by _GenerateWorld(), AfterLoadGame(), DEF_CONSOLE_CMD(), and ReloadNewGRFData().
Start/initialise one engine.
e | The engine to initialise. | |
aging_date | The date used for age calculations. |
Definition at line 647 of file engine.cpp.
References _date, _settings_game, EngineInfo::base_intro, EngineInfo::base_life, CalcEngineReliability(), EngineInfo::climates, Engine::company_avail, ConvertYMDToDate(), Engine::duration_phase_1, Engine::duration_phase_2, Engine::duration_phase_3, Engine::flags, GameSettings::game_creation, GB(), HasBit(), Engine::intro_date, GameCreationSettings::landscape, Engine::reliability_final, Engine::reliability_max, Engine::reliability_spd_dec, Engine::reliability_start, and GameCreationSettings::starting_year.
Referenced by FixTTOEngines(), and StartupEngines().
const uint8 _engine_counts[4] |
{ lengthof(_orig_rail_vehicle_info), lengthof(_orig_road_vehicle_info), lengthof(_orig_ship_vehicle_info), lengthof(_orig_aircraft_vehicle_info), }
Number of engines of each vehicle type in original engine data.
Definition at line 53 of file engine.cpp.
Referenced by GetNewEngine(), and ParamSet().
const uint8 _engine_offsets[4] |
{ 0, lengthof(_orig_rail_vehicle_info), lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info), lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info), }
Offset of the first engine of each vehicle type in original engine data.
Definition at line 61 of file engine.cpp.
Referenced by ParamSet().
uint16 _introduced_railtypes [static] |
The railtypes that have been or never will be introduced, or an inverse bitmap of rail types that have to be introduced.
Definition at line 50 of file engine.cpp.
Referenced by CheckRailIntroduction(), SetupEngines(), and StartupEngines().
Year _year_engine_aging_stops [static] |
Year that engine aging stops.
Engines will not reduce in reliability and no more engines will be introduced
Definition at line 45 of file engine.cpp.
Referenced by EnginesDailyLoop(), SetYearEngineAgingStops(), and StartupEngines().