OpenTTD Source  1.11.0-beta2
vehicle_cmd.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 "roadveh.h"
12 #include "news_func.h"
13 #include "airport.h"
14 #include "cmd_helper.h"
15 #include "command_func.h"
16 #include "company_func.h"
17 #include "train.h"
18 #include "aircraft.h"
19 #include "newgrf_text.h"
20 #include "vehicle_func.h"
21 #include "string_func.h"
22 #include "depot_map.h"
23 #include "vehiclelist.h"
24 #include "engine_func.h"
25 #include "articulated_vehicles.h"
26 #include "autoreplace_gui.h"
27 #include "group.h"
28 #include "order_backup.h"
29 #include "ship.h"
30 #include "newgrf.h"
31 #include "company_base.h"
32 #include "core/random_func.hpp"
33 #include <sstream>
34 #include <iomanip>
35 
36 #include "table/strings.h"
37 
38 #include "safeguards.h"
39 
40 /* Tables used in vehicle.h to find the right command for a certain vehicle type */
41 const uint32 _veh_build_proc_table[] = {
42  CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN),
43  CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_ROAD_VEHICLE),
44  CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_SHIP),
45  CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_AIRCRAFT),
46 };
47 
48 const uint32 _veh_sell_proc_table[] = {
49  CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN),
50  CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE),
51  CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP),
52  CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT),
53 };
54 
55 const uint32 _veh_refit_proc_table[] = {
56  CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN),
57  CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE),
58  CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_SHIP),
59  CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_AIRCRAFT),
60 };
61 
62 const uint32 _send_to_depot_proc_table[] = {
63  CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT),
64  CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT),
65  CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT),
66  CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR),
67 };
68 
69 
70 CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
71 CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
72 CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
73 CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
74 
75 CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
76 
89 CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
90 {
91  /* Elementary check for valid location. */
92  if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
93 
94  VehicleType type = GetDepotVehicleType(tile);
95 
96  /* Validate the engine type. */
97  EngineID eid = GB(p1, 0, 16);
98  if (!IsEngineBuildable(eid, type, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type);
99 
100  /* Validate the cargo type. */
101  CargoID cargo = GB(p1, 24, 8);
102  if (cargo >= NUM_CARGO && cargo != CT_INVALID) return CMD_ERROR;
103 
104  const Engine *e = Engine::Get(eid);
106 
107  /* Engines without valid cargo should not be available */
108  CargoID default_cargo = e->GetDefaultCargoType();
109  if (default_cargo == CT_INVALID) return CMD_ERROR;
110 
111  bool refitting = cargo != CT_INVALID && cargo != default_cargo;
112 
113  /* Check whether the number of vehicles we need to build can be built according to pool space. */
114  uint num_vehicles;
115  switch (type) {
116  case VEH_TRAIN: num_vehicles = (e->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid, false); break;
117  case VEH_ROAD: num_vehicles = 1 + CountArticulatedParts(eid, false); break;
118  case VEH_SHIP: num_vehicles = 1; break;
119  case VEH_AIRCRAFT: num_vehicles = e->u.air.subtype & AIR_CTOL ? 2 : 3; break;
120  default: NOT_REACHED(); // Safe due to IsDepotTile()
121  }
122  if (!Vehicle::CanAllocateItem(num_vehicles)) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
123 
124  /* Check whether we can allocate a unit number. Autoreplace does not allocate
125  * an unit number as it will (always) reuse the one of the replaced vehicle
126  * and (train) wagons don't have an unit number in any scenario. */
127  UnitID unit_num = (flags & DC_AUTOREPLACE || (type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type);
128  if (unit_num == UINT16_MAX) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
129 
130  /* If we are refitting we need to temporarily purchase the vehicle to be able to
131  * test it. */
132  DoCommandFlag subflags = flags;
133  if (refitting && !(flags & DC_EXEC)) subflags |= DC_EXEC | DC_AUTOREPLACE;
134 
135  /* Vehicle construction needs random bits, so we have to save the random
136  * seeds to prevent desyncs. */
137  SavedRandomSeeds saved_seeds;
138  SaveRandomSeeds(&saved_seeds);
139 
140  Vehicle *v = nullptr;
141  switch (type) {
142  case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(tile, subflags, e, GB(p1, 16, 8), &v)); break;
143  case VEH_ROAD: value.AddCost(CmdBuildRoadVehicle(tile, subflags, e, GB(p1, 16, 8), &v)); break;
144  case VEH_SHIP: value.AddCost(CmdBuildShip (tile, subflags, e, GB(p1, 16, 8), &v)); break;
145  case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft (tile, subflags, e, GB(p1, 16, 8), &v)); break;
146  default: NOT_REACHED(); // Safe due to IsDepotTile()
147  }
148 
149  if (value.Succeeded()) {
150  if (subflags & DC_EXEC) {
151  v->unitnumber = unit_num;
152  v->value = value.GetCost();
153  }
154 
155  if (refitting) {
156  /* Refit only one vehicle. If we purchased an engine, it may have gained free wagons. */
157  value.AddCost(CmdRefitVehicle(tile, flags, v->index, cargo | (1 << 16), nullptr));
158  } else {
159  /* Fill in non-refitted capacities */
161  }
162 
163  if (flags & DC_EXEC) {
167  if (IsLocalCompany()) {
168  InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the auto replace window (must be called before incrementing num_engines)
169  }
170  }
171 
172  if (subflags & DC_EXEC) {
175 
176  if (v->IsPrimaryVehicle()) {
178  if (!(subflags & DC_AUTOREPLACE)) OrderBackup::Restore(v, p2);
179  }
180  }
181 
182 
183  /* If we are not in DC_EXEC undo everything */
184  if (flags != subflags) {
185  DoCommand(0, v->index, 0, DC_EXEC, GetCmdSellVeh(v));
186  }
187  }
188 
189  /* Only restore if we actually did some refitting */
190  if (flags != subflags) RestoreRandomSeeds(saved_seeds);
191 
192  return value;
193 }
194 
195 CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *v, uint16 data, uint32 user);
196 
209 CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
210 {
211  Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
212  if (v == nullptr) return CMD_ERROR;
213 
214  Vehicle *front = v->First();
215 
216  CommandCost ret = CheckOwnership(front->owner);
217  if (ret.Failed()) return ret;
218 
219  if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
220 
221  if (!front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
222 
223  /* Can we actually make the order backup, i.e. are there enough orders? */
224  if (p1 & MAKE_ORDER_BACKUP_FLAG &&
225  front->orders.list != nullptr &&
226  !front->orders.list->IsShared() &&
228  /* Only happens in exceptional cases when there aren't enough orders anyhow.
229  * Thus it should be safe to just drop the orders in that case. */
230  p1 &= ~MAKE_ORDER_BACKUP_FLAG;
231  }
232 
233  if (v->type == VEH_TRAIN) {
234  ret = CmdSellRailWagon(flags, v, GB(p1, 20, 12), p2);
235  } else {
236  ret = CommandCost(EXPENSES_NEW_VEHICLES, -front->value);
237 
238  if (flags & DC_EXEC) {
239  if (front->IsPrimaryVehicle() && p1 & MAKE_ORDER_BACKUP_FLAG) OrderBackup::Backup(front, p2);
240  delete front;
241  }
242  }
243 
244  return ret;
245 }
246 
256 static int GetRefitCostFactor(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
257 {
258  /* Prepare callback param with info about the new cargo type. */
259  const Engine *e = Engine::Get(engine_type);
260 
261  /* Is this vehicle a NewGRF vehicle? */
262  if (e->GetGRF() != nullptr) {
263  const CargoSpec *cs = CargoSpec::Get(new_cid);
264  uint32 param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cid];
265 
266  uint16 cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
267  if (cb_res != CALLBACK_FAILED) {
268  *auto_refit_allowed = HasBit(cb_res, 14);
269  int factor = GB(cb_res, 0, 14);
270  if (factor >= 0x2000) factor -= 0x4000; // Treat as signed integer.
271  return factor;
272  }
273  }
274 
275  *auto_refit_allowed = e->info.refit_cost == 0;
276  return (v == nullptr || v->cargo_type != new_cid) ? e->info.refit_cost : 0;
277 }
278 
288 static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
289 {
290  ExpensesType expense_type;
291  const Engine *e = Engine::Get(engine_type);
292  Price base_price;
293  int cost_factor = GetRefitCostFactor(v, engine_type, new_cid, new_subtype, auto_refit_allowed);
294  switch (e->type) {
295  case VEH_SHIP:
296  base_price = PR_BUILD_VEHICLE_SHIP;
297  expense_type = EXPENSES_SHIP_RUN;
298  break;
299 
300  case VEH_ROAD:
301  base_price = PR_BUILD_VEHICLE_ROAD;
302  expense_type = EXPENSES_ROADVEH_RUN;
303  break;
304 
305  case VEH_AIRCRAFT:
306  base_price = PR_BUILD_VEHICLE_AIRCRAFT;
307  expense_type = EXPENSES_AIRCRAFT_RUN;
308  break;
309 
310  case VEH_TRAIN:
311  base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
312  cost_factor <<= 1;
313  expense_type = EXPENSES_TRAIN_RUN;
314  break;
315 
316  default: NOT_REACHED();
317  }
318  if (cost_factor < 0) {
319  return CommandCost(expense_type, -GetPrice(base_price, -cost_factor, e->GetGRF(), -10));
320  } else {
321  return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->GetGRF(), -10));
322  }
323 }
324 
326 struct RefitResult {
328  uint capacity;
330  byte subtype;
331 };
332 
345 static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
346 {
347  CommandCost cost(v->GetExpenseType(false));
348  uint total_capacity = 0;
349  uint total_mail_capacity = 0;
350  num_vehicles = num_vehicles == 0 ? UINT8_MAX : num_vehicles;
351 
352  VehicleSet vehicles_to_refit;
353  if (!only_this) {
354  GetVehicleSet(vehicles_to_refit, v, num_vehicles);
355  /* In this case, we need to check the whole chain. */
356  v = v->First();
357  }
358 
359  std::vector<RefitResult> refit_result;
360 
362  byte actual_subtype = new_subtype;
363  for (; v != nullptr; v = (only_this ? nullptr : v->Next())) {
364  /* Reset actual_subtype for every new vehicle */
365  if (!v->IsArticulatedPart()) actual_subtype = new_subtype;
366 
367  if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end() && !only_this) continue;
368 
369  const Engine *e = v->GetEngine();
370  if (!e->CanCarryCargo()) continue;
371 
372  /* If the vehicle is not refittable, or does not allow automatic refitting,
373  * count its capacity nevertheless if the cargo matches */
374  bool refittable = HasBit(e->info.refit_mask, new_cid) && (!auto_refit || HasBit(e->info.misc_flags, EF_AUTO_REFIT));
375  if (!refittable && v->cargo_type != new_cid) continue;
376 
377  /* Determine best fitting subtype if requested */
378  if (actual_subtype == 0xFF) {
379  actual_subtype = GetBestFittingSubType(v, v, new_cid);
380  }
381 
382  /* Back up the vehicle's cargo type */
383  CargoID temp_cid = v->cargo_type;
384  byte temp_subtype = v->cargo_subtype;
385  if (refittable) {
386  v->cargo_type = new_cid;
387  v->cargo_subtype = actual_subtype;
388  }
389 
390  uint16 mail_capacity = 0;
391  uint amount = e->DetermineCapacity(v, &mail_capacity);
392  total_capacity += amount;
393  /* mail_capacity will always be zero if the vehicle is not an aircraft. */
394  total_mail_capacity += mail_capacity;
395 
396  if (!refittable) continue;
397 
398  /* Restore the original cargo type */
399  v->cargo_type = temp_cid;
400  v->cargo_subtype = temp_subtype;
401 
402  bool auto_refit_allowed;
403  CommandCost refit_cost = GetRefitCost(v, v->engine_type, new_cid, actual_subtype, &auto_refit_allowed);
404  if (auto_refit && (flags & DC_QUERY_COST) == 0 && !auto_refit_allowed) {
405  /* Sorry, auto-refitting not allowed, subtract the cargo amount again from the total.
406  * When querrying cost/capacity (for example in order refit GUI), we always assume 'allowed'.
407  * It is not predictable. */
408  total_capacity -= amount;
409  total_mail_capacity -= mail_capacity;
410 
411  if (v->cargo_type == new_cid) {
412  /* Add the old capacity nevertheless, if the cargo matches */
413  total_capacity += v->cargo_cap;
414  if (v->type == VEH_AIRCRAFT) total_mail_capacity += v->Next()->cargo_cap;
415  }
416  continue;
417  }
418  cost.AddCost(refit_cost);
419 
420  /* Record the refitting.
421  * Do not execute the refitting immediately, so DetermineCapacity and GetRefitCost do the same in test and exec run.
422  * (weird NewGRFs)
423  * Note:
424  * - If the capacity of vehicles depends on other vehicles in the chain, the actual capacity is
425  * set after RefitVehicle() via ConsistChanged() and friends. The estimation via _returned_refit_capacity will be wrong.
426  * - We have to call the refit cost callback with the pre-refit configuration of the chain because we want refit and
427  * autorefit to behave the same, and we need its result for auto_refit_allowed.
428  */
429  refit_result.push_back({v, amount, mail_capacity, actual_subtype});
430  }
431 
432  if (flags & DC_EXEC) {
433  /* Store the result */
434  for (RefitResult &result : refit_result) {
435  Vehicle *u = result.v;
436  u->refit_cap = (u->cargo_type == new_cid) ? std::min<uint16>(result.capacity, u->refit_cap) : 0;
437  if (u->cargo.TotalCount() > u->refit_cap) u->cargo.Truncate(u->cargo.TotalCount() - u->refit_cap);
438  u->cargo_type = new_cid;
439  u->cargo_cap = result.capacity;
440  u->cargo_subtype = result.subtype;
441  if (u->type == VEH_AIRCRAFT) {
442  Vehicle *w = u->Next();
443  w->refit_cap = std::min<uint16>(w->refit_cap, result.mail_capacity);
444  w->cargo_cap = result.mail_capacity;
445  if (w->cargo.TotalCount() > w->refit_cap) w->cargo.Truncate(w->cargo.TotalCount() - w->refit_cap);
446  }
447  }
448  }
449 
450  refit_result.clear();
451  _returned_refit_capacity = total_capacity;
452  _returned_mail_refit_capacity = total_mail_capacity;
453  return cost;
454 }
455 
471 CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
472 {
473  Vehicle *v = Vehicle::GetIfValid(p1);
474  if (v == nullptr) return CMD_ERROR;
475 
476  /* Don't allow disasters and sparks and such to be refitted.
477  * We cannot check for IsPrimaryVehicle as autoreplace also refits in free wagon chains. */
479 
480  Vehicle *front = v->First();
481 
482  CommandCost ret = CheckOwnership(front->owner);
483  if (ret.Failed()) return ret;
484 
485  bool auto_refit = HasBit(p2, 24);
486  bool free_wagon = v->type == VEH_TRAIN && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew
487 
488  /* Don't allow shadows and such to be refitted. */
489  if (v != front && (v->type == VEH_SHIP || v->type == VEH_AIRCRAFT)) return CMD_ERROR;
490 
491  /* Allow auto-refitting only during loading and normal refitting only in a depot. */
492  if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
493  !free_wagon && // used by autoreplace/renew
494  (!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
495  !front->IsStoppedInDepot()) { // refit inside depots
496  return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
497  }
498 
499  if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
500 
501  /* Check cargo */
502  CargoID new_cid = GB(p2, 0, 8);
503  byte new_subtype = GB(p2, 8, 8);
504  if (new_cid >= NUM_CARGO) return CMD_ERROR;
505 
506  /* For ships and aircraft there is always only one. */
507  bool only_this = HasBit(p2, 25) || front->type == VEH_SHIP || front->type == VEH_AIRCRAFT;
508  uint8 num_vehicles = GB(p2, 16, 8);
509 
510  CommandCost cost = RefitVehicle(v, only_this, num_vehicles, new_cid, new_subtype, flags, auto_refit);
511 
512  if (flags & DC_EXEC) {
513  /* Update the cached variables */
514  switch (v->type) {
515  case VEH_TRAIN:
516  Train::From(front)->ConsistChanged(auto_refit ? CCF_AUTOREFIT : CCF_REFIT);
517  break;
518  case VEH_ROAD:
519  RoadVehUpdateCache(RoadVehicle::From(front), auto_refit);
521  break;
522 
523  case VEH_SHIP:
525  Ship::From(v)->UpdateCache();
526  break;
527 
528  case VEH_AIRCRAFT:
531  break;
532 
533  default: NOT_REACHED();
534  }
535  front->MarkDirty();
536 
537  if (!free_wagon) {
540  }
542  } else {
543  /* Always invalidate the cache; querycost might have filled it. */
545  }
546 
547  return cost;
548 }
549 
559 CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
560 {
561  /* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
562  if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
563 
564  Vehicle *v = Vehicle::GetIfValid(p1);
565  if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
566 
567  CommandCost ret = CheckOwnership(v->owner);
568  if (ret.Failed()) return ret;
569 
570  if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
571 
572  switch (v->type) {
573  case VEH_TRAIN:
574  if ((v->vehstatus & VS_STOPPED) && Train::From(v)->gcache.cached_power == 0) return_cmd_error(STR_ERROR_TRAIN_START_NO_POWER);
575  break;
576 
577  case VEH_SHIP:
578  case VEH_ROAD:
579  break;
580 
581  case VEH_AIRCRAFT: {
582  Aircraft *a = Aircraft::From(v);
583  /* cannot stop airplane when in flight, or when taking off / landing */
584  if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
585  if (HasBit(a->flags, VAF_HELI_DIRECT_DESCENT)) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
586  break;
587  }
588 
589  default: return CMD_ERROR;
590  }
591 
592  if (HasBit(p2, 0)) {
593  /* Check if this vehicle can be started/stopped. Failure means 'allow'. */
594  uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
595  StringID error = STR_NULL;
596  if (callback != CALLBACK_FAILED) {
597  if (v->GetGRF()->grf_version < 8) {
598  /* 8 bit result 0xFF means 'allow' */
599  if (callback < 0x400 && GB(callback, 0, 8) != 0xFF) error = GetGRFStringID(v->GetGRFID(), 0xD000 + callback);
600  } else {
601  if (callback < 0x400) {
602  error = GetGRFStringID(v->GetGRFID(), 0xD000 + callback);
603  } else {
604  switch (callback) {
605  case 0x400: // allow
606  break;
607 
608  default: // unknown reason -> disallow
609  error = STR_ERROR_INCOMPATIBLE_RAIL_TYPES;
610  break;
611  }
612  }
613  }
614  }
615  if (error != STR_NULL) return_cmd_error(error);
616  }
617 
618  if (flags & DC_EXEC) {
619  if (v->IsStoppedInDepot() && (flags & DC_AUTOREPLACE) == 0) DeleteVehicleNews(p1, STR_NEWS_TRAIN_IS_WAITING + v->type);
620 
621  v->vehstatus ^= VS_STOPPED;
622  if (v->type != VEH_TRAIN) v->cur_speed = 0; // trains can stop 'slowly'
623  v->MarkDirty();
628  }
629  return CommandCost();
630 }
631 
643 CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
644 {
645  VehicleList list;
646  bool do_start = HasBit(p1, 0);
647  bool vehicle_list_window = HasBit(p1, 1);
648 
650  if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
652 
653  if (vehicle_list_window) {
654  if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
655  } else {
656  /* Get the list of vehicles in the depot */
657  BuildDepotVehicleList(vli.vtype, tile, &list, nullptr);
658  }
659 
660  for (uint i = 0; i < list.size(); i++) {
661  const Vehicle *v = list[i];
662 
663  if (!!(v->vehstatus & VS_STOPPED) != do_start) continue;
664 
665  if (!vehicle_list_window && !v->IsChainInDepot()) continue;
666 
667  /* Just try and don't care if some vehicle's can't be stopped. */
668  DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
669  }
670 
671  return CommandCost();
672 }
673 
683 CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
684 {
685  VehicleList list;
686 
688  VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
689 
690  if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
691 
692  uint sell_command = GetCmdSellVeh(vehicle_type);
693 
694  /* Get the list of vehicles in the depot */
695  BuildDepotVehicleList(vehicle_type, tile, &list, &list);
696 
697  CommandCost last_error = CMD_ERROR;
698  bool had_success = false;
699  for (uint i = 0; i < list.size(); i++) {
700  CommandCost ret = DoCommand(tile, list[i]->index | (1 << 20), 0, flags, sell_command);
701  if (ret.Succeeded()) {
702  cost.AddCost(ret);
703  had_success = true;
704  } else {
705  last_error = ret;
706  }
707  }
708 
709  return had_success ? cost : last_error;
710 }
711 
721 CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
722 {
723  VehicleList list;
725  VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
726 
727  if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
728  if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
729 
730  /* Get the list of vehicles in the depot */
731  BuildDepotVehicleList(vehicle_type, tile, &list, &list, true);
732 
733  for (uint i = 0; i < list.size(); i++) {
734  const Vehicle *v = list[i];
735 
736  /* Ensure that the vehicle completely in the depot */
737  if (!v->IsChainInDepot()) continue;
738 
739  CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE);
740 
741  if (ret.Succeeded()) cost.AddCost(ret);
742  }
743  return cost;
744 }
745 
751 static bool IsUniqueVehicleName(const char *name)
752 {
753  for (const Vehicle *v : Vehicle::Iterate()) {
754  if (!v->name.empty() && v->name == name) return false;
755  }
756 
757  return true;
758 }
759 
765 static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
766 {
767  std::string buf;
768 
769  /* Find the position of the first digit in the last group of digits. */
770  size_t number_position;
771  for (number_position = src->name.length(); number_position > 0; number_position--) {
772  /* The design of UTF-8 lets this work simply without having to check
773  * for UTF-8 sequences. */
774  if (src->name[number_position - 1] < '0' || src->name[number_position - 1] > '9') break;
775  }
776 
777  /* Format buffer and determine starting number. */
778  long num;
779  byte padding = 0;
780  if (number_position == src->name.length()) {
781  /* No digit at the end, so start at number 2. */
782  buf = src->name;
783  buf += " ";
784  number_position = buf.length();
785  num = 2;
786  } else {
787  /* Found digits, parse them and start at the next number. */
788  buf = src->name.substr(0, number_position);
789 
790  auto num_str = src->name.substr(number_position);
791  padding = (byte)num_str.length();
792 
793  std::istringstream iss(num_str);
794  iss >> num;
795  num++;
796  }
797 
798  /* Check if this name is already taken. */
799  for (int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) {
800  std::ostringstream oss;
801 
802  /* Attach the number to the temporary name. */
803  oss << buf << std::setw(padding) << std::setfill('0') << std::internal << num;
804 
805  /* Check the name is unique. */
806  auto new_name = oss.str();
807  if (IsUniqueVehicleName(new_name.c_str())) {
808  dst->name = new_name;
809  break;
810  }
811  }
812 
813  /* All done. If we didn't find a name, it'll just use its default. */
814 }
815 
825 CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
826 {
828 
829  Vehicle *v = Vehicle::GetIfValid(p1);
830  if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
831  Vehicle *v_front = v;
832  Vehicle *w = nullptr;
833  Vehicle *w_front = nullptr;
834  Vehicle *w_rear = nullptr;
835 
836  /*
837  * v_front is the front engine in the original vehicle
838  * v is the car/vehicle of the original vehicle that is currently being copied
839  * w_front is the front engine of the cloned vehicle
840  * w is the car/vehicle currently being cloned
841  * w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
842  */
843 
844  CommandCost ret = CheckOwnership(v->owner);
845  if (ret.Failed()) return ret;
846 
847  if (v->type == VEH_TRAIN && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR;
848 
849  /* check that we can allocate enough vehicles */
850  if (!(flags & DC_EXEC)) {
851  int veh_counter = 0;
852  do {
853  veh_counter++;
854  } while ((v = v->Next()) != nullptr);
855 
856  if (!Vehicle::CanAllocateItem(veh_counter)) {
857  return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
858  }
859  }
860 
861  v = v_front;
862 
863  do {
864  if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) {
865  /* we build the rear ends of multiheaded trains with the front ones */
866  continue;
867  }
868 
869  /* In case we're building a multi headed vehicle and the maximum number of
870  * vehicles is almost reached (e.g. max trains - 1) not all vehicles would
871  * be cloned. When the non-primary engines were build they were seen as
872  * 'new' vehicles whereas they would immediately be joined with a primary
873  * engine. This caused the vehicle to be not build as 'the limit' had been
874  * reached, resulting in partially build vehicles and such. */
875  DoCommandFlag build_flags = flags;
876  if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
877 
878  CommandCost cost = DoCommand(tile, v->engine_type | (1 << 16) | (CT_INVALID << 24), 0, build_flags, GetCmdBuildVeh(v));
879 
880  if (cost.Failed()) {
881  /* Can't build a part, then sell the stuff we already made; clear up the mess */
882  if (w_front != nullptr) DoCommand(w_front->tile, w_front->index | (1 << 20), 0, flags, GetCmdSellVeh(w_front));
883  return cost;
884  }
885 
886  total_cost.AddCost(cost);
887 
888  if (flags & DC_EXEC) {
889  w = Vehicle::Get(_new_vehicle_id);
890 
891  if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
893  }
894 
895  if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
896  /* this s a train car
897  * add this unit to the end of the train */
898  CommandCost result = DoCommand(0, w->index | 1 << 20, w_rear->index, flags, CMD_MOVE_RAIL_VEHICLE);
899  if (result.Failed()) {
900  /* The train can't be joined to make the same consist as the original.
901  * Sell what we already made (clean up) and return an error. */
902  DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
903  DoCommand(w_front->tile, w->index | 1 << 20, 0, flags, GetCmdSellVeh(w));
904  return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
905  }
906  } else {
907  /* this is a front engine or not a train. */
908  w_front = w;
910  w->SetServiceIntervalIsCustom(v->ServiceIntervalIsCustom());
911  w->SetServiceIntervalIsPercent(v->ServiceIntervalIsPercent());
912  }
913  w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
914  }
915  } while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != nullptr);
916 
917  if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) {
918  /* for trains this needs to be the front engine due to the callback function */
919  _new_vehicle_id = w_front->index;
920  }
921 
922  if (flags & DC_EXEC) {
923  /* Cloned vehicles belong to the same group */
924  DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP);
925  }
926 
927 
928  /* Take care of refitting. */
929  w = w_front;
930  v = v_front;
931 
932  /* Both building and refitting are influenced by newgrf callbacks, which
933  * makes it impossible to accurately estimate the cloning costs. In
934  * particular, it is possible for engines of the same type to be built with
935  * different numbers of articulated parts, so when refitting we have to
936  * loop over real vehicles first, and then the articulated parts of those
937  * vehicles in a different loop. */
938  do {
939  do {
940  if (flags & DC_EXEC) {
941  assert(w != nullptr);
942 
943  /* Find out what's the best sub type */
944  byte subtype = GetBestFittingSubType(v, w, v->cargo_type);
945  if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
946  CommandCost cost = DoCommand(0, w->index, v->cargo_type | 1U << 25 | (subtype << 8), flags, GetCmdRefitVeh(v));
947  if (cost.Succeeded()) total_cost.AddCost(cost);
948  }
949 
950  if (w->IsGroundVehicle() && w->HasArticulatedPart()) {
951  w = w->GetNextArticulatedPart();
952  } else {
953  break;
954  }
955  } else {
956  const Engine *e = v->GetEngine();
957  CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
958 
959  if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) {
960  bool dummy;
961  total_cost.AddCost(GetRefitCost(nullptr, v->engine_type, v->cargo_type, v->cargo_subtype, &dummy));
962  }
963  }
964 
965  if (v->IsGroundVehicle() && v->HasArticulatedPart()) {
966  v = v->GetNextArticulatedPart();
967  } else {
968  break;
969  }
970  } while (v != nullptr);
971 
972  if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = w->GetNextVehicle();
973  } while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != nullptr);
974 
975  if (flags & DC_EXEC) {
976  /*
977  * Set the orders of the vehicle. Cannot do it earlier as we need
978  * the vehicle refitted before doing this, otherwise the moved
979  * cargo types might not match (passenger vs non-passenger)
980  */
981  CommandCost result = DoCommand(0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index, flags, CMD_CLONE_ORDER);
982  if (result.Failed()) {
983  /* The vehicle has already been bought, so now it must be sold again. */
984  DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
985  return result;
986  }
987 
988  /* Now clone the vehicle's name, if it has one. */
989  if (!v_front->name.empty()) CloneVehicleName(v_front, w_front);
990 
991  /* Since we can't estimate the cost of cloning a vehicle accurately we must
992  * check whether the company has enough money manually. */
993  if (!CheckCompanyHasMoney(total_cost)) {
994  /* The vehicle has already been bought, so now it must be sold again. */
995  DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
996  return total_cost;
997  }
998  }
999 
1000  return total_cost;
1001 }
1002 
1011 {
1012  VehicleList list;
1013 
1014  if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
1015 
1016  /* Send all the vehicles to a depot */
1017  bool had_success = false;
1018  for (uint i = 0; i < list.size(); i++) {
1019  const Vehicle *v = list[i];
1020  CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(vli.vtype));
1021 
1022  if (ret.Succeeded()) {
1023  had_success = true;
1024 
1025  /* Return 0 if DC_EXEC is not set this is a valid goto depot command)
1026  * In this case we know that at least one vehicle can be sent to a depot
1027  * and we will issue the command. We can now safely quit the loop, knowing
1028  * it will succeed at least once. With DC_EXEC we really need to send them to the depot */
1029  if (!(flags & DC_EXEC)) break;
1030  }
1031  }
1032 
1033  return had_success ? CommandCost() : CMD_ERROR;
1034 }
1035 
1047 CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1048 {
1049  if (p1 & DEPOT_MASS_SEND) {
1050  /* Mass goto depot requested */
1052  if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
1053  return SendAllVehiclesToDepot(flags, (p1 & DEPOT_SERVICE) != 0, vli);
1054  }
1055 
1056  Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
1057  if (v == nullptr) return CMD_ERROR;
1058  if (!v->IsPrimaryVehicle()) return CMD_ERROR;
1059 
1060  return v->SendToDepot(flags, (DepotCommand)(p1 & DEPOT_COMMAND_MASK));
1061 }
1062 
1072 CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1073 {
1074  Vehicle *v = Vehicle::GetIfValid(p1);
1075  if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1076 
1077  CommandCost ret = CheckOwnership(v->owner);
1078  if (ret.Failed()) return ret;
1079 
1080  bool reset = StrEmpty(text);
1081 
1082  if (!reset) {
1084  if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1085  }
1086 
1087  if (flags & DC_EXEC) {
1088  if (reset) {
1089  v->name.clear();
1090  } else {
1091  v->name = text;
1092  }
1095  }
1096 
1097  return CommandCost();
1098 }
1099 
1100 
1113 CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1114 {
1115  Vehicle *v = Vehicle::GetIfValid(p1);
1116  if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1117 
1118  CommandCost ret = CheckOwnership(v->owner);
1119  if (ret.Failed()) return ret;
1120 
1121  const Company *company = Company::Get(v->owner);
1122  bool iscustom = HasBit(p2, 16);
1123  bool ispercent = iscustom ? HasBit(p2, 17) : company->settings.vehicle.servint_ispercent;
1124 
1125  uint16 serv_int;
1126  if (iscustom) {
1127  serv_int = GB(p2, 0, 16);
1128  if (serv_int != GetServiceIntervalClamped(serv_int, ispercent)) return CMD_ERROR;
1129  } else {
1130  serv_int = CompanyServiceInterval(company, v->type);
1131  }
1132 
1133  if (flags & DC_EXEC) {
1134  v->SetServiceInterval(serv_int);
1135  v->SetServiceIntervalIsCustom(iscustom);
1136  v->SetServiceIntervalIsPercent(ispercent);
1138  }
1139 
1140  return CommandCost();
1141 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
VehicleCargoList::TotalCount
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
Definition: cargopacket.h:360
Vehicle::IsChainInDepot
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:521
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:99
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
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:3321
CMD_REFIT_VEHICLE
@ CMD_REFIT_VEHICLE
refit the cargo space of a vehicle
Definition: command_type.h:216
CmdBuildShip
CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
Build a ship.
Definition: ship_cmd.cpp:827
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition: economy_type.h:161
RefitResult::mail_capacity
uint mail_capacity
New mail capacity of aircraft.
Definition: vehicle_cmd.cpp:329
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:61
VehicleList
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition: vehiclelist.h:53
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
CmdSellRailWagon
CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *v, uint16 data, uint32 user)
Sell a (single) train wagon/engine.
Definition: train_cmd.cpp:1357
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3220
GetServiceIntervalClamped
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1918
GroupStatistics::CountEngine
static void CountEngine(const Vehicle *v, int delta)
Update num_engines when adding/removing an engine.
Definition: group_cmd.cpp:156
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:950
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
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:251
CMD_ADD_VEHICLE_GROUP
@ CMD_ADD_VEHICLE_GROUP
add a vehicle to a group
Definition: command_type.h:324
CMD_MOVE_RAIL_VEHICLE
@ CMD_MOVE_RAIL_VEHICLE
move a rail vehicle (in the depot)
Definition: command_type.h:220
train.h
AircraftVehicleInfo::subtype
byte subtype
Type of aircraft.
Definition: engine_type.h:101
command_func.h
CBID_VEHICLE_START_STOP_CHECK
@ CBID_VEHICLE_START_STOP_CHECK
Called when the company (or AI) tries to start or stop a vehicle.
Definition: newgrf_callbacks.h:141
Pool::PoolItem<&_vehicle_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:340
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
Vehicle::GetNextVehicle
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:966
company_base.h
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:592
SendAllVehiclesToDepot
static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, const VehicleListIdentifier &vli)
Send all vehicles of type to depots.
Definition: vehicle_cmd.cpp:1010
UnitID
uint16 UnitID
Type for the company global vehicle unit number.
Definition: transport_type.h:16
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:74
vehiclelist.h
GetVehicleSet
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
Calculates the set of vehicles that will be affected by a given selection.
Definition: vehicle.cpp:2946
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
BaseConsist::name
std::string name
Name of vehicle.
Definition: base_consist.h:19
DEPOT_MASS_SEND
@ DEPOT_MASS_SEND
Tells that it's a mass send to depot command (type in VLW flag)
Definition: vehicle_type.h:67
SavedRandomSeeds
Stores the state of all random number generators.
Definition: random_func.hpp:33
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
CMD_SEND_VEHICLE_TO_DEPOT
@ CMD_SEND_VEHICLE_TO_DEPOT
send a vehicle to a depot
Definition: command_type.h:217
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
Train::crash_anim_pos
uint16 crash_anim_pos
Crash animation counter.
Definition: train.h:91
VehicleListIdentifier::UnpackIfValid
bool UnpackIfValid(uint32 data)
Unpack a VehicleListIdentifier from a single uint32.
Definition: vehiclelist.cpp:38
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:335
CmdBuildRoadVehicle
CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
Build a road vehicle.
Definition: roadveh_cmd.cpp:259
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:902
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
CmdSellVehicle
CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Sell a vehicle.
Definition: vehicle_cmd.cpp:209
GroupStatistics::CountVehicle
static void CountVehicle(const Vehicle *v, int delta)
Update num_vehicle when adding or removing a vehicle.
Definition: group_cmd.cpp:133
ship.h
SaveRandomSeeds
static void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
Definition: random_func.hpp:42
_returned_mail_refit_capacity
uint16 _returned_mail_refit_capacity
Stores the mail capacity after a refit operation (Aircraft only).
Definition: vehicle.cpp:86
group.h
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:544
Vehicle::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:751
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition: economy_type.h:162
autoreplace_gui.h
aircraft.h
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:55
IsUniqueVehicleName
static bool IsUniqueVehicleName(const char *name)
Test if a name is unique among vehicle names.
Definition: vehicle_cmd.cpp:751
GroundVehicle::IsRearDualheaded
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
Definition: ground_vehicle.hpp:334
CCF_REFIT
@ CCF_REFIT
Valid changes for refitting in a depot.
Definition: train.h:51
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:362
Vehicle::GetNextArticulatedPart
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:923
Engine
Definition: engine_base.h:21
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:302
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:444
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:482
OrderList::IsShared
bool IsShared() const
Is this a shared order list?
Definition: order_base.h:331
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:79
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:283
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1188
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
CmdChangeServiceInt
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the service interval of a vehicle.
Definition: vehicle_cmd.cpp:1113
IsLocalCompany
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:43
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
CountArticulatedParts
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
Definition: articulated_vehicles.cpp:73
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
CMD_SELL_VEHICLE
@ CMD_SELL_VEHICLE
sell a vehicle
Definition: command_type.h:215
TERM7
@ TERM7
Heading for terminal 7.
Definition: airport.h:80
RestoreRandomSeeds
static void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
Definition: random_func.hpp:52
IsDepotTile
static bool IsDepotTile(TileIndex tile)
Is the given tile a tile with a depot on it?
Definition: depot_map.h:41
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:904
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:138
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3234
GetRefitCostFactor
static int GetRefitCostFactor(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
Helper to run the refit cost callback.
Definition: vehicle_cmd.cpp:256
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:334
CBID_VEHICLE_REFIT_COST
@ CBID_VEHICLE_REFIT_COST
Called to determine the cost factor for refitting a vehicle.
Definition: newgrf_callbacks.h:275
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:310
EF_AUTO_REFIT
@ EF_AUTO_REFIT
Automatic refitting is allowed.
Definition: engine_type.h:158
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:33
CommandCost
Common return value for all commands.
Definition: command_type.h:23
VAF_HELI_DIRECT_DESCENT
@ VAF_HELI_DIRECT_DESCENT
The helicopter is descending directly at its destination (helipad or in front of hangar)
Definition: aircraft.h:47
cmd_helper.h
VehicleCargoList::Truncate
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
Definition: cargopacket.cpp:654
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:332
GetRefitCost
static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
Learn the price of refitting a certain engine.
Definition: vehicle_cmd.cpp:288
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:240
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:297
CmdDepotSellAllVehicles
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Sells all vehicles in a depot.
Definition: vehicle_cmd.cpp:683
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
do_start
bool do_start
flag for starting playback of next_file at next opportunity
Definition: dmusic.cpp:126
GetFreeUnitNumber
UnitID GetFreeUnitNumber(VehicleType type)
Get an unused unit number for a vehicle (if allowed).
Definition: vehicle.cpp:1785
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:318
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
Vehicle::GetExpenseType
virtual ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: vehicle_base.h:434
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:327
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:895
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
DC_AUTOREPLACE
@ DC_AUTOREPLACE
autoreplace/autorenew is in progress, this shall disable vehicle limits when building,...
Definition: command_type.h:355
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:193
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
Vehicle::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:761
CloneVehicleName
static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
Clone the custom name of a vehicle, adding or incrementing a number.
Definition: vehicle_cmd.cpp:765
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
BuildDepotVehicleList
void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engines, VehicleList *wagons, bool individual_wagons)
Generate a list of vehicles inside a depot.
Definition: vehiclelist.cpp:69
GenerateVehicleSortList
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli)
Generate a list of vehicles based on window type.
Definition: vehiclelist.cpp:113
safeguards.h
GroupStatistics::UpdateAutoreplace
static void UpdateAutoreplace(CompanyID company)
Update autoreplace_defined and autoreplace_finished of all statistics of a company.
Definition: group_cmd.cpp:204
RefitResult::v
Vehicle * v
Vehicle to refit.
Definition: vehicle_cmd.cpp:327
MAKE_ORDER_BACKUP_FLAG
static const uint32 MAKE_ORDER_BACKUP_FLAG
Flag to pass to the vehicle construction command when an order should be preserved.
Definition: order_backup.h:29
OrderBackup::Restore
static void Restore(Vehicle *v, uint32 user)
Restore the data of this order to the given vehicle.
Definition: order_backup.cpp:118
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
DepotCommand
DepotCommand
Flags to add to p1 for goto depot commands.
Definition: vehicle_type.h:65
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:602
IsTileOwner
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
VRF_REVERSE_DIRECTION
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
Definition: train.h:28
newgrf_text.h
RefitVehicle
static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
Refits a vehicle (chain).
Definition: vehicle_cmd.cpp:345
CmdSendVehicleToDepot
CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Send a vehicle to the depot.
Definition: vehicle_cmd.cpp:1047
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:317
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:62
stdafx.h
Vehicle::SendToDepot
CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command)
Send this vehicle to the depot using the given command(s).
Definition: vehicle.cpp:2364
WID_VV_START_STOP
@ WID_VV_START_STOP
Start or stop this vehicle, and show information about the current state.
Definition: vehicle_widget.h:17
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
CmdRefitVehicle
CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Refits a vehicle to the specified cargo type.
Definition: vehicle_cmd.cpp:471
CheckCompanyHasMoney
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
Definition: company_cmd.cpp:195
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:142
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
_returned_refit_capacity
uint _returned_refit_capacity
Stores the capacity after a refit operation.
Definition: vehicle.cpp:85
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:591
Vehicle::list
OrderList * list
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:330
CMD_START_STOP_VEHICLE
@ CMD_START_STOP_VEHICLE
start or stop a vehicle
Definition: command_type.h:315
GetWindowClassForVehicleType
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:91
string_func.h
RefitResult
Helper structure for RefitVehicle()
Definition: vehicle_cmd.cpp:326
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CCF_AUTOREFIT
@ CCF_AUTOREFIT
Valid changes for autorefitting in stations.
Definition: train.h:50
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
DEPOT_SERVICE
@ DEPOT_SERVICE
The vehicle will leave the depot right after arrival (service only)
Definition: vehicle_type.h:66
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:378
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:605
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:316
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:169
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:215
MAX_LENGTH_VEHICLE_NAME_CHARS
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
Definition: vehicle_type.h:73
GroundVehicleCache::cached_power
uint32 cached_power
Total power of the consist (valid only for the first engine).
Definition: ground_vehicle.hpp:38
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:453
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:106
VehicleListIdentifier::vtype
VehicleType vtype
The vehicle type associated with this list.
Definition: vehiclelist.h:31
Vehicle::InvalidateNewGRFCacheOfChain
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition: vehicle_base.h:471
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1152
CmdBuildRailVehicle
CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
Build a railroad vehicle.
Definition: train_cmd.cpp:715
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:3339
CmdStartStopVehicle
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Start/Stop a vehicle.
Definition: vehicle_cmd.cpp:559
CMD_AUTOREPLACE_VEHICLE
@ CMD_AUTOREPLACE_VEHICLE
replace/renew a vehicle while it is in a depot
Definition: command_type.h:317
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
WC_VEHICLE_DEPOT
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
Definition: window_type.h:344
CargoSpec::classes
uint16 classes
Classes of this cargo type.
Definition: cargotype.h:78
Vehicle::orders
union Vehicle::@51 orders
The orders currently assigned to the vehicle.
newgrf.h
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:913
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:127
Pool::PoolItem<&_vehicle_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:299
CmdDepotMassAutoReplace
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Autoreplace all vehicles in the depot.
Definition: vehicle_cmd.cpp:721
CmdMassStartStopVehicle
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Starts or stops a lot of vehicles.
Definition: vehicle_cmd.cpp:643
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:300
depot_map.h
company_func.h
EXPENSES_NEW_VEHICLES
@ EXPENSES_NEW_VEHICLES
New vehicles.
Definition: economy_type.h:159
InvalidateAutoreplaceWindow
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
Definition: autoreplace_gui.cpp:49
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:129
AIR_CTOL
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition: engine_type.h:92
BaseConsist::service_interval
uint16 service_interval
The interval for (automatic) servicing; either in days or %.
Definition: base_consist.h:26
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition: settings_type.h:531
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1619
OrderBackup::Backup
static void Backup(const Vehicle *v, uint32 user)
Create an order backup for the given vehicle.
Definition: order_backup.cpp:100
random_func.hpp
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition: economy_type.h:160
STARTTAKEOFF
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
Definition: airport.h:72
Engine::DetermineCapacity
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
Definition: engine.cpp:202
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Vehicle::IsStoppedInDepot
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition: vehicle_base.h:527
GroundVehicle::CargoChanged
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Definition: ground_vehicle.cpp:79
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:314
Aircraft::state
byte state
State of the airport.
Definition: aircraft.h:79
airport.h
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:558
CMD_BUILD_VEHICLE
@ CMD_BUILD_VEHICLE
build a vehicle
Definition: command_type.h:214
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:315
GroundVehicle::IsFreeWagon
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
Definition: ground_vehicle.hpp:310
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
RefitResult::capacity
uint capacity
New capacity of vehicle.
Definition: vehicle_cmd.cpp:328
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:350
RefitResult::subtype
byte subtype
cargo subtype to refit to
Definition: vehicle_cmd.cpp:330
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:157
order_backup.h
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:68
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:110
CmdBuildAircraft
CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
Build an aircraft.
Definition: aircraft_cmd.cpp:268
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3248
CmdRenameVehicle
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Give a custom name to your vehicle.
Definition: vehicle_cmd.cpp:1072
CmdCloneVehicle
CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clone a vehicle.
Definition: vehicle_cmd.cpp:825
Company::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:122
Aircraft::flags
byte flags
Aircraft flags.
Definition: aircraft.h:83
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1123
GetBestFittingSubType
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
Definition: vehicle_gui.cpp:312
OrderList::GetNumOrders
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
Definition: order_base.h:312
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:163
Vehicle::MarkDirty
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: vehicle_base.h:375
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:40
Vehicle::refit_cap
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:317
engine_func.h
news_func.h
CMD_CLONE_ORDER
@ CMD_CLONE_ORDER
clone (and share) an order
Definition: command_type.h:273
roadveh.h
DEPOT_DONT_CANCEL
@ DEPOT_DONT_CANCEL
Don't cancel current goto depot command if any.
Definition: vehicle_type.h:68
GetDepotVehicleType
static VehicleType GetDepotVehicleType(TileIndex t)
Get the type of vehicles that can use a depot.
Definition: depot_map.h:65
CmdBuildVehicle
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a vehicle.
Definition: vehicle_cmd.cpp:89