1
0
Fork 0

(svn r25008) -Codechange: Make CargoList::Truncate behave similarly to CargoList::MoveTo, i.e. pass the amount to truncate (fonsinchen)

release/1.4
rubidium 2013-02-17 14:10:15 +00:00
parent 6647cb9179
commit 2795ed5b09
8 changed files with 22 additions and 12 deletions

View File

@ -1160,8 +1160,8 @@ static void CrashAirplane(Aircraft *v)
uint pass = v->Crash(); uint pass = v->Crash();
SetDParam(0, pass); SetDParam(0, pass);
v->cargo.Truncate(0); v->cargo.Truncate();
v->Next()->cargo.Truncate(0); v->Next()->cargo.Truncate();
const Station *st = GetTargetAirportIfValid(v); const Station *st = GetTargetAirportIfValid(v);
StringID newsitem; StringID newsitem;
if (st == NULL) { if (st == NULL) {
@ -1205,7 +1205,7 @@ static void MaybeCrashAirplane(Aircraft *v)
/* Crash the airplane. Remove all goods stored at the station. */ /* Crash the airplane. Remove all goods stored at the station. */
for (CargoID i = 0; i < NUM_CARGO; i++) { for (CargoID i = 0; i < NUM_CARGO; i++) {
st->goods[i].rating = 1; st->goods[i].rating = 1;
st->goods[i].cargo.Truncate(0); st->goods[i].cargo.Truncate();
} }
CrashAirplane(v); CrashAirplane(v);

View File

@ -111,7 +111,7 @@ void CheckCargoCapacity(Vehicle *v)
} }
/* Any left-overs will be thrown away, but not their feeder share. */ /* 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);
} }
} }

View File

@ -209,11 +209,14 @@ void CargoList<Tinst>::Append(CargoPacket *cp)
/** /**
* Truncates the cargo in this list to the given amount. It leaves the * Truncates the cargo in this list to the given amount. It leaves the
* first count cargo entities and removes the rest. * 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> 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*/) { for (Iterator it(packets.begin()); it != packets.end(); /* done during loop*/) {
CargoPacket *cp = *it; CargoPacket *cp = *it;
if (max_remaining == 0) { if (max_remaining == 0) {
@ -236,6 +239,7 @@ void CargoList<Tinst>::Truncate(uint max_remaining)
} }
++it; ++it;
} }
return max_move;
} }
/** /**

View File

@ -246,7 +246,7 @@ public:
void Append(CargoPacket *cp); void Append(CargoPacket *cp);
void Truncate(uint max_remaining); uint Truncate(uint max_move = UINT_MAX);
template <class Tother_inst> template <class Tother_inst>
bool MoveTo(Tother_inst *dest, uint count, MoveToAction mta, CargoPayment *payment, uint data = 0); bool MoveTo(Tother_inst *dest, uint count, MoveToAction mta, CargoPayment *payment, uint data = 0);

View File

@ -114,7 +114,7 @@ Station::~Station()
DeleteStationNews(this->index); DeleteStationNews(this->index);
for (CargoID c = 0; c < NUM_CARGO; c++) { for (CargoID c = 0; c < NUM_CARGO; c++) {
this->goods[c].cargo.Truncate(0); this->goods[c].cargo.Truncate();
} }
CargoPacket::InvalidateAllFrom(this->index); CargoPacket::InvalidateAllFrom(this->index);

View File

@ -3307,7 +3307,7 @@ static void UpdateStationRating(Station *st)
waiting_changed = true; waiting_changed = true;
} }
if (waiting_changed) ge->cargo.Truncate(waiting); if (waiting_changed) ge->cargo.Truncate(ge->cargo.Count() - waiting);
} }
} }
} }

View File

@ -769,7 +769,7 @@ void Vehicle::PreDestructor()
} }
InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0);
this->cargo.Truncate(0); this->cargo.Truncate();
DeleteVehicleOrders(this); DeleteVehicleOrders(this);
DeleteDepotHighlightOfVehicle(this); DeleteDepotHighlightOfVehicle(this);

View File

@ -386,14 +386,20 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
/* Store the result */ /* Store the result */
for (RefitResult *result = refit_result.Begin(); result != refit_result.End(); result++) { for (RefitResult *result = refit_result.Begin(); result != refit_result.End(); result++) {
Vehicle *u = result->v; 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_type = new_cid;
u->cargo_cap = result->capacity; u->cargo_cap = result->capacity;
u->cargo_subtype = new_subtype; u->cargo_subtype = new_subtype;
if (u->type == VEH_AIRCRAFT) { if (u->type == VEH_AIRCRAFT) {
Vehicle *w = u->Next(); 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_cap = result->mail_capacity;
w->cargo.Truncate(result->mail_capacity);
} }
} }
} }