MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DoRestore

Method DoRestore

src/order_backup.cpp:54–76  ·  view source on GitHub ↗

* Restore the data of this order to the given vehicle. * @param v The vehicle to restore to. */

Source from the content-addressed store, hash-verified

52 * @param v The vehicle to restore to.
53 */
54void OrderBackup::DoRestore(Vehicle *v)
55{
56 /* If we had shared orders, recover that */
57 if (this->clone != nullptr) {
58 Command<CMD_CLONE_ORDER>::Do(DoCommandFlag::Execute, CO_SHARE, v->index, this->clone->index);
59 } else if (!this->orders.empty() && OrderList::CanAllocateItem()) {
60 v->orders = new OrderList(std::move(this->orders), v);
61 /* Make sure buoys/oil rigs are updated in the station list. */
62 InvalidateWindowClassesData(WC_STATION_LIST, 0);
63 }
64
65 /* Remove backed up name if it's no longer unique. */
66 if (!IsUniqueVehicleName(this->name)) this->name.clear();
67
68 v->CopyConsistPropertiesFrom(this);
69
70 /* Make sure orders are in range */
71 v->UpdateRealOrderIndex();
72 if (v->cur_implicit_order_index >= v->GetNumOrders()) v->cur_implicit_order_index = v->cur_real_order_index;
73
74 /* Restore vehicle group */
75 Command<CMD_ADD_VEHICLE_GROUP>::Do(DoCommandFlag::Execute, this->group, v->index, false, VehicleListIdentifier{});
76}
77
78/**
79 * Create an order backup for the given vehicle.

Callers 1

RestoreMethod · 0.80

Calls 7

IsUniqueVehicleNameFunction · 0.85
UpdateRealOrderIndexMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45
GetNumOrdersMethod · 0.45

Tested by

no test coverage detected