OpenTTD Source  13.2.1
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 #include "engine_base.h"
33 
34 #include "table/strings.h"
35 #include "table/engines.h"
36 
37 #include "safeguards.h"
38 
39 EnginePool _engine_pool("Engine");
41 
42 EngineOverrideManager _engine_mngr;
43 
49 
51 const uint8 _engine_counts[4] = {
52  lengthof(_orig_rail_vehicle_info),
53  lengthof(_orig_road_vehicle_info),
54  lengthof(_orig_ship_vehicle_info),
55  lengthof(_orig_aircraft_vehicle_info),
56 };
57 
59 const uint8 _engine_offsets[4] = {
60  0,
61  lengthof(_orig_rail_vehicle_info),
62  lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
63  lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
64 };
65 
66 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));
67 
69 
70 Engine::Engine(VehicleType type, EngineID base)
71 {
72  this->type = type;
73  this->grf_prop.local_id = base;
74  this->list_position = base;
77 
78  /* Check if this base engine is within the original engine data range */
79  if (base >= _engine_counts[type]) {
80  /* 'power' defaults to zero, so we also have to default to 'wagon' */
81  if (type == VEH_TRAIN) this->u.rail.railveh_type = RAILVEH_WAGON;
82  /* Set model life to maximum to make wagons available */
83  this->info.base_life = 0xFF;
84  /* Set road vehicle tractive effort to the default value */
85  if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C;
86  /* Aircraft must have CT_INVALID as default, as there is no property */
87  if (type == VEH_AIRCRAFT) this->info.cargo_type = CT_INVALID;
88  /* Set visual effect to the default value */
89  switch (type) {
90  case VEH_TRAIN: this->u.rail.visual_effect = VE_DEFAULT; break;
91  case VEH_ROAD: this->u.road.visual_effect = VE_DEFAULT; break;
92  case VEH_SHIP: this->u.ship.visual_effect = VE_DEFAULT; break;
93  default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects
94  }
95  /* Set cargo aging period to the default value. */
97  /* Not a variant */
98  this->info.variant_id = INVALID_ENGINE;
99  return;
100  }
101 
102  /* Copy the original engine info for this slot */
103  this->info = _orig_engine_info[_engine_offsets[type] + base];
104 
105  /* Copy the original engine data for this slot */
106  switch (type) {
107  default: NOT_REACHED();
108 
109  case VEH_TRAIN:
110  this->u.rail = _orig_rail_vehicle_info[base];
111  this->original_image_index = this->u.rail.image_index;
112  this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base;
113 
114  /* Set the default model life of original wagons to "infinite" */
115  if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = 0xFF;
116 
117  break;
118 
119  case VEH_ROAD:
120  this->u.road = _orig_road_vehicle_info[base];
121  this->original_image_index = this->u.road.image_index;
122  this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base;
123  break;
124 
125  case VEH_SHIP:
126  this->u.ship = _orig_ship_vehicle_info[base];
127  this->original_image_index = this->u.ship.image_index;
128  this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base;
129  break;
130 
131  case VEH_AIRCRAFT:
132  this->u.air = _orig_aircraft_vehicle_info[base];
133  this->original_image_index = this->u.air.image_index;
134  this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base;
135  break;
136  }
137 }
138 
143 bool Engine::IsEnabled() const
144 {
145  return this->info.string_id != STR_NEWGRF_INVALID_ENGINE && HasBit(this->info.climates, _settings_game.game_creation.landscape);
146 }
147 
153 uint32 Engine::GetGRFID() const
154 {
155  const GRFFile *file = this->GetGRF();
156  return file == nullptr ? 0 : file->grfid;
157 }
158 
165 {
166  /* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity
167  * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used
168  * for livery selection etc.
169  * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
170  */
171  switch (this->type) {
172  case VEH_TRAIN:
173  if (this->u.rail.capacity == 0) return false;
174  break;
175 
176  case VEH_ROAD:
177  if (this->u.road.capacity == 0) return false;
178  break;
179 
180  case VEH_SHIP:
181  case VEH_AIRCRAFT:
182  break;
183 
184  default: NOT_REACHED();
185  }
186  return this->GetDefaultCargoType() != CT_INVALID;
187 }
188 
189 
197 uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
198 {
199  assert(v == nullptr || this->index == v->engine_type);
200  if (mail_capacity != nullptr) *mail_capacity = 0;
201 
202  if (!this->CanCarryCargo()) return 0;
203 
204  bool new_multipliers = HasBit(this->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER);
205  CargoID default_cargo = this->GetDefaultCargoType();
206  CargoID cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
207 
208  if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) {
209  *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
210  }
211 
212  /* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */
214  (new_multipliers || default_cargo != cargo_type || (v != nullptr && v->cargo_subtype != 0))) {
215  uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v);
216  if (callback != CALLBACK_FAILED) return callback;
217  }
218 
219  /* Get capacity according to property resp. CB */
220  uint capacity;
221  uint extra_mail_cap = 0;
222  switch (this->type) {
223  case VEH_TRAIN:
224  capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v);
225 
226  /* In purchase list add the capacity of the second head. Always use the plain property for this. */
227  if (v == nullptr && this->u.rail.railveh_type == RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
228  break;
229 
230  case VEH_ROAD:
231  capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity, v);
232  break;
233 
234  case VEH_SHIP:
235  capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity, v);
236  break;
237 
238  case VEH_AIRCRAFT:
239  capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v);
240  if (!IsCargoInClass(cargo_type, CC_PASSENGERS)) {
241  extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
242  }
243  if (!new_multipliers && cargo_type == CT_MAIL) return capacity + extra_mail_cap;
244  default_cargo = CT_PASSENGERS; // Always use 'passengers' wrt. cargo multipliers
245  break;
246 
247  default: NOT_REACHED();
248  }
249 
250  if (!new_multipliers) {
251  /* Use the passenger multiplier for mail as well */
252  capacity += extra_mail_cap;
253  extra_mail_cap = 0;
254  }
255 
256  /* Apply multipliers depending on cargo- and vehicletype. */
257  if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) {
258  uint16 default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier;
259  uint16 cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier;
260  capacity *= cargo_multiplier;
261  if (extra_mail_cap > 0) {
262  uint mail_multiplier = CargoSpec::Get(CT_MAIL)->multiplier;
263  capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier;
264  }
265  capacity = (capacity + default_multiplier / 2) / default_multiplier;
266  }
267 
268  return capacity;
269 }
270 
276 {
277  Price base_price;
278  uint cost_factor;
279  switch (this->type) {
280  case VEH_ROAD:
281  base_price = this->u.road.running_cost_class;
282  if (base_price == INVALID_PRICE) return 0;
283  cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost);
284  break;
285 
286  case VEH_TRAIN:
287  base_price = this->u.rail.running_cost_class;
288  if (base_price == INVALID_PRICE) return 0;
289  cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost);
290  break;
291 
292  case VEH_SHIP:
293  base_price = PR_RUNNING_SHIP;
294  cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost);
295  break;
296 
297  case VEH_AIRCRAFT:
298  base_price = PR_RUNNING_AIRCRAFT;
299  cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost);
300  break;
301 
302  default: NOT_REACHED();
303  }
304 
305  return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
306 }
307 
313 {
314  Price base_price;
315  uint cost_factor;
316  switch (this->type) {
317  case VEH_ROAD:
318  base_price = PR_BUILD_VEHICLE_ROAD;
319  cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor);
320  break;
321 
322  case VEH_TRAIN:
323  if (this->u.rail.railveh_type == RAILVEH_WAGON) {
324  base_price = PR_BUILD_VEHICLE_WAGON;
325  cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
326  } else {
327  base_price = PR_BUILD_VEHICLE_TRAIN;
328  cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
329  }
330  break;
331 
332  case VEH_SHIP:
333  base_price = PR_BUILD_VEHICLE_SHIP;
334  cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor);
335  break;
336 
337  case VEH_AIRCRAFT:
338  base_price = PR_BUILD_VEHICLE_AIRCRAFT;
339  cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor);
340  break;
341 
342  default: NOT_REACHED();
343  }
344 
345  return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
346 }
347 
353 {
354  switch (this->type) {
355  case VEH_TRAIN:
356  return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->u.rail.max_speed);
357 
358  case VEH_ROAD: {
359  uint max_speed = GetEngineProperty(this->index, PROP_ROADVEH_SPEED, 0);
360  return (max_speed != 0) ? max_speed * 2 : this->u.road.max_speed / 2;
361  }
362 
363  case VEH_SHIP:
364  return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->u.ship.max_speed) / 2;
365 
366  case VEH_AIRCRAFT: {
367  uint max_speed = GetEngineProperty(this->index, PROP_AIRCRAFT_SPEED, 0);
368  if (max_speed != 0) {
369  return (max_speed * 128) / 10;
370  }
371  return this->u.air.max_speed;
372  }
373 
374  default: NOT_REACHED();
375  }
376 }
377 
384 uint Engine::GetPower() const
385 {
386  /* Only trains and road vehicles have 'power'. */
387  switch (this->type) {
388  case VEH_TRAIN:
389  return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->u.rail.power);
390  case VEH_ROAD:
391  return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->u.road.power) * 10;
392 
393  default: NOT_REACHED();
394  }
395 }
396 
403 {
404  /* Only trains and road vehicles have 'weight'. */
405  switch (this->type) {
406  case VEH_TRAIN:
407  return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
408  case VEH_ROAD:
409  return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->u.road.weight) / 4;
410 
411  default: NOT_REACHED();
412  }
413 }
414 
421 {
422  /* Only trains and road vehicles have 'tractive effort'. */
423  switch (this->type) {
424  case VEH_TRAIN:
425  return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256 / 1000;
426  case VEH_ROAD:
427  return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256 / 1000;
428 
429  default: NOT_REACHED();
430  }
431 }
432 
438 {
439  /* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */
441 }
442 
447 uint16 Engine::GetRange() const
448 {
449  switch (this->type) {
450  case VEH_AIRCRAFT:
451  return GetEngineProperty(this->index, PROP_AIRCRAFT_RANGE, this->u.air.max_range);
452 
453  default: NOT_REACHED();
454  }
455 }
456 
462 {
463  switch (this->type) {
464  case VEH_AIRCRAFT:
465  switch (this->u.air.subtype) {
466  case AIR_HELI: return STR_LIVERY_HELICOPTER;
467  case AIR_CTOL: return STR_LIVERY_SMALL_PLANE;
468  case AIR_CTOL | AIR_FAST: return STR_LIVERY_LARGE_PLANE;
469  default: NOT_REACHED();
470  }
471 
472  default: NOT_REACHED();
473  }
474 }
475 
480 {
481  this->clear();
482  for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
483  for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
484  EngineIDMapping &eid = this->emplace_back();
485  eid.type = type;
486  eid.grfid = INVALID_GRFID;
487  eid.internal_id = internal_id;
488  eid.substitute_id = internal_id;
489  }
490  }
491 }
492 
502 EngineID EngineOverrideManager::GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
503 {
504  EngineID index = 0;
505  for (const EngineIDMapping &eid : *this) {
506  if (eid.type == type && eid.grfid == grfid && eid.internal_id == grf_local_id) {
507  return index;
508  }
509  index++;
510  }
511  return INVALID_ENGINE;
512 }
513 
520 {
521  for (const Vehicle *v : Vehicle::Iterate()) {
522  if (IsCompanyBuildableVehicleType(v)) return false;
523  }
524 
525  /* Reset the engines, they will get new EngineIDs */
526  _engine_mngr.ResetToDefaultMapping();
528 
529  return true;
530 }
531 
536 {
538  _engine_pool.CleanPool();
539 
540  assert(_engine_mngr.size() >= _engine_mngr.NUM_DEFAULT_ENGINES);
541  [[maybe_unused]] uint index = 0;
542  for (const EngineIDMapping &eid : _engine_mngr) {
543  /* Assert is safe; there won't be more than 256 original vehicles
544  * in any case, and we just cleaned the pool. */
545  assert(Engine::CanAllocateItem());
546  [[maybe_unused]] const Engine *e = new Engine(eid.type, eid.internal_id);
547  assert(e->index == index);
548  index++;
549  }
550 }
551 
552 void ShowEnginePreviewWindow(EngineID engine);
553 
559 static bool IsWagon(EngineID index)
560 {
561  const Engine *e = Engine::Get(index);
562  return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON;
563 }
564 
570 static void ClearLastVariant(EngineID engine_id, VehicleType type)
571 {
572  for (Engine *e : Engine::IterateType(type)) {
573  if (e->display_last_variant == engine_id) e->display_last_variant = INVALID_ENGINE;
574  }
575 }
576 
581 void CalcEngineReliability(Engine *e, bool new_month)
582 {
583  /* Get source engine for reliability age. This is normally our engine unless variant reliability syncing is requested. */
584  Engine *re = e;
585  while (re->info.variant_id != INVALID_ENGINE && re->info.variant_id != re->index && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
586  re = Engine::Get(re->info.variant_id);
587  }
588 
589  uint age = re->age;
590  if (new_month && re->index > e->index && age != MAX_DAY) age++; /* parent variant's age has not yet updated. */
591 
592  /* Check for early retirement */
593  if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
594  int retire_early = e->info.retire_early;
595  uint retire_early_max_age = std::max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
596  if (retire_early != 0 && age >= retire_early_max_age) {
597  /* Early retirement is enabled and we're past the date... */
598  e->company_avail = 0;
599  ClearLastVariant(e->index, e->type);
601  }
602  }
603 
604  if (age < e->duration_phase_1) {
605  uint start = e->reliability_start;
606  e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
607  } else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) {
608  /* We are at the peak of this engines life. It will have max reliability.
609  * This is also true if the engines never expire. They will not go bad over time */
611  } else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
612  uint max = e->reliability_max;
613  e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
614  } else {
615  /* time's up for this engine.
616  * We will now completely retire this design */
617  e->company_avail = 0;
619  /* Kick this engine out of the lists */
620  ClearLastVariant(e->index, e->type);
622  }
623 
624 }
625 
628 {
629  /* Determine last engine aging year, default to 2050 as previously. */
631 
632  for (const Engine *e : Engine::Iterate()) {
633  const EngineInfo *ei = &e->info;
634 
635  /* Exclude certain engines */
637  if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
638 
639  /* Base year ending date on half the model life */
640  YearMonthDay ymd;
641  ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
642 
644  }
645 }
646 
653 void StartupOneEngine(Engine *e, Date aging_date, uint32 seed)
654 {
655  const EngineInfo *ei = &e->info;
656 
657  e->age = 0;
658  e->flags = 0;
659  e->company_avail = 0;
660  e->company_hidden = 0;
661 
662  /* Vehicles with the same base_intro date shall be introduced at the same time.
663  * Make sure they use the same randomisation of the date. */
664  SavedRandomSeeds saved_seeds;
665  SaveRandomSeeds(&saved_seeds);
667  ei->base_intro ^
668  e->type ^
669  e->GetGRFID());
670  uint32 r = Random();
671 
672  /* Don't randomise the start-date in the first two years after gamestart to ensure availability
673  * of engines in early starting games.
674  * Note: TTDP uses fixed 1922 */
676  if (e->intro_date <= _date) {
677  e->age = (aging_date - e->intro_date) >> 5;
678  e->company_avail = (CompanyMask)-1;
679  e->flags |= ENGINE_AVAILABLE;
680  }
681 
682  /* Get parent variant index for syncing reliability via random seed. */
683  const Engine *re = e;
684  while (re->info.variant_id != INVALID_ENGINE && re->info.variant_id != re->index && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
685  re = Engine::Get(re->info.variant_id);
686  }
687 
689  (re->index << 16) ^ (re->info.base_intro << 12) ^ (re->info.decay_speed << 8) ^
690  (re->info.lifelength << 4) ^ re->info.retire_early ^
691  e->type ^
692  e->GetGRFID());
693 
694  r = Random();
695  e->reliability_start = GB(r, 16, 14) + 0x7AE0;
696  e->reliability_max = GB(r, 0, 14) + 0xBFFF;
697 
698  r = Random();
699  e->reliability_final = GB(r, 16, 14) + 0x3FFF;
700  e->duration_phase_1 = GB(r, 0, 5) + 7;
701  e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
702  e->duration_phase_3 = GB(r, 9, 7) + 120;
703 
704  RestoreRandomSeeds(saved_seeds);
705 
706  e->reliability_spd_dec = ei->decay_speed << 2;
707 
708  /* prevent certain engines from ever appearing. */
710  e->flags |= ENGINE_AVAILABLE;
711  e->company_avail = 0;
712  }
713 }
714 
720 {
721  /* Aging of vehicles stops, so account for that when starting late */
722  const Date aging_date = std::min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
723  uint32 seed = Random();
724 
725  for (Engine *e : Engine::Iterate()) {
726  StartupOneEngine(e, aging_date, seed);
727  }
728  for (Engine *e : Engine::Iterate()) {
729  CalcEngineReliability(e, false);
730  }
731 
732  /* Update the bitmasks for the vehicle lists */
733  for (Company *c : Company::Iterate()) {
734  c->avail_railtypes = GetCompanyRailtypes(c->index);
735  c->avail_roadtypes = GetCompanyRoadTypes(c->index);
736  }
737 
738  /* Invalidate any open purchase lists */
740 
743 }
744 
750 static void EnableEngineForCompany(EngineID eid, CompanyID company)
751 {
752  Engine *e = Engine::Get(eid);
753  Company *c = Company::Get(company);
754 
755  SetBit(e->company_avail, company);
756  if (e->type == VEH_TRAIN) {
758  } else if (e->type == VEH_ROAD) {
760  }
761 
762  if (company == _local_company) {
764 
765  /* Update the toolbar. */
770  }
771 }
772 
778 static void DisableEngineForCompany(EngineID eid, CompanyID company)
779 {
780  Engine *e = Engine::Get(eid);
781  Company *c = Company::Get(company);
782 
783  ClrBit(e->company_avail, company);
784  if (e->type == VEH_TRAIN) {
786  } else if (e->type == VEH_ROAD) {
788  }
789 
790  if (company == _local_company) {
791  ClearLastVariant(e->index, e->type);
793  }
794 }
795 
802 static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_depth = 0)
803 {
804  Engine *e = Engine::Get(eid);
805 
807  e->preview_asked = (CompanyMask)-1;
808 
809  EnableEngineForCompany(eid, company);
810 
811  /* Notify preview window, that it might want to close.
812  * Note: We cannot directly close the window.
813  * In singleplayer this function is called from the preview window, so
814  * we have to use the GUI-scope scheduling of InvalidateWindowData.
815  */
817 
818  /* Don't search for variants to include if we are 10 levels deep already. */
819  if (recursion_depth >= 10) return;
820 
821  /* Find variants to be included in preview. */
822  for (Engine *ve : Engine::IterateType(e->type)) {
823  if (ve->index != eid && ve->info.variant_id == eid && (ve->info.extra_flags & ExtraEngineFlags::JoinPreview) != ExtraEngineFlags::None) {
824  AcceptEnginePreview(ve->index, company, recursion_depth + 1);
825  }
826  }
827 }
828 
835 {
836  CompanyID best_company = INVALID_COMPANY;
837 
838  /* For trains the cargomask has no useful meaning, since you can attach other wagons */
839  CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
840 
841  int32 best_hist = -1;
842  for (const Company *c : Company::Iterate()) {
843  if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
844  c->old_economy[0].performance_history > best_hist) {
845 
846  /* Check whether the company uses similar vehicles */
847  for (const Vehicle *v : Vehicle::Iterate()) {
848  if (v->owner != c->index || v->type != e->type) continue;
849  if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue;
850 
851  best_hist = c->old_economy[0].performance_history;
852  best_company = c->index;
853  break;
854  }
855  }
856  }
857 
858  return best_company;
859 }
860 
868 static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
869 {
870  switch (type) {
875 
876  default: NOT_REACHED();
877  }
878 }
879 
882 {
883  for (Company *c : Company::Iterate()) {
884  c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date);
885  c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, _date);
886  }
887 
888  if (_cur_year >= _year_engine_aging_stops) return;
889 
890  for (Engine *e : Engine::Iterate()) {
891  EngineID i = e->index;
892  if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
893  if (e->preview_company != INVALID_COMPANY) {
894  if (!--e->preview_wait) {
896  e->preview_company = INVALID_COMPANY;
897  }
898  } else if (CountBits(e->preview_asked) < MAX_COMPANIES) {
899  e->preview_company = GetPreviewCompany(e);
900 
901  if (e->preview_company == INVALID_COMPANY) {
902  e->preview_asked = (CompanyMask)-1;
903  continue;
904  }
905 
906  SetBit(e->preview_asked, e->preview_company);
907  e->preview_wait = 20;
908  /* AIs are intentionally not skipped for preview even if they cannot build a certain
909  * vehicle type. This is done to not give poor performing human companies an "unfair"
910  * boost that they wouldn't have gotten against other human companies. The check on
911  * the line below is just to make AIs not notice that they have a preview if they
912  * cannot build the vehicle. */
913  if (!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));
914  if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);
915  }
916  }
917  }
918 }
919 
925 {
926  for (Engine *e : Engine::Iterate()) {
927  SB(e->company_hidden, cid, 1, 0);
928  }
929 }
930 
939 {
940  Engine *e = Engine::GetIfValid(engine_id);
941  if (e == nullptr || _current_company >= MAX_COMPANIES) return CMD_ERROR;
942  if (!IsEngineBuildable(e->index, e->type, _current_company)) return CMD_ERROR;
943 
944  if ((flags & DC_EXEC) != 0) {
945  SB(e->company_hidden, _current_company, 1, hide ? 1 : 0);
947  }
948 
949  return CommandCost();
950 }
951 
960 {
961  Engine *e = Engine::GetIfValid(engine_id);
962  if (e == nullptr || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
963 
964  if (flags & DC_EXEC) AcceptEnginePreview(engine_id, _current_company);
965 
966  return CommandCost();
967 }
968 
977 CommandCost CmdEngineCtrl(DoCommandFlag flags, EngineID engine_id, CompanyID company_id, bool allow)
978 {
979  if (_current_company != OWNER_DEITY) return CMD_ERROR;
980 
981  if (!Engine::IsValidID(engine_id) || !Company::IsValidID(company_id)) return CMD_ERROR;
982 
983  if (flags & DC_EXEC) {
984  if (allow) {
985  EnableEngineForCompany(engine_id, company_id);
986  } else {
987  DisableEngineForCompany(engine_id, company_id);
988  }
989  }
990 
991  return CommandCost();
992 }
993 
1000 {
1001  EngineID index = e->index;
1002 
1003  /* In case the company didn't build the vehicle during the intro period,
1004  * prevent that company from getting future intro periods for a while. */
1005  if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
1006  for (Company *c : Company::Iterate()) {
1007  uint block_preview = c->block_preview;
1008 
1009  if (!HasBit(e->company_avail, c->index)) continue;
1010 
1011  /* We assume the user did NOT build it.. prove me wrong ;) */
1012  c->block_preview = 20;
1013 
1014  for (const Vehicle *v : Vehicle::Iterate()) {
1015  if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
1016  (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
1017  if (v->owner == c->index && v->engine_type == index) {
1018  /* The user did prove me wrong, so restore old value */
1019  c->block_preview = block_preview;
1020  break;
1021  }
1022  }
1023  }
1024  }
1025  }
1026 
1029 
1030  /* Now available for all companies */
1031  e->company_avail = (CompanyMask)-1;
1032 
1033  /* Do not introduce new rail wagons */
1034  if (IsWagon(index)) return;
1035 
1036  if (e->type == VEH_TRAIN) {
1037  /* maybe make another rail type available */
1038  assert(e->u.rail.railtype < RAILTYPE_END);
1039  for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
1040  } else if (e->type == VEH_ROAD) {
1041  /* maybe make another road type available */
1042  assert(e->u.road.roadtype < ROADTYPE_END);
1043  for (Company* c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
1044  }
1045 
1046  /* Only broadcast event if AIs are able to build this vehicle type. */
1047  if (!IsVehicleTypeDisabled(e->type, true)) AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index));
1048 
1049  /* Only provide the "New Vehicle available" news paper entry, if engine can be built. */
1050  if (!IsVehicleTypeDisabled(e->type, false) && (e->info.extra_flags & ExtraEngineFlags::NoNews) == ExtraEngineFlags::None) {
1051  SetDParam(0, GetEngineCategoryName(index));
1053  AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NT_NEW_VEHICLES, NF_VEHICLE, NR_ENGINE, index);
1054  }
1055 
1056  /* Update the toolbar. */
1060 
1061  /* Close pending preview windows */
1063 }
1064 
1067 {
1069  bool refresh = false;
1070  for (Engine *e : Engine::Iterate()) {
1071  /* Age the vehicle */
1072  if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) {
1073  e->age++;
1074  CalcEngineReliability(e, true);
1075  refresh = true;
1076  }
1077 
1078  /* Do not introduce invalid engines */
1079  if (!e->IsEnabled()) continue;
1080 
1081  if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) {
1082  /* Introduce it to all companies */
1084  } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
1085  /* Introduction date has passed...
1086  * Check if it is allowed to build this vehicle type at all
1087  * based on the current game settings. If not, it does not
1088  * make sense to show the preview dialog to any company. */
1089  if (IsVehicleTypeDisabled(e->type, false)) continue;
1090 
1091  /* Do not introduce new rail wagons */
1092  if (IsWagon(e->index)) continue;
1093 
1094  /* Engine has no preview */
1095  if ((e->info.extra_flags & ExtraEngineFlags::NoPreview) != ExtraEngineFlags::None) continue;
1096 
1097  /* Show preview dialog to one of the companies. */
1098  e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
1099  e->preview_company = INVALID_COMPANY;
1100  e->preview_asked = 0;
1101  }
1102  }
1103 
1104  InvalidateWindowClassesData(WC_BUILD_VEHICLE); // rebuild the purchase list (esp. when sorted by reliability)
1105 
1106  if (refresh) {
1109  }
1110  }
1111 }
1112 
1118 static bool IsUniqueEngineName(const std::string &name)
1119 {
1120  for (const Engine *e : Engine::Iterate()) {
1121  if (!e->name.empty() && e->name == name) return false;
1122  }
1123 
1124  return true;
1125 }
1126 
1134 CommandCost CmdRenameEngine(DoCommandFlag flags, EngineID engine_id, const std::string &text)
1135 {
1136  Engine *e = Engine::GetIfValid(engine_id);
1137  if (e == nullptr) return CMD_ERROR;
1138 
1139  bool reset = text.empty();
1140 
1141  if (!reset) {
1143  if (!IsUniqueEngineName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1144  }
1145 
1146  if (flags & DC_EXEC) {
1147  if (reset) {
1148  e->name.clear();
1149  } else {
1150  e->name = text;
1151  }
1152 
1154  }
1155 
1156  return CommandCost();
1157 }
1158 
1159 
1169 {
1170  const Engine *e = Engine::GetIfValid(engine);
1171 
1172  /* check if it's an engine that is in the engine array */
1173  if (e == nullptr) return false;
1174 
1175  /* check if it's an engine of specified type */
1176  if (e->type != type) return false;
1177 
1178  /* check if it's available ... */
1179  if (company == OWNER_DEITY) {
1180  /* ... for any company (preview does not count) */
1181  if (!(e->flags & ENGINE_AVAILABLE) || e->company_avail == 0) return false;
1182  } else {
1183  /* ... for this company */
1184  if (!HasBit(e->company_avail, company)) return false;
1185  }
1186 
1187  if (!e->IsEnabled()) return false;
1188 
1189  if (type == VEH_TRAIN && company != OWNER_DEITY) {
1190  /* Check if the rail type is available to this company */
1191  const Company *c = Company::Get(company);
1192  if (((GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false;
1193  }
1194  if (type == VEH_ROAD && company != OWNER_DEITY) {
1195  /* Check if the road type is available to this company */
1196  const Company *c = Company::Get(company);
1197  if ((GetRoadTypeInfo(e->u.road.roadtype)->powered_roadtypes & c->avail_roadtypes) == ROADTYPES_NONE) return false;
1198  }
1199 
1200  return true;
1201 }
1202 
1210 {
1211  const Engine *e = Engine::GetIfValid(engine);
1212 
1213  /* check if it's an engine that is in the engine array */
1214  if (e == nullptr) return false;
1215 
1216  if (!e->CanCarryCargo()) return false;
1217 
1218  const EngineInfo *ei = &e->info;
1219  if (ei->refit_mask == 0) return false;
1220 
1221  /* Are there suffixes?
1222  * Note: This does not mean the suffixes are actually available for every consist at any time. */
1223  if (HasBit(ei->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
1224 
1225  /* Is there any cargo except the default cargo? */
1226  CargoID default_cargo = e->GetDefaultCargoType();
1227  CargoTypes default_cargo_mask = 0;
1228  SetBit(default_cargo_mask, default_cargo);
1229  return default_cargo != CT_INVALID && ei->refit_mask != default_cargo_mask;
1230 }
1231 
1236 {
1237  Date min_date = INT32_MAX;
1238 
1239  for (const Engine *e : Engine::Iterate()) {
1240  if (!e->IsEnabled()) continue;
1241 
1242  /* Don't consider train wagons, we need a powered engine available. */
1243  if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
1244 
1245  /* We have an available engine... yay! */
1246  if ((e->flags & ENGINE_AVAILABLE) != 0 && e->company_avail != 0) return;
1247 
1248  /* Okay, try to find the earliest date. */
1249  min_date = std::min(min_date, e->info.base_intro);
1250  }
1251 
1252  if (min_date < INT32_MAX) {
1253  SetDParam(0, min_date);
1254  ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_YET, STR_ERROR_NO_VEHICLES_AVAILABLE_YET_EXPLANATION, WL_WARNING);
1255  } else {
1256  ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_AT_ALL, STR_ERROR_NO_VEHICLES_AVAILABLE_AT_ALL_EXPLANATION, WL_WARNING);
1257  }
1258 }
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:203
EngineInfo::base_life
Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life.
Definition: engine_type.h:146
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:497
Engine::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:153
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:3254
CheckEngines
void CheckEngines()
Check for engines that have an appropriate availability.
Definition: engine.cpp:1235
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:312
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
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:173
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:519
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:66
EngineOverrideManager::ResetToDefaultMapping
void ResetToDefaultMapping()
Initializes the EngineOverrideManager with the default engines.
Definition: engine.cpp:479
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:372
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:3247
EngineIDMapping::grfid
uint32 grfid
The GRF ID of the file the entity belongs to.
Definition: engine_base.h:180
Engine::reliability_max
uint16 reliability_max
Maximal reliability of the engine.
Definition: engine_base.h:43
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:961
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:47
PROP_ROADVEH_COST_FACTOR
@ PROP_ROADVEH_COST_FACTOR
Purchase cost.
Definition: newgrf_properties.h:35
command_func.h
PackEngineNameDParam
uint64 PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32 extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition: engine_type.h:196
Pool::PoolItem<&_engine_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CalcEngineReliability
void CalcEngineReliability(Engine *e, bool new_month)
Update Engine::reliability and (if needed) update the engine GUIs.
Definition: engine.cpp:581
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
Company::avail_railtypes
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:121
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:328
Engine::reliability_spd_dec
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:41
RoadTypeInfo::introduces_roadtypes
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition: road.h:175
Company::avail_roadtypes
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:122
_engine_counts
const uint8 _engine_counts[4]
Number of engines of each vehicle type in original engine data.
Definition: engine.cpp:51
company_base.h
IsWagon
static bool IsWagon(EngineID index)
Determine whether an engine type is a wagon (and not a loco).
Definition: engine.cpp:559
GetPreviewCompany
static CompanyID GetPreviewCompany(Engine *e)
Get the best company for an engine preview.
Definition: engine.cpp:834
_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:881
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:48
StartupOneEngine
void StartupOneEngine(Engine *e, Date aging_date, uint32 seed)
Start/initialise one engine.
Definition: engine.cpp:653
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:52
WC_ENGINE_PREVIEW
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Definition: window_type.h:582
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition: engine.cpp:420
VE_DEFAULT
@ VE_DEFAULT
Default value to indicate that visual effect should be based on engine class.
Definition: vehicle_base.h:96
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:118
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:45
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:750
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:275
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:827
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:42
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition: engine_gui.cpp:40
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
SetupEngines
void SetupEngines()
Initialise the engine pool with the data from the original vehicles.
Definition: engine.cpp:535
AddDateIntroducedRoadTypes
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:155
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:50
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition: road.cpp:188
Engine::GetLifeLengthInDays
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:437
EngineInfo
Information about a vehicle.
Definition: engine_type.h:143
EngineInfo::base_intro
Date base_intro
Basic date of engine introduction (without random parts).
Definition: engine_type.h:144
CBM_VEHICLE_CARGO_SUFFIX
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
Definition: newgrf_callbacks.h:297
Engine
Definition: engine_base.h:36
MAX_DAY
#define MAX_DAY
The number of days till the last day.
Definition: date_type.h:98
ExtraEngineFlags::NoPreview
@ NoPreview
No exclusive preview will be offered.
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:224
EngineIDMapping::internal_id
uint16 internal_id
The internal ID within the GRF file.
Definition: engine_base.h:181
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:95
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:53
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:127
StartupEngines
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:719
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:1162
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:357
DisableEngineForCompany
static void DisableEngineForCompany(EngineID eid, CompanyID company)
Forbids engine eid to be used by a company company.
Definition: engine.cpp:778
EngineOverrideManager::GetID
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Definition: engine.cpp:502
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:355
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:377
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:503
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
CmdWantEnginePreview
CommandCost CmdWantEnginePreview(DoCommandFlag flags, EngineID engine_id)
Accept an engine prototype.
Definition: engine.cpp:959
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:57
ai.hpp
EngineInfo::lifelength
Year lifelength
Lifetime of a single vehicle.
Definition: engine_type.h:145
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:154
IsUniqueEngineName
static bool IsUniqueEngineName(const std::string &name)
Is name still free as name for an engine?
Definition: engine.cpp:1118
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:182
Engine::display_last_variant
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Definition: engine_base.h:58
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition: engine.cpp:352
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:435
AcceptEnginePreview
static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_depth=0)
Company company accepts engine eid for preview.
Definition: engine.cpp:802
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:868
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:120
NT_NEW_VEHICLES
@ NT_NEW_VEHICLES
New vehicle has become available.
Definition: news_type.h:34
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
AISettings::ai_disable_veh_train
bool ai_disable_veh_train
disable types for AI
Definition: settings_type.h:371
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:236
CommandCost
Common return value for all commands.
Definition: command_type.h:24
_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:220
newgrf_engine.h
VehicleSettings::max_ships
UnitID max_ships
max ships in game per company
Definition: settings_type.h:498
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:302
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:201
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:49
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition: window_type.h:211
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition: engine.cpp:402
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:261
safeguards.h
IsInteractiveCompany
static bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
Definition: company_func.h:53
EngineInfo::callback_mask
uint16 callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition: engine_type.h:154
ExtraEngineFlags::SyncReliability
@ SyncReliability
Engine reliability will be synced with variant parent.
EnginesMonthlyLoop
void EnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition: engine.cpp:1066
ExtraEngineFlags::NoNews
@ NoNews
No 'new vehicle' news will be generated.
error.h
EngineIDMapping
Definition: engine_base.h:179
EngineInfo::retire_early
int8 retire_early
Number of years early to retire vehicle.
Definition: engine_type.h:155
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:183
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:312
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
ENGINE_AVAILABLE
@ ENGINE_AVAILABLE
This vehicle is available to everyone.
Definition: engine_type.h:181
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:153
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:295
Engine::reliability_final
uint16 reliability_final
Final reliability of the engine.
Definition: engine_base.h:44
_engine_offsets
const uint8 _engine_offsets[4]
Offset of the first engine of each vehicle type in original engine data.
Definition: engine.cpp:59
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:570
GameSettings::ai
AISettings ai
what may the AI do?
Definition: settings_type.h:589
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:408
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:374
_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:37
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
ExtraEngineFlags::JoinPreview
@ JoinPreview
Engine will join exclusive preview with variant parent.
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:164
CmdSetVehicleVisibility
CommandCost CmdSetVehicleVisibility(DoCommandFlag flags, EngineID engine_id, bool hide)
Set the visibility of an engine.
Definition: engine.cpp:938
VehicleSettings::max_trains
UnitID max_trains
max trains in game per company
Definition: settings_type.h:495
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:376
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1183
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition: engine.cpp:384
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:172
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1203
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:3271
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
CmdRenameEngine
CommandCost CmdRenameEngine(DoCommandFlag flags, EngineID engine_id, const std::string &text)
Rename an engine.
Definition: engine.cpp:1134
EngineOverrideManager
Stores the mapping of EngineID to the internal id of newgrfs.
Definition: engine_base.h:190
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:158
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:373
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:225
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:999
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
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:313
company_func.h
VehicleSettings::max_roadveh
UnitID max_roadveh
max trucks in game per company
Definition: settings_type.h:496
Engine::original_image_index
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:54
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:94
window_func.h
NF_VEHICLE
@ NF_VEHICLE
Vehicle news item. (new engine available)
Definition: news_type.h:80
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:386
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:1767
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:197
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:1191
VehicleSettings::never_expire_vehicles
bool never_expire_vehicles
never expire vehicles
Definition: settings_type.h:502
Engine::IsEnabled
bool IsEnabled() const
Checks whether the engine is a valid (non-articulated part of an) engine.
Definition: engine.cpp:143
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:977
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:320
Engine::grf_prop
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Definition: engine_base.h:76
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:595
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:321
EngineInfo::climates
byte climates
Climates supported by the engine.
Definition: engine_type.h:149
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:1209
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:447
EngineIDMapping::type
VehicleType type
The engine type.
Definition: engine_base.h:182
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:48
pool_func.hpp
EngineInfo::string_id
StringID string_id
Default name of engine.
Definition: engine_type.h:156
ClearEnginesHiddenFlagOfCompany
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the 'hidden' flag for all engines of a new company.
Definition: engine.cpp:924
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:200
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
ROADTYPES_NONE
@ ROADTYPES_NONE
No roadtypes.
Definition: road_type.h:37
Company
Definition: company_base.h:117
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:51
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3182
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:157
SetYearEngineAgingStops
void SetYearEngineAgingStops()
Compute the value for _year_engine_aging_stops.
Definition: engine.cpp:627
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1168
Engine::intro_date
Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:38
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:461
EngineOverrideManager::NUM_DEFAULT_ENGINES
static const uint NUM_DEFAULT_ENGINES
Number of default entries.
Definition: engine_base.h:191
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:106
Engine::reliability
uint16 reliability
Current reliability of the engine.
Definition: engine_base.h:40
PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
Definition: engine_type.h:192
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:55
Engine::duration_phase_2
uint16 duration_phase_2
Second reliability phase in months, keeping reliability_max.
Definition: engine_base.h:46
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