mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 06:52:05 +01:00
Codechange: Use single vector for next station order.
Pass vector to insert into to avoid handling multiple vectors. This may change the order of returned stations.
This commit is contained in:
committed by
Peter Nelson
parent
fd32d1447e
commit
d6eff806f0
@@ -135,7 +135,8 @@ static StationID FindNearestHangar(const Aircraft *v)
|
||||
next_dest = Station::GetIfValid(v->current_order.GetDestination().ToStationID());
|
||||
} else {
|
||||
last_dest = GetTargetAirportIfValid(v);
|
||||
std::vector<StationID> next_station = v->GetNextStoppingStation();
|
||||
std::vector<StationID> next_station;
|
||||
v->GetNextStoppingStation(next_station);
|
||||
if (!next_station.empty()) next_dest = Station::GetIfValid(next_station.back());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1270,7 +1270,8 @@ void PrepareUnload(Vehicle *front_v)
|
||||
assert(CargoPayment::CanAllocateItem());
|
||||
front_v->cargo_payment = new CargoPayment(front_v);
|
||||
|
||||
std::vector<StationID> next_station = front_v->GetNextStoppingStation();
|
||||
std::vector<StationID> next_station;
|
||||
front_v->GetNextStoppingStation(next_station);
|
||||
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()) {
|
||||
@@ -1618,7 +1619,8 @@ static void LoadUnloadVehicle(Vehicle *front)
|
||||
StationID last_visited = front->last_station_visited;
|
||||
Station *st = Station::Get(last_visited);
|
||||
|
||||
std::vector<StationID> next_station = front->GetNextStoppingStation();
|
||||
std::vector<StationID> next_station;
|
||||
front->GetNextStoppingStation(next_station);
|
||||
bool use_autorefit = front->current_order.IsRefit() && front->current_order.GetRefitCargo() == CARGO_AUTO_REFIT;
|
||||
CargoArray consist_capleft{};
|
||||
if (_settings_game.order.improved_load && use_autorefit ?
|
||||
|
||||
@@ -367,7 +367,7 @@ public:
|
||||
*/
|
||||
inline VehicleOrderID GetNumManualOrders() const { return this->num_manual_orders; }
|
||||
|
||||
std::vector<StationID> GetNextStoppingStation(const Vehicle *v, VehicleOrderID first = INVALID_VEH_ORDER_ID, uint hops = 0) const;
|
||||
void GetNextStoppingStation(std::vector<StationID> &next_station, const Vehicle *v, VehicleOrderID first = INVALID_VEH_ORDER_ID, uint hops = 0) const;
|
||||
VehicleOrderID GetNextDecisionNode(VehicleOrderID next, uint hops) const;
|
||||
|
||||
void InsertOrderAt(Order &&order, VehicleOrderID index);
|
||||
|
||||
@@ -361,14 +361,14 @@ VehicleOrderID OrderList::GetNextDecisionNode(VehicleOrderID next, uint hops) co
|
||||
* @pre The vehicle is currently loading and v->last_station_visited is meaningful.
|
||||
* @note This function may draw a random number. Don't use it from the GUI.
|
||||
*/
|
||||
std::vector<StationID> OrderList::GetNextStoppingStation(const Vehicle *v, VehicleOrderID first, uint hops) const
|
||||
void OrderList::GetNextStoppingStation(std::vector<StationID> &next_station, const Vehicle *v, VehicleOrderID first, uint hops) const
|
||||
{
|
||||
VehicleOrderID next = first;
|
||||
if (first == INVALID_VEH_ORDER_ID) {
|
||||
next = v->cur_implicit_order_index;
|
||||
if (next >= this->GetNumOrders()) {
|
||||
next = this->GetFirstOrder();
|
||||
if (next == INVALID_VEH_ORDER_ID) return {};
|
||||
if (next == INVALID_VEH_ORDER_ID) return;
|
||||
} else {
|
||||
/* GetNext never returns INVALID_VEH_ORDER_ID if there is a valid station in the list.
|
||||
* As the given "next" is already valid and a station in the list, we
|
||||
@@ -392,10 +392,9 @@ std::vector<StationID> OrderList::GetNextStoppingStation(const Vehicle *v, Vehic
|
||||
} else if (skip_to == INVALID_VEH_ORDER_ID || skip_to == first) {
|
||||
next = (advance == first) ? INVALID_VEH_ORDER_ID : advance;
|
||||
} else {
|
||||
std::vector<StationID> st1 = this->GetNextStoppingStation(v, skip_to, hops);
|
||||
std::vector<StationID> st2 = this->GetNextStoppingStation(v, advance, hops);
|
||||
std::copy(st2.rbegin(), st2.rend(), std::back_inserter(st1));
|
||||
return st1;
|
||||
this->GetNextStoppingStation(next_station, v, skip_to, hops);
|
||||
this->GetNextStoppingStation(next_station, v, advance, hops);
|
||||
return;
|
||||
}
|
||||
++hops;
|
||||
}
|
||||
@@ -404,11 +403,11 @@ std::vector<StationID> OrderList::GetNextStoppingStation(const Vehicle *v, Vehic
|
||||
if (next == INVALID_VEH_ORDER_ID || ((orders[next].IsType(OT_GOTO_STATION) || orders[next].IsType(OT_IMPLICIT)) &&
|
||||
orders[next].GetDestination() == v->last_station_visited &&
|
||||
(orders[next].GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) != 0)) {
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
} while (orders[next].IsType(OT_GOTO_DEPOT) || orders[next].GetDestination() == v->last_station_visited);
|
||||
|
||||
return {orders[next].GetDestination().ToStationID()};
|
||||
next_station.push_back(orders[next].GetDestination().ToStationID());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -714,9 +714,10 @@ public:
|
||||
* Get the next station the vehicle will stop at.
|
||||
* @return ID of the next station the vehicle will stop at or StationID::Invalid().
|
||||
*/
|
||||
inline std::vector<StationID> GetNextStoppingStation() const
|
||||
inline void GetNextStoppingStation(std::vector<StationID> &next_station) const
|
||||
{
|
||||
return (this->orders == nullptr) ? std::vector<StationID>{} : this->orders->GetNextStoppingStation(this);
|
||||
if (this->orders == nullptr) return;
|
||||
this->orders->GetNextStoppingStation(next_station, this);
|
||||
}
|
||||
|
||||
void ResetRefitCaps();
|
||||
|
||||
Reference in New Issue
Block a user