OpenTTD Source: src/vehicle_cmd.cpp Source File

OpenTTD Source 13.1

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 "command_func.h"
15 #include "company_func.h"
16 #include "train.h"
17 #include "aircraft.h"
18 #include "newgrf_text.h"
19 #include "vehicle_func.h"
20 #include "string_func.h"
21 #include "depot_map.h"
22 #include "vehiclelist.h"
23 #include "engine_func.h"
24 #include "articulated_vehicles.h"
25 #include "autoreplace_gui.h"
26 #include "group.h"
27 #include "order_backup.h"
28 #include "ship.h"
29 #include "newgrf.h"
30 #include "company_base.h"
31 #include "core/random_func.hpp"
32 #include "vehicle_cmd.h"
33 #include "aircraft_cmd.h"
34 #include "autoreplace_cmd.h"
35 #include "group_cmd.h"
36 #include "order_cmd.h"
37 #include "roadveh_cmd.h"
38 #include "train_cmd.h"
39 #include "ship_cmd.h"
40 #include <sstream>
41 #include <iomanip>
42
43 #include "table/strings.h"
44
45 #include "safeguards.h"
46
47 /* Tables used in vehicle_func.h to find the right error message for a certain vehicle type */
48 const StringID _veh_build_msg_table[] = {
49 STR_ERROR_CAN_T_BUY_TRAIN,
50 STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
51 STR_ERROR_CAN_T_BUY_SHIP,
52 STR_ERROR_CAN_T_BUY_AIRCRAFT,
53 };
54
55 const StringID _veh_sell_msg_table[] = {
56 STR_ERROR_CAN_T_SELL_TRAIN,
57 STR_ERROR_CAN_T_SELL_ROAD_VEHICLE,
58 STR_ERROR_CAN_T_SELL_SHIP,
59 STR_ERROR_CAN_T_SELL_AIRCRAFT,
60 };
61
62 const StringID _veh_refit_msg_table[] = {
63 STR_ERROR_CAN_T_REFIT_TRAIN,
64 STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE,
65 STR_ERROR_CAN_T_REFIT_SHIP,
66 STR_ERROR_CAN_T_REFIT_AIRCRAFT,
67 };
68
69 const StringID _send_to_depot_msg_table[] = {
70 STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT,
71 STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT,
72 STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT,
73 STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR,
74 };
75
76
87 std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
88 {
89 /* Elementary check for valid location. */
90 if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
91
92 VehicleType type = GetDepotVehicleType(tile);
93
94 /* Validate the engine type. */
95 if (!IsEngineBuildable(eid, type, _current_company)) return { CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type), INVALID_VEHICLE, 0, 0, {} };
96
97 /* Validate the cargo type. */
98 if (cargo >= NUM_CARGO && cargo != CT_INVALID) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
99
100 const Engine *e = Engine::Get(eid);
101 CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
102
103 /* Engines without valid cargo should not be available */
104 CargoID default_cargo = e->GetDefaultCargoType();
105 if (default_cargo == CT_INVALID) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
106
107 bool refitting = cargo != CT_INVALID && cargo != default_cargo;
108
109 /* Check whether the number of vehicles we need to build can be built according to pool space. */
110 uint num_vehicles;
111 switch (type) {
112 case VEH_TRAIN: num_vehicles = (e->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid, false); break;
113 case VEH_ROAD: num_vehicles = 1 + CountArticulatedParts(eid, false); break;
114 case VEH_SHIP: num_vehicles = 1; break;
115 case VEH_AIRCRAFT: num_vehicles = e->u.air.subtype & AIR_CTOL ? 2 : 3; break;
116 default: NOT_REACHED(); // Safe due to IsDepotTile()
117 }
118 if (!Vehicle::CanAllocateItem(num_vehicles)) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), INVALID_VEHICLE, 0, 0, {} };
119
120 /* Check whether we can allocate a unit number. Autoreplace does not allocate
121 * an unit number as it will (always) reuse the one of the replaced vehicle
122 * and (train) wagons don't have an unit number in any scenario. */
123 UnitID unit_num = (flags & DC_QUERY_COST || flags & DC_AUTOREPLACE || (type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type);
124 if (unit_num == UINT16_MAX) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), INVALID_VEHICLE, 0, 0, {} };
125
126 /* If we are refitting we need to temporarily purchase the vehicle to be able to
127 * test it. */
128 DoCommandFlag subflags = flags;
129 if (refitting && !(flags & DC_EXEC)) subflags |= DC_EXEC | DC_AUTOREPLACE;
130
131 /* Vehicle construction needs random bits, so we have to save the random
132 * seeds to prevent desyncs. */
133 SavedRandomSeeds saved_seeds;
134 SaveRandomSeeds(&saved_seeds);
135
136 Vehicle *v = nullptr;
137 switch (type) {
138 case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(subflags, tile, e, use_free_vehicles, &v)); break;
139 case VEH_ROAD: value.AddCost(CmdBuildRoadVehicle(subflags, tile, e, &v)); break;
140 case VEH_SHIP: value.AddCost(CmdBuildShip (subflags, tile, e, &v)); break;
141 case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft (subflags, tile, e, &v)); break;
142 default: NOT_REACHED(); // Safe due to IsDepotTile()
143 }
144
145 VehicleID veh_id = INVALID_VEHICLE;
146 uint refitted_capacity = 0;
147 uint16 refitted_mail_capacity = 0;
148 CargoArray cargo_capacities;
149 if (value.Succeeded()) {
150 if (subflags & DC_EXEC) {
151 v->unitnumber = unit_num;
152 v->value = value.GetCost();
153 veh_id = v->index;
154 }
155
156 if (refitting) {
157 /* Refit only one vehicle. If we purchased an engine, it may have gained free wagons. */
158 CommandCost cc;
159 std::tie(cc, refitted_capacity, refitted_mail_capacity, cargo_capacities) = CmdRefitVehicle(flags, v->index, cargo, 0, false, false, 1);
160 value.AddCost(cc);
161 } else {
162 /* Fill in non-refitted capacities */
163 if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
164 cargo_capacities = GetCapacityOfArticulatedParts(eid);
165 refitted_capacity = cargo_capacities[default_cargo];
166 refitted_mail_capacity = 0;
167 } else {
168 refitted_capacity = e->GetDisplayDefaultCapacity(&refitted_mail_capacity);
169 cargo_capacities.Clear();
170 cargo_capacities[default_cargo] = refitted_capacity;
171 cargo_capacities[CT_MAIL] = refitted_mail_capacity;
172 }
173 }
174
175 if (flags & DC_EXEC) {
176 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
177 InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0);
178 SetWindowDirty(WC_COMPANY, _current_company);
179 if (IsLocalCompany()) {
180 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the auto replace window (must be called before incrementing num_engines)
181 }
182 }
183
184 if (subflags & DC_EXEC) {
185 GroupStatistics::CountEngine(v, 1);
186 GroupStatistics::UpdateAutoreplace(_current_company);
187
188 if (v->IsPrimaryVehicle()) {
189 GroupStatistics::CountVehicle(v, 1);
190 if (!(subflags & DC_AUTOREPLACE)) OrderBackup::Restore(v, client_id);
191 }
192 }
193
194
195 /* If we are not in DC_EXEC undo everything */
196 if (flags != subflags) {
197 Command<CMD_SELL_VEHICLE>::Do(DC_EXEC, v->index, false, false, INVALID_CLIENT_ID);
198 }
199 }
200
201 /* Only restore if we actually did some refitting */
202 if (flags != subflags) RestoreRandomSeeds(saved_seeds);
203
204 return { value, veh_id, refitted_capacity, refitted_mail_capacity, cargo_capacities };
205 }
206
216 CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
217 {
218 Vehicle *v = Vehicle::GetIfValid(v_id);
219 if (v == nullptr) return CMD_ERROR;
220
221 Vehicle *front = v->First();
222
223 CommandCost ret = CheckOwnership(front->owner);
224 if (ret.Failed()) return ret;
225
226 if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
227
228 if (!front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
229
230 /* Can we actually make the order backup, i.e. are there enough orders? */
231 if (backup_order &&
232 front->orders != nullptr &&
233 !front->orders->IsShared() &&
234 !Order::CanAllocateItem(front->orders->GetNumOrders())) {
235 /* Only happens in exceptional cases when there aren't enough orders anyhow.
236 * Thus it should be safe to just drop the orders in that case. */
237 backup_order = false;
238 }
239
240 if (v->type == VEH_TRAIN) {
241 ret = CmdSellRailWagon(flags, v, sell_chain, backup_order, client_id);
242 } else {
243 ret = CommandCost(EXPENSES_NEW_VEHICLES, -front->value);
244
245 if (flags & DC_EXEC) {
246 if (front->IsPrimaryVehicle() && backup_order) OrderBackup::Backup(front, client_id);
247 delete front;
248 }
249 }
250
251 return ret;
252 }
253
263 static int GetRefitCostFactor(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
264 {
265 /* Prepare callback param with info about the new cargo type. */
266 const Engine *e = Engine::Get(engine_type);
267
268 /* Is this vehicle a NewGRF vehicle? */
269 if (e->GetGRF() != nullptr) {
270 const CargoSpec *cs = CargoSpec::Get(new_cid);
271 uint32 param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cid];
272
273 uint16 cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
274 if (cb_res != CALLBACK_FAILED) {
275 *auto_refit_allowed = HasBit(cb_res, 14);
276 int factor = GB(cb_res, 0, 14);
277 if (factor >= 0x2000) factor -= 0x4000; // Treat as signed integer.
278 return factor;
279 }
280 }
281
282 *auto_refit_allowed = e->info.refit_cost == 0;
283 return (v == nullptr || v->cargo_type != new_cid) ? e->info.refit_cost : 0;
284 }
285
295 static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
296 {
297 ExpensesType expense_type;
298 const Engine *e = Engine::Get(engine_type);
299 Price base_price;
300 int cost_factor = GetRefitCostFactor(v, engine_type, new_cid, new_subtype, auto_refit_allowed);
301 switch (e->type) {
302 case VEH_SHIP:
303 base_price = PR_BUILD_VEHICLE_SHIP;
304 expense_type = EXPENSES_SHIP_RUN;
305 break;
306
307 case VEH_ROAD:
308 base_price = PR_BUILD_VEHICLE_ROAD;
309 expense_type = EXPENSES_ROADVEH_RUN;
310 break;
311
312 case VEH_AIRCRAFT:
313 base_price = PR_BUILD_VEHICLE_AIRCRAFT;
314 expense_type = EXPENSES_AIRCRAFT_RUN;
315 break;
316
317 case VEH_TRAIN:
318 base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
319 cost_factor <<= 1;
320 expense_type = EXPENSES_TRAIN_RUN;
321 break;
322
323 default: NOT_REACHED();
324 }
325 if (cost_factor < 0) {
326 return CommandCost(expense_type, -GetPrice(base_price, -cost_factor, e->GetGRF(), -10));
327 } else {
328 return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->GetGRF(), -10));
329 }
330 }
331
333 struct RefitResult {
334 Vehicle *v;
335 uint capacity;
336 uint mail_capacity;
337 byte subtype;
338 };
339
352 static std::tuple<CommandCost, uint, uint16, CargoArray> RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
353 {
354 CommandCost cost(v->GetExpenseType(false));
355 uint total_capacity = 0;
356 uint total_mail_capacity = 0;
357 num_vehicles = num_vehicles == 0 ? UINT8_MAX : num_vehicles;
358 CargoArray cargo_capacities;
359
360 VehicleSet vehicles_to_refit;
361 if (!only_this) {
362 GetVehicleSet(vehicles_to_refit, v, num_vehicles);
363 /* In this case, we need to check the whole chain. */
364 v = v->First();
365 }
366
367 std::vector<RefitResult> refit_result;
368
369 v->InvalidateNewGRFCacheOfChain();
370 byte actual_subtype = new_subtype;
371 for (; v != nullptr; v = (only_this ? nullptr : v->Next())) {
372 /* Reset actual_subtype for every new vehicle */
373 if (!v->IsArticulatedPart()) actual_subtype = new_subtype;
374
375 if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end() && !only_this) continue;
376
377 const Engine *e = v->GetEngine();
378 if (!e->CanCarryCargo()) continue;
379
380 /* If the vehicle is not refittable, or does not allow automatic refitting,
381 * count its capacity nevertheless if the cargo matches */
382 bool refittable = HasBit(e->info.refit_mask, new_cid) && (!auto_refit || HasBit(e->info.misc_flags, EF_AUTO_REFIT));
383 if (!refittable && v->cargo_type != new_cid) {
384 uint amount = e->DetermineCapacity(v, nullptr);
385 if (amount > 0) cargo_capacities[v->cargo_type] += amount;
386 continue;
387 }
388
389 /* Determine best fitting subtype if requested */
390 if (actual_subtype == 0xFF) {
391 actual_subtype = GetBestFittingSubType(v, v, new_cid);
392 }
393
394 /* Back up the vehicle's cargo type */
395 CargoID temp_cid = v->cargo_type;
396 byte temp_subtype = v->cargo_subtype;
397 if (refittable) {
398 v->cargo_type = new_cid;
399 v->cargo_subtype = actual_subtype;
400 }
401
402 uint16 mail_capacity = 0;
403 uint amount = e->DetermineCapacity(v, &mail_capacity);
404 total_capacity += amount;
405 /* mail_capacity will always be zero if the vehicle is not an aircraft. */
406 total_mail_capacity += mail_capacity;
407
408 cargo_capacities[new_cid] += amount;
409 cargo_capacities[CT_MAIL] += mail_capacity;
410
411 if (!refittable) continue;
412
413 /* Restore the original cargo type */
414 v->cargo_type = temp_cid;
415 v->cargo_subtype = temp_subtype;
416
417 bool auto_refit_allowed;
418 CommandCost refit_cost = GetRefitCost(v, v->engine_type, new_cid, actual_subtype, &auto_refit_allowed);
419 if (auto_refit && (flags & DC_QUERY_COST) == 0 && !auto_refit_allowed) {
420 /* Sorry, auto-refitting not allowed, subtract the cargo amount again from the total.
421 * When querrying cost/capacity (for example in order refit GUI), we always assume 'allowed'.
422 * It is not predictable. */
423 total_capacity -= amount;
424 total_mail_capacity -= mail_capacity;
425
426 if (v->cargo_type == new_cid) {
427 /* Add the old capacity nevertheless, if the cargo matches */
428 total_capacity += v->cargo_cap;
429 if (v->type == VEH_AIRCRAFT) total_mail_capacity += v->Next()->cargo_cap;
430 }
431 continue;
432 }
433 cost.AddCost(refit_cost);
434
435 /* Record the refitting.
436 * Do not execute the refitting immediately, so DetermineCapacity and GetRefitCost do the same in test and exec run.
437 * (weird NewGRFs)
438 * Note:
439 * - If the capacity of vehicles depends on other vehicles in the chain, the actual capacity is
440 * set after RefitVehicle() via ConsistChanged() and friends. The estimation via _returned_refit_capacity will be wrong.
441 * - We have to call the refit cost callback with the pre-refit configuration of the chain because we want refit and
442 * autorefit to behave the same, and we need its result for auto_refit_allowed.
443 */
444 refit_result.push_back({v, amount, mail_capacity, actual_subtype});
445 }
446
447 if (flags & DC_EXEC) {
448 /* Store the result */
449 for (RefitResult &result : refit_result) {
450 Vehicle *u = result.v;
451 u->refit_cap = (u->cargo_type == new_cid) ? std::min<uint16>(result.capacity, u->refit_cap) : 0;
452 if (u->cargo.TotalCount() > u->refit_cap) u->cargo.Truncate(u->cargo.TotalCount() - u->refit_cap);
453 u->cargo_type = new_cid;
454 u->cargo_cap = result.capacity;
455 u->cargo_subtype = result.subtype;
456 if (u->type == VEH_AIRCRAFT) {
457 Vehicle *w = u->Next();
458 w->refit_cap = std::min<uint16>(w->refit_cap, result.mail_capacity);
459 w->cargo_cap = result.mail_capacity;
460 if (w->cargo.TotalCount() > w->refit_cap) w->cargo.Truncate(w->cargo.TotalCount() - w->refit_cap);
461 }
462 }
463 }
464
465 refit_result.clear();
466 return { cost, total_capacity, total_mail_capacity, cargo_capacities };
467 }
468
481 std::tuple<CommandCost, uint, uint16, CargoArray> CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8 num_vehicles)
482 {
483 Vehicle *v = Vehicle::GetIfValid(veh_id);
484 if (v == nullptr) return { CMD_ERROR, 0, 0, {} };
485
486 /* Don't allow disasters and sparks and such to be refitted.
487 * We cannot check for IsPrimaryVehicle as autoreplace also refits in free wagon chains. */
488 if (!IsCompanyBuildableVehicleType(v->type)) return { CMD_ERROR, 0, 0, {} };
489
490 Vehicle *front = v->First();
491
492 CommandCost ret = CheckOwnership(front->owner);
493 if (ret.Failed()) return { ret, 0, 0, {} };
494
495 bool free_wagon = v->type == VEH_TRAIN && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew
496
497 /* Don't allow shadows and such to be refitted. */
498 if (v != front && (v->type == VEH_SHIP || v->type == VEH_AIRCRAFT)) return { CMD_ERROR, 0, 0, {} };
499
500 /* Allow auto-refitting only during loading and normal refitting only in a depot. */
501 if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
502 !free_wagon && // used by autoreplace/renew
503 (!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
504 !front->IsStoppedInDepot()) { // refit inside depots
505 return { CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type), 0, 0, {} };
506 }
507
508 if (front->vehstatus & VS_CRASHED) return { CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED), 0, 0, {} };
509
510 /* Check cargo */
511 if (new_cid >= NUM_CARGO) return { CMD_ERROR, 0, 0, {} };
512
513 /* For ships and aircraft there is always only one. */
514 only_this |= front->type == VEH_SHIP || front->type == VEH_AIRCRAFT;
515
516 auto [cost, refit_capacity, mail_capacity, cargo_capacities] = RefitVehicle(v, only_this, num_vehicles, new_cid, new_subtype, flags, auto_refit);
517
518 if (flags & DC_EXEC) {
519 /* Update the cached variables */
520 switch (v->type) {
521 case VEH_TRAIN:
522 Train::From(front)->ConsistChanged(auto_refit ? CCF_AUTOREFIT : CCF_REFIT);
523 break;
524 case VEH_ROAD:
525 RoadVehUpdateCache(RoadVehicle::From(front), auto_refit);
526 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) RoadVehicle::From(front)->CargoChanged();
527 break;
528
529 case VEH_SHIP:
530 v->InvalidateNewGRFCacheOfChain();
531 Ship::From(v)->UpdateCache();
532 break;
533
534 case VEH_AIRCRAFT:
535 v->InvalidateNewGRFCacheOfChain();
536 UpdateAircraftCache(Aircraft::From(v), true);
537 break;
538
539 default: NOT_REACHED();
540 }
541 front->MarkDirty();
542
543 if (!free_wagon) {
544 InvalidateWindowData(WC_VEHICLE_DETAILS, front->index);
545 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
546 }
547 SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
548 } else {
549 /* Always invalidate the cache; querycost might have filled it. */
550 v->InvalidateNewGRFCacheOfChain();
551 }
552
553 return { cost, refit_capacity, mail_capacity, cargo_capacities };
554 }
555
563 CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool evaluate_startstop_cb)
564 {
565 /* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
566 if ((flags & DC_AUTOREPLACE) == 0) evaluate_startstop_cb = true;
567
568 Vehicle *v = Vehicle::GetIfValid(veh_id);
569 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
570
571 CommandCost ret = CheckOwnership(v->owner);
572 if (ret.Failed()) return ret;
573
574 if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
575
576 switch (v->type) {
577 case VEH_TRAIN:
578 if ((v->vehstatus & VS_STOPPED) && Train::From(v)->gcache.cached_power == 0) return_cmd_error(STR_ERROR_TRAIN_START_NO_POWER);
579 break;
580
581 case VEH_SHIP:
582 case VEH_ROAD:
583 break;
584
585 case VEH_AIRCRAFT: {
586 Aircraft *a = Aircraft::From(v);
587 /* cannot stop airplane when in flight, or when taking off / landing */
588 if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
589 if (HasBit(a->flags, VAF_HELI_DIRECT_DESCENT)) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
590 break;
591 }
592
593 default: return CMD_ERROR;
594 }
595
596 if (evaluate_startstop_cb) {
597 /* Check if this vehicle can be started/stopped. Failure means 'allow'. */
598 uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
599 StringID error = STR_NULL;
600 if (callback != CALLBACK_FAILED) {
601 if (v->GetGRF()->grf_version < 8) {
602 /* 8 bit result 0xFF means 'allow' */
603 if (callback < 0x400 && GB(callback, 0, 8) != 0xFF) error = GetGRFStringID(v->GetGRFID(), 0xD000 + callback);
604 } else {
605 if (callback < 0x400) {
606 error = GetGRFStringID(v->GetGRFID(), 0xD000 + callback);
607 } else {
608 switch (callback) {
609 case 0x400: // allow
610 break;
611
612 default: // unknown reason -> disallow
613 error = STR_ERROR_INCOMPATIBLE_RAIL_TYPES;
614 break;
615 }
616 }
617 }
618 }
619 if (error != STR_NULL) return_cmd_error(error);
620 }
621
622 if (flags & DC_EXEC) {
623 if (v->IsStoppedInDepot() && (flags & DC_AUTOREPLACE) == 0) DeleteVehicleNews(veh_id, STR_NEWS_TRAIN_IS_WAITING + v->type);
624
625 v->vehstatus ^= VS_STOPPED;
626 if (v->type != VEH_TRAIN) v->cur_speed = 0; // trains can stop 'slowly'
627 v->MarkDirty();
628 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
629 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
630 SetWindowClassesDirty(GetWindowClassForVehicleType(v->type));
631 InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
632 }
633 return CommandCost();
634 }
635
645 CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
646 {
647 VehicleList list;
648
649 if (!vli.Valid()) return CMD_ERROR;
650 if (!IsCompanyBuildableVehicleType(vli.vtype)) return CMD_ERROR;
651
652 if (vehicle_list_window) {
653 if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
654 } else {
655 if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
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 Command<CMD_START_STOP_VEHICLE>::Do(flags, v->index, false);
669 }
670
671 return CommandCost();
672 }
673
681 CommandCost CmdDepotSellAllVehicles(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
682 {
683 VehicleList list;
684
685 CommandCost cost(EXPENSES_NEW_VEHICLES);
686
687 if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
688 if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
689
690 /* Get the list of vehicles in the depot */
691 BuildDepotVehicleList(vehicle_type, tile, &list, &list);
692
693 CommandCost last_error = CMD_ERROR;
694 bool had_success = false;
695 for (uint i = 0; i < list.size(); i++) {
696 CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, list[i]->index, true, false, INVALID_CLIENT_ID);
697 if (ret.Succeeded()) {
698 cost.AddCost(ret);
699 had_success = true;
700 } else {
701 last_error = ret;
702 }
703 }
704
705 return had_success ? cost : last_error;
706 }
707
715 CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
716 {
717 VehicleList list;
718 CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
719
720 if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
721 if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
722
723 /* Get the list of vehicles in the depot */
724 BuildDepotVehicleList(vehicle_type, tile, &list, &list, true);
725
726 for (uint i = 0; i < list.size(); i++) {
727 const Vehicle *v = list[i];
728
729 /* Ensure that the vehicle completely in the depot */
730 if (!v->IsChainInDepot()) continue;
731
732 CommandCost ret = Command<CMD_AUTOREPLACE_VEHICLE>::Do(flags, v->index);
733
734 if (ret.Succeeded()) cost.AddCost(ret);
735 }
736 return cost;
737 }
738
744 static bool IsUniqueVehicleName(const std::string &name)
745 {
746 for (const Vehicle *v : Vehicle::Iterate()) {
747 if (!v->name.empty() && v->name == name) return false;
748 }
749
750 return true;
751 }
752
758 static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
759 {
760 std::string buf;
761
762 /* Find the position of the first digit in the last group of digits. */
763 size_t number_position;
764 for (number_position = src->name.length(); number_position > 0; number_position--) {
765 /* The design of UTF-8 lets this work simply without having to check
766 * for UTF-8 sequences. */
767 if (src->name[number_position - 1] < '0' || src->name[number_position - 1] > '9') break;
768 }
769
770 /* Format buffer and determine starting number. */
771 long num;
772 byte padding = 0;
773 if (number_position == src->name.length()) {
774 /* No digit at the end, so start at number 2. */
775 buf = src->name;
776 buf += " ";
777 number_position = buf.length();
778 num = 2;
779 } else {
780 /* Found digits, parse them and start at the next number. */
781 buf = src->name.substr(0, number_position);
782
783 auto num_str = src->name.substr(number_position);
784 padding = (byte)num_str.length();
785
786 std::istringstream iss(num_str);
787 iss >> num;
788 num++;
789 }
790
791 /* Check if this name is already taken. */
792 for (int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) {
793 std::ostringstream oss;
794
795 /* Attach the number to the temporary name. */
796 oss << buf << std::setw(padding) << std::setfill('0') << std::internal << num;
797
798 /* Check the name is unique. */
799 auto new_name = oss.str();
800 if (IsUniqueVehicleName(new_name)) {
801 dst->name = new_name;
802 break;
803 }
804 }
805
806 /* All done. If we didn't find a name, it'll just use its default. */
807 }
808
817 std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders)
818 {
819 CommandCost total_cost(EXPENSES_NEW_VEHICLES);
820
821 Vehicle *v = Vehicle::GetIfValid(veh_id);
822 if (v == nullptr || !v->IsPrimaryVehicle()) return { CMD_ERROR, INVALID_VEHICLE };
823 Vehicle *v_front = v;
824 Vehicle *w = nullptr;
825 Vehicle *w_front = nullptr;
826 Vehicle *w_rear = nullptr;
827
828 /*
829 * v_front is the front engine in the original vehicle
830 * v is the car/vehicle of the original vehicle that is currently being copied
831 * w_front is the front engine of the cloned vehicle
832 * w is the car/vehicle currently being cloned
833 * w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
834 */
835
836 CommandCost ret = CheckOwnership(v->owner);
837 if (ret.Failed()) return { ret, INVALID_VEHICLE };
838
839 if (v->type == VEH_TRAIN && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return { CMD_ERROR, INVALID_VEHICLE };
840
841 /* check that we can allocate enough vehicles */
842 if (!(flags & DC_EXEC)) {
843 int veh_counter = 0;
844 do {
845 veh_counter++;
846 } while ((v = v->Next()) != nullptr);
847
848 if (!Vehicle::CanAllocateItem(veh_counter)) {
849 return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), INVALID_VEHICLE };
850 }
851 }
852
853 v = v_front;
854
855 VehicleID new_veh_id = INVALID_VEHICLE;
856 do {
857 if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) {
858 /* we build the rear ends of multiheaded trains with the front ones */
859 continue;
860 }
861
862 /* In case we're building a multi headed vehicle and the maximum number of
863 * vehicles is almost reached (e.g. max trains - 1) not all vehicles would
864 * be cloned. When the non-primary engines were build they were seen as
865 * 'new' vehicles whereas they would immediately be joined with a primary
866 * engine. This caused the vehicle to be not build as 'the limit' had been
867 * reached, resulting in partially build vehicles and such. */
868 DoCommandFlag build_flags = flags;
869 if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
870
871 CommandCost cost;
872 std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(build_flags, tile, v->engine_type, false, CT_INVALID, INVALID_CLIENT_ID);
873
874 if (cost.Failed()) {
875 /* Can't build a part, then sell the stuff we already made; clear up the mess */
876 if (w_front != nullptr) Command<CMD_SELL_VEHICLE>::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID);
877 return { cost, INVALID_VEHICLE };
878 }
879
880 total_cost.AddCost(cost);
881
882 if (flags & DC_EXEC) {
883 w = Vehicle::Get(new_veh_id);
884
885 if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
886 SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION);
887 }
888
889 if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
890 /* this s a train car
891 * add this unit to the end of the train */
892 CommandCost result = Command<CMD_MOVE_RAIL_VEHICLE>::Do(flags, w->index, w_rear->index, true);
893 if (result.Failed()) {
894 /* The train can't be joined to make the same consist as the original.
895 * Sell what we already made (clean up) and return an error. */
896 Command<CMD_SELL_VEHICLE>::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID);
897 Command<CMD_SELL_VEHICLE>::Do(flags, w->index, true, false, INVALID_CLIENT_ID);
898 return { result, INVALID_VEHICLE }; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
899 }
900 } else {
901 /* this is a front engine or not a train. */
902 w_front = w;
903 w->service_interval = v->service_interval;
904 w->SetServiceIntervalIsCustom(v->ServiceIntervalIsCustom());
905 w->SetServiceIntervalIsPercent(v->ServiceIntervalIsPercent());
906 }
907 w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
908 }
909 } while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != nullptr);
910
911 if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) {
912 /* for trains this needs to be the front engine due to the callback function */
913 new_veh_id = w_front->index;
914 }
915
916 if (flags & DC_EXEC) {
917 /* Cloned vehicles belong to the same group */
918 Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, v_front->group_id, w_front->index, false);
919 }
920
921
922 /* Take care of refitting. */
923 w = w_front;
924 v = v_front;
925
926 /* Both building and refitting are influenced by newgrf callbacks, which
927 * makes it impossible to accurately estimate the cloning costs. In
928 * particular, it is possible for engines of the same type to be built with
929 * different numbers of articulated parts, so when refitting we have to
930 * loop over real vehicles first, and then the articulated parts of those
931 * vehicles in a different loop. */
932 do {
933 do {
934 if (flags & DC_EXEC) {
935 assert(w != nullptr);
936
937 /* Find out what's the best sub type */
938 byte subtype = GetBestFittingSubType(v, w, v->cargo_type);
939 if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
940 CommandCost cost = std::get<0>(Command<CMD_REFIT_VEHICLE>::Do(flags, w->index, v->cargo_type, subtype, false, true, 0));
941 if (cost.Succeeded()) total_cost.AddCost(cost);
942 }
943
944 if (w->IsGroundVehicle() && w->HasArticulatedPart()) {
945 w = w->GetNextArticulatedPart();
946 } else {
947 break;
948 }
949 } else {
950 const Engine *e = v->GetEngine();
951 CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
952
953 if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) {
954 bool dummy;
955 total_cost.AddCost(GetRefitCost(nullptr, v->engine_type, v->cargo_type, v->cargo_subtype, &dummy));
956 }
957 }
958
959 if (v->IsGroundVehicle() && v->HasArticulatedPart()) {
960 v = v->GetNextArticulatedPart();
961 } else {
962 break;
963 }
964 } while (v != nullptr);
965
966 if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = w->GetNextVehicle();
967 } while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != nullptr);
968
969 if (flags & DC_EXEC) {
970 /*
971 * Set the orders of the vehicle. Cannot do it earlier as we need
972 * the vehicle refitted before doing this, otherwise the moved
973 * cargo types might not match (passenger vs non-passenger)
974 */
975 CommandCost result = Command<CMD_CLONE_ORDER>::Do(flags, (share_orders ? CO_SHARE : CO_COPY), w_front->index, v_front->index);
976 if (result.Failed()) {
977 /* The vehicle has already been bought, so now it must be sold again. */
978 Command<CMD_SELL_VEHICLE>::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID);
979 return { result, INVALID_VEHICLE };
980 }
981
982 /* Now clone the vehicle's name, if it has one. */
983 if (!v_front->name.empty()) CloneVehicleName(v_front, w_front);
984
985 /* Since we can't estimate the cost of cloning a vehicle accurately we must
986 * check whether the company has enough money manually. */
987 if (!CheckCompanyHasMoney(total_cost)) {
988 /* The vehicle has already been bought, so now it must be sold again. */
989 Command<CMD_SELL_VEHICLE>::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID);
990 return { total_cost, INVALID_VEHICLE };
991 }
992 }
993
994 return { total_cost, new_veh_id };
995 }
996
1004 static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, const VehicleListIdentifier &vli)
1005 {
1006 VehicleList list;
1007
1008 if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
1009
1010 /* Send all the vehicles to a depot */
1011 bool had_success = false;
1012 for (uint i = 0; i < list.size(); i++) {
1013 const Vehicle *v = list[i];
1014 CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(flags, v->index, (service ? DepotCommand::Service : DepotCommand::None) | DepotCommand::DontCancel, {});
1015
1016 if (ret.Succeeded()) {
1017 had_success = true;
1018
1019 /* Return 0 if DC_EXEC is not set this is a valid goto depot command)
1020 * In this case we know that at least one vehicle can be sent to a depot
1021 * and we will issue the command. We can now safely quit the loop, knowing
1022 * it will succeed at least once. With DC_EXEC we really need to send them to the depot */
1023 if (!(flags & DC_EXEC)) break;
1024 }
1025 }
1026
1027 return had_success ? CommandCost() : CMD_ERROR;
1028 }
1029
1038 CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli)
1039 {
1040 if ((depot_cmd & DepotCommand::MassSend) != DepotCommand::None) {
1041 /* Mass goto depot requested */
1042 if (!vli.Valid()) return CMD_ERROR;
1043 return SendAllVehiclesToDepot(flags, (depot_cmd & DepotCommand::Service) != DepotCommand::None, vli);
1044 }
1045
1046 Vehicle *v = Vehicle::GetIfValid(veh_id);
1047 if (v == nullptr) return CMD_ERROR;
1048 if (!v->IsPrimaryVehicle()) return CMD_ERROR;
1049
1050 return v->SendToDepot(flags, depot_cmd);
1051 }
1052
1060 CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text)
1061 {
1062 Vehicle *v = Vehicle::GetIfValid(veh_id);
1063 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1064
1065 CommandCost ret = CheckOwnership(v->owner);
1066 if (ret.Failed()) return ret;
1067
1068 bool reset = text.empty();
1069
1070 if (!reset) {
1071 if (Utf8StringLength(text) >= MAX_LENGTH_VEHICLE_NAME_CHARS) return CMD_ERROR;
1072 if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1073 }
1074
1075 if (flags & DC_EXEC) {
1076 if (reset) {
1077 v->name.clear();
1078 } else {
1079 v->name = text;
1080 }
1081 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 1);
1082 MarkWholeScreenDirty();
1083 }
1084
1085 return CommandCost();
1086 }
1087
1088
1098 CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16 serv_int, bool is_custom, bool is_percent)
1099 {
1100 Vehicle *v = Vehicle::GetIfValid(veh_id);
1101 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1102
1103 CommandCost ret = CheckOwnership(v->owner);
1104 if (ret.Failed()) return ret;
1105
1106 const Company *company = Company::Get(v->owner);
1107 is_percent = is_custom ? is_percent : company->settings.vehicle.servint_ispercent;
1108
1109 if (is_custom) {
1110 if (serv_int != GetServiceIntervalClamped(serv_int, is_percent)) return CMD_ERROR;
1111 } else {
1112 serv_int = CompanyServiceInterval(company, v->type);
1113 }
1114
1115 if (flags & DC_EXEC) {
1116 v->SetServiceInterval(serv_int);
1117 v->SetServiceIntervalIsCustom(is_custom);
1118 v->SetServiceIntervalIsPercent(is_percent);
1119 SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
1120 }
1121
1122 return CommandCost();
1123 }
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:361
Vehicle::IsChainInDepot
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:537
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:115
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
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:3252
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:336
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
order_cmd.h
VehicleList
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition: vehiclelist.h:55
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3154
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:48
GetServiceIntervalClamped
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1878
GroupStatistics::CountEngine
static void CountEngine(const Vehicle *v, int delta)
Update num_engines when adding/removing an engine.
Definition: group_cmd.cpp:157
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
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:256
train.h
AircraftVehicleInfo::subtype
byte subtype
Type of aircraft.
Definition: engine_type.h:103
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:348
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
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:984
CmdRenameVehicle
CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text)
Give a custom name to your vehicle.
Definition: vehicle_cmd.cpp:1060
company_base.h
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:610
SendAllVehiclesToDepot
static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, const VehicleListIdentifier &vli)
Send all vehicles of type to depots.
Definition: vehicle_cmd.cpp:1004
UnitID
uint16 UnitID
Type for the company global vehicle unit number.
Definition: transport_type.h:16
CmdMassStartStopVehicle
CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
Starts or stops a lot of vehicles.
Definition: vehicle_cmd.cpp:645
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:74
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition: articulated_vehicles.cpp:139
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:2969
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
BaseConsist::name
std::string name
Name of vehicle.
Definition: base_consist.h:19
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:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
Train::crash_anim_pos
uint16 crash_anim_pos
Crash animation counter.
Definition: train.h:94
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:341
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:919
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
GroupStatistics::CountVehicle
static void CountVehicle(const Vehicle *v, int delta)
Update num_vehicle when adding or removing a vehicle.
Definition: group_cmd.cpp:132
ship.h
SaveRandomSeeds
static void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
Definition: random_func.hpp:42
group.h
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:581
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
CmdBuildShip
CommandCost CmdBuildShip(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build a ship.
Definition: ship_cmd.cpp:855
CmdRefitVehicle
std::tuple< CommandCost, uint, uint16, CargoArray > CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8 num_vehicles)
Refits a vehicle to the specified cargo type.
Definition: vehicle_cmd.cpp:481
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
CmdDepotMassAutoReplace
CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
Autoreplace all vehicles in the depot.
Definition: vehicle_cmd.cpp:715
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
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:941
Engine
Definition: engine_base.h:36
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:307
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:460
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:498
OrderList::IsShared
bool IsShared() const
Is this a shared order list?
Definition: order_base.h:341
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:95
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:288
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
aircraft_cmd.h
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:355
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:151
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
CargoArray::Clear
void Clear()
Reset all entries.
Definition: cargo_type.h:94
train_cmd.h
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:922
DepotCommand::Service
@ Service
The vehicle will leave the depot right after arrival (service only)
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:203
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:154
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:3167
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:263
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
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
DepotCommand
DepotCommand
Flags for goto depot commands.
Definition: vehicle_type.h:65
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:316
EF_AUTO_REFIT
@ EF_AUTO_REFIT
Automatic refitting is allowed.
Definition: engine_type.h:171
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
ship_cmd.h
CommandCost
Common return value for all commands.
Definition: command_type.h:24
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
CmdBuildRailVehicle
CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engine *e, bool free_cars, Vehicle **ret)
Build a railroad vehicle.
Definition: train_cmd.cpp:742
CmdDepotSellAllVehicles
CommandCost CmdDepotSellAllVehicles(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
Sells all vehicles in a depot.
Definition: vehicle_cmd.cpp:681
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:295
CmdBuildVehicle
std::tuple< CommandCost, VehicleID, uint, uint16, CargoArray > CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
Build a vehicle.
Definition: vehicle_cmd.cpp:87
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
DepotCommand::MassSend
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag)
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:302
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:41
do_start
bool do_start
flag for starting playback of next_file at next opportunity
Definition: dmusic.cpp:126
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:47
GetFreeUnitNumber
UnitID GetFreeUnitNumber(VehicleType type)
Get an unused unit number for a vehicle (if allowed).
Definition: vehicle.cpp:1806
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:324
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
Vehicle::GetExpenseType
virtual ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: vehicle_base.h:449
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:333
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
autoreplace_cmd.h
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:913
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:106
DC_AUTOREPLACE
@ DC_AUTOREPLACE
autoreplace/autorenew is in progress, this shall disable vehicle limits when building,...
Definition: command_type.h:364
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:35
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:758
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:220
RefitResult::v
Vehicle * v
Vehicle to refit.
Definition: vehicle_cmd.cpp:334
vehicle_cmd.h
OrderBackup::Restore
static void Restore(Vehicle *v, uint32 user)
Restore the data of this order to the given vehicle.
Definition: order_backup.cpp:120
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:601
IsTileOwner
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
VRF_REVERSE_DIRECTION
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
Definition: train.h:28
newgrf_text.h
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:312
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
stdafx.h
Vehicle::SendToDepot
CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command)
Send this vehicle to the depot using the given command(s).
Definition: vehicle.cpp:2387
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
CheckCompanyHasMoney
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
Definition: company_cmd.cpp:200
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:153
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:590
group_cmd.h
CmdChangeServiceInt
CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16 serv_int, bool is_custom, bool is_percent)
Change the service interval of a vehicle.
Definition: vehicle_cmd.cpp:1098
GetWindowClassForVehicleType
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:96
string_func.h
RefitResult
Helper structure for RefitVehicle()
Definition: vehicle_cmd.cpp:333
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
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
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
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:623
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:322
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:164
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:217
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:74
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:1183
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:490
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:108
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:487
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1137
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:3269
CmdSendVehicleToDepot
CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli)
Send a vehicle to the depot.
Definition: vehicle_cmd.cpp:1038
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
RefitVehicle
static std::tuple< CommandCost, uint, uint16, CargoArray > 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:352
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:79
newgrf.h
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:931
CmdSellVehicle
CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
Sell a vehicle.
Definition: vehicle_cmd.cpp:216
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:128
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:307
DepotCommand::DontCancel
@ DontCancel
Don't cancel current goto depot command if any.
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:305
depot_map.h
CmdStartStopVehicle
CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool evaluate_startstop_cb)
Start/Stop a vehicle.
Definition: vehicle_cmd.cpp:563
company_func.h
IsUniqueVehicleName
static bool IsUniqueVehicleName(const std::string &name)
Test if a name is unique among vehicle names.
Definition: vehicle_cmd.cpp:744
EXPENSES_NEW_VEHICLES
@ EXPENSES_NEW_VEHICLES
New vehicles.
Definition: economy_type.h:159
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
InvalidateAutoreplaceWindow
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
Definition: autoreplace_gui.cpp:52
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:134
AIR_CTOL
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition: engine_type.h:94
CommandHelper
Definition: command_func.h:94
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:568
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:1767
OrderBackup::Backup
static void Backup(const Vehicle *v, uint32 user)
Create an order backup for the given vehicle.
Definition: order_backup.cpp:102
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:197
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:543
CmdBuildRoadVehicle
CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build a road vehicle.
Definition: roadveh_cmd.cpp:260
GroundVehicle::CargoChanged
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Definition: ground_vehicle.cpp:79
CmdSellRailWagon
CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, bool sell_chain, bool backup_order, ClientID user)
Sell a (single) train wagon/engine.
Definition: train_cmd.cpp:1377
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:320
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:595
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:321
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:335
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:359
RefitResult::subtype
byte subtype
cargo subtype to refit to
Definition: vehicle_cmd.cpp:337
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:157
order_backup.h
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:117
CmdCloneVehicle
std::tuple< CommandCost, VehicleID > CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders)
Clone a vehicle.
Definition: vehicle_cmd.cpp:817
DepotCommand::None
@ None
No special flags.
Vehicle::orders
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:336
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3180
Aircraft::flags
byte flags
Aircraft flags.
Definition: aircraft.h:83
roadveh_cmd.h
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1168
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:439
OrderList::GetNumOrders
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
Definition: order_base.h:322
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:163
CmdBuildAircraft
CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build an aircraft.
Definition: aircraft_cmd.cpp:269
Vehicle::MarkDirty
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: vehicle_base.h:390
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:55
Vehicle::refit_cap
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:323
engine_func.h
news_func.h
roadveh.h
GetDepotVehicleType
static VehicleType GetDepotVehicleType(TileIndex t)
Get the type of vehicles that can use a depot.
Definition: depot_map.h:65