35 #include "table/strings.h" 56 lengthof(_orig_aircraft_vehicle_info),
82 this->list_position = base;
90 if (type ==
VEH_ROAD) this->u.road.tractive_effort = 0x4C;
110 default: NOT_REACHED();
113 this->u.rail = _orig_rail_vehicle_info[base];
115 this->info.
string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base;
123 this->u.road = _orig_road_vehicle_info[base];
125 this->info.
string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base;
129 this->u.ship = _orig_ship_vehicle_info[base];
131 this->info.
string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base;
135 this->u.air = _orig_aircraft_vehicle_info[base];
137 this->info.
string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base;
165 return file == NULL ? 0 : file->grfid;
180 switch (this->
type) {
182 if (this->u.rail.capacity == 0)
return false;
186 if (this->u.road.capacity == 0)
return false;
193 default: NOT_REACHED();
209 if (mail_capacity != NULL) *mail_capacity = 0;
223 (new_multipliers || default_cargo != cargo_type || (v != NULL && v->
cargo_subtype != 0))) {
230 uint extra_mail_cap = 0;
231 switch (this->
type) {
236 if (v == NULL && this->u.rail.railveh_type ==
RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
252 if (!new_multipliers && cargo_type == CT_MAIL)
return capacity + extra_mail_cap;
253 default_cargo = CT_PASSENGERS;
256 default: NOT_REACHED();
259 if (!new_multipliers) {
261 capacity += extra_mail_cap;
266 if (new_multipliers || (this->
type !=
VEH_SHIP && default_cargo != cargo_type)) {
269 capacity *= cargo_multiplier;
270 if (extra_mail_cap > 0) {
272 capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier;
274 capacity = (capacity + default_multiplier / 2) / default_multiplier;
288 switch (this->
type) {
290 base_price = this->u.road.running_cost_class;
291 if (base_price == INVALID_PRICE)
return 0;
296 base_price = this->u.rail.running_cost_class;
297 if (base_price == INVALID_PRICE)
return 0;
302 base_price = PR_RUNNING_SHIP;
307 base_price = PR_RUNNING_AIRCRAFT;
311 default: NOT_REACHED();
325 switch (this->
type) {
327 base_price = PR_BUILD_VEHICLE_ROAD;
333 base_price = PR_BUILD_VEHICLE_WAGON;
336 base_price = PR_BUILD_VEHICLE_TRAIN;
342 base_price = PR_BUILD_VEHICLE_SHIP;
347 base_price = PR_BUILD_VEHICLE_AIRCRAFT;
351 default: NOT_REACHED();
363 switch (this->
type) {
369 return (max_speed != 0) ? max_speed * 2 : this->u.road.max_speed / 2;
377 if (max_speed != 0) {
378 return (max_speed * 128) / 10;
380 return this->u.air.max_speed;
383 default: NOT_REACHED();
396 switch (this->
type) {
402 default: NOT_REACHED();
414 switch (this->
type) {
420 default: NOT_REACHED();
432 switch (this->
type) {
438 default: NOT_REACHED();
458 switch (this->
type) {
462 default: NOT_REACHED();
472 switch (this->
type) {
474 switch (this->u.air.subtype) {
475 case AIR_HELI:
return STR_LIVERY_HELICOPTER;
476 case AIR_CTOL:
return STR_LIVERY_SMALL_PLANE;
477 case AIR_CTOL | AIR_FAST:
return STR_LIVERY_LARGE_PLANE;
478 default: NOT_REACHED();
481 default: NOT_REACHED();
495 eid->
grfid = INVALID_GRFID;
515 for (
const EngineIDMapping *eid = this->Begin(); eid != end; eid++, index++) {
516 if (eid->type == type && eid->grfid == grfid && eid->internal_id == grf_local_id) {
557 const Engine *e =
new Engine(eid->type, eid->internal_id);
558 assert(e->
index == index);
562 void ShowEnginePreviewWindow(
EngineID engine);
587 if (retire_early != 0 && age >= retire_early_max_age) {
700 FOR_ALL_COMPANIES(c) {
757 int32 best_hist = -1;
759 FOR_ALL_COMPANIES(c) {
770 best_company = c->
index;
794 default: NOT_REACHED();
802 FOR_ALL_COMPANIES(c) {
908 FOR_ALL_COMPANIES(c) {
940 RailType railtype = e->u.rail.railtype;
1014 FOR_ALL_ENGINES(e) {
1015 if (e->
name != NULL && strcmp(e->
name, name) == 0)
return false;
1071 if (e == NULL)
return false;
1074 if (e->
type != type)
return false;
1107 if (e == NULL)
return false;
1112 if (ei->refit_mask == 0)
return false;
1120 return default_cargo !=
CT_INVALID && ei->refit_mask != 1U << default_cargo;
1129 Date min_date = INT32_MAX;
1131 FOR_ALL_ENGINES(e) {
1141 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.
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
RailType
Enumeration for all possible railtypes.
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.
int32 performance_history
Company score (scale 0-1000)
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.
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.
byte block_preview
Number of quarters that the company is not allowed to get new exclusive engine previews (see Companie...
Yearly runningcost (if dualheaded: sum of both vehicles)
void StartupOneEngine(Engine *e, Date aging_date)
Start/initialise one engine.
Functions related to vehicles.
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.
const T * Begin() const
Get the pointer to the first item (const)
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.
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Cargo capacity after refit.
RoadTypes GetCompanyRoadtypes(CompanyID company)
Get the road types the given company can build.
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.
const T * End() const
Get the pointer behind the last valid item (const)
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
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.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Pseudo random number generator.
uint16 multiplier
Capacity multiplier for vehicles. (8 fractional bits)
The object is owned by a superuser / goal script.
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...
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
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.
byte cargo_subtype
Used for livery refits (NewGRF variations)
uint Length() const
Get the number of items in the list.
void SetupEngines()
Initialise the engine pool with the data from the original vehicles.
void SetYearEngineAgingStops()
Compute the value for _year_engine_aging_stops.
int8 retire_early
Number of years early to retire vehicle.
UnitID max_roadveh
max trucks in game per company
Functions related to engines.
VehicleType
Available vehicle types.
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 #reliability of engine e, (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.
RailTypes GetCompanyRailtypes(CompanyID company)
Get the rail types the given company can build.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Maximum number of companies.
#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.
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=NULL) const
Determines capacity of a given vehicle from scratch.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Build toolbar; Window numbers:
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?
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.
byte preview_wait
Daily countdown timer for timeout of offering the engine to the preview_company company.
Functions related to companies.
Functions related to articulated vehicles.
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 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.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
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=NULL)
Add a new newsitem to be shown.
RailTypes avail_railtypes
Rail types available to the company.
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
VehicleTypeByte type
The engine type.
OwnerByte owner
Which company owns the vehicle?
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
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
bool ai_disable_veh_aircraft
disable types for AI
#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.
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.
CompanyByte preview_company
Company which is currently being offered a preview INVALID_COMPANY means no company.
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.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base functions for all AIs.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
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.
Road vehicle is a tram/light rail vehicle.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
This vehicle is available to everyone.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
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)
Functions related to news.
bool ai_disable_veh_roadveh
disable types for AI
uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
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.
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
VehicleTypeByte type
Type of vehicle.
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.