(svn r17813) -Codechange: unify the CargoPacket related coding style

pull/155/head
rubidium 15 years ago
parent 3adaa57a2e
commit fe575367f9

@ -73,7 +73,7 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, StationID source, T
{ {
CargoPacket *cp; CargoPacket *cp;
FOR_ALL_CARGOPACKETS(cp) { FOR_ALL_CARGOPACKETS(cp) {
if (cp->source == sid) cp->source_id = INVALID_SOURCE; if (cp->source == sid) cp->source = INVALID_STATION;
} }
} }
@ -86,9 +86,8 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, StationID source, T
template <class Tinst> template <class Tinst>
CargoList<Tinst>::~CargoList() CargoList<Tinst>::~CargoList()
{ {
while (!this->packets.empty()) { for (Iterator it(this->packets.begin()); it != this->packets.end(); ++it) {
delete this->packets.front(); delete *it;
this->packets.pop_front();
} }
} }
@ -111,7 +110,7 @@ void CargoList<Tinst>::Append(CargoPacket *cp)
{ {
assert(cp != NULL); assert(cp != NULL);
for (List::iterator it = this->packets.begin(); it != this->packets.end(); it++) { for (Iterator it(this->packets.begin()); it != this->packets.end(); it++) {
CargoPacket *icp = *it; CargoPacket *icp = *it;
if (Tinst::AreMergable(icp, cp) && icp->count + cp->count <= CargoPacket::MAX_COUNT) { if (Tinst::AreMergable(icp, cp) && icp->count + cp->count <= CargoPacket::MAX_COUNT) {
icp->count += cp->count; icp->count += cp->count;
@ -132,11 +131,11 @@ void CargoList<Tinst>::Append(CargoPacket *cp)
template <class Tinst> template <class Tinst>
void CargoList<Tinst>::Truncate(uint max_remaining) void CargoList<Tinst>::Truncate(uint max_remaining)
{ {
for (List::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) {
/* Nothing should remain, just remove the packets. */ /* Nothing should remain, just remove the packets. */
packets.erase(it++); this->packets.erase(it++);
static_cast<Tinst *>(this)->RemoveFromCache(cp); static_cast<Tinst *>(this)->RemoveFromCache(cp);
delete cp; delete cp;
continue; continue;
@ -163,8 +162,8 @@ bool CargoList<Tinst>::MoveTo(Tother_inst *dest, uint max_move, MoveToAction mta
assert(mta == MTA_FINAL_DELIVERY || dest != NULL); assert(mta == MTA_FINAL_DELIVERY || dest != NULL);
assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL); assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL);
List::iterator it = packets.begin(); Iterator it(this->packets.begin());
while (it != packets.end() && max_move > 0) { while (it != this->packets.end() && max_move > 0) {
CargoPacket *cp = *it; CargoPacket *cp = *it;
if (cp->source == data && mta == MTA_FINAL_DELIVERY) { if (cp->source == data && mta == MTA_FINAL_DELIVERY) {
/* Skip cargo that originated from this station. */ /* Skip cargo that originated from this station. */
@ -241,7 +240,7 @@ void CargoList<Tinst>::InvalidateCache()
this->count = 0; this->count = 0;
this->cargo_days_in_transit = 0; this->cargo_days_in_transit = 0;
for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) { for (ConstIterator it(this->packets.begin()); it != this->packets.end(); it++) {
static_cast<Tinst *>(this)->AddToCache(*it); static_cast<Tinst *>(this)->AddToCache(*it);
} }
} }
@ -261,12 +260,13 @@ void VehicleCargoList::AddToCache(const CargoPacket *cp)
void VehicleCargoList::AgeCargo() void VehicleCargoList::AgeCargo()
{ {
for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) { for (ConstIterator it(this->packets.begin()); it != this->packets.end(); it++) {
CargoPacket *cp = *it;
/* If we're at the maximum, then we can't increase no more. */ /* If we're at the maximum, then we can't increase no more. */
if ((*it)->days_in_transit == 0xFF) continue; if (cp->days_in_transit == 0xFF) continue;
(*it)->days_in_transit++; cp->days_in_transit++;
this->cargo_days_in_transit += (*it)->count; this->cargo_days_in_transit += cp->count;
} }
} }

@ -185,8 +185,12 @@ public:
template <class Tinst> template <class Tinst>
class CargoList { class CargoList {
public: public:
/** List of cargo packets */ /** Container with cargo packets */
typedef std::list<CargoPacket *> List; typedef std::list<CargoPacket *> List;
/** The iterator for our container */
typedef List::iterator Iterator;
/** The const iterator for our container */
typedef List::const_iterator ConstIterator;
/** Kind of actions that could be done with packets on move */ /** Kind of actions that could be done with packets on move */
enum MoveToAction { enum MoveToAction {

@ -28,7 +28,7 @@
*/ */
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
const VehicleCargoList::List *packets = v->cargo.Packets(); const VehicleCargoList::List *packets = v->cargo.Packets();
for (VehicleCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
CargoPacket *cp = *it; CargoPacket *cp = *it;
cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile; cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
cp->loaded_at_xy = cp->source_xy; cp->loaded_at_xy = cp->source_xy;
@ -47,7 +47,7 @@
GoodsEntry *ge = &st->goods[c]; GoodsEntry *ge = &st->goods[c];
const StationCargoList::List *packets = ge->cargo.Packets(); const StationCargoList::List *packets = ge->cargo.Packets();
for (StationCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
CargoPacket *cp = *it; CargoPacket *cp = *it;
cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy; cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
cp->loaded_at_xy = cp->source_xy; cp->loaded_at_xy = cp->source_xy;

@ -825,7 +825,7 @@ struct StationViewWindow : public Window {
/* Add an entry for each distinct cargo source. */ /* Add an entry for each distinct cargo source. */
const StationCargoList::List *packets = st->goods[i].cargo.Packets(); const StationCargoList::List *packets = st->goods[i].cargo.Packets();
for (StationCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
const CargoPacket *cp = *it; const CargoPacket *cp = *it;
if (cp->SourceStation() != station_id) { if (cp->SourceStation() != station_id) {
bool added = false; bool added = false;
@ -837,7 +837,7 @@ struct StationViewWindow : public Window {
if (!HasBit(this->cargo, i)) break; if (!HasBit(this->cargo, i)) break;
/* Check if we already have this source in the list */ /* Check if we already have this source in the list */
for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) { for (CargoDataList::iterator jt(cargolist.begin()); jt != cargolist.end(); jt++) {
CargoData *cd = &(*jt); CargoData *cd = &(*jt);
if (cd->cargo == i && cd->source == cp->SourceStation()) { if (cd->cargo == i && cd->source == cp->SourceStation()) {
cd->count += cp->Count(); cd->count += cp->Count();

Loading…
Cancel
Save