* Restore the data of this order to the given vehicle. * @param v The vehicle to restore to. */
| 52 | * @param v The vehicle to restore to. |
| 53 | */ |
| 54 | void 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. |
no test coverage detected