diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/economy.cpp | 12 | ||||
-rw-r--r-- | src/openttd.cpp | 12 | ||||
-rw-r--r-- | src/station.h | 2 | ||||
-rw-r--r-- | src/station_cmd.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 6 |
5 files changed, 27 insertions, 7 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index c78d0a8a4..6b8280587 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1331,7 +1331,6 @@ static int32 DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, static bool LoadWait(const Vehicle* v, const Vehicle* u) { const Vehicle *w; - const Vehicle *x; bool has_any_cargo = false; if (!(u->current_order.flags & OF_FULL_LOAD)) return false; @@ -1346,12 +1345,11 @@ static bool LoadWait(const Vehicle* v, const Vehicle* u) } } - FOR_ALL_VEHICLES(x) { - if ((x->type != VEH_TRAIN || IsFrontEngine(x)) && // for all locs - u->last_station_visited == x->last_station_visited && // at the same station - !(x->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed - x->current_order.type == OT_LOADING && // loading - u != x) { // not itself + const Station *st = GetStation(u->last_station_visited); + std::list<Vehicle *>::const_iterator iter; + for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) { + const Vehicle *x = *iter; + if (!(x->vehstatus & (VS_STOPPED | VS_CRASHED)) && u != x) { bool other_has_any_cargo = false; bool has_space_for_same_type = false; bool other_has_same_type = false; diff --git a/src/openttd.cpp b/src/openttd.cpp index 7d342a3de..b5a8b385f 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1926,6 +1926,18 @@ bool AfterLoadGame() } } + if (CheckSavegameVersion(57)) { + Vehicle *v; + /* Added a FIFO queue of vehicles loading at stations */ + FOR_ALL_VEHICLES(v) { + if ((v->type != VEH_TRAIN || IsFrontEngine(v)) && // for all locs + !(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed + v->current_order.type == OT_LOADING) { // loading + GetStation(v->last_station_visited)->loading_vehicles.push_back(v); + } + } + } + return true; } diff --git a/src/station.h b/src/station.h index 3cff76b8a..87b0b1154 100644 --- a/src/station.h +++ b/src/station.h @@ -11,6 +11,7 @@ #include "sprite.h" #include "tile.h" #include "newgrf_station.h" +#include <list> static const StationID INVALID_STATION = 0xFFFF; static const byte INITIAL_STATION_RATING = 175; @@ -157,6 +158,7 @@ struct Station { StationID index; byte last_vehicle_type; + std::list<Vehicle *> loading_vehicles; GoodsEntry goods[NUM_CARGO]; uint16 random_bits; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index ac5ceadff..5682b8baf 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2795,6 +2795,8 @@ static const SaveLoad _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), + // reserve extra space in savegame here. (currently 32 bytes) SLE_CONDNULL(32, 2, SL_MAX_VERSION), diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 3a779c256..c14d376e1 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -570,6 +570,10 @@ bool IsEngineCountable(const Vehicle *v) void DestroyVehicle(Vehicle *v) { + if (v->last_station_visited != INVALID_STATION) { + GetStation(v->last_station_visited)->loading_vehicles.remove(v); + } + if (IsEngineCountable(v)) { GetPlayer(v->owner)->num_engines[v->engine_type]--; if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type); @@ -2903,6 +2907,7 @@ void Vehicle::BeginLoading() { assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); current_order.type = OT_LOADING; + GetStation(this->last_station_visited)->loading_vehicles.push_back(this); } void Vehicle::LeaveStation() @@ -2911,4 +2916,5 @@ void Vehicle::LeaveStation() assert(current_order.type == OT_LOADING); current_order.type = OT_LEAVESTATION; current_order.flags = 0; + GetStation(this->last_station_visited)->loading_vehicles.push_back(this); } |