Changeset - r26178:733038a553ce
[Not reviewed]
master
0 17 0
Niels Martin Hansen - 2 years ago 2022-02-12 18:28:34
nielsm@indvikleren.dk
Codechange: Use anonymous union for vehicle orders/old orders list
17 files changed with 99 insertions and 99 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -211,7 +211,7 @@ static int GetIncompatibleRefitOrderIdFo
 
	const Order *o;
 
	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;
 
	for (VehicleOrderID i = 0; i < orders->GetNumOrders(); i++) {
 
		o = orders->GetOrderAt(i);
src/economy.cpp
Show inline comments
 
@@ -1268,7 +1268,7 @@ void PrepareUnload(Vehicle *front_v)
 
	front_v->cargo_payment = new CargoPayment(front_v);
 

	
 
	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);
 
		for (Vehicle *v = front_v; v != nullptr; v = v->Next()) {
 
			const GoodsEntry *ge = &st->goods[v->cargo_type];
src/linkgraph/refresh.cpp
Show inline comments
 
@@ -26,10 +26,10 @@
 
/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading)
 
{
 
	/* 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. */
 
	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;
 

	
 
	HopSet seen_hops;
 
@@ -173,9 +173,9 @@ const Order *LinkRefresher::PredictNextO
 
		SetBit(flags, USE_NEXT);
 

	
 
		if (next->IsType(OT_CONDITIONAL)) {
 
			const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
 
					this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops);
 
			if (skip_to != nullptr && num_hops < this->vehicle->orders.list->GetNumOrders()) {
 
			const Order *skip_to = this->vehicle->orders->GetNextDecisionNode(
 
					this->vehicle->orders->GetOrderAt(next->GetConditionSkipToOrder()), num_hops);
 
			if (skip_to != nullptr && num_hops < this->vehicle->orders->GetNumOrders()) {
 
				/* Make copies of capacity tracking lists. There is potential
 
				 * for optimization here: If the vehicle never refits we don't
 
				 * need to copy anything. Also, if we've seen the branched link
 
@@ -187,8 +187,8 @@ const Order *LinkRefresher::PredictNextO
 

	
 
		/* Reassign next with the following stop. This can be a station or a
 
		 * depot.*/
 
		next = this->vehicle->orders.list->GetNextDecisionNode(
 
				this->vehicle->orders.list->GetNext(next), num_hops++);
 
		next = this->vehicle->orders->GetNextDecisionNode(
 
				this->vehicle->orders->GetNext(next), num_hops++);
 
	}
 
	return next;
 
}
 
@@ -230,16 +230,16 @@ void LinkRefresher::RefreshStats(const O
 
			 * 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
 
			 * 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 &&
 
					this->vehicle->orders.list->GetTotalDuration() >
 
					this->vehicle->orders->GetTotalDuration() >
 
					(Ticks)this->vehicle->current_order_time) {
 
				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 /
 
							this->vehicle->orders.list->GetTotalDuration(), 0, 0,
 
							this->vehicle->orders->GetTotalDuration(), 0, 0,
 
							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);
 
				} else {
 
					IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode);
src/order_backup.cpp
Show inline comments
 
@@ -77,7 +77,7 @@ void OrderBackup::DoRestore(Vehicle *v)
 
	if (this->clone != nullptr) {
 
		Command<CMD_CLONE_ORDER>::Do(DC_EXEC, CO_SHARE, v->index, this->clone->index);
 
	} 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;
 
		/* Make sure buoys/oil rigs are updated in the station list. */
 
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
src/order_cmd.cpp
Show inline comments
 
@@ -637,7 +637,7 @@ void OrderList::DebugCheckSanity() const
 

	
 
	for (const Vehicle *v = this->first_shared; v != nullptr; v = v->NextShared()) {
 
		++check_num_vehicles;
 
		assert(v->orders.list == this);
 
		assert(v->orders == this);
 
	}
 
	assert(this->num_vehicles == check_num_vehicles);
 
	Debug(misc, 6, "... detected {} orders ({} manual), {} vehicles, {} timetabled, {} total",
 
@@ -715,7 +715,7 @@ uint GetOrderDistance(const Order *prev,
 
		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);
 
	}
 

	
 
@@ -906,7 +906,7 @@ CommandCost CmdInsertOrder(DoCommandFlag
 

	
 
	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 (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) {
 
		Order *new_o = new Order();
 
@@ -926,16 +926,16 @@ CommandCost CmdInsertOrder(DoCommandFlag
 
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
 
{
 
	/* Create new order and link in list */
 
	if (v->orders.list == nullptr) {
 
		v->orders.list = new OrderList(new_o, v);
 
	if (v->orders == nullptr) {
 
		v->orders = new OrderList(new_o, v);
 
	} else {
 
		v->orders.list->InsertOrderAt(new_o, sel_ord);
 
		v->orders->InsertOrderAt(new_o, sel_ord);
 
	}
 

	
 
	Vehicle *u = v->FirstShared();
 
	DeleteOrderWarnings(u);
 
	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
 
		 * to update the selected order. We do not change implicit/real order indices though.
 
@@ -1047,12 +1047,12 @@ static void CancelLoadingDueToDeletedOrd
 
 */
 
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
 
{
 
	v->orders.list->DeleteOrderAt(sel_ord);
 
	v->orders->DeleteOrderAt(sel_ord);
 

	
 
	Vehicle *u = v->FirstShared();
 
	DeleteOrderWarnings(u);
 
	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)) {
 
			CancelLoadingDueToDeletedOrder(u);
 
@@ -1159,7 +1159,7 @@ CommandCost CmdMoveOrder(DoCommandFlag f
 
	if (moving_one == nullptr) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		v->orders.list->MoveOrder(moving_order, target_order);
 
		v->orders->MoveOrder(moving_order, target_order);
 

	
 
		/* Update shared list */
 
		Vehicle *u = v->FirstShared();
 
@@ -1199,7 +1199,7 @@ CommandCost CmdMoveOrder(DoCommandFlag f
 
				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 */
 
			InvalidateVehicleOrder(u, moving_order | (target_order << 8));
 
		}
 
@@ -1541,7 +1541,7 @@ CommandCost CmdCloneOrder(DoCommandFlag 
 
				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);
 
			}
 

	
 
@@ -1551,7 +1551,7 @@ CommandCost CmdCloneOrder(DoCommandFlag 
 
				 * (We mainly do this to keep the order indices valid and in range.) */
 
				DeleteVehicleOrders(dst, false, dst->GetNumOrders() != src->GetNumOrders());
 

	
 
				dst->orders.list = src->orders.list;
 
				dst->orders = src->orders;
 

	
 
				/* Link this vehicle in the shared-list */
 
				dst->AddToShared(src);
 
@@ -1607,14 +1607,14 @@ CommandCost CmdCloneOrder(DoCommandFlag 
 
					(*order_dst)->AssignOrder(*order);
 
					order_dst = &(*order_dst)->next;
 
				}
 
				if (dst->orders.list == nullptr) {
 
					dst->orders.list = new OrderList(first, dst);
 
				if (dst->orders == nullptr) {
 
					dst->orders = new OrderList(first, dst);
 
				} else {
 
					assert(dst->orders.list->GetFirstOrder() == nullptr);
 
					assert(!dst->orders.list->IsShared());
 
					delete dst->orders.list;
 
					assert(dst->orders->GetFirstOrder() == nullptr);
 
					assert(!dst->orders->IsShared());
 
					delete dst->orders;
 
					assert(OrderList::CanAllocateItem());
 
					dst->orders.list = new OrderList(first, dst);
 
					dst->orders = new OrderList(first, dst);
 
				}
 

	
 
				InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
 
@@ -1734,7 +1734,7 @@ void CheckOrders(const Vehicle *v)
 
		if (v->GetNumOrders() > 1) {
 
			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;
 
			}
 
		}
 
@@ -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;
 

	
 
#ifdef WITH_ASSERT
 
		if (v->orders.list != nullptr) v->orders.list->DebugCheckSanity();
 
		if (v->orders != nullptr) v->orders->DebugCheckSanity();
 
#endif
 

	
 
		/* We don't have a problem */
 
@@ -1801,9 +1801,9 @@ restart:
 
				}
 

	
 
				/* Clear wait time */
 
				v->orders.list->UpdateTotalDuration(-order->GetWaitTime());
 
				v->orders->UpdateTotalDuration(-order->GetWaitTime());
 
				if (order->IsWaitTimetabled()) {
 
					v->orders.list->UpdateTimetableDuration(-order->GetTimetabledWait());
 
					v->orders->UpdateTimetableDuration(-order->GetTimetabledWait());
 
					order->SetWaitTimetabled(false);
 
				}
 
				order->SetWaitTime(0);
 
@@ -1854,11 +1854,11 @@ void DeleteVehicleOrders(Vehicle *v, boo
 
	if (v->IsOrderListShared()) {
 
		/* Remove ourself from the shared order list. */
 
		v->RemoveFromShared();
 
		v->orders.list = nullptr;
 
	} else if (v->orders.list != nullptr) {
 
		v->orders = nullptr;
 
	} else if (v->orders != nullptr) {
 
		/* Remove the orders */
 
		v->orders.list->FreeChain(keep_orderlist);
 
		if (!keep_orderlist) v->orders.list = nullptr;
 
		v->orders->FreeChain(keep_orderlist);
 
		if (!keep_orderlist) v->orders = nullptr;
 
	}
 

	
 
	if (reset_order_indices) {
src/saveload/afterload.cpp
Show inline comments
 
@@ -1720,9 +1720,9 @@ bool AfterLoadGame()
 
		for (Order *order : Order::Iterate()) order->ConvertFromOldSavegame();
 

	
 
		for (Vehicle *v : Vehicle::Iterate()) {
 
			if (v->orders.list != nullptr && v->orders.list->GetFirstOrder() != nullptr && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) {
 
				v->orders.list->FreeChain();
 
				v->orders.list = nullptr;
 
			if (v->orders != nullptr && v->orders->GetFirstOrder() != nullptr && v->orders->GetFirstOrder()->IsType(OT_NOTHING)) {
 
				v->orders->FreeChain();
 
				v->orders = nullptr;
 
			}
 

	
 
			v->current_order.ConvertFromOldSavegame();
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -1335,7 +1335,7 @@ bool LoadOldVehicle(LoadgameState *ls, i
 
		if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
 
			uint max = _savegame_type == SGT_TTO ? 3000 : 5000;
 
			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));
 

	
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -263,26 +263,26 @@ void AfterLoadVehicles(bool part_of_load
 
		std::map<Order*, OrderList*> mapping;
 

	
 
		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 (mapping[v->orders.old] == nullptr) {
 
					if (mapping[v->old_orders] == nullptr) {
 
						/* This adds the whole shared vehicle chain for case b */
 

	
 
						/* Creating an OrderList here is safe because the number of vehicles
 
						 * allowed in these savegames matches the number of OrderLists. As
 
						 * such each vehicle can get an OrderList and it will (still) fit. */
 
						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 {
 
						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 */
 
						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
 
					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)) {
 
			/* Before 105 there was no order for shared orders, thus it messed up horribly */
 
			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. */
 
				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) {
 
					u->orders.list = v->orders.list;
 
					u->orders = v->orders;
 
				}
 
			}
 
		}
src/script/api/script_order.cpp
Show inline comments
 
@@ -91,7 +91,7 @@ static int ScriptOrderPositionToRealOrde
 
	assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, 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++;
 
	while (order_position > 0) {
 
		order_position = (ScriptOrder::OrderPosition)(order_position - 1);
src/script/api/script_vehicle.cpp
Show inline comments
 
@@ -454,7 +454,7 @@
 
	if (!IsValidVehicle(vehicle_id)) return false;
 

	
 
	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)
src/timetable_cmd.cpp
Show inline comments
 
@@ -55,8 +55,8 @@ static void ChangeTimetable(Vehicle *v, 
 
		default:
 
			NOT_REACHED();
 
	}
 
	v->orders.list->UpdateTotalDuration(total_delta);
 
	v->orders.list->UpdateTimetableDuration(timetable_delta);
 
	v->orders->UpdateTotalDuration(total_delta);
 
	v->orders->UpdateTimetableDuration(timetable_delta);
 

	
 
	for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
 
		if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
 
@@ -182,7 +182,7 @@ CommandCost CmdChangeTimetable(DoCommand
 
CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID 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);
 
	if (ret.Failed()) return ret;
 
@@ -244,7 +244,7 @@ static bool VehicleTimetableSorter(Vehic
 
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date)
 
{
 
	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);
 
	if (ret.Failed()) return ret;
 
@@ -253,20 +253,20 @@ CommandCost CmdSetTimetableStart(DoComma
 
	if (start_date < 0 || start_date > MAX_DAY) 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 (timetable_all && !v->orders.list->IsCompleteTimetable()) return CMD_ERROR;
 
	if (timetable_all && !v->orders->IsCompleteTimetable()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		std::vector<Vehicle *> vehs;
 

	
 
		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);
 
			}
 
		} else {
 
			vehs.push_back(v);
 
		}
 

	
 
		int total_duration = v->orders.list->GetTimetableTotalDuration();
 
		int total_duration = v->orders->GetTimetableTotalDuration();
 
		int num_vehs = (uint)vehs.size();
 

	
 
		if (num_vehs >= 2) {
 
@@ -304,7 +304,7 @@ CommandCost CmdSetTimetableStart(DoComma
 
CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time)
 
{
 
	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);
 
	if (ret.Failed()) return ret;
 
@@ -441,7 +441,7 @@ void UpdateVehicleTimetable(Vehicle *v, 
 
	 * 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. */
 
	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) {
 
			v->lateness_counter %= cycle;
 
		}
src/timetable_gui.cpp
Show inline comments
 
@@ -123,7 +123,7 @@ static void FillTimetableArrivalDepartur
 
		if (i >= v->GetNumOrders()) {
 
			i = 0;
 
			assert(order == nullptr);
 
			order = v->orders.list->GetFirstOrder();
 
			order = v->orders->GetFirstOrder();
 
		}
 
	} while (i != start);
 

	
 
@@ -322,9 +322,9 @@ struct TimetableWindow : Window {
 
			this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed);
 
			this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !v->IsOrderListShared());
 

	
 
			this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders.list == nullptr);
 
			this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders.list == nullptr);
 
			this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders.list == nullptr);
 
			this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders == nullptr);
 
			this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders == nullptr);
 
			this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders == nullptr);
 
		} else {
 
			this->DisableWidget(WID_VT_START_DATE);
 
			this->DisableWidget(WID_VT_CHANGE_TIME);
 
@@ -424,7 +424,7 @@ struct TimetableWindow : Window {
 
				 * i.e. are only shown if we can calculate all times.
 
				 * 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;
 

	
 
				TimetableArrivalDeparture *arr_dep = AllocaM(TimetableArrivalDeparture, v->GetNumOrders());
 
@@ -475,10 +475,10 @@ struct TimetableWindow : Window {
 
			case WID_VT_SUMMARY_PANEL: {
 
				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) {
 
					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;
 

	
 
@@ -531,7 +531,7 @@ struct TimetableWindow : Window {
 
			}
 

	
 
			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;
 

	
 
			case WID_VT_CHANGE_TIME: { // "Wait For" button.
src/train_cmd.cpp
Show inline comments
 
@@ -1382,7 +1382,7 @@ CommandCost CmdSellRailWagon(DoCommandFl
 
		return ret;
 
	}
 

	
 
	if (first->orders.list == nullptr && !OrderList::CanAllocateItem()) {
 
	if (first->orders == nullptr && !OrderList::CanAllocateItem()) {
 
		/* Restore the train we had. */
 
		RestoreTrainBackup(original);
 
		return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
 
@@ -1399,7 +1399,7 @@ CommandCost CmdSellRailWagon(DoCommandFl
 
		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
 
			 * '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);
 
			DeleteVehicleOrders(first);
 

	
src/vehicle.cpp
Show inline comments
 
@@ -2161,7 +2161,7 @@ void Vehicle::BeginLoading()
 
						break;
 
					}
 
					target_index++;
 
					if (target_index >= this->orders.list->GetNumOrders()) {
 
					if (target_index >= this->orders->GetNumOrders()) {
 
						if (this->GetNumManualOrders() == 0 &&
 
								this->GetNumOrders() < IMPLICIT_ORDER_ONLY_CAP) {
 
							break;
 
@@ -2199,7 +2199,7 @@ void Vehicle::BeginLoading()
 
						}
 
					}
 
				} 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()) {
 
					/* Insert new implicit order */
 
					Order *implicit_order = new Order();
 
@@ -2770,10 +2770,10 @@ void Vehicle::AddToShared(Vehicle *share
 
{
 
	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->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;
 
@@ -2783,7 +2783,7 @@ void Vehicle::AddToShared(Vehicle *share
 

	
 
	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);
 
	VehicleListIdentifier vli(VL_SHARED_ORDERS, this->type, this->owner, this->FirstShared()->index);
 

	
 
	this->orders.list->RemoveVehicle(this);
 
	this->orders->RemoveVehicle(this);
 

	
 
	if (!were_first) {
 
		/* 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->orders.list->GetNumVehicles() == 1) {
 
	if (this->orders->GetNumVehicles() == 1) {
 
		/* When there is only one vehicle, remove the shared order list window. */
 
		CloseWindowById(GetWindowClassForVehicleType(this->type), vli.Pack());
 
		InvalidateVehicleOrder(this->FirstShared(), VIWD_MODIFY_ORDERS);
src/vehicle_base.h
Show inline comments
 
@@ -332,9 +332,9 @@ public:
 
	Order current_order;                ///< The current order (+ status, like: loading)
 

	
 
	union {
 
		OrderList *list;            ///< Pointer to the order list for this vehicle
 
		Order     *old;             ///< Only used during conversion of old save games
 
	} orders;                           ///< The orders currently assigned to the vehicle.
 
		OrderList *orders;              ///< Pointer to the order list for this vehicle
 
		Order *old_orders;              ///< Only used during conversion of old save games
 
	};
 

	
 
	uint16 load_unload_ticks;           ///< Ticks to wait before starting next cycle.
 
	GroupID group_id;                   ///< Index of group Pool array
 
@@ -669,7 +669,7 @@ public:
 
	 * Get the first order of the vehicles 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 RemoveFromShared();
 
@@ -690,25 +690,25 @@ public:
 
	 * Get the first vehicle of this vehicle 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.
 
	 * @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.
 
	 * @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.
 
	 * @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.
 
@@ -716,7 +716,7 @@ public:
 
	 */
 
	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();
 
@@ -878,7 +878,7 @@ public:
 
	 */
 
	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
 
	{
 
		return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetLastOrder();
 
		return (this->orders == nullptr) ? nullptr : this->orders->GetLastOrder();
 
	}
 

	
 
	bool IsEngineCountable() const;
 
@@ -1038,7 +1038,7 @@ public:
 
	 * Returns 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); }
 
};
 

	
 
/**
src/vehicle_cmd.cpp
Show inline comments
 
@@ -219,9 +219,9 @@ CommandCost CmdSellVehicle(DoCommandFlag
 

	
 
	/* Can we actually make the order backup, i.e. are there enough orders? */
 
	if (backup_order &&
 
			front->orders.list != nullptr &&
 
			!front->orders.list->IsShared() &&
 
			!Order::CanAllocateItem(front->orders.list->GetNumOrders())) {
 
			front->orders != nullptr &&
 
			!front->orders->IsShared() &&
 
			!Order::CanAllocateItem(front->orders->GetNumOrders())) {
 
		/* 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. */
 
		backup_order = false;
src/vehicle_gui.cpp
Show inline comments
 
@@ -1444,7 +1444,7 @@ static void DrawSmallOrderList(const Veh
 
		oid++;
 
		order = order->next;
 
		if (order == nullptr) {
 
			order = v->orders.list->GetFirstOrder();
 
			order = v->orders->GetFirstOrder();
 
			oid = 0;
 
		}
 
	} while (oid != start);
0 comments (0 inline, 0 general)