OpenTTD Source: src/engine.cpp Source File

OpenTTD Source 12.0-beta1

engine.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "stdafx.h"
11 #include "company_func.h"
12 #include "command_func.h"
13 #include "news_func.h"
14 #include "aircraft.h"
15 #include "newgrf.h"
16 #include "newgrf_engine.h"
17 #include "strings_func.h"
18 #include "core/random_func.hpp"
19 #include "window_func.h"
20 #include "date_func.h"
21 #include "autoreplace_gui.h"
22 #include "string_func.h"
23 #include "ai/ai.hpp"
24 #include "core/pool_func.hpp"
25 #include "engine_gui.h"
26 #include "engine_func.h"
27 #include "engine_base.h"
28 #include "company_base.h"
29 #include "vehicle_func.h"
30 #include "articulated_vehicles.h"
31 #include "error.h"
32
33 #include "table/strings.h"
34 #include "table/engines.h"
35
36 #include "safeguards.h"
37
38 EnginePool _engine_pool("Engine");
39 INSTANTIATE_POOL_METHODS(Engine)
40
41 EngineOverrideManager _engine_mngr;
42
47 static Year _year_engine_aging_stops;
48
50 const uint8 _engine_counts[4] = {
51 lengthof(_orig_rail_vehicle_info),
52 lengthof(_orig_road_vehicle_info),
53 lengthof(_orig_ship_vehicle_info),
54 lengthof(_orig_aircraft_vehicle_info),
55 };
56
58 const uint8 _engine_offsets[4] = {
59 0,
60 lengthof(_orig_rail_vehicle_info),
61 lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
62 lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
63 };
64
65 static_assert(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info));
66
67 const uint EngineOverrideManager::NUM_DEFAULT_ENGINES = _engine_counts[VEH_TRAIN] + _engine_counts[VEH_ROAD] + _engine_counts[VEH_SHIP] + _engine_counts[VEH_AIRCRAFT];
68
69 Engine::Engine(VehicleType type, EngineID base)
70 {
71 this->type = type;
72 this->grf_prop.local_id = base;
73 this->list_position = base;
74 this->preview_company = INVALID_COMPANY;
75
76 /* Check if this base engine is within the original engine data range */
77 if (base >= _engine_counts[type]) {
78 /* Set model life to maximum to make wagons available */
79 this->info.base_life = 0xFF;
80 /* Set road vehicle tractive effort to the default value */
81 if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C;
82 /* Aircraft must have CT_INVALID as default, as there is no property */
83 if (type == VEH_AIRCRAFT) this->info.cargo_type = CT_INVALID;
84 /* Set visual effect to the default value */
85 switch (type) {
86 case VEH_TRAIN: this->u.rail.visual_effect = VE_DEFAULT; break;
87 case VEH_ROAD: this->u.road.visual_effect = VE_DEFAULT; break;
88 case VEH_SHIP: this->u.ship.visual_effect = VE_DEFAULT; break;
89 default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects
90 }
91 /* Set cargo aging period to the default value. */
92 this->info.cargo_age_period = CARGO_AGING_TICKS;
93 return;
94 }
95
96 /* Copy the original engine info for this slot */
97 this->info = _orig_engine_info[_engine_offsets[type] + base];
98
99 /* Copy the original engine data for this slot */
100 switch (type) {
101 default: NOT_REACHED();
102
103 case VEH_TRAIN:
104 this->u.rail = _orig_rail_vehicle_info[base];
105 this->original_image_index = this->u.rail.image_index;
106 this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base;
107
108 /* Set the default model life of original wagons to "infinite" */
109 if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = 0xFF;
110
111 break;
112
113 case VEH_ROAD:
114 this->u.road = _orig_road_vehicle_info[base];
115 this->original_image_index = this->u.road.image_index;
116 this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base;
117 break;
118
119 case VEH_SHIP:
120 this->u.ship = _orig_ship_vehicle_info[base];
121 this->original_image_index = this->u.ship.image_index;
122 this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base;
123 break;
124
125 case VEH_AIRCRAFT:
126 this->u.air = _orig_aircraft_vehicle_info[base];
127 this->original_image_index = this->u.air.image_index;
128 this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base;
129 break;
130 }
131 }
132
137 bool Engine::IsEnabled() const
138 {
139 return this->info.string_id != STR_NEWGRF_INVALID_ENGINE && HasBit(this->info.climates, _settings_game.game_creation.landscape);
140 }
141
147 uint32 Engine::GetGRFID() const
148 {
149 const GRFFile *file = this->GetGRF();
150 return file == nullptr ? 0 : file->grfid;
151 }
152
158 bool Engine::CanCarryCargo() const
159 {
160 /* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity
161 * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used
162 * for livery selection etc.
163 * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
164 */
165 switch (this->type) {
166 case VEH_TRAIN:
167 if (this->u.rail.capacity == 0) return false;
168 break;
169
170 case VEH_ROAD:
171 if (this->u.road.capacity == 0) return false;
172 break;
173
174 case VEH_SHIP:
175 case VEH_AIRCRAFT:
176 break;
177
178 default: NOT_REACHED();
179 }
180 return this->GetDefaultCargoType() != CT_INVALID;
181 }
182
183
191 uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
192 {
193 assert(v == nullptr || this->index == v->engine_type);
194 if (mail_capacity != nullptr) *mail_capacity = 0;
195
196 if (!this->CanCarryCargo()) return 0;
197
198 bool new_multipliers = HasBit(this->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER);
199 CargoID default_cargo = this->GetDefaultCargoType();
200 CargoID cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
201
202 if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) {
203 *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
204 }
205
206 /* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */
207 if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) &&
208 (new_multipliers || default_cargo != cargo_type || (v != nullptr && v->cargo_subtype != 0))) {
209 uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v);
210 if (callback != CALLBACK_FAILED) return callback;
211 }
212
213 /* Get capacity according to property resp. CB */
214 uint capacity;
215 uint extra_mail_cap = 0;
216 switch (this->type) {
217 case VEH_TRAIN:
218 capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v);
219
220 /* In purchase list add the capacity of the second head. Always use the plain property for this. */
221 if (v == nullptr && this->u.rail.railveh_type == RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
222 break;
223
224 case VEH_ROAD:
225 capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity, v);
226 break;
227
228 case VEH_SHIP:
229 capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity, v);
230 break;
231
232 case VEH_AIRCRAFT:
233 capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v);
234 if (!IsCargoInClass(cargo_type, CC_PASSENGERS)) {
235 extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
236 }
237 if (!new_multipliers && cargo_type == CT_MAIL) return capacity + extra_mail_cap;
238 default_cargo = CT_PASSENGERS; // Always use 'passengers' wrt. cargo multipliers
239 break;
240
241 default: NOT_REACHED();
242 }
243
244 if (!new_multipliers) {
245 /* Use the passenger multiplier for mail as well */
246 capacity += extra_mail_cap;
247 extra_mail_cap = 0;
248 }
249
250 /* Apply multipliers depending on cargo- and vehicletype. */
251 if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) {
252 uint16 default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier;
253 uint16 cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier;
254 capacity *= cargo_multiplier;
255 if (extra_mail_cap > 0) {
256 uint mail_multiplier = CargoSpec::Get(CT_MAIL)->multiplier;
257 capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier;
258 }
259 capacity = (capacity + default_multiplier / 2) / default_multiplier;
260 }
261
262 return capacity;
263 }
264
269 Money Engine::GetRunningCost() const
270 {
271 Price base_price;
272 uint cost_factor;
273 switch (this->type) {
274 case VEH_ROAD:
275 base_price = this->u.road.running_cost_class;
276 if (base_price == INVALID_PRICE) return 0;
277 cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost);
278 break;
279
280 case VEH_TRAIN:
281 base_price = this->u.rail.running_cost_class;
282 if (base_price == INVALID_PRICE) return 0;
283 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost);
284 break;
285
286 case VEH_SHIP:
287 base_price = PR_RUNNING_SHIP;
288 cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost);
289 break;
290
291 case VEH_AIRCRAFT:
292 base_price = PR_RUNNING_AIRCRAFT;
293 cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost);
294 break;
295
296 default: NOT_REACHED();
297 }
298
299 return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
300 }
301
306 Money Engine::GetCost() const
307 {
308 Price base_price;
309 uint cost_factor;
310 switch (this->type) {
311 case VEH_ROAD:
312 base_price = PR_BUILD_VEHICLE_ROAD;
313 cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor);
314 break;
315
316 case VEH_TRAIN:
317 if (this->u.rail.railveh_type == RAILVEH_WAGON) {
318 base_price = PR_BUILD_VEHICLE_WAGON;
319 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
320 } else {
321 base_price = PR_BUILD_VEHICLE_TRAIN;
322 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
323 }
324 break;
325
326 case VEH_SHIP:
327 base_price = PR_BUILD_VEHICLE_SHIP;
328 cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor);
329 break;
330
331 case VEH_AIRCRAFT:
332 base_price = PR_BUILD_VEHICLE_AIRCRAFT;
333 cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor);
334 break;
335
336 default: NOT_REACHED();
337 }
338
339 return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
340 }
341
346 uint Engine::GetDisplayMaxSpeed() const
347 {
348 switch (this->type) {
349 case VEH_TRAIN:
350 return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->u.rail.max_speed);
351
352 case VEH_ROAD: {
353 uint max_speed = GetEngineProperty(this->index, PROP_ROADVEH_SPEED, 0);
354 return (max_speed != 0) ? max_speed * 2 : this->u.road.max_speed / 2;
355 }
356
357 case VEH_SHIP:
358 return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->u.ship.max_speed) / 2;
359
360 case VEH_AIRCRAFT: {
361 uint max_speed = GetEngineProperty(this->index, PROP_AIRCRAFT_SPEED, 0);
362 if (max_speed != 0) {
363 return (max_speed * 128) / 10;
364 }
365 return this->u.air.max_speed;
366 }
367
368 default: NOT_REACHED();
369 }
370 }
371
378 uint Engine::GetPower() const
379 {
380 /* Only trains and road vehicles have 'power'. */
381 switch (this->type) {
382 case VEH_TRAIN:
383 return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->u.rail.power);
384 case VEH_ROAD:
385 return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->u.road.power) * 10;
386
387 default: NOT_REACHED();
388 }
389 }
390
396 uint Engine::GetDisplayWeight() const
397 {
398 /* Only trains and road vehicles have 'weight'. */
399 switch (this->type) {
400 case VEH_TRAIN:
401 return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
402 case VEH_ROAD:
403 return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->u.road.weight) / 4;
404
405 default: NOT_REACHED();
406 }
407 }
408
414 uint Engine::GetDisplayMaxTractiveEffort() const
415 {
416 /* Only trains and road vehicles have 'tractive effort'. */
417 switch (this->type) {
418 case VEH_TRAIN:
419 return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256 / 1000;
420 case VEH_ROAD:
421 return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256 / 1000;
422
423 default: NOT_REACHED();
424 }
425 }
426
431 Date Engine::GetLifeLengthInDays() const
432 {
433 /* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */
434 return (this->info.lifelength + _settings_game.vehicle.extend_vehicle_life) * DAYS_IN_LEAP_YEAR;
435 }
436
441 uint16 Engine::GetRange() const
442 {
443 switch (this->type) {
444 case VEH_AIRCRAFT:
445 return GetEngineProperty(this->index, PROP_AIRCRAFT_RANGE, this->u.air.max_range);
446
447 default: NOT_REACHED();
448 }
449 }
450
455 StringID Engine::GetAircraftTypeText() const
456 {
457 switch (this->type) {
458 case VEH_AIRCRAFT:
459 switch (this->u.air.subtype) {
460 case AIR_HELI: return STR_LIVERY_HELICOPTER;
461 case AIR_CTOL: return STR_LIVERY_SMALL_PLANE;
462 case AIR_CTOL | AIR_FAST: return STR_LIVERY_LARGE_PLANE;
463 default: NOT_REACHED();
464 }
465
466 default: NOT_REACHED();
467 }
468 }
469
473 void EngineOverrideManager::ResetToDefaultMapping()
474 {
475 this->clear();
476 for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
477 for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
478 EngineIDMapping &eid = this->emplace_back();
479 eid.type = type;
480 eid.grfid = INVALID_GRFID;
481 eid.internal_id = internal_id;
482 eid.substitute_id = internal_id;
483 }
484 }
485 }
486
496 EngineID EngineOverrideManager::GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
497 {
498 EngineID index = 0;
499 for (const EngineIDMapping &eid : *this) {
500 if (eid.type == type && eid.grfid == grfid && eid.internal_id == grf_local_id) {
501 return index;
502 }
503 index++;
504 }
505 return INVALID_ENGINE;
506 }
507
513 bool EngineOverrideManager::ResetToCurrentNewGRFConfig()
514 {
515 for (const Vehicle *v : Vehicle::Iterate()) {
516 if (IsCompanyBuildableVehicleType(v)) return false;
517 }
518
519 /* Reset the engines, they will get new EngineIDs */
520 _engine_mngr.ResetToDefaultMapping();
521 ReloadNewGRFData();
522
523 return true;
524 }
525
529 void SetupEngines()
530 {
531 CloseWindowByClass(WC_ENGINE_PREVIEW);
532 _engine_pool.CleanPool();
533
534 assert(_engine_mngr.size() >= _engine_mngr.NUM_DEFAULT_ENGINES);
535 uint index = 0;
536 for (const EngineIDMapping &eid : _engine_mngr) {
537 /* Assert is safe; there won't be more than 256 original vehicles
538 * in any case, and we just cleaned the pool. */
539 assert(Engine::CanAllocateItem());
540 [[maybe_unused]] const Engine *e = new Engine(eid.type, eid.internal_id);
541 assert(e->index == index);
542 index++;
543 }
544 }
545
546 void ShowEnginePreviewWindow(EngineID engine);
547
553 static bool IsWagon(EngineID index)
554 {
555 const Engine *e = Engine::Get(index);
556 return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON;
557 }
558
563 static void CalcEngineReliability(Engine *e)
564 {
565 uint age = e->age;
566
567 /* Check for early retirement */
568 if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
569 int retire_early = e->info.retire_early;
570 uint retire_early_max_age = std::max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
571 if (retire_early != 0 && age >= retire_early_max_age) {
572 /* Early retirement is enabled and we're past the date... */
573 e->company_avail = 0;
574 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
575 }
576 }
577
578 if (age < e->duration_phase_1) {
579 uint start = e->reliability_start;
580 e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
581 } else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) {
582 /* We are at the peak of this engines life. It will have max reliability.
583 * This is also true if the engines never expire. They will not go bad over time */
584 e->reliability = e->reliability_max;
585 } else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
586 uint max = e->reliability_max;
587 e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
588 } else {
589 /* time's up for this engine.
590 * We will now completely retire this design */
591 e->company_avail = 0;
592 e->reliability = e->reliability_final;
593 /* Kick this engine out of the lists */
594 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
595 }
596 SetWindowClassesDirty(WC_BUILD_VEHICLE); // Update to show the new reliability
597 SetWindowClassesDirty(WC_REPLACE_VEHICLE);
598 }
599
601 void SetYearEngineAgingStops()
602 {
603 /* Determine last engine aging year, default to 2050 as previously. */
604 _year_engine_aging_stops = 2050;
605
606 for (const Engine *e : Engine::Iterate()) {
607 const EngineInfo *ei = &e->info;
608
609 /* Exclude certain engines */
610 if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue;
611 if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
612
613 /* Base year ending date on half the model life */
614 YearMonthDay ymd;
615 ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
616
617 _year_engine_aging_stops = std::max(_year_engine_aging_stops, ymd.year);
618 }
619 }
620
626 void StartupOneEngine(Engine *e, Date aging_date)
627 {
628 const EngineInfo *ei = &e->info;
629
630 e->age = 0;
631 e->flags = 0;
632 e->company_avail = 0;
633 e->company_hidden = 0;
634
635 /* Vehicles with the same base_intro date shall be introduced at the same time.
636 * Make sure they use the same randomisation of the date. */
637 SavedRandomSeeds saved_seeds;
638 SaveRandomSeeds(&saved_seeds);
639 SetRandomSeed(_settings_game.game_creation.generation_seed ^
640 ei->base_intro ^
641 e->type ^
642 e->GetGRFID());
643 uint32 r = Random();
644
645 /* Don't randomise the start-date in the first two years after gamestart to ensure availability
646 * of engines in early starting games.
647 * Note: TTDP uses fixed 1922 */
648 e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
649 if (e->intro_date <= _date) {
650 e->age = (aging_date - e->intro_date) >> 5;
651 e->company_avail = (CompanyMask)-1;
652 e->flags |= ENGINE_AVAILABLE;
653 }
654
655 RestoreRandomSeeds(saved_seeds);
656
657 r = Random();
658 e->reliability_start = GB(r, 16, 14) + 0x7AE0;
659 e->reliability_max = GB(r, 0, 14) + 0xBFFF;
660
661 r = Random();
662 e->reliability_final = GB(r, 16, 14) + 0x3FFF;
663 e->duration_phase_1 = GB(r, 0, 5) + 7;
664 e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
665 e->duration_phase_3 = GB(r, 9, 7) + 120;
666
667 e->reliability_spd_dec = ei->decay_speed << 2;
668
669 CalcEngineReliability(e);
670
671 /* prevent certain engines from ever appearing. */
672 if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) {
673 e->flags |= ENGINE_AVAILABLE;
674 e->company_avail = 0;
675 }
676 }
677
682 void StartupEngines()
683 {
684 /* Aging of vehicles stops, so account for that when starting late */
685 const Date aging_date = std::min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
686
687 for (Engine *e : Engine::Iterate()) {
688 StartupOneEngine(e, aging_date);
689 }
690
691 /* Update the bitmasks for the vehicle lists */
692 for (Company *c : Company::Iterate()) {
693 c->avail_railtypes = GetCompanyRailtypes(c->index);
694 c->avail_roadtypes = GetCompanyRoadTypes(c->index);
695 }
696
697 /* Invalidate any open purchase lists */
698 InvalidateWindowClassesData(WC_BUILD_VEHICLE);
699 }
700
706 static void EnableEngineForCompany(EngineID eid, CompanyID company)
707 {
708 Engine *e = Engine::Get(eid);
709 Company *c = Company::Get(company);
710
711 SetBit(e->company_avail, company);
712 if (e->type == VEH_TRAIN) {
713 c->avail_railtypes = GetCompanyRailtypes(c->index);
714 } else if (e->type == VEH_ROAD) {
715 c->avail_roadtypes = GetCompanyRoadTypes(c->index);
716 }
717
718 if (company == _local_company) {
719 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
720
721 /* Update the toolbar. */
722 InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
723 if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
724 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
725 if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
726 }
727 }
728
734 static void DisableEngineForCompany(EngineID eid, CompanyID company)
735 {
736 Engine *e = Engine::Get(eid);
737 Company *c = Company::Get(company);
738
739 ClrBit(e->company_avail, company);
740 if (e->type == VEH_TRAIN) {
741 c->avail_railtypes = GetCompanyRailtypes(c->index);
742 } else if (e->type == VEH_ROAD) {
743 c->avail_roadtypes = GetCompanyRoadTypes(c->index);
744 }
745
746 if (company == _local_company) {
747 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
748 }
749 }
750
756 static void AcceptEnginePreview(EngineID eid, CompanyID company)
757 {
758 Engine *e = Engine::Get(eid);
759
760 e->preview_company = INVALID_COMPANY;
761 e->preview_asked = (CompanyMask)-1;
762
763 EnableEngineForCompany(eid, company);
764
765 /* Notify preview window, that it might want to close.
766 * Note: We cannot directly close the window.
767 * In singleplayer this function is called from the preview window, so
768 * we have to use the GUI-scope scheduling of InvalidateWindowData.
769 */
770 InvalidateWindowData(WC_ENGINE_PREVIEW, eid);
771 }
772
778 static CompanyID GetPreviewCompany(Engine *e)
779 {
780 CompanyID best_company = INVALID_COMPANY;
781
782 /* For trains the cargomask has no useful meaning, since you can attach other wagons */
783 CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
784
785 int32 best_hist = -1;
786 for (const Company *c : Company::Iterate()) {
787 if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
788 c->old_economy[0].performance_history > best_hist) {
789
790 /* Check whether the company uses similar vehicles */
791 for (const Vehicle *v : Vehicle::Iterate()) {
792 if (v->owner != c->index || v->type != e->type) continue;
793 if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue;
794
795 best_hist = c->old_economy[0].performance_history;
796 best_company = c->index;
797 break;
798 }
799 }
800 }
801
802 return best_company;
803 }
804
812 static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
813 {
814 switch (type) {
815 case VEH_TRAIN: return _settings_game.vehicle.max_trains == 0 || (ai && _settings_game.ai.ai_disable_veh_train);
816 case VEH_ROAD: return _settings_game.vehicle.max_roadveh == 0 || (ai && _settings_game.ai.ai_disable_veh_roadveh);
817 case VEH_SHIP: return _settings_game.vehicle.max_ships == 0 || (ai && _settings_game.ai.ai_disable_veh_ship);
818 case VEH_AIRCRAFT: return _settings_game.vehicle.max_aircraft == 0 || (ai && _settings_game.ai.ai_disable_veh_aircraft);
819
820 default: NOT_REACHED();
821 }
822 }
823
825 void EnginesDailyLoop()
826 {
827 for (Company *c : Company::Iterate()) {
828 c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date);
829 c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, _date);
830 }
831
832 if (_cur_year >= _year_engine_aging_stops) return;
833
834 for (Engine *e : Engine::Iterate()) {
835 EngineID i = e->index;
836 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
837 if (e->preview_company != INVALID_COMPANY) {
838 if (!--e->preview_wait) {
839 CloseWindowById(WC_ENGINE_PREVIEW, i);
840 e->preview_company = INVALID_COMPANY;
841 }
842 } else if (CountBits(e->preview_asked) < MAX_COMPANIES) {
843 e->preview_company = GetPreviewCompany(e);
844
845 if (e->preview_company == INVALID_COMPANY) {
846 e->preview_asked = (CompanyMask)-1;
847 continue;
848 }
849
850 SetBit(e->preview_asked, e->preview_company);
851 e->preview_wait = 20;
852 /* AIs are intentionally not skipped for preview even if they cannot build a certain
853 * vehicle type. This is done to not give poor performing human companies an "unfair"
854 * boost that they wouldn't have gotten against other human companies. The check on
855 * the line below is just to make AIs not notice that they have a preview if they
856 * cannot build the vehicle. */
857 if (!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));
858 if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);
859 }
860 }
861 }
862 }
863
868 void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
869 {
870 for (Engine *e : Engine::Iterate()) {
871 SB(e->company_hidden, cid, 1, 0);
872 }
873 }
874
884 CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
885 {
886 Engine *e = Engine::GetIfValid(GB(p2, 0, 31));
887 if (e == nullptr || _current_company >= MAX_COMPANIES) return CMD_ERROR;
888 if (!IsEngineBuildable(e->index, e->type, _current_company)) return CMD_ERROR;
889
890 if ((flags & DC_EXEC) != 0) {
891 SB(e->company_hidden, _current_company, 1, GB(p2, 31, 1));
892 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
893 }
894
895 return CommandCost();
896 }
897
908 CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
909 {
910 Engine *e = Engine::GetIfValid(p1);
911 if (e == nullptr || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
912
913 if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
914
915 return CommandCost();
916 }
917
929 CommandCost CmdEngineCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
930 {
931 if (_current_company != OWNER_DEITY) return CMD_ERROR;
932 EngineID engine_id = (EngineID)p1;
933 CompanyID company_id = (CompanyID)GB(p2, 0, 8);
934 bool allow = HasBit(p2, 31);
935
936 if (!Engine::IsValidID(engine_id) || !Company::IsValidID(company_id)) return CMD_ERROR;
937
938 if (flags & DC_EXEC) {
939 if (allow) {
940 EnableEngineForCompany(engine_id, company_id);
941 } else {
942 DisableEngineForCompany(engine_id, company_id);
943 }
944 }
945
946 return CommandCost();
947 }
948
954 static void NewVehicleAvailable(Engine *e)
955 {
956 EngineID index = e->index;
957
958 /* In case the company didn't build the vehicle during the intro period,
959 * prevent that company from getting future intro periods for a while. */
960 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
961 for (Company *c : Company::Iterate()) {
962 uint block_preview = c->block_preview;
963
964 if (!HasBit(e->company_avail, c->index)) continue;
965
966 /* We assume the user did NOT build it.. prove me wrong ;) */
967 c->block_preview = 20;
968
969 for (const Vehicle *v : Vehicle::Iterate()) {
970 if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
971 (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
972 if (v->owner == c->index && v->engine_type == index) {
973 /* The user did prove me wrong, so restore old value */
974 c->block_preview = block_preview;
975 break;
976 }
977 }
978 }
979 }
980 }
981
982 e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
983 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
984
985 /* Now available for all companies */
986 e->company_avail = (CompanyMask)-1;
987
988 /* Do not introduce new rail wagons */
989 if (IsWagon(index)) return;
990
991 if (e->type == VEH_TRAIN) {
992 /* maybe make another rail type available */
993 assert(e->u.rail.railtype < RAILTYPE_END);
994 for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
995 } else if (e->type == VEH_ROAD) {
996 /* maybe make another road type available */
997 assert(e->u.road.roadtype < ROADTYPE_END);
998 for (Company* c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
999 }
1000
1001 /* Only broadcast event if AIs are able to build this vehicle type. */
1002 if (!IsVehicleTypeDisabled(e->type, true)) AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index));
1003
1004 /* Only provide the "New Vehicle available" news paper entry, if engine can be built. */
1005 if (!IsVehicleTypeDisabled(e->type, false)) {
1006 SetDParam(0, GetEngineCategoryName(index));
1007 SetDParam(1, index);
1008 AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NT_NEW_VEHICLES, NF_VEHICLE, NR_ENGINE, index);
1009 }
1010
1011 /* Update the toolbar. */
1012 if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
1013 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
1014 if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
1015
1016 /* Close pending preview windows */
1017 CloseWindowById(WC_ENGINE_PREVIEW, index);
1018 }
1019
1021 void EnginesMonthlyLoop()
1022 {
1023 if (_cur_year < _year_engine_aging_stops) {
1024 for (Engine *e : Engine::Iterate()) {
1025 /* Age the vehicle */
1026 if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) {
1027 e->age++;
1028 CalcEngineReliability(e);
1029 }
1030
1031 /* Do not introduce invalid engines */
1032 if (!e->IsEnabled()) continue;
1033
1034 if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) {
1035 /* Introduce it to all companies */
1036 NewVehicleAvailable(e);
1037 } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
1038 /* Introduction date has passed...
1039 * Check if it is allowed to build this vehicle type at all
1040 * based on the current game settings. If not, it does not
1041 * make sense to show the preview dialog to any company. */
1042 if (IsVehicleTypeDisabled(e->type, false)) continue;
1043
1044 /* Do not introduce new rail wagons */
1045 if (IsWagon(e->index)) continue;
1046
1047 /* Show preview dialog to one of the companies. */
1048 e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
1049 e->preview_company = INVALID_COMPANY;
1050 e->preview_asked = 0;
1051 }
1052 }
1053
1054 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // rebuild the purchase list (esp. when sorted by reliability)
1055 }
1056 }
1057
1063 static bool IsUniqueEngineName(const std::string &name)
1064 {
1065 for (const Engine *e : Engine::Iterate()) {
1066 if (!e->name.empty() && e->name == name) return false;
1067 }
1068
1069 return true;
1070 }
1071
1081 CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
1082 {
1083 Engine *e = Engine::GetIfValid(p1);
1084 if (e == nullptr) return CMD_ERROR;
1085
1086 bool reset = text.empty();
1087
1088 if (!reset) {
1089 if (Utf8StringLength(text) >= MAX_LENGTH_ENGINE_NAME_CHARS) return CMD_ERROR;
1090 if (!IsUniqueEngineName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1091 }
1092
1093 if (flags & DC_EXEC) {
1094 if (reset) {
1095 e->name.clear();
1096 } else {
1097 e->name = text;
1098 }
1099
1100 MarkWholeScreenDirty();
1101 }
1102
1103 return CommandCost();
1104 }
1105
1106
1115 bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
1116 {
1117 const Engine *e = Engine::GetIfValid(engine);
1118
1119 /* check if it's an engine that is in the engine array */
1120 if (e == nullptr) return false;
1121
1122 /* check if it's an engine of specified type */
1123 if (e->type != type) return false;
1124
1125 /* check if it's available ... */
1126 if (company == OWNER_DEITY) {
1127 /* ... for any company (preview does not count) */
1128 if (!(e->flags & ENGINE_AVAILABLE) || e->company_avail == 0) return false;
1129 } else {
1130 /* ... for this company */
1131 if (!HasBit(e->company_avail, company)) return false;
1132 }
1133
1134 if (!e->IsEnabled()) return false;
1135
1136 if (type == VEH_TRAIN && company != OWNER_DEITY) {
1137 /* Check if the rail type is available to this company */
1138 const Company *c = Company::Get(company);
1139 if (((GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false;
1140 }
1141 if (type == VEH_ROAD && company != OWNER_DEITY) {
1142 /* Check if the road type is available to this company */
1143 const Company *c = Company::Get(company);
1144 if ((GetRoadTypeInfo(e->u.road.roadtype)->powered_roadtypes & c->avail_roadtypes) == ROADTYPES_NONE) return false;
1145 }
1146
1147 return true;
1148 }
1149
1156 bool IsEngineRefittable(EngineID engine)
1157 {
1158 const Engine *e = Engine::GetIfValid(engine);
1159
1160 /* check if it's an engine that is in the engine array */
1161 if (e == nullptr) return false;
1162
1163 if (!e->CanCarryCargo()) return false;
1164
1165 const EngineInfo *ei = &e->info;
1166 if (ei->refit_mask == 0) return false;
1167
1168 /* Are there suffixes?
1169 * Note: This does not mean the suffixes are actually available for every consist at any time. */
1170 if (HasBit(ei->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
1171
1172 /* Is there any cargo except the default cargo? */
1173 CargoID default_cargo = e->GetDefaultCargoType();
1174 CargoTypes default_cargo_mask = 0;
1175 SetBit(default_cargo_mask, default_cargo);
1176 return default_cargo != CT_INVALID && ei->refit_mask != default_cargo_mask;
1177 }
1178
1182 void CheckEngines()
1183 {
1184 Date min_date = INT32_MAX;
1185
1186 for (const Engine *e : Engine::Iterate()) {
1187 if (!e->IsEnabled()) continue;
1188
1189 /* We have an available engine... yay! */
1190 if ((e->flags & ENGINE_AVAILABLE) != 0 && e->company_avail != 0) return;
1191
1192 /* Okay, try to find the earliest date. */
1193 min_date = std::min(min_date, e->info.base_intro);
1194 }
1195
1196 if (min_date < INT32_MAX) {
1197 SetDParam(0, min_date);
1198 ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_YET, STR_ERROR_NO_VEHICLES_AVAILABLE_YET_EXPLANATION, WL_WARNING);
1199 } else {
1200 ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_AT_ALL, STR_ERROR_NO_VEHICLES_AVAILABLE_AT_ALL_EXPLANATION, WL_WARNING);
1201 }
1202 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
AddDateIntroducedRailTypes
RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date)
Add the rail types that are to be introduced at the given date.
Definition: rail.cpp:218
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:175
EngineInfo::base_life
Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life.
Definition: engine_type.h:136
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
VehicleSettings::max_aircraft
UnitID max_aircraft
max planes in game per company
Definition: settings_type.h:486
Engine::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:147
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
InvalidateWindowData
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-...
Definition: window.cpp:3218
CheckEngines
void CheckEngines()
Check for engines that have an appropriate availability.
Definition: engine.cpp:1182
PROP_TRAIN_SPEED
@ PROP_TRAIN_SPEED
Max. speed: 1 unit = 1/1.6 mph = 1 km-ish/h.
Definition: newgrf_properties.h:21
GameCreationSettings::generation_seed
uint32 generation_seed
noise seed for world generation
Definition: settings_type.h:304
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:513
NT_NEW_VEHICLES
@ NT_NEW_VEHICLES
New vehicle has become available.
Definition: news_type.h:33
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:65
EngineOverrideManager::ResetToDefaultMapping
void ResetToDefaultMapping()
Initializes the EngineOverrideManager with the default engines.
Definition: engine.cpp:473
PROP_TRAIN_CARGO_CAPACITY
@ PROP_TRAIN_CARGO_CAPACITY
Capacity (if dualheaded: for each single vehicle)
Definition: newgrf_properties.h:24
AISettings::ai_disable_veh_roadveh
bool ai_disable_veh_roadveh
disable types for AI
Definition: settings_type.h:361
PROP_ROADVEH_TRACTIVE_EFFORT
@ PROP_ROADVEH_TRACTIVE_EFFORT
Tractive effort coefficient in 1/256.
Definition: newgrf_properties.h:39
ReloadNewGRFData
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3182
EngineIDMapping::grfid
uint32 grfid
The GRF ID of the file the entity belongs to.
Definition: engine_base.h:168
Engine::reliability_max
uint16 reliability_max
Maximal reliability of the engine.
Definition: engine_base.h:34
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:953
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Engine::duration_phase_3
uint16 duration_phase_3
Third reliability phase in months, decaying to reliability_final.
Definition: engine_base.h:38
PROP_ROADVEH_COST_FACTOR
@ PROP_ROADVEH_COST_FACTOR
Purchase cost.
Definition: newgrf_properties.h:35
command_func.h
Pool::PoolItem<&_engine_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
Company::avail_railtypes
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:119
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:23
PROP_TRAIN_RUNNING_COST_FACTOR
@ PROP_TRAIN_RUNNING_COST_FACTOR
Yearly runningcost (if dualheaded: sum of both vehicles)
Definition: newgrf_properties.h:23
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:320
Engine::reliability_spd_dec
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:32
RoadTypeInfo::introduces_roadtypes
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition: road.h:174
Company::avail_roadtypes
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:120
_engine_counts
const uint8 _engine_counts[4]
Number of engines of each vehicle type in original engine data.
Definition: engine.cpp:50
company_base.h
IsWagon
static bool IsWagon(EngineID index)
Determine whether an engine type is a wagon (and not a loco).
Definition: engine.cpp:553
GetPreviewCompany
static CompanyID GetPreviewCompany(Engine *e)
Get the best company for an engine preview.
Definition: engine.cpp:778
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
PROP_TRAIN_TRACTIVE_EFFORT
@ PROP_TRAIN_TRACTIVE_EFFORT
Tractive effort coefficient in 1/256.
Definition: newgrf_properties.h:27
EnginesDailyLoop
void EnginesDailyLoop()
Daily check to offer an exclusive engine preview to the companies.
Definition: engine.cpp:825
Pool::CleanPool
virtual void CleanPool()
Virtual method that deletes all items in the pool.
_year_engine_aging_stops
static Year _year_engine_aging_stops
Year that engine aging stops.
Definition: engine.cpp:47
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:74
PROP_AIRCRAFT_MAIL_CAPACITY
@ PROP_AIRCRAFT_MAIL_CAPACITY
Mail Capacity.
Definition: newgrf_properties.h:53
Engine::company_avail
CompanyMask company_avail
Bit for each company whether the engine is available for that company.
Definition: engine_base.h:43
WC_ENGINE_PREVIEW
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Definition: window_type.h:581
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition: engine.cpp:414
VE_DEFAULT
@ VE_DEFAULT
Default value to indicate that visual effect should be based on engine class.
Definition: vehicle_base.h:93
SavedRandomSeeds
Stores the state of all random number generators.
Definition: random_func.hpp:33
Pool::PoolItem<&_engine_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:119
PROP_SHIP_CARGO_CAPACITY
@ PROP_SHIP_CARGO_CAPACITY
Capacity.
Definition: newgrf_properties.h:45
Engine::duration_phase_1
uint16 duration_phase_1
First reliability phase in months, increasing reliability from reliability_start to reliability_max.
Definition: engine_base.h:36
PROP_AIRCRAFT_RUNNING_COST_FACTOR
@ PROP_AIRCRAFT_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:51
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
EnableEngineForCompany
static void EnableEngineForCompany(EngineID eid, CompanyID company)
Allows engine eid to be used by a company company.
Definition: engine.cpp:706
SaveRandomSeeds
static void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
Definition: random_func.hpp:42
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition: engine.cpp:269
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, const NewsAllocatedData *data=nullptr)
Add a new newsitem to be shown.
Definition: news_gui.cpp:807
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
Engine::reliability_start
uint16 reliability_start
Initial reliability of the engine.
Definition: engine_base.h:33
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition: engine_gui.cpp:38
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
autoreplace_gui.h
aircraft.h
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
SetupEngines
void SetupEngines()
Initialise the engine pool with the data from the original vehicles.
Definition: engine.cpp:529
AddDateIntroducedRoadTypes
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:155
Engine::preview_company
CompanyID preview_company
Company which is currently being offered a preview INVALID_COMPANY means no company.
Definition: engine_base.h:41
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition: road.cpp:188
StartupOneEngine
void StartupOneEngine(Engine *e, Date aging_date)
Start/initialise one engine.
Definition: engine.cpp:626
Engine::GetLifeLengthInDays
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:431
EngineInfo
Information about a vehicle.
Definition: engine_type.h:133
EngineInfo::base_intro
Date base_intro
Basic date of engine introduction (without random parts).
Definition: engine_type.h:134
CBM_VEHICLE_CARGO_SUFFIX
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
Definition: newgrf_callbacks.h:294
Engine
Definition: engine_base.h:27
MAX_DAY
#define MAX_DAY
The number of days till the last day.
Definition: date_type.h:98
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:41
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:221
EngineIDMapping::internal_id
uint16 internal_id
The internal ID within the GRF file.
Definition: engine_base.h:169
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:83
Engine::company_hidden
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
Definition: engine_base.h:44
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:126
StartupEngines
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:682
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1155
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
DisableEngineForCompany
static void DisableEngineForCompany(EngineID eid, CompanyID company)
Forbids engine eid to be used by a company company.
Definition: engine.cpp:734
EngineOverrideManager::GetID
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Definition: engine.cpp:496
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
RestoreRandomSeeds
static void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
Definition: random_func.hpp:52
ShowErrorMessage
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.
Definition: error_gui.cpp:383
CountBits
static uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:251
VehicleSettings::extend_vehicle_life
byte extend_vehicle_life
extend vehicle life by this many years
Definition: settings_type.h:492
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:576
ai.hpp
EngineInfo::lifelength
Year lifelength
Lifetime of a single vehicle.
Definition: engine_type.h:135
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:142
IsUniqueEngineName
static bool IsUniqueEngineName(const std::string &name)
Is name still free as name for an engine?
Definition: engine.cpp:1063
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
ENGINE_EXCLUSIVE_PREVIEW
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
Definition: engine_type.h:170
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition: engine.cpp:346
Utf8StringLength
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...
Definition: string.cpp:417
PROP_ROADVEH_SPEED
@ PROP_ROADVEH_SPEED
Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h.
Definition: newgrf_properties.h:38
IsVehicleTypeDisabled
static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
Checks if a vehicle type is disabled for all/ai companies.
Definition: engine.cpp:812
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:119
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:33
AISettings::ai_disable_veh_train
bool ai_disable_veh_train
disable types for AI
Definition: settings_type.h:360
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:234
CommandCost
Common return value for all commands.
Definition: command_type.h:23
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:255
newgrf_engine.h
EngineInfo::callback_mask
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition: engine_type.h:144
VehicleSettings::max_ships
UnitID max_ships
max ships in game per company
Definition: settings_type.h:487
CARGO_AGING_TICKS
static const int CARGO_AGING_TICKS
cycle duration for aging cargo
Definition: date_type.h:36
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:299
SB
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.
Definition: bitmath_func.hpp:58
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
GROUND_ACCELERATION
static const int GROUND_ACCELERATION
Acceleration due to gravity, 9.8 m/s^2.
Definition: vehicle_type.h:18
MAX_LENGTH_ENGINE_NAME_CHARS
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
Definition: engine_type.h:173
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
Engine::preview_asked
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
Definition: engine_base.h:40
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition: window_type.h:210
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:53
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition: engine.cpp:396
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:259
safeguards.h
IsInteractiveCompany
static bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
Definition: company_func.h:53
CalcEngineReliability
static void CalcEngineReliability(Engine *e)
Update Engine::reliability and (if needed) update the engine GUIs.
Definition: engine.cpp:563
EnginesMonthlyLoop
void EnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition: engine.cpp:1021
error.h
EngineIDMapping
Definition: engine_base.h:167
EngineInfo::retire_early
int8 retire_early
Number of years early to retire vehicle.
Definition: engine_type.h:145
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
EngineIDMapping::substitute_id
uint8 substitute_id
The (original) entity ID to use if this GRF is not available (currently not used)
Definition: engine_base.h:171
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:306
date_func.h
stdafx.h
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
PROP_AIRCRAFT_COST_FACTOR
@ PROP_AIRCRAFT_COST_FACTOR
Purchase cost.
Definition: newgrf_properties.h:49
CmdRenameEngine
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Rename an engine.
Definition: engine.cpp:1081
ENGINE_AVAILABLE
@ ENGINE_AVAILABLE
This vehicle is available to everyone.
Definition: engine_type.h:169
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:143
PROP_SHIP_RUNNING_COST_FACTOR
@ PROP_SHIP_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:46
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
CBM_VEHICLE_REFIT_CAPACITY
@ CBM_VEHICLE_REFIT_CAPACITY
Cargo capacity after refit.
Definition: newgrf_callbacks.h:292
Engine::reliability_final
uint16 reliability_final
Final reliability of the engine.
Definition: engine_base.h:35
_engine_offsets
const uint8 _engine_offsets[4]
Offset of the first engine of each vehicle type in original engine data.
Definition: engine.cpp:58
GameSettings::ai
AISettings ai
what may the AI do?
Definition: settings_type.h:578
YearMonthDay::year
Year year
Year (0...)
Definition: date_type.h:105
string_func.h
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
AISettings::ai_disable_veh_ship
bool ai_disable_veh_ship
disable types for AI
Definition: settings_type.h:363
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
PROP_TRAIN_WEIGHT
@ PROP_TRAIN_WEIGHT
Weight in t (if dualheaded: for each single vehicle)
Definition: newgrf_properties.h:25
Engine::name
std::string name
Custom name of engine.
Definition: engine_base.h:28
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
engine_gui.h
strings_func.h
Pool
Base class for all pools.
Definition: pool_type.hpp:81
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:158
VehicleSettings::max_trains
UnitID max_trains
max trains in game per company
Definition: settings_type.h:484
SetRandomSeed
void SetRandomSeed(uint32 seed)
(Re)set the state of the random number generators.
Definition: random_func.cpp:65
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:375
CmdSetVehicleVisibility
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Set the visibility of an engine.
Definition: engine.cpp:884
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1164
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition: engine.cpp:378
CmdWantEnginePreview
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Accept an engine prototype.
Definition: engine.cpp:908
RAILTYPE_END
@ RAILTYPE_END
Used for iterations.
Definition: rail_type.h:33
EF_NO_DEFAULT_CARGO_MULTIPLIER
@ EF_NO_DEFAULT_CARGO_MULTIPLIER
Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipl...
Definition: engine_type.h:160
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1188
InvalidateWindowClassesData
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...
Definition: window.cpp:3235
Aircraft::IsNormalAircraft
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow.
Definition: aircraft.h:121
EngineOverrideManager
Stores the mapping of EngineID to the internal id of newgrfs.
Definition: engine_base.h:178
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
GetCompanyRailtypes
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:251
AISettings::ai_disable_veh_aircraft
bool ai_disable_veh_aircraft
disable types for AI
Definition: settings_type.h:362
newgrf.h
Pool::PoolItem<&_engine_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:307
DAYS_IN_YEAR
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:29
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:224
TRANSPORT_AIR
@ TRANSPORT_AIR
Transport through air.
Definition: transport_type.h:30
NewVehicleAvailable
static void NewVehicleAvailable(Engine *e)
An engine has become available for general use.
Definition: engine.cpp:954
PROP_ROADVEH_CARGO_CAPACITY
@ PROP_ROADVEH_CARGO_CAPACITY
Capacity.
Definition: newgrf_properties.h:34
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:305
company_func.h
VehicleSettings::max_roadveh
UnitID max_roadveh
max trucks in game per company
Definition: settings_type.h:485
Engine::original_image_index
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:45
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:224
CargoSpec::multiplier
uint16 multiplier
Capacity multiplier for vehicles. (8 fractional bits)
Definition: cargotype.h:63
AIR_CTOL
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition: engine_type.h:93
window_func.h
NF_VEHICLE
@ NF_VEHICLE
Vehicle news item. (new engine available)
Definition: news_type.h:79
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1689
CBID_VEHICLE_REFIT_CAPACITY
@ CBID_VEHICLE_REFIT_CAPACITY
Refit capacity, the passed vehicle needs to have its ->cargo_type set to the cargo we are refitting t...
Definition: newgrf_callbacks.h:48
random_func.hpp
Engine::DetermineCapacity
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
Definition: engine.cpp:191
OverflowSafeInt< int64 >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
VehicleSettings::never_expire_vehicles
bool never_expire_vehicles
never expire vehicles
Definition: settings_type.h:491
Engine::IsEnabled
bool IsEnabled() const
Checks whether the engine is a valid (non-articulated part of an) engine.
Definition: engine.cpp:137
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
PROP_SHIP_COST_FACTOR
@ PROP_SHIP_COST_FACTOR
Purchase cost.
Definition: newgrf_properties.h:43
engine_base.h
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:316
Engine::grf_prop
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Definition: engine_base.h:64
GRFFilePropsBase::local_id
uint16 local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:319
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:584
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:317
EngineInfo::climates
byte climates
Climates supported by the engine.
Definition: engine_type.h:139
PROP_SHIP_SPEED
@ PROP_SHIP_SPEED
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
Definition: newgrf_properties.h:44
PROP_AIRCRAFT_PASSENGER_CAPACITY
@ PROP_AIRCRAFT_PASSENGER_CAPACITY
Passenger Capacity.
Definition: newgrf_properties.h:52
IsEngineRefittable
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1156
PROP_ROADVEH_POWER
@ PROP_ROADVEH_POWER
Power in 10 HP.
Definition: newgrf_properties.h:36
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_engine_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
PROP_TRAIN_COST_FACTOR
@ PROP_TRAIN_COST_FACTOR
Purchase cost (if dualheaded: sum of both vehicles)
Definition: newgrf_properties.h:26
PROP_AIRCRAFT_SPEED
@ PROP_AIRCRAFT_SPEED
Max. speed: 1 unit = 8 mph = 12.8 km-ish/h.
Definition: newgrf_properties.h:50
engines.h
Engine::GetRange
uint16 GetRange() const
Get the range of an aircraft type.
Definition: engine.cpp:441
EngineIDMapping::type
VehicleType type
The engine type.
Definition: engine_base.h:170
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:39
pool_func.hpp
EngineInfo::string_id
StringID string_id
Default name of engine.
Definition: engine_type.h:146
ClearEnginesHiddenFlagOfCompany
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the 'hidden' flag for all engines of a new company.
Definition: engine.cpp:868
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
IsCargoInClass
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:194
PROP_TRAIN_POWER
@ PROP_TRAIN_POWER
Power in hp (if dualheaded: sum of both vehicles)
Definition: newgrf_properties.h:22
AddRemoveEngineFromAutoreplaceAndBuildWindows
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
Definition: autoreplace_gui.cpp:63
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
ROADTYPES_NONE
@ ROADTYPES_NONE
No roadtypes.
Definition: road_type.h:37
Company
Definition: company_base.h:115
PROP_ROADVEH_RUNNING_COST_FACTOR
@ PROP_ROADVEH_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:33
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:50
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3146
PROP_AIRCRAFT_RANGE
@ PROP_AIRCRAFT_RANGE
Aircraft range.
Definition: newgrf_properties.h:55
EngineInfo::cargo_age_period
uint16 cargo_age_period
Number of ticks before carried cargo is aged.
Definition: engine_type.h:147
SetYearEngineAgingStops
void SetYearEngineAgingStops()
Compute the value for _year_engine_aging_stops.
Definition: engine.cpp:601
CmdEngineCtrl
CommandCost CmdEngineCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Allow or forbid a specific company to use an engine.
Definition: engine.cpp:929
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1115
Engine::intro_date
Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:29
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:455
EngineOverrideManager::NUM_DEFAULT_ENGINES
static const uint NUM_DEFAULT_ENGINES
Number of default entries.
Definition: engine_base.h:179
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:56
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
Engine::reliability
uint16 reliability
Current reliability of the engine.
Definition: engine_base.h:31
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:46
AcceptEnginePreview
static void AcceptEnginePreview(EngineID eid, CompanyID company)
Company company accepts engine eid for preview.
Definition: engine.cpp:756
Engine::duration_phase_2
uint16 duration_phase_2
Second reliability phase in months, keeping reliability_max.
Definition: engine_base.h:37
PROP_ROADVEH_WEIGHT
@ PROP_ROADVEH_WEIGHT
Weight in 1/4 t.
Definition: newgrf_properties.h:37
engine_func.h
news_func.h
RailtypeInfo::introduces_railtypes
RailTypes introduces_railtypes
Bitmask of which other railtypes are introduced when this railtype is introduced.
Definition: rail.h:263