diff options
author | rubidium <rubidium@openttd.org> | 2013-02-17 14:54:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2013-02-17 14:54:50 +0000 |
commit | cdb0a7695820ac088df6736cb59ac9989f945c8e (patch) | |
tree | 4eb4c9a8818a518622d32c3599c1c3e285dafdbe /src/vehicle.cpp | |
parent | 446d50f6580d6d71ac30d6d64b72cb3e5c4c3aaa (diff) | |
download | openttd-cdb0a7695820ac088df6736cb59ac9989f945c8e.tar.xz |
(svn r25012) -Codechange: persistently keep 'reserved' cargo (for full-load improved loading) instead of calculating if for every cycle
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 11269db5c..8a3b51750 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -720,10 +720,11 @@ void Vehicle::PreDestructor() if (CleaningPool()) return; if (Station::IsValidID(this->last_station_visited)) { - Station::Get(this->last_station_visited)->loading_vehicles.remove(this); + Station *st = Station::Get(this->last_station_visited); + st->loading_vehicles.remove(this); HideFillingPercent(&this->fill_percent_te_id); - + this->CancelReservation(st); delete this->cargo_payment; } @@ -1255,7 +1256,7 @@ uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour) /* Count up max and used */ for (const Vehicle *v = front; v != NULL; v = v->Next()) { - count += v->cargo.Count(); + count += v->cargo.OnboardCount(); max += v->cargo_cap; if (v->cargo_cap != 0 && colour != NULL) { unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; @@ -1981,6 +1982,22 @@ void Vehicle::BeginLoading() } /** + * Return all reserved cargo packets to the station. + * @param st the station where the reserved packets should go. + */ +void Vehicle::CancelReservation(Station *st) +{ + for (Vehicle *v = this; v != NULL; v = v->next) { + VehicleCargoList &cargo = v->cargo; + if (cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) { + DEBUG(misc, 1, "cancelling cargo reservation"); + cargo.Return(UINT_MAX, &st->goods[v->cargo_type].cargo); + cargo.KeepAll(); + } + } +} + +/** * Perform all actions when leaving a station. * @pre this->current_order.IsType(OT_LOADING) */ @@ -1995,6 +2012,7 @@ void Vehicle::LeaveStation() this->current_order.MakeLeaveStation(); Station *st = Station::Get(this->last_station_visited); + this->CancelReservation(st); st->loading_vehicles.remove(this); HideFillingPercent(&this->fill_percent_te_id); |