(svn r25185) -Fix [FS#5508]: Remove ambivalent functions CargoList::Empty() and Count(), and replace them with VehicleCargoList::StoredCount(), TotalCount(), StationCargoList::AvailableCount() and TotalCount(). (fonsinchen)

This commit is contained in:
frosch 2013-04-13 13:42:08 +00:00
parent 8d1d521456
commit 5eddbb338b
20 changed files with 105 additions and 82 deletions

View File

@ -50,7 +50,7 @@ void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
}
if (u->cargo_cap != 0) {
uint cargo_count = u->cargo.Count();
uint cargo_count = u->cargo.StoredCount();
y_offset += FONT_HEIGHT_NORMAL + 1;
if (cargo_count != 0) {

View File

@ -91,27 +91,32 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
/**
* Check the capacity of all vehicles in a chain and spread cargo if needed.
* @param v The vehicle to check.
* @pre You can only do this if the consist is not loading or unloading. It
* must not carry reserved cargo, nor cargo to be unloaded or transferred.
*/
void CheckCargoCapacity(Vehicle *v)
{
assert(v == NULL || v->First() == v);
for (Vehicle *src = v; src != NULL; src = src->Next()) {
assert(src->cargo.TotalCount() == src->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
/* Do we need to more cargo away? */
if (src->cargo.Count() <= src->cargo_cap) continue;
if (src->cargo.TotalCount() <= src->cargo_cap) continue;
/* We need to move a particular amount. Try that on the other vehicles. */
uint to_spread = src->cargo.Count() - src->cargo_cap;
uint to_spread = src->cargo.TotalCount() - src->cargo_cap;
for (Vehicle *dest = v; dest != NULL && to_spread != 0; dest = dest->Next()) {
if (dest->cargo.Count() >= dest->cargo_cap || dest->cargo_type != src->cargo_type) continue;
assert(dest->cargo.TotalCount() == dest->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
if (dest->cargo.TotalCount() >= dest->cargo_cap || dest->cargo_type != src->cargo_type) continue;
uint amount = min(to_spread, dest->cargo_cap - dest->cargo.Count());
uint amount = min(to_spread, dest->cargo_cap - dest->cargo.TotalCount());
src->cargo.Shift(amount, &dest->cargo);
to_spread -= amount;
}
/* Any left-overs will be thrown away, but not their feeder share. */
if (src->cargo_cap < src->cargo.Count()) src->cargo.Truncate(src->cargo.Count() - src->cargo_cap);
if (src->cargo_cap < src->cargo.TotalCount()) src->cargo.Truncate(src->cargo.TotalCount() - src->cargo_cap);
}
}
@ -120,21 +125,26 @@ void CheckCargoCapacity(Vehicle *v)
* @param old_veh Old vehicle that will be sold
* @param new_head Head of the completely constructed new vehicle chain
* @param part_of_chain The vehicle is part of a train
* @pre You can only do this if both consists are not loading or unloading.
* They must not carry reserved cargo, nor cargo to be unloaded or
* transferred.
*/
static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chain)
{
assert(!part_of_chain || new_head->IsPrimaryVehicle());
/* Loop through source parts */
for (Vehicle *src = old_veh; src != NULL; src = src->Next()) {
assert(src->cargo.TotalCount() == src->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !src->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to old_veh */
src = src->GetLastEnginePart();
continue;
}
if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue;
if (src->cargo_type >= NUM_CARGO || src->cargo.TotalCount() == 0) continue;
/* Find free space in the new chain */
for (Vehicle *dest = new_head; dest != NULL && src->cargo.Count() > 0; dest = dest->Next()) {
for (Vehicle *dest = new_head; dest != NULL && src->cargo.TotalCount() > 0; dest = dest->Next()) {
assert(dest->cargo.TotalCount() == dest->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !dest->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to new_head */
dest = dest->GetLastEnginePart();
@ -142,7 +152,7 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
}
if (dest->cargo_type != src->cargo_type) continue;
uint amount = min(src->cargo.Count(), dest->cargo_cap - dest->cargo.Count());
uint amount = min(src->cargo.TotalCount(), dest->cargo_cap - dest->cargo.TotalCount());
if (amount <= 0) continue;
src->cargo.Shift(amount, &dest->cargo);

View File

@ -248,31 +248,13 @@ public:
return &this->packets;
}
/**
* Checks whether this list is empty.
* @return True if and only if the list is empty.
*/
inline bool Empty() const
{
return this->count == 0;
}
/**
* Returns the number of cargo entities in this list.
* @return The before mentioned number.
*/
inline uint Count() const
{
return this->count;
}
/**
* Returns source of the first cargo packet in this list.
* @return The before mentioned source.
*/
inline StationID Source() const
{
return this->Empty() ? INVALID_STATION : this->packets.front()->source;
return this->count == 0 ? INVALID_STATION : this->packets.front()->source;
}
/**
@ -354,11 +336,29 @@ public:
* reserved).
* @return Cargo on board the vehicle.
*/
inline uint OnboardCount() const
inline uint StoredCount() const
{
return this->count - this->action_counts[MTA_LOAD];
}
/**
* Returns sum of cargo, including reserved cargo.
* @return Sum of cargo.
*/
inline uint TotalCount() const
{
return this->count;
}
/**
* Returns sum of reserved cargo.
* @return Sum of reserved cargo.
*/
inline uint ReservedCount() const
{
return this->action_counts[MTA_LOAD];
}
/**
* Returns sum of cargo to be moved out of the vehicle at the current station.
* @return Cargo to be moved.
@ -445,6 +445,16 @@ public:
friend class CargoReservation;
friend class CargoReturn;
/**
* Returns sum of cargo still available for loading at the sation.
* (i.e. not counting cargo which is already reserved for loading)
* @return Cargo on board the vehicle.
*/
inline uint AvailableCount() const
{
return this->count;
}
/**
* Returns sum of cargo reserved for loading onto vehicles.
* @return Cargo reserved for loading.
@ -455,8 +465,8 @@ public:
}
/**
* Returns total count of cargo, including reserved cargo that's not
* actually in the list.
* Returns total count of cargo at the station, including
* cargo which is already reserved for loading.
* @return Total cargo count.
*/
inline uint TotalCount() const

View File

@ -802,7 +802,7 @@ struct DepotWindow : Window {
for (const Vehicle *w = v; w != NULL; w = w->Next()) {
if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
capacity[w->cargo_type] += w->cargo_cap;
loaded [w->cargo_type] += w->cargo.Count();
loaded [w->cargo_type] += w->cargo.StoredCount();
}
if (w->type == VEH_TRAIN && !w->HasArticulatedPart()) {

View File

@ -1216,7 +1216,7 @@ void PrepareUnload(Vehicle *front_v)
if ((front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
if (v->cargo_cap > 0 && !v->cargo.Empty()) {
if (v->cargo_cap > 0 && v->cargo.TotalCount() > 0) {
v->cargo.Stage(
HasBit(Station::Get(front_v->last_station_visited)->goods[v->cargo_type].acceptance_pickup, GoodsEntry::GES_ACCEPTANCE),
front_v->last_station_visited, front_v->current_order.GetUnloadType());
@ -1323,7 +1323,7 @@ static bool IsArticulatedVehicleEmpty(Vehicle *v)
v = v->GetFirstEnginePart();
for (; v != NULL; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL) {
if (v->cargo.Count() != 0) return false;
if (v->cargo.TotalCount() != 0) return false;
}
return true;
@ -1438,7 +1438,7 @@ static void LoadUnloadVehicle(Vehicle *front)
/* This order has a refit, if this is the first vehicle part carrying cargo and the whole vehicle is empty, try refitting. */
if (front->current_order.IsRefit() && artic_part == 1 && IsArticulatedVehicleEmpty(v) &&
(v->type != VEH_AIRCRAFT || (Aircraft::From(v)->IsNormalAircraft() && v->Next()->cargo.Count() == 0))) {
(v->type != VEH_AIRCRAFT || (Aircraft::From(v)->IsNormalAircraft() && v->Next()->cargo.TotalCount() == 0))) {
Vehicle *v_start = v->GetFirstEnginePart();
CargoID new_cid = front->current_order.GetRefitCargo();
@ -1456,7 +1456,7 @@ static void LoadUnloadVehicle(Vehicle *front)
Vehicle *w = v_start;
while (w->HasArticulatedPart()) {
w = w->GetNextArticulatedPart();
if (w->cargo.Count() > 0) new_cid = CT_NO_REFIT;
if (w->cargo.TotalCount() > 0) new_cid = CT_NO_REFIT;
refit_mask |= EngInfo(w->engine_type)->refit_mask;
}
@ -1467,12 +1467,12 @@ static void LoadUnloadVehicle(Vehicle *front)
FOR_EACH_SET_CARGO_ID(cid, refit_mask) {
/* Consider refitting to this cargo, if other vehicles of the consist cannot
* already take the cargo without refitting */
if ((int)st->goods[cid].cargo.Count() > (int)consist_capleft[cid] + amount) {
if ((int)st->goods[cid].cargo.AvailableCount() > (int)consist_capleft[cid] + amount) {
/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
* the returned refit capacity will be greater than zero. */
DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
if (_returned_refit_capacity > 0) {
amount = st->goods[cid].cargo.Count() - consist_capleft[cid];
amount = st->goods[cid].cargo.AvailableCount() - consist_capleft[cid];
new_cid = cid;
}
}
@ -1490,7 +1490,7 @@ static void LoadUnloadVehicle(Vehicle *front)
w = v_start;
do {
st->goods[w->cargo_type].cargo.Reserve(w->cargo_cap, &w->cargo, st->xy);
consist_capleft[w->cargo_type] += w->cargo_cap - w->cargo.Count();
consist_capleft[w->cargo_type] += w->cargo_cap - w->cargo.RemainingCount();
w = w->HasArticulatedPart() ? w->GetNextArticulatedPart() : NULL;
} while (w != NULL);
@ -1523,10 +1523,10 @@ static void LoadUnloadVehicle(Vehicle *front)
/* If there's goods waiting at the station, and the vehicle
* has capacity for it, load it on the vehicle. */
int cap_left = v->cargo_cap - v->cargo.OnboardCount();
if (cap_left > 0 && (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0 || !ge->cargo.Empty())) {
int cap_left = v->cargo_cap - v->cargo.StoredCount();
if (cap_left > 0 && (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0 || ge->cargo.AvailableCount() > 0)) {
if (_settings_game.order.gradual_loading) cap_left = min(cap_left, load_amount);
if (v->cargo.OnboardCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
uint loaded = ge->cargo.Load(cap_left, &v->cargo, st->xy);
if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
@ -1556,7 +1556,7 @@ static void LoadUnloadVehicle(Vehicle *front)
st->time_since_load = 0;
st->last_vehicle_type = v->type;
if (ge->cargo.Empty()) {
if (ge->cargo.TotalCount() == 0) {
TriggerStationRandomisation(st, st->xy, SRT_CARGO_TAKEN, v->cargo_type);
TriggerStationAnimation(st, st->xy, SAT_CARGO_TAKEN, v->cargo_type);
AirportAnimationTrigger(st, AAT_STATION_CARGO_TAKEN, v->cargo_type);
@ -1568,7 +1568,7 @@ static void LoadUnloadVehicle(Vehicle *front)
}
}
if (v->cargo.OnboardCount() >= v->cargo_cap) {
if (v->cargo.StoredCount() >= v->cargo_cap) {
SetBit(cargo_full, v->cargo_type);
} else {
SetBit(cargo_not_full, v->cargo_type);
@ -1608,7 +1608,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (front->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) {
/* if the aircraft carries passengers and is NOT full, then
* continue loading, no matter how much mail is in */
if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CC_PASSENGERS) && front->cargo_cap > front->cargo.OnboardCount()) ||
if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CC_PASSENGERS) && front->cargo_cap > front->cargo.StoredCount()) ||
(cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes
finished_loading = false;
}

View File

@ -768,8 +768,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
case 0x39: return v->cargo_type;
case 0x3A: return v->cargo_cap;
case 0x3B: return GB(v->cargo_cap, 8, 8);
case 0x3C: return ClampToU16(v->cargo.Count());
case 0x3D: return GB(ClampToU16(v->cargo.Count()), 8, 8);
case 0x3C: return ClampToU16(v->cargo.StoredCount());
case 0x3D: return GB(ClampToU16(v->cargo.StoredCount()), 8, 8);
case 0x3E: return v->cargo.Source();
case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF);
case 0x40: return ClampToU16(v->age);
@ -922,7 +922,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
if (totalsets == 0) return NULL;
uint set = (v->cargo.Count() * totalsets) / max((uint16)1, v->cargo_cap);
uint set = (v->cargo.StoredCount() * totalsets) / max((uint16)1, v->cargo_cap);
set = min(set, totalsets - 1);
return in_motion ? group->loaded[set] : group->loading[set];

View File

@ -421,7 +421,7 @@ uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, b
const GoodsEntry *ge = &this->goods[c];
switch (variable) {
case 0x60: return min(ge->cargo.Count(), 4095);
case 0x60: return min(ge->cargo.TotalCount(), 4095);
case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0;
case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF;
case 0x63: return ge->cargo.DaysInTransit();
@ -440,8 +440,8 @@ uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, b
if (variable >= 0x8C && variable <= 0xEC) {
const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
switch (GB(variable - 0x8C, 0, 3)) {
case 0: return g->cargo.Count();
case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
case 0: return g->cargo.TotalCount();
case 1: return GB(min(g->cargo.TotalCount(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
case 2: return g->time_since_pickup;
case 3: return g->rating;
case 4: return g->cargo.Source();
@ -507,12 +507,12 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject *object, byte variable,
case CT_DEFAULT:
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
cargo += st->goods[cargo_type].cargo.Count();
cargo += st->goods[cargo_type].cargo.TotalCount();
}
break;
default:
cargo = st->goods[this->station_scope.cargo_type].cargo.Count();
cargo = st->goods[this->station_scope.cargo_type].cargo.TotalCount();
break;
}
@ -587,7 +587,7 @@ static const SpriteGroup *ResolveStation(StationResolverObject *object)
const CargoSpec *cs;
FOR_ALL_CARGOSPECS(cs) {
if (object->station_scope.statspec->grf_prop.spritegroup[cs->Index()] != NULL &&
!st->goods[cs->Index()].cargo.Empty()) {
st->goods[cs->Index()].cargo.TotalCount() > 0) {
ctype = cs->Index();
break;
}
@ -998,7 +998,7 @@ void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigg
if (trigger == SRT_CARGO_TAKEN) {
/* Create a bitmask of completely empty cargo types to be matched */
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (st->goods[i].cargo.Empty()) {
if (st->goods[i].cargo.TotalCount() == 0) {
SetBit(empty_mask, i);
}
}

View File

@ -157,7 +157,7 @@ protected: // These functions should not be called outside acceleration code.
*/
inline uint16 GetWeight() const
{
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count()) / 16;
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.StoredCount()) / 16;
/* Vehicle weight is not added for articulated parts. */
if (!this->IsArticulatedPart()) {

View File

@ -133,7 +133,7 @@ SpriteID RoadVehicle::GetImage(Direction direction, EngineImageType image_type)
sprite = direction + _roadveh_images[spritenum];
if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _roadveh_full_adder[spritenum];
if (this->cargo.StoredCount() >= this->cargo_cap / 2U) sprite += _roadveh_full_adder[spritenum];
return sprite;
}

View File

@ -81,9 +81,9 @@ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
if (u->cargo_cap == 0) continue;
str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
if (!u->cargo.Empty()) {
if (u->cargo.StoredCount() > 0) {
SetDParam(0, u->cargo_type);
SetDParam(1, u->cargo.Count());
SetDParam(1, u->cargo.StoredCount());
SetDParam(2, u->cargo.Source());
str = STR_VEHICLE_DETAILS_CARGO_FROM;
feeder_share += u->cargo.FeederShare();
@ -101,9 +101,9 @@ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, STR_VEHICLE_INFO_CAPACITY);
str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
if (!v->cargo.Empty()) {
if (v->cargo.StoredCount() > 0) {
SetDParam(0, v->cargo_type);
SetDParam(1, v->cargo.Count());
SetDParam(1, v->cargo.StoredCount());
SetDParam(2, v->cargo.Source());
str = STR_VEHICLE_DETAILS_CARGO_FROM;
feeder_share += v->cargo.FeederShare();

View File

@ -1539,7 +1539,7 @@ bool AfterLoadGame()
FOR_ALL_STATIONS(st) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
st->goods[c].last_speed = 0;
if (st->goods[c].cargo.Count() != 0) SetBit(st->goods[c].acceptance_pickup, GoodsEntry::GES_PICKUP);
if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].acceptance_pickup, GoodsEntry::GES_PICKUP);
}
}
}

View File

@ -41,7 +41,7 @@
if (!IsValidStation(station_id)) return -1;
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
return ::Station::Get(station_id)->goods[cargo_id].cargo.Count();
return ::Station::Get(station_id)->goods[cargo_id].cargo.TotalCount();
}
/* static */ bool ScriptStation::HasCargoRating(StationID station_id, CargoID cargo_id)

View File

@ -399,7 +399,7 @@
uint32 amount = 0;
for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != NULL; v = v->Next()) {
if (v->cargo_type == cargo) amount += v->cargo.Count();
if (v->cargo_type == cargo) amount += v->cargo.StoredCount();
}
return amount;

View File

@ -70,9 +70,9 @@ void DrawShipDetails(const Vehicle *v, int left, int right, int y)
DrawString(left, right, y + FONT_HEIGHT_NORMAL, STR_VEHICLE_INFO_CAPACITY);
StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
if (!v->cargo.Empty()) {
if (v->cargo.StoredCount() > 0) {
SetDParam(0, v->cargo_type);
SetDParam(1, v->cargo.Count());
SetDParam(1, v->cargo.StoredCount());
SetDParam(2, v->cargo.Source());
str = STR_VEHICLE_DETAILS_CARGO_FROM;
}

View File

@ -3225,7 +3225,7 @@ static void UpdateStationRating(Station *st)
bool skip = false;
int rating = 0;
uint waiting = ge->cargo.Count();
uint waiting = ge->cargo.TotalCount();
if (HasBit(cs->callback_mask, CBM_CARGO_STATION_RATING_CALC)) {
/* Perform custom station rating. If it succeeds the speed, days in transit and
@ -3315,8 +3315,10 @@ static void UpdateStationRating(Station *st)
waiting_changed = true;
}
if (waiting_changed && waiting < ge->cargo.Count()) {
ge->cargo.Truncate(ge->cargo.Count() - waiting);
/* We can't truncate cargo that's already reserved for loading.
* Thus StoredCount() here. */
if (waiting_changed && waiting < ge->cargo.AvailableCount()) {
ge->cargo.Truncate(ge->cargo.AvailableCount() - waiting);
}
}
}

View File

@ -231,8 +231,8 @@ protected:
CargoID j;
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
if (!(*a)->goods[j].cargo.Empty()) diff += GetTransportedGoodsIncome((*a)->goods[j].cargo.Count(), 20, 50, j);
if (!(*b)->goods[j].cargo.Empty()) diff -= GetTransportedGoodsIncome((*b)->goods[j].cargo.Count(), 20, 50, j);
if ((*a)->goods[j].cargo.TotalCount() > 0) diff += GetTransportedGoodsIncome((*a)->goods[j].cargo.TotalCount(), 20, 50, j);
if ((*b)->goods[j].cargo.TotalCount() > 0) diff -= GetTransportedGoodsIncome((*b)->goods[j].cargo.TotalCount(), 20, 50, j);
}
return ClampToI32(diff);
@ -407,7 +407,7 @@ public:
/* show cargo waiting and station ratings */
for (uint j = 0; j < _sorted_standard_cargo_specs_size; j++) {
CargoID cid = _sorted_cargo_specs[j]->Index();
if (!st->goods[cid].cargo.Empty()) {
if (st->goods[cid].cargo.TotalCount() > 0) {
/* For RTL we work in exactly the opposite direction. So
* decrement the space needed first, then draw to the left
* instead of drawing to the left and then incrementing
@ -416,7 +416,7 @@ public:
x -= 20;
if (x < r.left + WD_FRAMERECT_LEFT) break;
}
StationsWndShowStationRating(x, x + 16, y, cid, st->goods[cid].cargo.Count(), st->goods[cid].rating);
StationsWndShowStationRating(x, x + 16, y, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
if (!rtl) {
x += 20;
if (x > r.right - WD_FRAMERECT_RIGHT) break;
@ -934,7 +934,7 @@ struct StationViewWindow : public Window {
/* count types of cargoes waiting in station */
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (st->goods[i].cargo.Empty()) {
if (st->goods[i].cargo.TotalCount() == 0) {
this->cargo_rows[i] = 0;
} else {
/* Add an entry for total amount of cargo of this type waiting. */
@ -994,7 +994,7 @@ struct StationViewWindow : public Window {
if (--pos < 0) {
StringID str = STR_JUST_NOTHING;
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
if (st->goods[i].cargo.TotalCount() > 0) str = STR_EMPTY;
}
SetDParam(0, str);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_VIEW_WAITING_TITLE);

View File

@ -199,7 +199,7 @@ protected: // These functions should not be called outside acceleration code.
*/
inline uint16 GetWeight() const
{
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count() * FreightWagonMult(this->cargo_type)) / 16;
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.StoredCount() * FreightWagonMult(this->cargo_type)) / 16;
/* Vehicle weight is not added for articulated parts. */
if (!this->IsArticulatedPart()) {

View File

@ -477,7 +477,7 @@ SpriteID Train::GetImage(Direction direction, EngineImageType image_type) const
sprite = GetDefaultTrainSprite(spritenum, direction);
if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum];
if (this->cargo.StoredCount() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum];
return sprite;
}

View File

@ -276,7 +276,7 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *su
}
item->capacity += v->cargo_cap;
item->amount += v->cargo.Count();
item->amount += v->cargo.StoredCount();
if (item->source == INVALID_STATION) item->source = v->cargo.Source();
} while ((v = v->Next()) != NULL && v->IsArticulatedPart());
}
@ -311,7 +311,7 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
CargoArray act_cargo;
CargoArray max_cargo;
for (const Vehicle *v = Vehicle::Get(veh_id); v != NULL; v = v->Next()) {
act_cargo[v->cargo_type] += v->cargo.Count();
act_cargo[v->cargo_type] += v->cargo.StoredCount();
max_cargo[v->cargo_type] += v->cargo_cap;
}
@ -424,7 +424,7 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
Money feeder_share = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
act_cargo[u->cargo_type] += u->cargo.Count();
act_cargo[u->cargo_type] += u->cargo.StoredCount();
max_cargo[u->cargo_type] += u->cargo_cap;
feeder_share += u->cargo.FeederShare();
}

View File

@ -189,7 +189,8 @@ uint Vehicle::Crash(bool flooded)
if (this->IsPrimaryVehicle()) this->vehstatus |= VS_STOPPED;
/* crash all wagons, and count passengers */
for (Vehicle *v = this; v != NULL; v = v->Next()) {
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
/* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.TotalCount();
v->vehstatus |= VS_CRASHED;
MarkSingleVehicleDirty(v);
}
@ -1256,7 +1257,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.OnboardCount();
count += v->cargo.StoredCount();
max += v->cargo_cap;
if (v->cargo_cap != 0 && colour != NULL) {
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;