1
0
Fork 0

Codechange: Use anonymous union for vehicle orders/old orders list

pull/9818/head
Niels Martin Hansen 2022-02-12 19:28:34 +01:00
parent 41c40f130b
commit e68bf58989
17 changed files with 99 additions and 99 deletions

View File

@ -211,7 +211,7 @@ static int GetIncompatibleRefitOrderIdForAutoreplace(const Vehicle *v, EngineID
const Order *o; const Order *o;
const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v; const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v;
const OrderList *orders = u->orders.list; const OrderList *orders = u->orders;
if (orders == nullptr) return -1; if (orders == nullptr) return -1;
for (VehicleOrderID i = 0; i < orders->GetNumOrders(); i++) { for (VehicleOrderID i = 0; i < orders->GetNumOrders(); i++) {
o = orders->GetOrderAt(i); o = orders->GetOrderAt(i);

View File

@ -1268,7 +1268,7 @@ void PrepareUnload(Vehicle *front_v)
front_v->cargo_payment = new CargoPayment(front_v); front_v->cargo_payment = new CargoPayment(front_v);
StationIDStack next_station = front_v->GetNextStoppingStation(); StationIDStack next_station = front_v->GetNextStoppingStation();
if (front_v->orders.list == nullptr || (front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { if (front_v->orders == nullptr || (front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
Station *st = Station::Get(front_v->last_station_visited); Station *st = Station::Get(front_v->last_station_visited);
for (Vehicle *v = front_v; v != nullptr; v = v->Next()) { for (Vehicle *v = front_v; v != nullptr; v = v->Next()) {
const GoodsEntry *ge = &st->goods[v->cargo_type]; const GoodsEntry *ge = &st->goods[v->cargo_type];

View File

@ -26,10 +26,10 @@
/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading) /* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading)
{ {
/* If there are no orders we can't predict anything.*/ /* If there are no orders we can't predict anything.*/
if (v->orders.list == nullptr) return; if (v->orders == nullptr) return;
/* Make sure the first order is a useful order. */ /* Make sure the first order is a useful order. */
const Order *first = v->orders.list->GetNextDecisionNode(v->GetOrder(v->cur_implicit_order_index), 0); const Order *first = v->orders->GetNextDecisionNode(v->GetOrder(v->cur_implicit_order_index), 0);
if (first == nullptr) return; if (first == nullptr) return;
HopSet seen_hops; HopSet seen_hops;
@ -173,9 +173,9 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next
SetBit(flags, USE_NEXT); SetBit(flags, USE_NEXT);
if (next->IsType(OT_CONDITIONAL)) { if (next->IsType(OT_CONDITIONAL)) {
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode( const Order *skip_to = this->vehicle->orders->GetNextDecisionNode(
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops); this->vehicle->orders->GetOrderAt(next->GetConditionSkipToOrder()), num_hops);
if (skip_to != nullptr && num_hops < this->vehicle->orders.list->GetNumOrders()) { if (skip_to != nullptr && num_hops < this->vehicle->orders->GetNumOrders()) {
/* Make copies of capacity tracking lists. There is potential /* Make copies of capacity tracking lists. There is potential
* for optimization here: If the vehicle never refits we don't * for optimization here: If the vehicle never refits we don't
* need to copy anything. Also, if we've seen the branched link * need to copy anything. Also, if we've seen the branched link
@ -187,8 +187,8 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next
/* Reassign next with the following stop. This can be a station or a /* Reassign next with the following stop. This can be a station or a
* depot.*/ * depot.*/
next = this->vehicle->orders.list->GetNextDecisionNode( next = this->vehicle->orders->GetNextDecisionNode(
this->vehicle->orders.list->GetNext(next), num_hops++); this->vehicle->orders->GetNext(next), num_hops++);
} }
return next; return next;
} }
@ -230,16 +230,16 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
* loading. Don't do that if the vehicle has been waiting for longer than the entire * loading. Don't do that if the vehicle has been waiting for longer than the entire
* order list is supposed to take, though. If that is the case the total duration is * order list is supposed to take, though. If that is the case the total duration is
* probably far off and we'd greatly overestimate the capacity by increasing.*/ * probably far off and we'd greatly overestimate the capacity by increasing.*/
if (this->is_full_loading && this->vehicle->orders.list != nullptr && if (this->is_full_loading && this->vehicle->orders != nullptr &&
st->index == vehicle->last_station_visited && st->index == vehicle->last_station_visited &&
this->vehicle->orders.list->GetTotalDuration() > this->vehicle->orders->GetTotalDuration() >
(Ticks)this->vehicle->current_order_time) { (Ticks)this->vehicle->current_order_time) {
uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks; uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
if (effective_capacity > (uint)this->vehicle->orders.list->GetTotalDuration()) { if (effective_capacity > (uint)this->vehicle->orders->GetTotalDuration()) {
IncreaseStats(st, c, next_station, effective_capacity / IncreaseStats(st, c, next_station, effective_capacity /
this->vehicle->orders.list->GetTotalDuration(), 0, 0, this->vehicle->orders->GetTotalDuration(), 0, 0,
EUM_INCREASE | restricted_mode); EUM_INCREASE | restricted_mode);
} else if (RandomRange(this->vehicle->orders.list->GetTotalDuration()) < effective_capacity) { } else if (RandomRange(this->vehicle->orders->GetTotalDuration()) < effective_capacity) {
IncreaseStats(st, c, next_station, 1, 0, 0, EUM_INCREASE | restricted_mode); IncreaseStats(st, c, next_station, 1, 0, 0, EUM_INCREASE | restricted_mode);
} else { } else {
IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode); IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode);

View File

@ -77,7 +77,7 @@ void OrderBackup::DoRestore(Vehicle *v)
if (this->clone != nullptr) { if (this->clone != nullptr) {
Command<CMD_CLONE_ORDER>::Do(DC_EXEC, CO_SHARE, v->index, this->clone->index); Command<CMD_CLONE_ORDER>::Do(DC_EXEC, CO_SHARE, v->index, this->clone->index);
} else if (this->orders != nullptr && OrderList::CanAllocateItem()) { } else if (this->orders != nullptr && OrderList::CanAllocateItem()) {
v->orders.list = new OrderList(this->orders, v); v->orders = new OrderList(this->orders, v);
this->orders = nullptr; this->orders = nullptr;
/* Make sure buoys/oil rigs are updated in the station list. */ /* Make sure buoys/oil rigs are updated in the station list. */
InvalidateWindowClassesData(WC_STATION_LIST, 0); InvalidateWindowClassesData(WC_STATION_LIST, 0);

View File

@ -637,7 +637,7 @@ void OrderList::DebugCheckSanity() const
for (const Vehicle *v = this->first_shared; v != nullptr; v = v->NextShared()) { for (const Vehicle *v = this->first_shared; v != nullptr; v = v->NextShared()) {
++check_num_vehicles; ++check_num_vehicles;
assert(v->orders.list == this); assert(v->orders == this);
} }
assert(this->num_vehicles == check_num_vehicles); assert(this->num_vehicles == check_num_vehicles);
Debug(misc, 6, "... detected {} orders ({} manual), {} vehicles, {} timetabled, {} total", Debug(misc, 6, "... detected {} orders ({} manual), {} vehicles, {} timetabled, {} total",
@ -715,7 +715,7 @@ uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int
conditional_depth++; conditional_depth++;
int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth); int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
int dist2 = GetOrderDistance(prev, cur->next == nullptr ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth); int dist2 = GetOrderDistance(prev, cur->next == nullptr ? v->orders->GetFirstOrder() : cur->next, v, conditional_depth);
return std::max(dist1, dist2); return std::max(dist1, dist2);
} }
@ -906,7 +906,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS); if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS);
if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
if (v->orders.list == nullptr && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); if (v->orders == nullptr && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Order *new_o = new Order(); Order *new_o = new Order();
@ -926,16 +926,16 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord) void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
{ {
/* Create new order and link in list */ /* Create new order and link in list */
if (v->orders.list == nullptr) { if (v->orders == nullptr) {
v->orders.list = new OrderList(new_o, v); v->orders = new OrderList(new_o, v);
} else { } else {
v->orders.list->InsertOrderAt(new_o, sel_ord); v->orders->InsertOrderAt(new_o, sel_ord);
} }
Vehicle *u = v->FirstShared(); Vehicle *u = v->FirstShared();
DeleteOrderWarnings(u); DeleteOrderWarnings(u);
for (; u != nullptr; u = u->NextShared()) { for (; u != nullptr; u = u->NextShared()) {
assert(v->orders.list == u->orders.list); assert(v->orders == u->orders);
/* If there is added an order before the current one, we need /* If there is added an order before the current one, we need
* to update the selected order. We do not change implicit/real order indices though. * to update the selected order. We do not change implicit/real order indices though.
@ -1047,12 +1047,12 @@ static void CancelLoadingDueToDeletedOrder(Vehicle *v)
*/ */
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord) void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
{ {
v->orders.list->DeleteOrderAt(sel_ord); v->orders->DeleteOrderAt(sel_ord);
Vehicle *u = v->FirstShared(); Vehicle *u = v->FirstShared();
DeleteOrderWarnings(u); DeleteOrderWarnings(u);
for (; u != nullptr; u = u->NextShared()) { for (; u != nullptr; u = u->NextShared()) {
assert(v->orders.list == u->orders.list); assert(v->orders == u->orders);
if (sel_ord == u->cur_real_order_index && u->current_order.IsType(OT_LOADING)) { if (sel_ord == u->cur_real_order_index && u->current_order.IsType(OT_LOADING)) {
CancelLoadingDueToDeletedOrder(u); CancelLoadingDueToDeletedOrder(u);
@ -1159,7 +1159,7 @@ CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID movi
if (moving_one == nullptr) return CMD_ERROR; if (moving_one == nullptr) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
v->orders.list->MoveOrder(moving_order, target_order); v->orders->MoveOrder(moving_order, target_order);
/* Update shared list */ /* Update shared list */
Vehicle *u = v->FirstShared(); Vehicle *u = v->FirstShared();
@ -1199,7 +1199,7 @@ CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID movi
u->cur_implicit_order_index++; u->cur_implicit_order_index++;
} }
assert(v->orders.list == u->orders.list); assert(v->orders == u->orders);
/* Update any possible open window of the vehicle */ /* Update any possible open window of the vehicle */
InvalidateVehicleOrder(u, moving_order | (target_order << 8)); InvalidateVehicleOrder(u, moving_order | (target_order << 8));
} }
@ -1541,7 +1541,7 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve
return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE); return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
} }
if (src->orders.list == nullptr && !OrderList::CanAllocateItem()) { if (src->orders == nullptr && !OrderList::CanAllocateItem()) {
return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
} }
@ -1551,7 +1551,7 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve
* (We mainly do this to keep the order indices valid and in range.) */ * (We mainly do this to keep the order indices valid and in range.) */
DeleteVehicleOrders(dst, false, dst->GetNumOrders() != src->GetNumOrders()); DeleteVehicleOrders(dst, false, dst->GetNumOrders() != src->GetNumOrders());
dst->orders.list = src->orders.list; dst->orders = src->orders;
/* Link this vehicle in the shared-list */ /* Link this vehicle in the shared-list */
dst->AddToShared(src); dst->AddToShared(src);
@ -1607,14 +1607,14 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve
(*order_dst)->AssignOrder(*order); (*order_dst)->AssignOrder(*order);
order_dst = &(*order_dst)->next; order_dst = &(*order_dst)->next;
} }
if (dst->orders.list == nullptr) { if (dst->orders == nullptr) {
dst->orders.list = new OrderList(first, dst); dst->orders = new OrderList(first, dst);
} else { } else {
assert(dst->orders.list->GetFirstOrder() == nullptr); assert(dst->orders->GetFirstOrder() == nullptr);
assert(!dst->orders.list->IsShared()); assert(!dst->orders->IsShared());
delete dst->orders.list; delete dst->orders;
assert(OrderList::CanAllocateItem()); assert(OrderList::CanAllocateItem());
dst->orders.list = new OrderList(first, dst); dst->orders = new OrderList(first, dst);
} }
InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS); InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
@ -1734,7 +1734,7 @@ void CheckOrders(const Vehicle *v)
if (v->GetNumOrders() > 1) { if (v->GetNumOrders() > 1) {
const Order *last = v->GetLastOrder(); const Order *last = v->GetLastOrder();
if (v->orders.list->GetFirstOrder()->Equals(*last)) { if (v->orders->GetFirstOrder()->Equals(*last)) {
message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY; message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
} }
} }
@ -1743,7 +1743,7 @@ void CheckOrders(const Vehicle *v)
if (n_st < 2 && message == INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS; if (n_st < 2 && message == INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
#ifdef WITH_ASSERT #ifdef WITH_ASSERT
if (v->orders.list != nullptr) v->orders.list->DebugCheckSanity(); if (v->orders != nullptr) v->orders->DebugCheckSanity();
#endif #endif
/* We don't have a problem */ /* We don't have a problem */
@ -1801,9 +1801,9 @@ restart:
} }
/* Clear wait time */ /* Clear wait time */
v->orders.list->UpdateTotalDuration(-order->GetWaitTime()); v->orders->UpdateTotalDuration(-order->GetWaitTime());
if (order->IsWaitTimetabled()) { if (order->IsWaitTimetabled()) {
v->orders.list->UpdateTimetableDuration(-order->GetTimetabledWait()); v->orders->UpdateTimetableDuration(-order->GetTimetabledWait());
order->SetWaitTimetabled(false); order->SetWaitTimetabled(false);
} }
order->SetWaitTime(0); order->SetWaitTime(0);
@ -1854,11 +1854,11 @@ void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indic
if (v->IsOrderListShared()) { if (v->IsOrderListShared()) {
/* Remove ourself from the shared order list. */ /* Remove ourself from the shared order list. */
v->RemoveFromShared(); v->RemoveFromShared();
v->orders.list = nullptr; v->orders = nullptr;
} else if (v->orders.list != nullptr) { } else if (v->orders != nullptr) {
/* Remove the orders */ /* Remove the orders */
v->orders.list->FreeChain(keep_orderlist); v->orders->FreeChain(keep_orderlist);
if (!keep_orderlist) v->orders.list = nullptr; if (!keep_orderlist) v->orders = nullptr;
} }
if (reset_order_indices) { if (reset_order_indices) {

View File

@ -1720,9 +1720,9 @@ bool AfterLoadGame()
for (Order *order : Order::Iterate()) order->ConvertFromOldSavegame(); for (Order *order : Order::Iterate()) order->ConvertFromOldSavegame();
for (Vehicle *v : Vehicle::Iterate()) { for (Vehicle *v : Vehicle::Iterate()) {
if (v->orders.list != nullptr && v->orders.list->GetFirstOrder() != nullptr && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) { if (v->orders != nullptr && v->orders->GetFirstOrder() != nullptr && v->orders->GetFirstOrder()->IsType(OT_NOTHING)) {
v->orders.list->FreeChain(); v->orders->FreeChain();
v->orders.list = nullptr; v->orders = nullptr;
} }
v->current_order.ConvertFromOldSavegame(); v->current_order.ConvertFromOldSavegame();

View File

@ -1335,7 +1335,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) { if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
uint max = _savegame_type == SGT_TTO ? 3000 : 5000; uint max = _savegame_type == SGT_TTO ? 3000 : 5000;
uint old_id = RemapOrderIndex(_old_order_ptr); uint old_id = RemapOrderIndex(_old_order_ptr);
if (old_id < max) v->orders.old = Order::Get(old_id); // don't accept orders > max number of orders if (old_id < max) v->old_orders = Order::Get(old_id); // don't accept orders > max number of orders
} }
v->current_order.AssignOrder(UnpackOldOrder(_old_order)); v->current_order.AssignOrder(UnpackOldOrder(_old_order));

View File

@ -263,26 +263,26 @@ void AfterLoadVehicles(bool part_of_load)
std::map<Order*, OrderList*> mapping; std::map<Order*, OrderList*> mapping;
for (Vehicle *v : Vehicle::Iterate()) { for (Vehicle *v : Vehicle::Iterate()) {
if (v->orders.old != nullptr) { if (v->old_orders != nullptr) {
if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
if (mapping[v->orders.old] == nullptr) { if (mapping[v->old_orders] == nullptr) {
/* This adds the whole shared vehicle chain for case b */ /* This adds the whole shared vehicle chain for case b */
/* Creating an OrderList here is safe because the number of vehicles /* Creating an OrderList here is safe because the number of vehicles
* allowed in these savegames matches the number of OrderLists. As * allowed in these savegames matches the number of OrderLists. As
* such each vehicle can get an OrderList and it will (still) fit. */ * such each vehicle can get an OrderList and it will (still) fit. */
assert(OrderList::CanAllocateItem()); assert(OrderList::CanAllocateItem());
v->orders.list = mapping[v->orders.old] = new OrderList(v->orders.old, v); v->orders = mapping[v->old_orders] = new OrderList(v->old_orders, v);
} else { } else {
v->orders.list = mapping[v->orders.old]; v->orders = mapping[v->old_orders];
/* For old games (case a) we must create the shared vehicle chain */ /* For old games (case a) we must create the shared vehicle chain */
if (IsSavegameVersionBefore(SLV_5, 2)) { if (IsSavegameVersionBefore(SLV_5, 2)) {
v->AddToShared(v->orders.list->GetFirstSharedVehicle()); v->AddToShared(v->orders->GetFirstSharedVehicle());
} }
} }
} else { // OrderList was saved as such, only recalculate not saved values } else { // OrderList was saved as such, only recalculate not saved values
if (v->PreviousShared() == nullptr) { if (v->PreviousShared() == nullptr) {
v->orders.list->Initialize(v->orders.list->first, v); v->orders->Initialize(v->orders->first, v);
} }
} }
} }
@ -302,13 +302,13 @@ void AfterLoadVehicles(bool part_of_load)
if (IsSavegameVersionBefore(SLV_105)) { if (IsSavegameVersionBefore(SLV_105)) {
/* Before 105 there was no order for shared orders, thus it messed up horribly */ /* Before 105 there was no order for shared orders, thus it messed up horribly */
for (Vehicle *v : Vehicle::Iterate()) { for (Vehicle *v : Vehicle::Iterate()) {
if (v->First() != v || v->orders.list != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue; if (v->First() != v || v->orders != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue;
/* As above, allocating OrderList here is safe. */ /* As above, allocating OrderList here is safe. */
assert(OrderList::CanAllocateItem()); assert(OrderList::CanAllocateItem());
v->orders.list = new OrderList(nullptr, v); v->orders = new OrderList(nullptr, v);
for (Vehicle *u = v; u != nullptr; u = u->next_shared) { for (Vehicle *u = v; u != nullptr; u = u->next_shared) {
u->orders.list = v->orders.list; u->orders = v->orders;
} }
} }
} }

View File

@ -91,7 +91,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, order_position)); assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, order_position));
int res = (int)order_position; int res = (int)order_position;
const Order *order = v->orders.list->GetFirstOrder(); const Order *order = v->orders->GetFirstOrder();
for (; order->GetType() == OT_IMPLICIT; order = order->next) res++; for (; order->GetType() == OT_IMPLICIT; order = order->next) res++;
while (order_position > 0) { while (order_position > 0) {
order_position = (ScriptOrder::OrderPosition)(order_position - 1); order_position = (ScriptOrder::OrderPosition)(order_position - 1);

View File

@ -454,7 +454,7 @@
if (!IsValidVehicle(vehicle_id)) return false; if (!IsValidVehicle(vehicle_id)) return false;
Vehicle *v = ::Vehicle::Get(vehicle_id); Vehicle *v = ::Vehicle::Get(vehicle_id);
return v->orders.list != nullptr && v->orders.list->GetNumVehicles() > 1; return v->orders != nullptr && v->orders->GetNumVehicles() > 1;
} }
/* static */ int ScriptVehicle::GetReliability(VehicleID vehicle_id) /* static */ int ScriptVehicle::GetReliability(VehicleID vehicle_id)

View File

@ -55,8 +55,8 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val,
default: default:
NOT_REACHED(); NOT_REACHED();
} }
v->orders.list->UpdateTotalDuration(total_delta); v->orders->UpdateTotalDuration(total_delta);
v->orders.list->UpdateTimetableDuration(timetable_delta); v->orders->UpdateTimetableDuration(timetable_delta);
for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) { for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) { if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
@ -182,7 +182,7 @@ CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderI
CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh) CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh)
{ {
Vehicle *v = Vehicle::GetIfValid(veh); Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner); CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
@ -244,7 +244,7 @@ static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date) CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date)
{ {
Vehicle *v = Vehicle::GetIfValid(veh_id); Vehicle *v = Vehicle::GetIfValid(veh_id);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner); CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
@ -253,20 +253,20 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim
if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR; if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR; if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR; if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (timetable_all && !v->orders.list->IsCompleteTimetable()) return CMD_ERROR; if (timetable_all && !v->orders->IsCompleteTimetable()) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
std::vector<Vehicle *> vehs; std::vector<Vehicle *> vehs;
if (timetable_all) { if (timetable_all) {
for (Vehicle *w = v->orders.list->GetFirstSharedVehicle(); w != nullptr; w = w->NextShared()) { for (Vehicle *w = v->orders->GetFirstSharedVehicle(); w != nullptr; w = w->NextShared()) {
vehs.push_back(w); vehs.push_back(w);
} }
} else { } else {
vehs.push_back(v); vehs.push_back(v);
} }
int total_duration = v->orders.list->GetTimetableTotalDuration(); int total_duration = v->orders->GetTimetableTotalDuration();
int num_vehs = (uint)vehs.size(); int num_vehs = (uint)vehs.size();
if (num_vehs >= 2) { if (num_vehs >= 2) {
@ -304,7 +304,7 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim
CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time) CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time)
{ {
Vehicle *v = Vehicle::GetIfValid(veh); Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner); CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
@ -441,7 +441,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
* length of a full cycle till lateness is less than the length of a timetable * length of a full cycle till lateness is less than the length of a timetable
* cycle. When the timetable isn't fully filled the cycle will be INVALID_TICKS. */ * cycle. When the timetable isn't fully filled the cycle will be INVALID_TICKS. */
if (v->lateness_counter > (int)timetabled) { if (v->lateness_counter > (int)timetabled) {
Ticks cycle = v->orders.list->GetTimetableTotalDuration(); Ticks cycle = v->orders->GetTimetableTotalDuration();
if (cycle != INVALID_TICKS && v->lateness_counter > cycle) { if (cycle != INVALID_TICKS && v->lateness_counter > cycle) {
v->lateness_counter %= cycle; v->lateness_counter %= cycle;
} }

View File

@ -123,7 +123,7 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
if (i >= v->GetNumOrders()) { if (i >= v->GetNumOrders()) {
i = 0; i = 0;
assert(order == nullptr); assert(order == nullptr);
order = v->orders.list->GetFirstOrder(); order = v->orders->GetFirstOrder();
} }
} while (i != start); } while (i != start);
@ -322,9 +322,9 @@ struct TimetableWindow : Window {
this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed); this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed);
this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !v->IsOrderListShared()); this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !v->IsOrderListShared());
this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders.list == nullptr); this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders == nullptr);
this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders.list == nullptr); this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders == nullptr);
this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders.list == nullptr); this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders == nullptr);
} else { } else {
this->DisableWidget(WID_VT_START_DATE); this->DisableWidget(WID_VT_START_DATE);
this->DisableWidget(WID_VT_CHANGE_TIME); this->DisableWidget(WID_VT_CHANGE_TIME);
@ -424,7 +424,7 @@ struct TimetableWindow : Window {
* i.e. are only shown if we can calculate all times. * i.e. are only shown if we can calculate all times.
* Excluding order lists with only one order makes some things easier. * Excluding order lists with only one order makes some things easier.
*/ */
Ticks total_time = v->orders.list != nullptr ? v->orders.list->GetTimetableDurationIncomplete() : 0; Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
if (total_time <= 0 || v->GetNumOrders() <= 1 || !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) break; if (total_time <= 0 || v->GetNumOrders() <= 1 || !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) break;
TimetableArrivalDeparture *arr_dep = AllocaM(TimetableArrivalDeparture, v->GetNumOrders()); TimetableArrivalDeparture *arr_dep = AllocaM(TimetableArrivalDeparture, v->GetNumOrders());
@ -475,10 +475,10 @@ struct TimetableWindow : Window {
case WID_VT_SUMMARY_PANEL: { case WID_VT_SUMMARY_PANEL: {
int y = r.top + WD_FRAMERECT_TOP; int y = r.top + WD_FRAMERECT_TOP;
Ticks total_time = v->orders.list != nullptr ? v->orders.list->GetTimetableDurationIncomplete() : 0; Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
if (total_time != 0) { if (total_time != 0) {
SetTimetableParams(0, 1, total_time); SetTimetableParams(0, 1, total_time);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, v->orders.list->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, v->orders->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE);
} }
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
@ -531,7 +531,7 @@ struct TimetableWindow : Window {
} }
case WID_VT_START_DATE: // Change the date that the timetable starts. case WID_VT_START_DATE: // Change the date that the timetable starts.
ShowSetDateWindow(this, v->index, _date, _cur_year, _cur_year + 15, ChangeTimetableStartCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(v->orders.list->IsCompleteTimetable() && _ctrl_pressed))); ShowSetDateWindow(this, v->index, _date, _cur_year, _cur_year + 15, ChangeTimetableStartCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(v->orders->IsCompleteTimetable() && _ctrl_pressed)));
break; break;
case WID_VT_CHANGE_TIME: { // "Wait For" button. case WID_VT_CHANGE_TIME: { // "Wait For" button.

View File

@ -1382,7 +1382,7 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, bool sell_chain, b
return ret; return ret;
} }
if (first->orders.list == nullptr && !OrderList::CanAllocateItem()) { if (first->orders == nullptr && !OrderList::CanAllocateItem()) {
/* Restore the train we had. */ /* Restore the train we had. */
RestoreTrainBackup(original); RestoreTrainBackup(original);
return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
@ -1399,7 +1399,7 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, bool sell_chain, b
if (v == first && v->IsEngine() && !sell_chain && new_head != nullptr && new_head->IsFrontEngine()) { if (v == first && v->IsEngine() && !sell_chain && new_head != nullptr && new_head->IsFrontEngine()) {
/* We are selling the front engine. In this case we want to /* We are selling the front engine. In this case we want to
* 'give' the order, unit number and such to the new head. */ * 'give' the order, unit number and such to the new head. */
new_head->orders.list = first->orders.list; new_head->orders = first->orders;
new_head->AddToShared(first); new_head->AddToShared(first);
DeleteVehicleOrders(first); DeleteVehicleOrders(first);

View File

@ -2161,7 +2161,7 @@ void Vehicle::BeginLoading()
break; break;
} }
target_index++; target_index++;
if (target_index >= this->orders.list->GetNumOrders()) { if (target_index >= this->orders->GetNumOrders()) {
if (this->GetNumManualOrders() == 0 && if (this->GetNumManualOrders() == 0 &&
this->GetNumOrders() < IMPLICIT_ORDER_ONLY_CAP) { this->GetNumOrders() < IMPLICIT_ORDER_ONLY_CAP) {
break; break;
@ -2199,7 +2199,7 @@ void Vehicle::BeginLoading()
} }
} }
} else if (!suppress_implicit_orders && } else if (!suppress_implicit_orders &&
((this->orders.list == nullptr ? OrderList::CanAllocateItem() : this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID)) && ((this->orders == nullptr ? OrderList::CanAllocateItem() : this->orders->GetNumOrders() < MAX_VEH_ORDER_ID)) &&
Order::CanAllocateItem()) { Order::CanAllocateItem()) {
/* Insert new implicit order */ /* Insert new implicit order */
Order *implicit_order = new Order(); Order *implicit_order = new Order();
@ -2770,10 +2770,10 @@ void Vehicle::AddToShared(Vehicle *shared_chain)
{ {
assert(this->previous_shared == nullptr && this->next_shared == nullptr); assert(this->previous_shared == nullptr && this->next_shared == nullptr);
if (shared_chain->orders.list == nullptr) { if (shared_chain->orders == nullptr) {
assert(shared_chain->previous_shared == nullptr); assert(shared_chain->previous_shared == nullptr);
assert(shared_chain->next_shared == nullptr); assert(shared_chain->next_shared == nullptr);
this->orders.list = shared_chain->orders.list = new OrderList(nullptr, shared_chain); this->orders = shared_chain->orders = new OrderList(nullptr, shared_chain);
} }
this->next_shared = shared_chain->next_shared; this->next_shared = shared_chain->next_shared;
@ -2783,7 +2783,7 @@ void Vehicle::AddToShared(Vehicle *shared_chain)
if (this->next_shared != nullptr) this->next_shared->previous_shared = this; if (this->next_shared != nullptr) this->next_shared->previous_shared = this;
shared_chain->orders.list->AddVehicle(this); shared_chain->orders->AddVehicle(this);
} }
/** /**
@ -2796,7 +2796,7 @@ void Vehicle::RemoveFromShared()
bool were_first = (this->FirstShared() == this); bool were_first = (this->FirstShared() == this);
VehicleListIdentifier vli(VL_SHARED_ORDERS, this->type, this->owner, this->FirstShared()->index); VehicleListIdentifier vli(VL_SHARED_ORDERS, this->type, this->owner, this->FirstShared()->index);
this->orders.list->RemoveVehicle(this); this->orders->RemoveVehicle(this);
if (!were_first) { if (!were_first) {
/* We are not the first shared one, so only relink our previous one. */ /* We are not the first shared one, so only relink our previous one. */
@ -2806,7 +2806,7 @@ void Vehicle::RemoveFromShared()
if (this->next_shared != nullptr) this->next_shared->previous_shared = this->previous_shared; if (this->next_shared != nullptr) this->next_shared->previous_shared = this->previous_shared;
if (this->orders.list->GetNumVehicles() == 1) { if (this->orders->GetNumVehicles() == 1) {
/* When there is only one vehicle, remove the shared order list window. */ /* When there is only one vehicle, remove the shared order list window. */
CloseWindowById(GetWindowClassForVehicleType(this->type), vli.Pack()); CloseWindowById(GetWindowClassForVehicleType(this->type), vli.Pack());
InvalidateVehicleOrder(this->FirstShared(), VIWD_MODIFY_ORDERS); InvalidateVehicleOrder(this->FirstShared(), VIWD_MODIFY_ORDERS);

View File

@ -332,9 +332,9 @@ public:
Order current_order; ///< The current order (+ status, like: loading) Order current_order; ///< The current order (+ status, like: loading)
union { union {
OrderList *list; ///< Pointer to the order list for this vehicle OrderList *orders; ///< Pointer to the order list for this vehicle
Order *old; ///< Only used during conversion of old save games Order *old_orders; ///< Only used during conversion of old save games
} orders; ///< The orders currently assigned to the vehicle. };
uint16 load_unload_ticks; ///< Ticks to wait before starting next cycle. uint16 load_unload_ticks; ///< Ticks to wait before starting next cycle.
GroupID group_id; ///< Index of group Pool array GroupID group_id; ///< Index of group Pool array
@ -669,7 +669,7 @@ public:
* Get the first order of the vehicles order list. * Get the first order of the vehicles order list.
* @return first order of order list. * @return first order of order list.
*/ */
inline Order *GetFirstOrder() const { return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetFirstOrder(); } inline Order *GetFirstOrder() const { return (this->orders == nullptr) ? nullptr : this->orders->GetFirstOrder(); }
void AddToShared(Vehicle *shared_chain); void AddToShared(Vehicle *shared_chain);
void RemoveFromShared(); void RemoveFromShared();
@ -690,25 +690,25 @@ public:
* Get the first vehicle of this vehicle chain. * Get the first vehicle of this vehicle chain.
* @return the first vehicle of the chain. * @return the first vehicle of the chain.
*/ */
inline Vehicle *FirstShared() const { return (this->orders.list == nullptr) ? this->First() : this->orders.list->GetFirstSharedVehicle(); } inline Vehicle *FirstShared() const { return (this->orders == nullptr) ? this->First() : this->orders->GetFirstSharedVehicle(); }
/** /**
* Check if we share our orders with another vehicle. * Check if we share our orders with another vehicle.
* @return true if there are other vehicles sharing the same order * @return true if there are other vehicles sharing the same order
*/ */
inline bool IsOrderListShared() const { return this->orders.list != nullptr && this->orders.list->IsShared(); } inline bool IsOrderListShared() const { return this->orders != nullptr && this->orders->IsShared(); }
/** /**
* Get the number of orders this vehicle has. * Get the number of orders this vehicle has.
* @return the number of orders this vehicle has. * @return the number of orders this vehicle has.
*/ */
inline VehicleOrderID GetNumOrders() const { return (this->orders.list == nullptr) ? 0 : this->orders.list->GetNumOrders(); } inline VehicleOrderID GetNumOrders() const { return (this->orders == nullptr) ? 0 : this->orders->GetNumOrders(); }
/** /**
* Get the number of manually added orders this vehicle has. * Get the number of manually added orders this vehicle has.
* @return the number of manually added orders this vehicle has. * @return the number of manually added orders this vehicle has.
*/ */
inline VehicleOrderID GetNumManualOrders() const { return (this->orders.list == nullptr) ? 0 : this->orders.list->GetNumManualOrders(); } inline VehicleOrderID GetNumManualOrders() const { return (this->orders == nullptr) ? 0 : this->orders->GetNumManualOrders(); }
/** /**
* Get the next station the vehicle will stop at. * Get the next station the vehicle will stop at.
@ -716,7 +716,7 @@ public:
*/ */
inline StationIDStack GetNextStoppingStation() const inline StationIDStack GetNextStoppingStation() const
{ {
return (this->orders.list == nullptr) ? INVALID_STATION : this->orders.list->GetNextStoppingStation(this); return (this->orders == nullptr) ? INVALID_STATION : this->orders->GetNextStoppingStation(this);
} }
void ResetRefitCaps(); void ResetRefitCaps();
@ -878,7 +878,7 @@ public:
*/ */
inline Order *GetOrder(int index) const inline Order *GetOrder(int index) const
{ {
return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetOrderAt(index); return (this->orders == nullptr) ? nullptr : this->orders->GetOrderAt(index);
} }
/** /**
@ -887,7 +887,7 @@ public:
*/ */
inline Order *GetLastOrder() const inline Order *GetLastOrder() const
{ {
return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetLastOrder(); return (this->orders == nullptr) ? nullptr : this->orders->GetLastOrder();
} }
bool IsEngineCountable() const; bool IsEngineCountable() const;
@ -1038,7 +1038,7 @@ public:
* Returns an iterable ensemble of orders of a vehicle * Returns an iterable ensemble of orders of a vehicle
* @return an iterable ensemble of orders of a vehicle * @return an iterable ensemble of orders of a vehicle
*/ */
IterateWrapper Orders() const { return IterateWrapper(this->orders.list); } IterateWrapper Orders() const { return IterateWrapper(this->orders); }
}; };
/** /**

View File

@ -219,9 +219,9 @@ CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain,
/* Can we actually make the order backup, i.e. are there enough orders? */ /* Can we actually make the order backup, i.e. are there enough orders? */
if (backup_order && if (backup_order &&
front->orders.list != nullptr && front->orders != nullptr &&
!front->orders.list->IsShared() && !front->orders->IsShared() &&
!Order::CanAllocateItem(front->orders.list->GetNumOrders())) { !Order::CanAllocateItem(front->orders->GetNumOrders())) {
/* Only happens in exceptional cases when there aren't enough orders anyhow. /* Only happens in exceptional cases when there aren't enough orders anyhow.
* Thus it should be safe to just drop the orders in that case. */ * Thus it should be safe to just drop the orders in that case. */
backup_order = false; backup_order = false;

View File

@ -1444,7 +1444,7 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, uin
oid++; oid++;
order = order->next; order = order->next;
if (order == nullptr) { if (order == nullptr) {
order = v->orders.list->GetFirstOrder(); order = v->orders->GetFirstOrder();
oid = 0; oid = 0;
} }
} while (oid != start); } while (oid != start);