summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp6
-rw-r--r--src/autoreplace_cmd.cpp2
-rw-r--r--src/cargopacket.cpp8
-rw-r--r--src/cargopacket.h2
-rw-r--r--src/station.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_cmd.cpp10
8 files changed, 22 insertions, 12 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 385eb9be1..cad674a20 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1160,8 +1160,8 @@ static void CrashAirplane(Aircraft *v)
uint pass = v->Crash();
SetDParam(0, pass);
- v->cargo.Truncate(0);
- v->Next()->cargo.Truncate(0);
+ v->cargo.Truncate();
+ v->Next()->cargo.Truncate();
const Station *st = GetTargetAirportIfValid(v);
StringID newsitem;
if (st == NULL) {
@@ -1205,7 +1205,7 @@ static void MaybeCrashAirplane(Aircraft *v)
/* Crash the airplane. Remove all goods stored at the station. */
for (CargoID i = 0; i < NUM_CARGO; i++) {
st->goods[i].rating = 1;
- st->goods[i].cargo.Truncate(0);
+ st->goods[i].cargo.Truncate();
}
CrashAirplane(v);
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 6afcc48d1..7571da114 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -111,7 +111,7 @@ void CheckCargoCapacity(Vehicle *v)
}
/* Any left-overs will be thrown away, but not their feeder share. */
- src->cargo.Truncate(src->cargo_cap);
+ if (src->cargo_cap < src->cargo.Count()) src->cargo.Truncate(src->cargo.Count() - src->cargo_cap);
}
}
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp
index 0b92de0c8..0603d9125 100644
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -209,11 +209,14 @@ void CargoList<Tinst>::Append(CargoPacket *cp)
/**
* Truncates the cargo in this list to the given amount. It leaves the
* first count cargo entities and removes the rest.
- * @param max_remaining Maximum amount of entities to be in the list after the command.
+ * @param max_move Maximum amount of entities to be removed from the list.
+ * @return Amount of entities actually moved.
*/
template <class Tinst>
-void CargoList<Tinst>::Truncate(uint max_remaining)
+uint CargoList<Tinst>::Truncate(uint max_move)
{
+ max_move = min(this->count, max_move);
+ uint max_remaining = this->count - max_move;
for (Iterator it(packets.begin()); it != packets.end(); /* done during loop*/) {
CargoPacket *cp = *it;
if (max_remaining == 0) {
@@ -236,6 +239,7 @@ void CargoList<Tinst>::Truncate(uint max_remaining)
}
++it;
}
+ return max_move;
}
/**
diff --git a/src/cargopacket.h b/src/cargopacket.h
index dcb1415fc..1e2093134 100644
--- a/src/cargopacket.h
+++ b/src/cargopacket.h
@@ -246,7 +246,7 @@ public:
void Append(CargoPacket *cp);
- void Truncate(uint max_remaining);
+ uint Truncate(uint max_move = UINT_MAX);
template <class Tother_inst>
bool MoveTo(Tother_inst *dest, uint count, MoveToAction mta, CargoPayment *payment, uint data = 0);
diff --git a/src/station.cpp b/src/station.cpp
index 43b659476..7fb6e1916 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -114,7 +114,7 @@ Station::~Station()
DeleteStationNews(this->index);
for (CargoID c = 0; c < NUM_CARGO; c++) {
- this->goods[c].cargo.Truncate(0);
+ this->goods[c].cargo.Truncate();
}
CargoPacket::InvalidateAllFrom(this->index);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index dc898d9bc..128528672 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -3307,7 +3307,7 @@ static void UpdateStationRating(Station *st)
waiting_changed = true;
}
- if (waiting_changed) ge->cargo.Truncate(waiting);
+ if (waiting_changed) ge->cargo.Truncate(ge->cargo.Count() - waiting);
}
}
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 2f11421d6..11269db5c 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -769,7 +769,7 @@ void Vehicle::PreDestructor()
}
InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0);
- this->cargo.Truncate(0);
+ this->cargo.Truncate();
DeleteVehicleOrders(this);
DeleteDepotHighlightOfVehicle(this);
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 7271d27b0..2cbe2c654 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -386,14 +386,20 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
/* Store the result */
for (RefitResult *result = refit_result.Begin(); result != refit_result.End(); result++) {
Vehicle *u = result->v;
- u->cargo.Truncate((u->cargo_type == new_cid) ? result->capacity : 0);
+ if (u->cargo_type != new_cid) {
+ u->cargo.Truncate(u->cargo_cap);
+ } else if (u->cargo_cap > result->capacity) {
+ u->cargo.Truncate(u->cargo_cap - result->capacity);
+ }
u->cargo_type = new_cid;
u->cargo_cap = result->capacity;
u->cargo_subtype = new_subtype;
if (u->type == VEH_AIRCRAFT) {
Vehicle *w = u->Next();
+ if (w->cargo_cap > result->mail_capacity) {
+ w->cargo.Truncate(w->cargo_cap - result->mail_capacity);
+ }
w->cargo_cap = result->mail_capacity;
- w->cargo.Truncate(result->mail_capacity);
}
}
}