OpenTTD Source  14.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 "autoreplace_gui.h"
21 #include "string_func.h"
22 #include "ai/ai.hpp"
23 #include "core/pool_func.hpp"
24 #include "engine_gui.h"
25 #include "engine_func.h"
26 #include "engine_base.h"
27 #include "company_base.h"
28 #include "vehicle_func.h"
29 #include "articulated_vehicles.h"
30 #include "error.h"
31 #include "engine_base.h"
32 #include "timer/timer.h"
33 #include "timer/timer_game_tick.h"
35 
36 #include "table/strings.h"
37 #include "table/engines.h"
38 
39 #include "safeguards.h"
40 
41 EnginePool _engine_pool("Engine");
43 
44 EngineOverrideManager _engine_mngr;
45 
51 
53 const uint8_t _engine_counts[4] = {
54  lengthof(_orig_rail_vehicle_info),
55  lengthof(_orig_road_vehicle_info),
56  lengthof(_orig_ship_vehicle_info),
57  lengthof(_orig_aircraft_vehicle_info),
58 };
59 
61 const uint8_t _engine_offsets[4] = {
62  0,
63  lengthof(_orig_rail_vehicle_info),
64  lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
65  lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
66 };
67 
68 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));
69 
71 
72 Engine::Engine(VehicleType type, EngineID base)
73 {
74  this->type = type;
75  this->grf_prop.local_id = base;
76  this->list_position = base;
79 
80  /* Check if this base engine is within the original engine data range */
81  if (base >= _engine_counts[type]) {
82  /* 'power' defaults to zero, so we also have to default to 'wagon' */
83  if (type == VEH_TRAIN) this->u.rail.railveh_type = RAILVEH_WAGON;
84  /* Set model life to maximum to make wagons available */
85  this->info.base_life = 0xFF;
86  /* Set road vehicle tractive effort to the default value */
87  if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C;
88  /* Aircraft must have INVALID_CARGO as default, as there is no property */
89  if (type == VEH_AIRCRAFT) this->info.cargo_type = INVALID_CARGO;
90  /* Ships must have a non-zero acceleration. */
91  if (type == VEH_SHIP) this->u.ship.acceleration = 1;
92  /* Set visual effect to the default value */
93  switch (type) {
94  case VEH_TRAIN: this->u.rail.visual_effect = VE_DEFAULT; break;
95  case VEH_ROAD: this->u.road.visual_effect = VE_DEFAULT; break;
96  case VEH_SHIP: this->u.ship.visual_effect = VE_DEFAULT; break;
97  default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects
98  }
99  /* Set cargo aging period to the default value. */
101  /* Not a variant */
102  this->info.variant_id = INVALID_ENGINE;
103  return;
104  }
105 
106  /* Copy the original engine info for this slot */
107  this->info = _orig_engine_info[_engine_offsets[type] + base];
108 
109  /* Copy the original engine data for this slot */
110  switch (type) {
111  default: NOT_REACHED();
112 
113  case VEH_TRAIN:
114  this->u.rail = _orig_rail_vehicle_info[base];
115  this->original_image_index = this->u.rail.image_index;
116  this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base;
117 
118  /* Set the default model life of original wagons to "infinite" */
119  if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = 0xFF;
120 
121  break;
122 
123  case VEH_ROAD:
124  this->u.road = _orig_road_vehicle_info[base];
125  this->original_image_index = this->u.road.image_index;
126  this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base;
127  break;
128 
129  case VEH_SHIP:
130  this->u.ship = _orig_ship_vehicle_info[base];
131  this->original_image_index = this->u.ship.image_index;
132  this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base;
133  break;
134 
135  case VEH_AIRCRAFT:
136  this->u.air = _orig_aircraft_vehicle_info[base];
137  this->original_image_index = this->u.air.image_index;
138  this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base;
139  break;
140  }
141 }
142 
147 bool Engine::IsEnabled() const
148 {
149  return this->info.string_id != STR_NEWGRF_INVALID_ENGINE && HasBit(this->info.climates, _settings_game.game_creation.landscape);
150 }
151 
157 uint32_t Engine::GetGRFID() const
158 {
159  const GRFFile *file = this->GetGRF();
160  return file == nullptr ? 0 : file->grfid;
161 }
162 
169 {
170  /* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity
171  * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used
172  * for livery selection etc.
173  * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
174  */
175  switch (this->type) {
176  case VEH_TRAIN:
177  if (this->u.rail.capacity == 0) return false;
178  break;
179 
180  case VEH_ROAD:
181  if (this->u.road.capacity == 0) return false;
182  break;
183 
184  case VEH_SHIP:
185  case VEH_AIRCRAFT:
186  break;
187 
188  default: NOT_REACHED();
189  }
190  return IsValidCargoID(this->GetDefaultCargoType());
191 }
192 
193 
201 uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
202 {
203  assert(v == nullptr || this->index == v->engine_type);
204  if (mail_capacity != nullptr) *mail_capacity = 0;
205 
206  if (!this->CanCarryCargo()) return 0;
207 
208  bool new_multipliers = HasBit(this->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER);
209  CargoID default_cargo = this->GetDefaultCargoType();
210  CargoID cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
211 
212  if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) {
213  *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
214  }
215 
216  /* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */
218  (new_multipliers || default_cargo != cargo_type || (v != nullptr && v->cargo_subtype != 0))) {
219  uint16_t callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v);
220  if (callback != CALLBACK_FAILED) return callback;
221  }
222 
223  /* Get capacity according to property resp. CB */
224  uint capacity;
225  uint extra_mail_cap = 0;
226  switch (this->type) {
227  case VEH_TRAIN:
228  capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v);
229 
230  /* In purchase list add the capacity of the second head. Always use the plain property for this. */
231  if (v == nullptr && this->u.rail.railveh_type == RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
232  break;
233 
234  case VEH_ROAD:
235  capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity, v);
236  break;
237 
238  case VEH_SHIP:
239  capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity, v);
240  break;
241 
242  case VEH_AIRCRAFT:
243  capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v);
244  if (!IsCargoInClass(cargo_type, CC_PASSENGERS)) {
245  extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
246  }
247  if (!new_multipliers && cargo_type == CT_MAIL) return capacity + extra_mail_cap;
248  default_cargo = CT_PASSENGERS; // Always use 'passengers' wrt. cargo multipliers
249  break;
250 
251  default: NOT_REACHED();
252  }
253 
254  if (!new_multipliers) {
255  /* Use the passenger multiplier for mail as well */
256  capacity += extra_mail_cap;
257  extra_mail_cap = 0;
258  }
259 
260  /* Apply multipliers depending on cargo- and vehicletype. */
261  if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) {
262  uint16_t default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier;
263  uint16_t cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier;
264  capacity *= cargo_multiplier;
265  if (extra_mail_cap > 0) {
266  uint mail_multiplier = CargoSpec::Get(CT_MAIL)->multiplier;
267  capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier;
268  }
269  capacity = (capacity + default_multiplier / 2) / default_multiplier;
270  }
271 
272  return capacity;
273 }
274 
280 {
281  Price base_price;
282  uint cost_factor;
283  switch (this->type) {
284  case VEH_ROAD:
285  base_price = this->u.road.running_cost_class;
286  if (base_price == INVALID_PRICE) return 0;
287  cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost);
288  break;
289 
290  case VEH_TRAIN:
291  base_price = this->u.rail.running_cost_class;
292  if (base_price == INVALID_PRICE) return 0;
293  cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost);
294  break;
295 
296  case VEH_SHIP:
297  base_price = PR_RUNNING_SHIP;
298  cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost);
299  break;
300 
301  case VEH_AIRCRAFT:
302  base_price = PR_RUNNING_AIRCRAFT;
303  cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost);
304  break;
305 
306  default: NOT_REACHED();
307  }
308 
309  return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
310 }
311 
317 {
318  Price base_price;
319  uint cost_factor;
320  switch (this->type) {
321  case VEH_ROAD:
322  base_price = PR_BUILD_VEHICLE_ROAD;
323  cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor);
324  break;
325 
326  case VEH_TRAIN:
327  if (this->u.rail.railveh_type == RAILVEH_WAGON) {
328  base_price = PR_BUILD_VEHICLE_WAGON;
329  cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
330  } else {
331  base_price = PR_BUILD_VEHICLE_TRAIN;
332  cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
333  }
334  break;
335 
336  case VEH_SHIP:
337  base_price = PR_BUILD_VEHICLE_SHIP;
338  cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor);
339  break;
340 
341  case VEH_AIRCRAFT:
342  base_price = PR_BUILD_VEHICLE_AIRCRAFT;
343  cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor);
344  break;
345 
346  default: NOT_REACHED();
347  }
348 
349  return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
350 }
351 
357 {
358  switch (this->type) {
359  case VEH_TRAIN:
360  return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->u.rail.max_speed);
361 
362  case VEH_ROAD: {
363  uint max_speed = GetEngineProperty(this->index, PROP_ROADVEH_SPEED, 0);
364  return (max_speed != 0) ? max_speed * 2 : this->u.road.max_speed / 2;
365  }
366 
367  case VEH_SHIP:
368  return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->u.ship.max_speed) / 2;
369 
370  case VEH_AIRCRAFT: {
371  uint max_speed = GetEngineProperty(this->index, PROP_AIRCRAFT_SPEED, 0);
372  if (max_speed != 0) {
373  return (max_speed * 128) / 10;
374  }
375  return this->u.air.max_speed;
376  }
377 
378  default: NOT_REACHED();
379  }
380 }
381 
388 uint Engine::GetPower() const
389 {
390  /* Only trains and road vehicles have 'power'. */
391  switch (this->type) {
392  case VEH_TRAIN:
393  return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->u.rail.power);
394  case VEH_ROAD:
395  return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->u.road.power) * 10;
396 
397  default: NOT_REACHED();
398  }
399 }
400 
407 {
408  /* Only trains and road vehicles have 'weight'. */
409  switch (this->type) {
410  case VEH_TRAIN:
411  return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
412  case VEH_ROAD:
413  return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->u.road.weight) / 4;
414 
415  default: NOT_REACHED();
416  }
417 }
418 
425 {
426  /* Only trains and road vehicles have 'tractive effort'. */
427  switch (this->type) {
428  case VEH_TRAIN:
429  return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256;
430  case VEH_ROAD:
431  return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256;
432 
433  default: NOT_REACHED();
434  }
435 }
436 
442 {
443  /* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */
445 }
446 
451 uint16_t Engine::GetRange() const
452 {
453  switch (this->type) {
454  case VEH_AIRCRAFT:
455  return GetEngineProperty(this->index, PROP_AIRCRAFT_RANGE, this->u.air.max_range);
456 
457  default: NOT_REACHED();
458  }
459 }
460 
466 {
467  switch (this->type) {
468  case VEH_AIRCRAFT:
469  switch (this->u.air.subtype) {
470  case AIR_HELI: return STR_LIVERY_HELICOPTER;
471  case AIR_CTOL: return STR_LIVERY_SMALL_PLANE;
472  case AIR_CTOL | AIR_FAST: return STR_LIVERY_LARGE_PLANE;
473  default: NOT_REACHED();
474  }
475 
476  default: NOT_REACHED();
477  }
478 }
479 
486 {
487  /* In case company is spectator. */
488  if (c >= MAX_COMPANIES) return false;
489 
490  /* Shortcut if this engine is explicitly hidden. */
491  if (this->IsHidden(c)) return true;
492 
493  /* Check for hidden parent variants. This is a bit convoluted as we must check hidden status of
494  * the last display variant rather than the actual parent variant. */
495  const Engine *re = this;
496  const Engine *ve = re->GetDisplayVariant();
497  while (!(ve->IsHidden(c)) && re->info.variant_id != INVALID_ENGINE) {
498  re = Engine::Get(re->info.variant_id);
499  ve = re->GetDisplayVariant();
500  }
501  return ve->IsHidden(c);
502 }
503 
508 {
509  this->clear();
510  for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
511  for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
512  EngineIDMapping &eid = this->emplace_back();
513  eid.type = type;
514  eid.grfid = INVALID_GRFID;
515  eid.internal_id = internal_id;
516  eid.substitute_id = internal_id;
517  }
518  }
519 }
520 
530 EngineID EngineOverrideManager::GetID(VehicleType type, uint16_t grf_local_id, uint32_t grfid)
531 {
532  EngineID index = 0;
533  for (const EngineIDMapping &eid : *this) {
534  if (eid.type == type && eid.grfid == grfid && eid.internal_id == grf_local_id) {
535  return index;
536  }
537  index++;
538  }
539  return INVALID_ENGINE;
540 }
541 
548 {
549  for (const Vehicle *v : Vehicle::Iterate()) {
550  if (IsCompanyBuildableVehicleType(v)) return false;
551  }
552 
553  /* Reset the engines, they will get new EngineIDs */
554  _engine_mngr.ResetToDefaultMapping();
556 
557  return true;
558 }
559 
564 {
566  _engine_pool.CleanPool();
567 
568  assert(_engine_mngr.size() >= _engine_mngr.NUM_DEFAULT_ENGINES);
569  [[maybe_unused]] uint index = 0;
570  for (const EngineIDMapping &eid : _engine_mngr) {
571  /* Assert is safe; there won't be more than 256 original vehicles
572  * in any case, and we just cleaned the pool. */
573  assert(Engine::CanAllocateItem());
574  [[maybe_unused]] const Engine *e = new Engine(eid.type, eid.internal_id);
575  assert(e->index == index);
576  index++;
577  }
578 }
579 
580 void ShowEnginePreviewWindow(EngineID engine);
581 
587 static bool IsWagon(EngineID index)
588 {
589  const Engine *e = Engine::Get(index);
590  return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON;
591 }
592 
598 static void ClearLastVariant(EngineID engine_id, VehicleType type)
599 {
600  for (Engine *e : Engine::IterateType(type)) {
601  if (e->display_last_variant == engine_id) e->display_last_variant = INVALID_ENGINE;
602  }
603 }
604 
609 void CalcEngineReliability(Engine *e, bool new_month)
610 {
611  /* Get source engine for reliability age. This is normally our engine unless variant reliability syncing is requested. */
612  Engine *re = e;
613  while (re->info.variant_id != INVALID_ENGINE && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
614  re = Engine::Get(re->info.variant_id);
615  }
616 
617  uint32_t age = re->age;
618  if (new_month && re->index > e->index && age != INT32_MAX) age++; /* parent variant's age has not yet updated. */
619 
620  /* Check for early retirement */
621  if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
622  int retire_early = e->info.retire_early;
623  uint retire_early_max_age = std::max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
624  if (retire_early != 0 && age >= retire_early_max_age) {
625  /* Early retirement is enabled and we're past the date... */
626  e->company_avail = 0;
627  ClearLastVariant(e->index, e->type);
629  }
630  }
631 
632  if (age < e->duration_phase_1) {
633  uint start = e->reliability_start;
634  e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
635  } else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) {
636  /* We are at the peak of this engines life. It will have max reliability.
637  * This is also true if the engines never expire. They will not go bad over time */
639  } else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
640  uint max = e->reliability_max;
641  e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
642  } else {
643  /* time's up for this engine.
644  * We will now completely retire this design */
645  e->company_avail = 0;
647  /* Kick this engine out of the lists */
648  ClearLastVariant(e->index, e->type);
650  }
651 
652 }
653 
656 {
657  /* Determine last engine aging year, default to 2050 as previously. */
659 
660  for (const Engine *e : Engine::Iterate()) {
661  const EngineInfo *ei = &e->info;
662 
663  /* Exclude certain engines */
665  if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
666 
667  /* Base year ending date on half the model life */
668  TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (ei->lifelength.base() * CalendarTime::DAYS_IN_LEAP_YEAR) / 2);
669 
671  }
672 }
673 
680 void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ymd, uint32_t seed)
681 {
682  const EngineInfo *ei = &e->info;
683 
684  e->age = 0;
685  e->flags = 0;
686  e->company_avail = 0;
687  e->company_hidden = 0;
688 
689  /* Vehicles with the same base_intro date shall be introduced at the same time.
690  * Make sure they use the same randomisation of the date. */
691  SavedRandomSeeds saved_seeds;
692  SaveRandomSeeds(&saved_seeds);
694  ei->base_intro.base() ^
695  e->type ^
696  e->GetGRFID());
697  uint32_t r = Random();
698 
699  /* Don't randomise the start-date in the first two years after gamestart to ensure availability
700  * of engines in early starting games.
701  * Note: TTDP uses fixed 1922 */
702  e->intro_date = ei->base_intro <= TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (TimerGameCalendar::Date)GB(r, 0, 9) + ei->base_intro;
704  TimerGameCalendar::YearMonthDay intro_ymd = TimerGameCalendar::ConvertDateToYMD(e->intro_date);
705  int aging_months = aging_ymd.year.base() * 12 + aging_ymd.month;
706  int intro_months = intro_ymd.year.base() * 12 + intro_ymd.month;
707  if (intro_ymd.day > 1) intro_months++; // Engines are introduced at the first month start at/after intro date.
708  e->age = aging_months - intro_months;
709  e->company_avail = MAX_UVALUE(CompanyMask);
710  e->flags |= ENGINE_AVAILABLE;
711  }
712 
713  /* Get parent variant index for syncing reliability via random seed. */
714  const Engine *re = e;
715  while (re->info.variant_id != INVALID_ENGINE && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
716  re = Engine::Get(re->info.variant_id);
717  }
718 
720  (re->index << 16) ^ (re->info.base_intro.base() << 12) ^ (re->info.decay_speed << 8) ^
721  (re->info.lifelength.base() << 4) ^ re->info.retire_early ^
722  e->type ^
723  e->GetGRFID());
724 
725  /* Base reliability defined as a percentage of UINT16_MAX. */
726  const uint16_t RELIABILITY_START = UINT16_MAX * 48 / 100;
727  const uint16_t RELIABILITY_MAX = UINT16_MAX * 75 / 100;
728  const uint16_t RELIABILITY_FINAL = UINT16_MAX * 25 / 100;
729 
730  static_assert(RELIABILITY_START == 0x7AE0);
731  static_assert(RELIABILITY_MAX == 0xBFFF);
732  static_assert(RELIABILITY_FINAL == 0x3FFF);
733 
734  r = Random();
735  /* 14 bits gives a value between 0 and 16383, which is up to an additional 25%p reliability on top of the base reliability. */
736  e->reliability_start = GB(r, 16, 14) + RELIABILITY_START;
737  e->reliability_max = GB(r, 0, 14) + RELIABILITY_MAX;
738 
739  r = Random();
740  e->reliability_final = GB(r, 16, 14) + RELIABILITY_FINAL;
741 
742  e->duration_phase_1 = GB(r, 0, 5) + 7;
743  e->duration_phase_2 = std::max(0, int(GB(r, 5, 4)) + ei->base_life.base() * 12 - 96);
744  e->duration_phase_3 = GB(r, 9, 7) + 120;
745 
746  RestoreRandomSeeds(saved_seeds);
747 
748  e->reliability_spd_dec = ei->decay_speed << 2;
749 
750  /* prevent certain engines from ever appearing. */
752  e->flags |= ENGINE_AVAILABLE;
753  e->company_avail = 0;
754  }
755 }
756 
762 {
763  /* Aging of vehicles stops, so account for that when starting late */
764  const TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date, TimerGameCalendar::ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
765  TimerGameCalendar::YearMonthDay aging_ymd = TimerGameCalendar::ConvertDateToYMD(aging_date);
766  uint32_t seed = Random();
767 
768  for (Engine *e : Engine::Iterate()) {
769  StartupOneEngine(e, aging_ymd, seed);
770  }
771  for (Engine *e : Engine::Iterate()) {
772  CalcEngineReliability(e, false);
773  }
774 
775  /* Update the bitmasks for the vehicle lists */
776  for (Company *c : Company::Iterate()) {
777  c->avail_railtypes = GetCompanyRailTypes(c->index);
778  c->avail_roadtypes = GetCompanyRoadTypes(c->index);
779  }
780 
781  /* Invalidate any open purchase lists */
783 
786 }
787 
793 static void EnableEngineForCompany(EngineID eid, CompanyID company)
794 {
795  Engine *e = Engine::Get(eid);
796  Company *c = Company::Get(company);
797 
798  SetBit(e->company_avail, company);
799  if (e->type == VEH_TRAIN) {
801  } else if (e->type == VEH_ROAD) {
803  }
804 
805  if (company == _local_company) {
807 
808  /* Update the toolbar. */
813  }
814 }
815 
821 static void DisableEngineForCompany(EngineID eid, CompanyID company)
822 {
823  Engine *e = Engine::Get(eid);
824  Company *c = Company::Get(company);
825 
826  ClrBit(e->company_avail, company);
827  if (e->type == VEH_TRAIN) {
829  } else if (e->type == VEH_ROAD) {
831  }
832 
833  if (company == _local_company) {
834  ClearLastVariant(e->index, e->type);
836  }
837 }
838 
845 static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_depth = 0)
846 {
847  Engine *e = Engine::Get(eid);
848 
850  e->preview_asked = MAX_UVALUE(CompanyMask);
851 
852  EnableEngineForCompany(eid, company);
853 
854  /* Notify preview window, that it might want to close.
855  * Note: We cannot directly close the window.
856  * In singleplayer this function is called from the preview window, so
857  * we have to use the GUI-scope scheduling of InvalidateWindowData.
858  */
860 
861  /* Don't search for variants to include if we are 10 levels deep already. */
862  if (recursion_depth >= 10) return;
863 
864  /* Find variants to be included in preview. */
865  for (Engine *ve : Engine::IterateType(e->type)) {
866  if (ve->index != eid && ve->info.variant_id == eid && (ve->info.extra_flags & ExtraEngineFlags::JoinPreview) != ExtraEngineFlags::None) {
867  AcceptEnginePreview(ve->index, company, recursion_depth + 1);
868  }
869  }
870 }
871 
878 {
879  CompanyID best_company = INVALID_COMPANY;
880 
881  /* For trains the cargomask has no useful meaning, since you can attach other wagons */
882  CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
883 
884  int32_t best_hist = -1;
885  for (const Company *c : Company::Iterate()) {
886  if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
887  c->old_economy[0].performance_history > best_hist) {
888 
889  /* Check whether the company uses similar vehicles */
890  for (const Vehicle *v : Vehicle::Iterate()) {
891  if (v->owner != c->index || v->type != e->type) continue;
892  if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue;
893 
894  best_hist = c->old_economy[0].performance_history;
895  best_company = c->index;
896  break;
897  }
898  }
899  }
900 
901  return best_company;
902 }
903 
911 static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
912 {
913  switch (type) {
918 
919  default: NOT_REACHED();
920  }
921 }
922 
924 static IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto)
925 {
926  for (Company *c : Company::Iterate()) {
927  c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, TimerGameCalendar::date);
928  c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, TimerGameCalendar::date);
929  }
930 
932 
933  for (Engine *e : Engine::Iterate()) {
934  EngineID i = e->index;
935  if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
936  if (e->preview_company != INVALID_COMPANY) {
937  if (!--e->preview_wait) {
939  e->preview_company = INVALID_COMPANY;
940  }
941  } else if (CountBits(e->preview_asked) < MAX_COMPANIES) {
942  e->preview_company = GetPreviewCompany(e);
943 
944  if (e->preview_company == INVALID_COMPANY) {
945  e->preview_asked = MAX_UVALUE(CompanyMask);
946  continue;
947  }
948 
949  SetBit(e->preview_asked, e->preview_company);
950  e->preview_wait = 20;
951  /* AIs are intentionally not skipped for preview even if they cannot build a certain
952  * vehicle type. This is done to not give poor performing human companies an "unfair"
953  * boost that they wouldn't have gotten against other human companies. The check on
954  * the line below is just to make AIs not notice that they have a preview if they
955  * cannot build the vehicle. */
956  if (!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));
957  if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);
958  }
959  }
960  }
961 });
962 
968 {
969  for (Engine *e : Engine::Iterate()) {
970  SB(e->company_hidden, cid, 1, 0);
971  }
972 }
973 
982 {
983  Engine *e = Engine::GetIfValid(engine_id);
984  if (e == nullptr || _current_company >= MAX_COMPANIES) return CMD_ERROR;
985  if (!IsEngineBuildable(e->index, e->type, _current_company)) return CMD_ERROR;
986 
987  if ((flags & DC_EXEC) != 0) {
988  SB(e->company_hidden, _current_company, 1, hide ? 1 : 0);
990  }
991 
992  return CommandCost();
993 }
994 
1003 {
1004  Engine *e = Engine::GetIfValid(engine_id);
1005  if (e == nullptr || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
1006 
1007  if (flags & DC_EXEC) AcceptEnginePreview(engine_id, _current_company);
1008 
1009  return CommandCost();
1010 }
1011 
1020 CommandCost CmdEngineCtrl(DoCommandFlag flags, EngineID engine_id, CompanyID company_id, bool allow)
1021 {
1022  if (_current_company != OWNER_DEITY) return CMD_ERROR;
1023 
1024  if (!Engine::IsValidID(engine_id) || !Company::IsValidID(company_id)) return CMD_ERROR;
1025 
1026  if (flags & DC_EXEC) {
1027  if (allow) {
1028  EnableEngineForCompany(engine_id, company_id);
1029  } else {
1030  DisableEngineForCompany(engine_id, company_id);
1031  }
1032  }
1033 
1034  return CommandCost();
1035 }
1036 
1043 {
1044  EngineID index = e->index;
1045 
1046  /* In case the company didn't build the vehicle during the intro period,
1047  * prevent that company from getting future intro periods for a while. */
1048  if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
1049  for (Company *c : Company::Iterate()) {
1050  uint block_preview = c->block_preview;
1051 
1052  if (!HasBit(e->company_avail, c->index)) continue;
1053 
1054  /* We assume the user did NOT build it.. prove me wrong ;) */
1055  c->block_preview = 20;
1056 
1057  for (const Vehicle *v : Vehicle::Iterate()) {
1058  if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
1059  (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
1060  if (v->owner == c->index && v->engine_type == index) {
1061  /* The user did prove me wrong, so restore old value */
1062  c->block_preview = block_preview;
1063  break;
1064  }
1065  }
1066  }
1067  }
1068  }
1069 
1072 
1073  /* Now available for all companies */
1074  e->company_avail = MAX_UVALUE(CompanyMask);
1075 
1076  /* Do not introduce new rail wagons */
1077  if (IsWagon(index)) return;
1078 
1079  if (e->type == VEH_TRAIN) {
1080  /* maybe make another rail type available */
1081  assert(e->u.rail.railtype < RAILTYPE_END);
1082  for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, TimerGameCalendar::date);
1083  } else if (e->type == VEH_ROAD) {
1084  /* maybe make another road type available */
1085  assert(e->u.road.roadtype < ROADTYPE_END);
1086  for (Company *c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, TimerGameCalendar::date);
1087  }
1088 
1089  /* Only broadcast event if AIs are able to build this vehicle type. */
1090  if (!IsVehicleTypeDisabled(e->type, true)) AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index));
1091 
1092  /* Only provide the "New Vehicle available" news paper entry, if engine can be built. */
1093  if (!IsVehicleTypeDisabled(e->type, false) && (e->info.extra_flags & ExtraEngineFlags::NoNews) == ExtraEngineFlags::None) {
1094  SetDParam(0, GetEngineCategoryName(index));
1096  AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NT_NEW_VEHICLES, NF_VEHICLE, NR_ENGINE, index);
1097  }
1098 
1099  /* Update the toolbar. */
1103 
1104  /* Close pending preview windows */
1106 }
1107 
1110 {
1112  bool refresh = false;
1113  for (Engine *e : Engine::Iterate()) {
1114  /* Age the vehicle */
1115  if ((e->flags & ENGINE_AVAILABLE) && e->age != INT32_MAX) {
1116  e->age++;
1117  CalcEngineReliability(e, true);
1118  refresh = true;
1119  }
1120 
1121  /* Do not introduce invalid engines */
1122  if (!e->IsEnabled()) continue;
1123 
1124  if (!(e->flags & ENGINE_AVAILABLE) && TimerGameCalendar::date >= (e->intro_date + CalendarTime::DAYS_IN_YEAR)) {
1125  /* Introduce it to all companies */
1127  } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && TimerGameCalendar::date >= e->intro_date) {
1128  /* Introduction date has passed...
1129  * Check if it is allowed to build this vehicle type at all
1130  * based on the current game settings. If not, it does not
1131  * make sense to show the preview dialog to any company. */
1132  if (IsVehicleTypeDisabled(e->type, false)) continue;
1133 
1134  /* Do not introduce new rail wagons */
1135  if (IsWagon(e->index)) continue;
1136 
1137  /* Engine has no preview */
1138  if ((e->info.extra_flags & ExtraEngineFlags::NoPreview) != ExtraEngineFlags::None) continue;
1139 
1140  /* Show preview dialog to one of the companies. */
1141  e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
1142  e->preview_company = INVALID_COMPANY;
1143  e->preview_asked = 0;
1144  }
1145  }
1146 
1147  InvalidateWindowClassesData(WC_BUILD_VEHICLE); // rebuild the purchase list (esp. when sorted by reliability)
1148 
1149  if (refresh) {
1152  }
1153  }
1154 }
1155 
1156 static IntervalTimer<TimerGameCalendar> _calendar_engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto)
1157 {
1159 });
1160 
1166 static bool IsUniqueEngineName(const std::string &name)
1167 {
1168  for (const Engine *e : Engine::Iterate()) {
1169  if (!e->name.empty() && e->name == name) return false;
1170  }
1171 
1172  return true;
1173 }
1174 
1182 CommandCost CmdRenameEngine(DoCommandFlag flags, EngineID engine_id, const std::string &text)
1183 {
1184  Engine *e = Engine::GetIfValid(engine_id);
1185  if (e == nullptr) return CMD_ERROR;
1186 
1187  bool reset = text.empty();
1188 
1189  if (!reset) {
1191  if (!IsUniqueEngineName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1192  }
1193 
1194  if (flags & DC_EXEC) {
1195  if (reset) {
1196  e->name.clear();
1197  } else {
1198  e->name = text;
1199  }
1200 
1202  }
1203 
1204  return CommandCost();
1205 }
1206 
1207 
1217 {
1218  const Engine *e = Engine::GetIfValid(engine);
1219 
1220  /* check if it's an engine that is in the engine array */
1221  if (e == nullptr) return false;
1222 
1223  /* check if it's an engine of specified type */
1224  if (e->type != type) return false;
1225 
1226  /* check if it's available ... */
1227  if (company == OWNER_DEITY) {
1228  /* ... for any company (preview does not count) */
1229  if (!(e->flags & ENGINE_AVAILABLE) || e->company_avail == 0) return false;
1230  } else {
1231  /* ... for this company */
1232  if (!HasBit(e->company_avail, company)) return false;
1233  }
1234 
1235  if (!e->IsEnabled()) return false;
1236 
1237  if (type == VEH_TRAIN && company != OWNER_DEITY) {
1238  /* Check if the rail type is available to this company */
1239  const Company *c = Company::Get(company);
1240  if (((GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false;
1241  }
1242  if (type == VEH_ROAD && company != OWNER_DEITY) {
1243  /* Check if the road type is available to this company */
1244  const Company *c = Company::Get(company);
1245  if ((GetRoadTypeInfo(e->u.road.roadtype)->powered_roadtypes & c->avail_roadtypes) == ROADTYPES_NONE) return false;
1246  }
1247 
1248  return true;
1249 }
1250 
1258 {
1259  const Engine *e = Engine::GetIfValid(engine);
1260 
1261  /* check if it's an engine that is in the engine array */
1262  if (e == nullptr) return false;
1263 
1264  if (!e->CanCarryCargo()) return false;
1265 
1266  const EngineInfo *ei = &e->info;
1267  if (ei->refit_mask == 0) return false;
1268 
1269  /* Are there suffixes?
1270  * Note: This does not mean the suffixes are actually available for every consist at any time. */
1271  if (HasBit(ei->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
1272 
1273  /* Is there any cargo except the default cargo? */
1274  CargoID default_cargo = e->GetDefaultCargoType();
1275  CargoTypes default_cargo_mask = 0;
1276  SetBit(default_cargo_mask, default_cargo);
1277  return IsValidCargoID(default_cargo) && ei->refit_mask != default_cargo_mask;
1278 }
1279 
1284 {
1285  TimerGameCalendar::Date min_date = INT32_MAX;
1286 
1287  for (const Engine *e : Engine::Iterate()) {
1288  if (!e->IsEnabled()) continue;
1289 
1290  /* Don't consider train wagons, we need a powered engine available. */
1291  if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
1292 
1293  /* We have an available engine... yay! */
1294  if ((e->flags & ENGINE_AVAILABLE) != 0 && e->company_avail != 0) return;
1295 
1296  /* Okay, try to find the earliest date. */
1297  min_date = std::min(min_date, e->info.base_intro);
1298  }
1299 
1300  if (min_date < INT32_MAX) {
1301  SetDParam(0, min_date);
1302  ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_YET, STR_ERROR_NO_VEHICLES_AVAILABLE_YET_EXPLANATION, WL_WARNING);
1303  } else {
1304  ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_AT_ALL, STR_ERROR_NO_VEHICLES_AVAILABLE_AT_ALL_EXPLANATION, WL_WARNING);
1305  }
1306 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
Ticks::CARGO_AGING_TICKS
static constexpr TimerGameTick::Ticks CARGO_AGING_TICKS
Cycle duration for aging cargo.
Definition: timer_game_tick.h:54
Engine::reliability_max
uint16_t reliability_max
Maximal reliability of the engine.
Definition: engine_base.h:44
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:205
VehicleSettings::max_aircraft
UnitID max_aircraft
max planes in game per company
Definition: settings_type.h:526
Engine::IsVariantHidden
bool IsVariantHidden(CompanyID c) const
Check whether the engine variant chain is hidden in the GUI for the given company.
Definition: engine.cpp:485
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:3200
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
CheckEngines
void CheckEngines()
Check for engines that have an appropriate availability.
Definition: engine.cpp:1283
PROP_TRAIN_SPEED
@ PROP_TRAIN_SPEED
Max. speed: 1 unit = 1/1.6 mph = 1 km-ish/h.
Definition: newgrf_properties.h:21
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:29
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition: engine_base.h:186
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:547
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:73
EngineOverrideManager::ResetToDefaultMapping
void ResetToDefaultMapping()
Initializes the EngineOverrideManager with the default engines.
Definition: engine.cpp:507
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:401
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:3334
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:970
PROP_ROADVEH_COST_FACTOR
@ PROP_ROADVEH_COST_FACTOR
Purchase cost.
Definition: newgrf_properties.h:35
command_func.h
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
Pool::PoolItem<&_engine_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
CalcEngineReliability
void CalcEngineReliability(Engine *e, bool new_month)
Update Engine::reliability and (if needed) update the engine GUIs.
Definition: engine.cpp:609
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
_engine_offsets
const uint8_t _engine_offsets[4]
Offset of the first engine of each vehicle type in original engine data.
Definition: engine.cpp:61
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
Company::avail_railtypes
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:120
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:25
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:356
RoadTypeInfo::introduces_roadtypes
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition: road.h:177
Company::avail_roadtypes
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:121
company_base.h
IsWagon
static bool IsWagon(EngineID index)
Determine whether an engine type is a wagon (and not a loco).
Definition: engine.cpp:587
GetPreviewCompany
static CompanyID GetPreviewCompany(Engine *e)
Get the best company for an engine preview.
Definition: engine.cpp:877
Engine::reliability_spd_dec
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:42
PROP_TRAIN_TRACTIVE_EFFORT
@ PROP_TRAIN_TRACTIVE_EFFORT
Tractive effort coefficient in 1/256.
Definition: newgrf_properties.h:27
timer_game_calendar.h
Engine::GetLifeLengthInDays
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:441
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:89
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:53
WC_ENGINE_PREVIEW
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Definition: window_type.h:595
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition: engine.cpp:424
IntervalTimer< TimerGameCalendar >
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
VE_DEFAULT
@ VE_DEFAULT
Default value to indicate that visual effect should be based on engine class.
Definition: vehicle_base.h:95
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:234
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:134
PROP_SHIP_CARGO_CAPACITY
@ PROP_SHIP_CARGO_CAPACITY
Capacity.
Definition: newgrf_properties.h:45
PROP_AIRCRAFT_RUNNING_COST_FACTOR
@ PROP_AIRCRAFT_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:51
Engine::reliability_final
uint16_t reliability_final
Final reliability of the engine.
Definition: engine_base.h:45
EnableEngineForCompany
static void EnableEngineForCompany(EngineID eid, CompanyID company)
Allows engine eid to be used by a company company.
Definition: engine.cpp:793
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition: engine.cpp:279
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition: engine_gui.cpp:40
autoreplace_gui.h
aircraft.h
SaveRandomSeeds
void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
Definition: random_func.hpp:42
SetupEngines
void SetupEngines()
Initialise the engine pool with the data from the original vehicles.
Definition: engine.cpp:563
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
Engine::preview_company
CompanyID preview_company
Company which is currently being offered a preview INVALID_COMPANY means no company.
Definition: engine_base.h:51
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition: road.cpp:199
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition: strong_typedef_type.hpp:150
EngineInfo
Information about a vehicle.
Definition: engine_type.h:144
CBM_VEHICLE_CARGO_SUFFIX
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
Definition: newgrf_callbacks.h:300
Engine
Definition: engine_base.h:37
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:53
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:96
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:54
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:128
StartupEngines
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:761
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
_engine_counts
const uint8_t _engine_counts[4]
Number of engines of each vehicle type in original engine data.
Definition: engine.cpp:53
Engine::GetGRFID
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:157
DisableEngineForCompany
static void DisableEngineForCompany(EngineID eid, CompanyID company)
Forbids engine eid to be used by a company company.
Definition: engine.cpp:821
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
VehicleSettings::extend_vehicle_life
byte extend_vehicle_life
extend vehicle life by this many years
Definition: settings_type.h:532
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
CmdWantEnginePreview
CommandCost CmdWantEnginePreview(DoCommandFlag flags, EngineID engine_id)
Accept an engine prototype.
Definition: engine.cpp:1002
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:59
ai.hpp
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:167
IsUniqueEngineName
static bool IsUniqueEngineName(const std::string &name)
Is name still free as name for an engine?
Definition: engine.cpp:1166
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:183
Engine::display_last_variant
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Definition: engine_base.h:59
Engine::DetermineCapacity
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
Definition: engine.cpp:201
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition: engine.cpp:356
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:378
AcceptEnginePreview
static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_depth=0)
Company company accepts engine eid for preview.
Definition: engine.cpp:845
ROADTYPES_NONE
@ ROADTYPES_NONE
No roadtypes.
Definition: road_type.h:39
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:911
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:122
NT_NEW_VEHICLES
@ NT_NEW_VEHICLES
New vehicle has become available.
Definition: news_type.h:36
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
EngineInfo::callback_mask
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition: engine_type.h:155
AISettings::ai_disable_veh_train
bool ai_disable_veh_train
disable types for AI
Definition: settings_type.h:400
TimerGameConst< struct Calendar >::DAYS_IN_LEAP_YEAR
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: timer_game_common.h:150
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:235
CommandCost
Common return value for all commands.
Definition: command_type.h:23
PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
Definition: engine_type.h:193
StartupOneEngine
void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ymd, uint32_t seed)
Start/initialise one engine.
Definition: engine.cpp:680
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:251
newgrf_engine.h
VehicleSettings::max_ships
UnitID max_ships
max ships in game per company
Definition: settings_type.h:527
AddDateIntroducedRailTypes
RailTypes AddDateIntroducedRailTypes(RailTypes current, TimerGameCalendar::Date date)
Add the rail types that are to be introduced at the given date.
Definition: rail.cpp:218
PackEngineNameDParam
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition: engine_type.h:198
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:318
Engine::intro_date
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:39
EngineIDMapping::grfid
uint32_t grfid
The GRF ID of the file the entity belongs to.
Definition: engine_base.h:193
TimerGameCalendar::ConvertYMDToDate
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: timer_game_calendar.cpp:55
GROUND_ACCELERATION
static const int GROUND_ACCELERATION
Acceleration due to gravity, 9.8 m/s^2.
Definition: vehicle_type.h:18
CalendarEnginesMonthlyLoop
void CalendarEnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition: engine.cpp:1109
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:203
Engine::preview_asked
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
Definition: engine_base.h:50
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition: window_type.h:218
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
IsCompanyBuildableVehicleType
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
timer_game_tick.h
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition: engine.cpp:406
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:49
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:260
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition: timer_game_calendar.cpp:42
safeguards.h
EngineIDMapping::substitute_id
uint8_t substitute_id
The (original) entity ID to use if this GRF is not available (currently not used)
Definition: engine_base.h:196
timer.h
GameCreationSettings::starting_year
TimerGameCalendar::Year starting_year
starting date
Definition: settings_type.h:341
SetRandomSeed
void SetRandomSeed(uint32_t seed)
(Re)set the state of the random number generators.
Definition: random_func.cpp:77
error.h
ExtraEngineFlags::NoNews
@ NoNews
No 'new vehicle' news will be generated.
EngineIDMapping
Definition: engine_base.h:192
Pool::CleanPool
void CleanPool() override
Virtual method that deletes all items in the pool.
ExtraEngineFlags::JoinPreview
@ JoinPreview
Engine will join exclusive preview with variant parent.
Engine::duration_phase_1
uint16_t duration_phase_1
First reliability phase in months, increasing reliability from reliability_start to reliability_max.
Definition: engine_base.h:46
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:316
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
CountBits
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:243
Engine::reliability
uint16_t reliability
Current reliability of the engine.
Definition: engine_base.h:41
ENGINE_AVAILABLE
@ ENGINE_AVAILABLE
This vehicle is available to everyone.
Definition: engine_type.h:182
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:154
ExtraEngineFlags::NoPreview
@ NoPreview
No exclusive preview will be offered.
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:298
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:318
ExtraEngineFlags::SyncReliability
@ SyncReliability
Engine reliability will be synced with variant parent.
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
ClearLastVariant
static void ClearLastVariant(EngineID engine_id, VehicleType type)
Ensure engine is not set as the last used variant for any other engine.
Definition: engine.cpp:598
Engine::reliability_start
uint16_t reliability_start
Initial reliability of the engine.
Definition: engine_base.h:43
GameSettings::ai
AISettings ai
what may the AI do?
Definition: settings_type.h:621
AddDateIntroducedRoadTypes
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:166
string_func.h
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
AISettings::ai_disable_veh_ship
bool ai_disable_veh_ship
disable types for AI
Definition: settings_type.h:403
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
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:38
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:384
engine_gui.h
strings_func.h
Pool
Base class for all pools.
Definition: pool_type.hpp:80
Engine::IsHidden
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
Definition: engine_base.h:136
EngineIDMapping::internal_id
uint16_t internal_id
The internal ID within the GRF file.
Definition: engine_base.h:194
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:168
EngineInfo::base_life
TimerGameCalendar::Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life.
Definition: engine_type.h:147
GameCreationSettings::generation_seed
uint32_t generation_seed
noise seed for world generation
Definition: settings_type.h:340
CmdSetVehicleVisibility
CommandCost CmdSetVehicleVisibility(DoCommandFlag flags, EngineID engine_id, bool hide)
Set the visibility of an engine.
Definition: engine.cpp:981
VehicleSettings::max_trains
UnitID max_trains
max trains in game per company
Definition: settings_type.h:524
GetCompanyRailTypes
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:251
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:383
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition: engine.cpp:388
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
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:173
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:3217
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:122
CmdRenameEngine
CommandCost CmdRenameEngine(DoCommandFlag flags, EngineID engine_id, const std::string &text)
Rename an engine.
Definition: engine.cpp:1182
EngineOverrideManager
Stores the mapping of EngineID to the internal id of newgrfs.
Definition: engine_base.h:203
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
EngineInfo::variant_id
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
Definition: engine_type.h:159
EngineOverrideManager::GetID
EngineID GetID(VehicleType type, uint16_t grf_local_id, uint32_t grfid)
Looks up an EngineID in the EngineOverrideManager.
Definition: engine.cpp:530
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32_t ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32_t ref2=UINT32_MAX, const NewsAllocatedData *data=nullptr)
Add a new newsitem to be shown.
Definition: news_gui.cpp:827
AISettings::ai_disable_veh_aircraft
bool ai_disable_veh_aircraft
disable types for AI
Definition: settings_type.h:402
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:305
EngineInfo::cargo_age_period
uint16_t cargo_age_period
Number of ticks before carried cargo is aged.
Definition: engine_type.h:158
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:388
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:1042
RailVehicleInfo::railtype
RailType railtype
Railtype, mangled if elrail is disabled.
Definition: engine_type.h:46
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
company_func.h
VehicleSettings::max_roadveh
UnitID max_roadveh
max trucks in game per company
Definition: settings_type.h:525
RestoreRandomSeeds
void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
Definition: random_func.hpp:52
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:225
RailTypeInfo::introduces_railtypes
RailTypes introduces_railtypes
Bitmask of which other railtypes are introduced when this railtype is introduced.
Definition: rail.h:266
AIR_CTOL
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition: engine_type.h:95
window_func.h
NF_VEHICLE
@ NF_VEHICLE
Vehicle news item. (new engine available)
Definition: news_type.h:82
EngineInfo::retire_early
int8_t retire_early
Number of years early to retire vehicle.
Definition: engine_type.h:156
_calendar_engines_daily
static IntervalTimer< TimerGameCalendar > _calendar_engines_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto) { for(Company *c :Company::Iterate()) { c->avail_railtypes=AddDateIntroducedRailTypes(c->avail_railtypes, TimerGameCalendar::date);c->avail_roadtypes=AddDateIntroducedRoadTypes(c->avail_roadtypes, TimerGameCalendar::date);} if(TimerGameCalendar::year >=_year_engine_aging_stops) return;for(Engine *e :Engine::Iterate()) { EngineID i=e->index;if(e->flags &ENGINE_EXCLUSIVE_PREVIEW) { if(e->preview_company !=INVALID_COMPANY) { if(!--e->preview_wait) { CloseWindowById(WC_ENGINE_PREVIEW, i);e->preview_company=INVALID_COMPANY;} } else if(CountBits(e->preview_asked)< MAX_COMPANIES) { e->preview_company=GetPreviewCompany(e);if(e->preview_company==INVALID_COMPANY) { e->preview_asked=MAX_UVALUE(CompanyMask);continue;} SetBit(e->preview_asked, e->preview_company);e->preview_wait=20;if(!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));if(IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);} } } })
Daily check to offer an exclusive engine preview to the companies.
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
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
OverflowSafeInt< int64_t >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
VehicleSettings::never_expire_vehicles
bool never_expire_vehicles
never expire vehicles
Definition: settings_type.h:531
Engine::IsEnabled
bool IsEnabled() const
Checks whether the engine is a valid (non-articulated part of an) engine.
Definition: engine.cpp:147
IsInteractiveCompany
bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
Definition: company_func.h:57
CmdEngineCtrl
CommandCost CmdEngineCtrl(DoCommandFlag flags, EngineID engine_id, CompanyID company_id, bool allow)
Allow or forbid a specific company to use an engine.
Definition: engine.cpp:1020
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
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
Engine::original_image_index
uint8_t original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:55
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
Engine::grf_prop
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Definition: engine_base.h:77
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:627
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:337
EngineInfo::climates
byte climates
Climates supported by the engine.
Definition: engine_type.h:150
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:1257
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:324
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
_year_engine_aging_stops
static TimerGameCalendar::Year _year_engine_aging_stops
Year that engine aging stops.
Definition: engine.cpp:50
EngineIDMapping::type
VehicleType type
The engine type.
Definition: engine_base.h:195
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:49
pool_func.hpp
EngineInfo::string_id
StringID string_id
Default name of engine.
Definition: engine_type.h:157
ClearEnginesHiddenFlagOfCompany
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the 'hidden' flag for all engines of a new company.
Definition: engine.cpp:967
GetVehicleCallback
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1149
Engine::duration_phase_2
uint16_t duration_phase_2
Second reliability phase in months, keeping reliability_max.
Definition: engine_base.h:47
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:66
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
IsCargoInClass
bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:222
Company
Definition: company_base.h:116
PROP_ROADVEH_RUNNING_COST_FACTOR
@ PROP_ROADVEH_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:33
TimerGameConst< struct Calendar >::DAYS_IN_YEAR
static constexpr int DAYS_IN_YEAR
days per year
Definition: timer_game_common.h:149
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:58
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3108
PROP_AIRCRAFT_RANGE
@ PROP_AIRCRAFT_RANGE
Aircraft range.
Definition: newgrf_properties.h:55
Engine::duration_phase_3
uint16_t duration_phase_3
Third reliability phase in months, decaying to reliability_final.
Definition: engine_base.h:48
SetYearEngineAgingStops
void SetYearEngineAgingStops()
Compute the value for _year_engine_aging_stops.
Definition: engine.cpp:655
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1216
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:465
CargoSpec::multiplier
uint16_t multiplier
Capacity multiplier for vehicles. (8 fractional bits)
Definition: cargotype.h:77
EngineOverrideManager::NUM_DEFAULT_ENGINES
static const uint NUM_DEFAULT_ENGINES
Number of default entries.
Definition: engine_base.h:204
EngineInfo::base_intro
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
Definition: engine_type.h:145
EngineInfo::lifelength
TimerGameCalendar::Year lifelength
Lifetime of a single vehicle.
Definition: engine_type.h:146
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:56
Engine::GetRange
uint16_t GetRange() const
Get the range of an aircraft type.
Definition: engine.cpp:451
PROP_ROADVEH_WEIGHT
@ PROP_ROADVEH_WEIGHT
Weight in 1/4 t.
Definition: newgrf_properties.h:37
engine_func.h
Engine::GetDisplayVariant
const Engine * GetDisplayVariant() const
Get the last display variant for an engine.
Definition: engine_base.h:145
news_func.h
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition: timer_game_calendar.h:32
Engine::age
int32_t age
Age of the engine in months.
Definition: engine_base.h:40
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103