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

This commit is contained in:
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();
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);

View File

@ -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);
}
}

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
* 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;
}
/**

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}
}

View File

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

View File

@ -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);
}
}
}