Use vector instead of list for Station::loading_vehicles.
This commit is contained in:
@@ -1969,12 +1969,9 @@ void LoadUnloadStation(Station *st)
|
||||
if (st->loading_vehicles.empty()) return;
|
||||
|
||||
Vehicle *last_loading = NULL;
|
||||
std::list<Vehicle *>::iterator iter;
|
||||
|
||||
/* Check if anything will be loaded at all. Otherwise we don't need to reserve either. */
|
||||
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
|
||||
Vehicle *v = *iter;
|
||||
|
||||
for (Vehicle *v : st->loading_vehicles) {
|
||||
if ((v->vehstatus & (VS_STOPPED | VS_CRASHED))) continue;
|
||||
|
||||
assert(v->load_unload_ticks != 0);
|
||||
@@ -1990,8 +1987,7 @@ void LoadUnloadStation(Station *st)
|
||||
*/
|
||||
if (last_loading == NULL) return;
|
||||
|
||||
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
|
||||
Vehicle *v = *iter;
|
||||
for (Vehicle *v : st->loading_vehicles) {
|
||||
if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v);
|
||||
if (v == last_loading) break;
|
||||
}
|
||||
|
@@ -62,6 +62,7 @@
|
||||
#include "saveload_internal.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
@@ -1658,12 +1659,10 @@ bool AfterLoadGame()
|
||||
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
std::list<Vehicle *>::iterator iter;
|
||||
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
|
||||
Vehicle *v = *iter;
|
||||
iter++;
|
||||
if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
|
||||
}
|
||||
st->loading_vehicles.erase(std::remove_if(st->loading_vehicles.begin(), st->loading_vehicles.end(),
|
||||
[](Vehicle *v) {
|
||||
return !v->current_order.IsType(OT_LOADING);
|
||||
}), st->loading_vehicles.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2248,13 +2247,11 @@ bool AfterLoadGame()
|
||||
*/
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
std::list<Vehicle *>::iterator iter;
|
||||
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
|
||||
for (Vehicle *v : st->loading_vehicles) {
|
||||
/* There are always as many CargoPayments as Vehicles. We need to make the
|
||||
* assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
|
||||
assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
|
||||
assert(CargoPayment::CanAllocateItem());
|
||||
Vehicle *v = *iter;
|
||||
if (v->cargo_payment == NULL) v->cargo_payment = new CargoPayment(v);
|
||||
}
|
||||
}
|
||||
|
@@ -218,7 +218,7 @@ static const SaveLoad _old_station_desc[] = {
|
||||
SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, 27, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION),
|
||||
|
||||
SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION),
|
||||
SLE_CONDVEC(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION),
|
||||
|
||||
/* reserve extra space in savegame here. (currently 32 bytes) */
|
||||
SLE_CONDNULL(32, 2, SL_MAX_VERSION),
|
||||
@@ -440,7 +440,7 @@ static const SaveLoad _station_desc[] = {
|
||||
SLE_VAR(Station, time_since_unload, SLE_UINT8),
|
||||
SLE_VAR(Station, last_vehicle_type, SLE_UINT8),
|
||||
SLE_VAR(Station, had_vehicle_of_type, SLE_UINT8),
|
||||
SLE_LST(Station, loading_vehicles, REF_VEHICLE),
|
||||
SLE_VEC(Station, loading_vehicles, REF_VEHICLE),
|
||||
SLE_CONDVAR(Station, always_accepted, SLE_UINT32, 127, SL_MAX_VERSION),
|
||||
|
||||
SLE_END()
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "linkgraph/linkgraph_type.h"
|
||||
#include "newgrf_storage.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
||||
extern StationPool _station_pool;
|
||||
@@ -468,7 +469,7 @@ public:
|
||||
byte time_since_unload;
|
||||
|
||||
byte last_vehicle_type;
|
||||
std::list<Vehicle *> loading_vehicles;
|
||||
std::vector<Vehicle *> loading_vehicles;
|
||||
GoodsEntry goods[NUM_CARGO]; ///< Goods at this station
|
||||
uint32 always_accepted; ///< Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)
|
||||
|
||||
|
@@ -3558,8 +3558,8 @@ void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
|
||||
ge.cargo.Reroute(UINT_MAX, &ge.cargo, avoid, avoid2, &ge);
|
||||
|
||||
/* Reroute cargo staged to be transfered. */
|
||||
for (std::list<Vehicle *>::iterator it(st->loading_vehicles.begin()); it != st->loading_vehicles.end(); ++it) {
|
||||
for (Vehicle *v = *it; v != NULL; v = v->Next()) {
|
||||
for (Vehicle *v : st->loading_vehicles) {
|
||||
for (; v != NULL; v = v->Next()) {
|
||||
if (v->cargo_type != c) continue;
|
||||
v->cargo.Reroute(UINT_MAX, &v->cargo, avoid, avoid2, &ge);
|
||||
}
|
||||
|
@@ -60,6 +60,8 @@
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
#define GEN_HASH(x, y) ((GB((y), 6 + ZOOM_LVL_SHIFT, 6) << 6) + GB((x), 7 + ZOOM_LVL_SHIFT, 6))
|
||||
@@ -830,7 +832,7 @@ void Vehicle::PreDestructor()
|
||||
|
||||
if (Station::IsValidID(this->last_station_visited)) {
|
||||
Station *st = Station::Get(this->last_station_visited);
|
||||
st->loading_vehicles.remove(this);
|
||||
st->loading_vehicles.erase(std::remove(st->loading_vehicles.begin(), st->loading_vehicles.end(), this), st->loading_vehicles.end());
|
||||
|
||||
HideFillingPercent(&this->fill_percent_te_id);
|
||||
this->CancelReservation(INVALID_STATION, st);
|
||||
@@ -2592,7 +2594,7 @@ void Vehicle::LeaveStation()
|
||||
this->current_order.MakeLeaveStation();
|
||||
Station *st = Station::Get(this->last_station_visited);
|
||||
this->CancelReservation(INVALID_STATION, st);
|
||||
st->loading_vehicles.remove(this);
|
||||
st->loading_vehicles.erase(std::remove(st->loading_vehicles.begin(), st->loading_vehicles.end(), this), st->loading_vehicles.end());
|
||||
|
||||
HideFillingPercent(&this->fill_percent_te_id);
|
||||
trip_occupancy = CalcPercentVehicleFilled(this, NULL);
|
||||
|
Reference in New Issue
Block a user