33 #include "table/strings.h" 54 lengthof(_orig_aircraft_vehicle_info),
80 this->list_position = base;
88 if (type ==
VEH_ROAD) this->u.road.tractive_effort = 0x4C;
108 default: NOT_REACHED();
111 this->u.rail = _orig_rail_vehicle_info[base];
113 this->info.
string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base;
121 this->u.road = _orig_road_vehicle_info[base];
123 this->info.
string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base;
127 this->u.ship = _orig_ship_vehicle_info[base];
129 this->info.
string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base;
133 this->u.air = _orig_aircraft_vehicle_info[base];
135 this->info.
string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base;
163 return file ==
nullptr ? 0 : file->grfid;
178 switch (this->
type) {
180 if (this->u.rail.capacity == 0)
return false;
184 if (this->u.road.capacity == 0)
return false;
191 default: NOT_REACHED();
207 if (mail_capacity !=
nullptr) *mail_capacity = 0;
221 (new_multipliers || default_cargo != cargo_type || (v !=
nullptr && v->
cargo_subtype != 0))) {
228 uint extra_mail_cap = 0;
229 switch (this->
type) {
234 if (v ==
nullptr && this->u.rail.railveh_type ==
RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
250 if (!new_multipliers && cargo_type == CT_MAIL)
return capacity + extra_mail_cap;
251 default_cargo = CT_PASSENGERS;
254 default: NOT_REACHED();
257 if (!new_multipliers) {
259 capacity += extra_mail_cap;
264 if (new_multipliers || (this->
type !=
VEH_SHIP && default_cargo != cargo_type)) {
267 capacity *= cargo_multiplier;
268 if (extra_mail_cap > 0) {
270 capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier;
272 capacity = (capacity + default_multiplier / 2) / default_multiplier;
286 switch (this->
type) {
288 base_price = this->u.road.running_cost_class;
289 if (base_price == INVALID_PRICE)
return 0;
294 base_price = this->u.rail.running_cost_class;
295 if (base_price == INVALID_PRICE)
return 0;
300 base_price = PR_RUNNING_SHIP;
305 base_price = PR_RUNNING_AIRCRAFT;
309 default: NOT_REACHED();
323 switch (this->
type) {
325 base_price = PR_BUILD_VEHICLE_ROAD;
331 base_price = PR_BUILD_VEHICLE_WAGON;
334 base_price = PR_BUILD_VEHICLE_TRAIN;
340 base_price = PR_BUILD_VEHICLE_SHIP;
345 base_price = PR_BUILD_VEHICLE_AIRCRAFT;
349 default: NOT_REACHED();
361 switch (this->
type) {
367 return (max_speed != 0) ? max_speed * 2 : this->u.road.max_speed / 2;
375 if (max_speed != 0) {
376 return (max_speed * 128) / 10;
378 return this->u.air.max_speed;
381 default: NOT_REACHED();
394 switch (this->
type) {
400 default: NOT_REACHED();
412 switch (this->
type) {
418 default: NOT_REACHED();
430 switch (this->
type) {
436 default: NOT_REACHED();
456 switch (this->
type) {
460 default: NOT_REACHED();
470 switch (this->
type) {
472 switch (this->u.air.subtype) {
473 case AIR_HELI:
return STR_LIVERY_HELICOPTER;
474 case AIR_CTOL:
return STR_LIVERY_SMALL_PLANE;
475 case AIR_CTOL | AIR_FAST:
return STR_LIVERY_LARGE_PLANE;
476 default: NOT_REACHED();
479 default: NOT_REACHED();
491 this->emplace_back();
494 eid.
grfid = INVALID_GRFID;
554 const Engine *e =
new Engine(eid.type, eid.internal_id);
555 assert(e->
index == index);
560 void ShowEnginePreviewWindow(
EngineID engine);
585 if (retire_early != 0 && age >= retire_early_max_age) {
761 int32 best_hist = -1;
764 c->old_economy[0].performance_history > best_hist) {
768 if (v->owner != c->index || v->type != e->
type)
continue;
769 if (!v->GetEngine()->CanCarryCargo() || !
HasBit(cargomask, v->cargo_type))
continue;
771 best_hist = c->old_economy[0].performance_history;
772 best_company = c->index;
796 default: NOT_REACHED();
814 if (!--e->preview_wait) {
822 e->preview_asked = (CompanyMask)-1;
826 SetBit(e->preview_asked, e->preview_company);
827 e->preview_wait = 20;
847 SB(e->company_hidden, cid, 1, 0);
907 uint block_preview = c->block_preview;
912 c->block_preview = 20;
917 if (v->owner == c->index && v->engine_type == index) {
919 c->block_preview = block_preview;
938 RailType railtype = e->u.rail.railtype;
977 if (!e->IsEnabled())
continue;
990 if (
IsWagon(e->index))
continue;
995 e->preview_asked = 0;
1011 if (e->name !=
nullptr && strcmp(e->name, name) == 0)
return false;
1067 if (e ==
nullptr)
return false;
1070 if (e->
type != type)
return false;
1108 if (e ==
nullptr)
return false;
1113 if (ei->refit_mask == 0)
return false;
1121 CargoTypes default_cargo_mask = 0;
1122 SetBit(default_cargo_mask, default_cargo);
1123 return default_cargo !=
CT_INVALID && ei->refit_mask != default_cargo_mask;
1131 Date min_date = INT32_MAX;
1134 if (!e->IsEnabled())
continue;
1140 min_date =
min(min_date, e->info.base_intro);
1143 if (min_date < INT32_MAX) {
AISettings ai
what may the AI do?
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
VehicleSettings vehicle
options for vehicles
This vehicle is in the exclusive preview stage, either being used or being offered to a company...
uint16 reliability_start
Initial reliability of the engine.
uint16 reliability
Current reliability of the engine.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Functions for NewGRF engines.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static const int DAYS_IN_YEAR
days per year
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void CheckEngines()
Check for engines that have an appropriate availability.
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
void EnginesDailyLoop()
Daily check to offer an exclusive engine preview to the companies.
void UnloadWagonOverrides(Engine *e)
Unload all wagon override sprite groups.
byte landscape
the landscape we're currently in
Functions related to the autoreplace GUIs.
static bool IsUniqueEngineName(const char *name)
Is name still free as name for an engine?
uint32 grfid
The GRF ID of the file the entity belongs to.
bool IsEnabled() const
Checks whether the engine is a valid (non-articulated part of an) engine.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
static CompanyID GetPreviewCompany(Engine *e)
Get the best company for an engine preview.
Max. speed: 1 unit = 1/1.6 mph = 1 km-ish/h.
static Titem * Get(size_t index)
Returns Titem with given index.
bool CanCarryCargo() const
Determines whether an engine can carry something.
Functions related to dates.
Power in hp (if dualheaded: sum of both vehicles)
Conventional Take Off and Landing, i.e. planes.
const uint8 _engine_offsets[4]
Offset of the first engine of each vehicle type in original engine data.
Stores the state of all random number generators.
uint16 GetRange() const
Get the range of an aircraft type.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Replace vehicle window; Window numbers:
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Date intro_date
Date of introduction of the engine.
static const int GROUND_ACCELERATION
Acceleration due to gravity, 9.8 m/s^2.
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
VehicleType
Available vehicle types.
Yearly runningcost (if dualheaded: sum of both vehicles)
static void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
void StartupOneEngine(Engine *e, Date aging_date)
Start/initialise one engine.
void SetRandomSeed(uint32 seed)
(Re)set the state of the random number generators.
Functions related to vehicles.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
static bool IsWagon(EngineID index)
Determine whether an engine type is a wagon (and not a loco).
Price
Enumeration of all base prices for use with Prices.
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company...
Build vehicle; Window numbers:
UnitID max_aircraft
max planes in game per company
New vehicle has become available.
Purchase cost (if dualheaded: sum of both vehicles)
static Year _year_engine_aging_stops
Year that engine aging stops.
static const uint NUM_DEFAULT_ENGINES
Number of default entries.
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Tindex index
Index of this pool item.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Cargo capacity after refit.
Tractive effort coefficient in 1/256.
Common return value for all commands.
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
static T max(const T a, const T b)
Returns the maximum of two values.
static void NewVehicleAvailable(Engine *e)
An engine has become available for general use.
byte flags
Flags of the engine.
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the 'hidden' flag for all engines of a new company.
bool never_expire_vehicles
never expire vehicles
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set the visibility of an engine.
Year _cur_year
Current year, starting at 0.
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Date base_intro
Basic date of engine introduction (without random parts).
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Year lifelength
Lifetime of a single vehicle.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
uint16 duration_phase_2
Second reliability phase in months, keeping reliability_max.
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
RoadType roadtype
Road type.
Pseudo random number generator.
uint16 multiplier
Capacity multiplier for vehicles. (8 fractional bits)
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
bool ai_disable_veh_train
disable types for AI
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Functions related to low-level strings.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
Money GetCost() const
Return how much a new engine costs.
Engine preview window; Window numbers:
Information about a vehicle.
uint16 internal_id
The internal ID within the GRF file.
Functions related to errors.
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power ...
byte cargo_subtype
Used for livery refits (NewGRF variations)
void SetupEngines()
Initialise the engine pool with the data from the original vehicles.
void SetYearEngineAgingStops()
Compute the value for _year_engine_aging_stops.
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
Add the road types that are to be introduced at the given date.
int8 retire_early
Number of years early to retire vehicle.
UnitID max_roadveh
max trucks in game per company
Functions related to engines.
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Accept an engine prototype.
DoCommandFlag
List of flags for a command.
uint16 duration_phase_3
Third reliability phase on months, decaying to reliability_final.
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
simple wagon, not motorized
Stores the mapping of EngineID to the internal id of newgrfs.
Capacity (if dualheaded: for each single vehicle)
Definition of base types and functions in a cross-platform compatible way.
Show suffix after cargo name.
uint16 duration_phase_1
First reliability phase in months, increasing reliability from reliability_start to reliability_max...
Data structure to convert between Date and triplet (year, month, and day).
A number of safeguards to prevent using unsafe methods.
static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
Checks if a vehicle type is disabled for all/ai companies.
RailTypes introduces_railtypes
Bitmask of which other railtypes are introduced when this railtype is introduced. ...
Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
CargoID cargo_type
type of cargo this vehicle is carrying
static const int CARGO_AGING_TICKS
cycle duration for aging cargo
CompanyMask company_avail
Bit for each company whether the engine is available for that company.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
uint16 reliability_max
Maximal reliability of the engine.
static void CalcEngineReliability(Engine *e)
Update Engine::reliability and (if needed) update the engine GUIs.
byte misc_flags
Miscellaneous flags.
#define lengthof(x)
Return the length of an fixed size array.
uint16 reliability_final
Final reliability of the engine.
static T min(const T a, const T b)
Returns the minimum of two values.
bool ai_disable_veh_ship
disable types for AI
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
char * name
Custom name of engine.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
const uint8 _engine_counts[4]
Number of engines of each vehicle type in original engine data.
static void AcceptEnginePreview(EngineID eid, CompanyID company)
Company company accepts engine eid for preview.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Base class for all pools.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Build toolbar; Window numbers:
VehicleType type
The engine type.
void StartupEngines()
Start/initialise all our engines.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
CompanyID preview_company
Company which is currently being offered a preview INVALID_COMPANY means no company.
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
execute the given command
UnitID max_ships
max ships in game per company
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Functions related to companies.
Functions related to articulated vehicles.
RailType
Enumeration for all possible railtypes.
uint32 generation_seed
noise seed for world generation
void EnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Refit capacity, the passed vehicle needs to have its ->cargo_type set to the cargo we are refitting t...
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
uint16 EngineID
Unique identification number of an engine.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
uint32 TileIndex
The index/ID of a Tile.
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
indicates a combination of two locomotives
RoadTypes avail_roadtypes
Road types available to this company.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename an engine.
StringID string_id
Default name of engine.
byte extend_vehicle_life
extend vehicle life by this many years
bool ai_disable_veh_aircraft
disable types for AI
Maximum number of companies.
#define MAX_DAY
The number of days till the last day.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Transport by road vehicle.
Default value to indicate that visual effect should be based on engine class.
static uint CountBits(T value)
Counts the number of set bits in a variable.
uint8 substitute_id
The (original) entity ID to use if this GRF is not available (currently not used) ...
Functions related to commands.
CompanyID _current_company
Company currently doing an action.
uint16 local_id
id defined by the grf file for this entity
UnitID max_trains
max trains in game per company
Max. speed: 1 unit = 8 mph = 12.8 km-ish/h.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
int32 Date
The type to store our dates in.
Tractive effort coefficient in 1/256.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
Money GetRunningCost() const
Return how much the running costs of this engine are.
EngineID engine_type
The type of engine used for this vehicle.
RailTypes avail_railtypes
Rail types available to this company.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base functions for all AIs.
static void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, void *free_data=nullptr)
Add a new newsitem to be shown.
GameCreationSettings game_creation
settings used during the creation of a game (map)
byte CargoID
Cargo slots to indicate a cargo type within a game.
uint16 cargo_age_period
Number of ticks before carried cargo is aged.
Weight in t (if dualheaded: for each single vehicle)
Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life...
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
This vehicle is available to everyone.
Window functions not directly related to making/drawing windows.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced. ...
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipl...
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
Functions related to news.
bool ai_disable_veh_roadveh
disable types for AI
byte climates
Climates supported by the engine.
Date _date
Current date in days (day counter)
Vehicle news item. (new engine available)
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
The object is owned by a superuser / goal script.
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date)
Add the rail types that are to be introduced at the given date.
Year starting_year
starting date
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
virtual void CleanPool()
Virtual method that deletes all items in the pool.
void ResetToDefaultMapping()
Initializes the EngineOverrideManager with the default engines.
Dynamic data of a loaded NewGRF.
This file contains all the data for vehicles.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Base for the NewGRF implementation.