1
0
Fork 0

Codechange: Rename short CargoType parameters `cargo`. (#13848)

Rename CargoType variables and parameters using short or meaningless names.
pull/13886/head
Peter Nelson 2025-03-24 18:18:21 +00:00 committed by GitHub
parent bdea29c414
commit b96b26ef15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 163 additions and 163 deletions

View File

@ -552,12 +552,12 @@ static GUIEngineList::FilterFunction * const _engine_filter_funcs[] = {
static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype) static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype)
{ {
uint weight = 0; uint weight = 0;
for (CargoType c = 0; c < NUM_CARGO; c++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (cap[c] != 0) { if (cap[cargo] != 0) {
if (vtype == VEH_TRAIN) { if (vtype == VEH_TRAIN) {
weight += CargoSpec::Get(c)->WeightOfNUnitsInTrain(cap[c]); weight += CargoSpec::Get(cargo)->WeightOfNUnitsInTrain(cap[cargo]);
} else { } else {
weight += CargoSpec::Get(c)->WeightOfNUnits(cap[c]); weight += CargoSpec::Get(cargo)->WeightOfNUnits(cap[cargo]);
} }
} }
} }

View File

@ -103,7 +103,7 @@ namespace CargoFilterCriteria {
}; };
/** Test whether cargo type is not INVALID_CARGO */ /** Test whether cargo type is not INVALID_CARGO */
inline bool IsValidCargoType(CargoType t) { return t != INVALID_CARGO; } inline bool IsValidCargoType(CargoType cargo) { return cargo != INVALID_CARGO; }
typedef uint64_t CargoTypes; typedef uint64_t CargoTypes;

View File

@ -229,13 +229,13 @@ extern std::span<const CargoSpec *> _sorted_standard_cargo_specs;
/** /**
* Does cargo \a c have cargo class \a cc? * Does cargo \a c have cargo class \a cc?
* @param c Cargo type. * @param cargo Cargo type.
* @param cc Cargo class. * @param cc Cargo class.
* @return The type fits in the class. * @return The type fits in the class.
*/ */
inline bool IsCargoInClass(CargoType c, CargoClasses cc) inline bool IsCargoInClass(CargoType cargo, CargoClasses cc)
{ {
return CargoSpec::Get(c)->classes.Any(cc); return CargoSpec::Get(cargo)->classes.Any(cc);
} }
using SetCargoBitIterator = SetBitIterator<CargoType, CargoTypes>; using SetCargoBitIterator = SetBitIterator<CargoType, CargoTypes>;

View File

@ -32,7 +32,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update);
void StartupIndustryDailyChanges(bool init_counter); void StartupIndustryDailyChanges(bool init_counter);
Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_periods, CargoType cargo_type); Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_periods, CargoType cargo_type);
uint MoveGoodsToStation(CargoType type, uint amount, Source source, const StationList &all_stations, Owner exclusivity = INVALID_OWNER); uint MoveGoodsToStation(CargoType cargo, uint amount, Source source, const StationList &all_stations, Owner exclusivity = INVALID_OWNER);
void PrepareUnload(Vehicle *front_v); void PrepareUnload(Vehicle *front_v);
void LoadUnloadStation(Station *st); void LoadUnloadStation(Station *st);

View File

@ -455,20 +455,20 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca
} }
for (uint8_t i = 0; i < std::size(itspec->accepts_cargo); i++) { for (uint8_t i = 0; i < std::size(itspec->accepts_cargo); i++) {
CargoType a = accepts_cargo[i]; CargoType cargo = accepts_cargo[i];
if (!IsValidCargoType(a) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes if (!IsValidCargoType(cargo) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes
/* Add accepted cargo */ /* Add accepted cargo */
acceptance[a] += cargo_acceptance[i]; acceptance[cargo] += cargo_acceptance[i];
/* Maybe set 'always accepted' bit (if it's not set already) */ /* Maybe set 'always accepted' bit (if it's not set already) */
if (HasBit(always_accepted, a)) continue; if (HasBit(always_accepted, cargo)) continue;
/* Test whether the industry itself accepts the cargo type */ /* Test whether the industry itself accepts the cargo type */
if (ind->IsCargoAccepted(a)) continue; if (ind->IsCargoAccepted(cargo)) continue;
/* If the industry itself doesn't accept this cargo, set 'always accepted' bit */ /* If the industry itself doesn't accept this cargo, set 'always accepted' bit */
SetBit(always_accepted, a); SetBit(always_accepted, cargo);
} }
} }
@ -2761,11 +2761,11 @@ int WhoCanServiceIndustry(Industry *ind)
/** /**
* Report news that industry production has changed significantly * Report news that industry production has changed significantly
* *
* @param ind: Industry with changed production * @param ind Industry with changed production
* @param type: Cargo type that has changed * @param cargo Cargo type that has changed
* @param percent: Percentage of change (>0 means increase, <0 means decrease) * @param percent Percentage of change (>0 means increase, <0 means decrease)
*/ */
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoType type, int percent) static void ReportNewsProductionChangeIndustry(Industry *ind, CargoType cargo, int percent)
{ {
NewsType nt; NewsType nt;
@ -2777,7 +2777,7 @@ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoType type, in
} }
AddIndustryNewsItem( AddIndustryNewsItem(
GetEncodedString(percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH, GetEncodedString(percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH,
CargoSpec::Get(type)->name, ind->index, abs(percent) CargoSpec::Get(cargo)->name, ind->index, abs(percent)
), ),
nt, nt,
ind->index ind->index

View File

@ -86,12 +86,12 @@ void LinkGraphOverlay::RebuildCache()
StationLinkMap &seen_links = this->cached_links[from]; StationLinkMap &seen_links = this->cached_links[from];
uint supply = 0; uint supply = 0;
for (CargoType c : SetCargoBitIterator(this->cargo_mask)) { for (CargoType cargo : SetCargoBitIterator(this->cargo_mask)) {
if (!CargoSpec::Get(c)->IsValid()) continue; if (!CargoSpec::Get(cargo)->IsValid()) continue;
if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue; if (!LinkGraph::IsValidID(sta->goods[cargo].link_graph)) continue;
const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph); const LinkGraph &lg = *LinkGraph::Get(sta->goods[cargo].link_graph);
ConstNode &from_node = lg[sta->goods[c].node]; ConstNode &from_node = lg[sta->goods[cargo].node];
supply += lg.Monthly(from_node.supply); supply += lg.Monthly(from_node.supply);
for (const Edge &edge : from_node.edges) { for (const Edge &edge : from_node.edges) {
StationID to = lg[edge.dest_node].station; StationID to = lg[edge.dest_node].station;
@ -212,17 +212,17 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
*/ */
void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
{ {
for (CargoType c : SetCargoBitIterator(this->cargo_mask)) { for (CargoType cargo : SetCargoBitIterator(this->cargo_mask)) {
if (!CargoSpec::Get(c)->IsValid()) continue; if (!CargoSpec::Get(cargo)->IsValid()) continue;
const GoodsEntry &ge = from->goods[c]; const GoodsEntry &ge = from->goods[cargo];
if (!LinkGraph::IsValidID(ge.link_graph) || if (!LinkGraph::IsValidID(ge.link_graph) ||
ge.link_graph != to->goods[c].link_graph) { ge.link_graph != to->goods[cargo].link_graph) {
continue; continue;
} }
const LinkGraph &lg = *LinkGraph::Get(ge.link_graph); const LinkGraph &lg = *LinkGraph::Get(ge.link_graph);
if (lg[ge.node].HasEdgeTo(to->goods[c].node)) { if (lg[ge.node].HasEdgeTo(to->goods[cargo].node)) {
ConstEdge &edge = lg[ge.node][to->goods[c].node]; ConstEdge &edge = lg[ge.node][to->goods[cargo].node];
this->AddStats(c, lg.Monthly(edge.capacity), lg.Monthly(edge.usage), this->AddStats(cargo, lg.Monthly(edge.capacity), lg.Monthly(edge.usage),
ge.HasData() ? ge.GetData().flows.GetFlowVia(to->index) : 0, ge.HasData() ? ge.GetData().flows.GetFlowVia(to->index) : 0,
edge.TravelTime() / Ticks::DAY_TICKS, edge.TravelTime() / Ticks::DAY_TICKS,
from->owner == OWNER_NONE || to->owner == OWNER_NONE, from->owner == OWNER_NONE || to->owner == OWNER_NONE,

View File

@ -202,17 +202,17 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
Station *st = Station::GetIfValid(cur->GetDestination().ToStationID()); Station *st = Station::GetIfValid(cur->GetDestination().ToStationID());
if (st != nullptr && next_station != StationID::Invalid() && next_station != st->index) { if (st != nullptr && next_station != StationID::Invalid() && next_station != st->index) {
Station *st_to = Station::Get(next_station); Station *st_to = Station::Get(next_station);
for (CargoType c = 0; c < NUM_CARGO; c++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
/* Refresh the link and give it a minimum capacity. */ /* Refresh the link and give it a minimum capacity. */
uint cargo_quantity = this->capacities[c]; uint cargo_quantity = this->capacities[cargo];
if (cargo_quantity == 0) continue; if (cargo_quantity == 0) continue;
if (this->vehicle->GetDisplayMaxSpeed() == 0) continue; if (this->vehicle->GetDisplayMaxSpeed() == 0) continue;
/* If not allowed to merge link graphs, make sure the stations are /* If not allowed to merge link graphs, make sure the stations are
* already in the same link graph. */ * already in the same link graph. */
if (!this->allow_merge && st->goods[c].link_graph != st_to->goods[c].link_graph) { if (!this->allow_merge && st->goods[cargo].link_graph != st_to->goods[cargo].link_graph) {
continue; continue;
} }
@ -234,16 +234,16 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
this->vehicle->orders->GetTotalDuration() > this->vehicle->current_order_time) { this->vehicle->orders->GetTotalDuration() > this->vehicle->current_order_time) {
uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks; uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
if (effective_capacity > (uint)this->vehicle->orders->GetTotalDuration()) { if (effective_capacity > (uint)this->vehicle->orders->GetTotalDuration()) {
IncreaseStats(st, c, next_station, effective_capacity / IncreaseStats(st, cargo, next_station, effective_capacity /
this->vehicle->orders->GetTotalDuration(), 0, 0, this->vehicle->orders->GetTotalDuration(), 0, 0,
{EdgeUpdateMode::Increase, restricted_mode}); {EdgeUpdateMode::Increase, restricted_mode});
} else if (RandomRange(this->vehicle->orders->GetTotalDuration()) < effective_capacity) { } else if (RandomRange(this->vehicle->orders->GetTotalDuration()) < effective_capacity) {
IncreaseStats(st, c, next_station, 1, 0, 0, {EdgeUpdateMode::Increase, restricted_mode}); IncreaseStats(st, cargo, next_station, 1, 0, 0, {EdgeUpdateMode::Increase, restricted_mode});
} else { } else {
IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, {EdgeUpdateMode::Refresh, restricted_mode}); IncreaseStats(st, cargo, next_station, cargo_quantity, 0, time_estimate, {EdgeUpdateMode::Refresh, restricted_mode});
} }
} else { } else {
IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, {EdgeUpdateMode::Refresh, restricted_mode}); IncreaseStats(st, cargo, next_station, cargo_quantity, 0, time_estimate, {EdgeUpdateMode::Refresh, restricted_mode});
} }
} }
} }
@ -271,8 +271,8 @@ void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8_t fl
} else if (!HasBit(flags, IN_AUTOREFIT)) { } else if (!HasBit(flags, IN_AUTOREFIT)) {
SetBit(flags, IN_AUTOREFIT); SetBit(flags, IN_AUTOREFIT);
LinkRefresher backup(*this); LinkRefresher backup(*this);
for (CargoType c = 0; c != NUM_CARGO; ++c) { for (CargoType cargo = 0; cargo != NUM_CARGO; ++cargo) {
if (CargoSpec::Get(c)->IsValid() && this->HandleRefit(c)) { if (CargoSpec::Get(cargo)->IsValid() && this->HandleRefit(cargo)) {
this->RefreshLinks(cur, next, flags, num_hops); this->RefreshLinks(cur, next, flags, num_hops);
*this = backup; *this = backup;
} }

View File

@ -430,16 +430,16 @@ uint32_t Station::GetNewGRFVariable(const ResolverObject &object, uint8_t variab
/* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */ /* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) { if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
CargoType c = GetCargoTranslation(parameter, object.grffile); CargoType cargo = GetCargoTranslation(parameter, object.grffile);
if (!IsValidCargoType(c)) { if (!IsValidCargoType(cargo)) {
switch (variable) { switch (variable) {
case 0x62: return 0xFFFFFFFF; case 0x62: return 0xFFFFFFFF;
case 0x64: return 0xFF00; case 0x64: return 0xFF00;
default: return 0; default: return 0;
} }
} }
const GoodsEntry *ge = &this->goods[c]; const GoodsEntry *ge = &this->goods[cargo];
switch (variable) { switch (variable) {
case 0x60: return ge->HasData() ? std::min(ge->GetData().cargo.TotalCount(), 4095u) : 0; case 0x60: return ge->HasData() ? std::min(ge->GetData().cargo.TotalCount(), 4095u) : 0;

View File

@ -53,7 +53,7 @@ ScriptCargoList_StationAccepting::ScriptCargoList_StationAccepting(StationID sta
if (!ScriptStation::IsValidStation(station_id)) return; if (!ScriptStation::IsValidStation(station_id)) return;
const Station *st = ::Station::Get(station_id); const Station *st = ::Station::Get(station_id);
for (CargoType i = 0; i < NUM_CARGO; i++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(i); if (HasBit(st->goods[cargo].status, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(cargo);
} }
} }

View File

@ -71,8 +71,8 @@
const IndustrySpec *ins = ::GetIndustrySpec(industry_type); const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
ScriptList *list = new ScriptList(); ScriptList *list = new ScriptList();
for (const CargoType &c : ins->produced_cargo) { for (const CargoType &cargo : ins->produced_cargo) {
if (::IsValidCargoType(c)) list->AddItem(c); if (::IsValidCargoType(cargo)) list->AddItem(cargo);
} }
return list; return list;
@ -85,8 +85,8 @@
const IndustrySpec *ins = ::GetIndustrySpec(industry_type); const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
ScriptList *list = new ScriptList(); ScriptList *list = new ScriptList();
for (const CargoType &c : ins->accepts_cargo) { for (const CargoType &cargo : ins->accepts_cargo) {
if (::IsValidCargoType(c)) list->AddItem(c); if (::IsValidCargoType(cargo)) list->AddItem(cargo);
} }
return list; return list;

View File

@ -99,20 +99,20 @@ Station::~Station()
if (a->targetairport == this->index) a->targetairport = StationID::Invalid(); if (a->targetairport == this->index) a->targetairport = StationID::Invalid();
} }
for (CargoType c = 0; c < NUM_CARGO; ++c) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph); LinkGraph *lg = LinkGraph::GetIfValid(this->goods[cargo].link_graph);
if (lg == nullptr) continue; if (lg == nullptr) continue;
for (NodeID node = 0; node < lg->Size(); ++node) { for (NodeID node = 0; node < lg->Size(); ++node) {
Station *st = Station::Get((*lg)[node].station); Station *st = Station::Get((*lg)[node].station);
if (!st->goods[c].HasData()) continue; if (!st->goods[cargo].HasData()) continue;
st->goods[c].GetData().flows.erase(this->index); st->goods[cargo].GetData().flows.erase(this->index);
if ((*lg)[node].HasEdgeTo(this->goods[c].node) && (*lg)[node][this->goods[c].node].LastUpdate() != EconomyTime::INVALID_DATE) { if ((*lg)[node].HasEdgeTo(this->goods[cargo].node) && (*lg)[node][this->goods[cargo].node].LastUpdate() != EconomyTime::INVALID_DATE) {
st->goods[c].GetData().flows.DeleteFlows(this->index); st->goods[cargo].GetData().flows.DeleteFlows(this->index);
RerouteCargo(st, c, this->index, st->index); RerouteCargo(st, cargo, this->index, st->index);
} }
} }
lg->RemoveNode(this->goods[c].node); lg->RemoveNode(this->goods[cargo].node);
if (lg->Size() == 0) { if (lg->Size() == 0) {
LinkGraphSchedule::instance.Unqueue(lg); LinkGraphSchedule::instance.Unqueue(lg);
delete lg; delete lg;

View File

@ -630,17 +630,17 @@ void UpdateStationAcceptance(Station *st, bool show_msg)
} }
/* Adjust in case our station only accepts fewer kinds of goods */ /* Adjust in case our station only accepts fewer kinds of goods */
for (CargoType i = 0; i < NUM_CARGO; i++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
uint amt = acceptance[i]; uint amt = acceptance[cargo];
/* Make sure the station can accept the goods type. */ /* Make sure the station can accept the goods type. */
bool is_passengers = IsCargoInClass(i, CargoClass::Passengers); bool is_passengers = IsCargoInClass(cargo, CargoClass::Passengers);
if ((!is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::TruckStop, StationFacility::Airport, StationFacility::Dock})) || if ((!is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::TruckStop, StationFacility::Airport, StationFacility::Dock})) ||
(is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::BusStop, StationFacility::Airport, StationFacility::Dock}))) { (is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::BusStop, StationFacility::Airport, StationFacility::Dock}))) {
amt = 0; amt = 0;
} }
GoodsEntry &ge = st->goods[i]; GoodsEntry &ge = st->goods[cargo];
SB(ge.status, GoodsEntry::GES_ACCEPTANCE, 1, amt >= 8); SB(ge.status, GoodsEntry::GES_ACCEPTANCE, 1, amt >= 8);
if (LinkGraph::IsValidID(ge.link_graph)) { if (LinkGraph::IsValidID(ge.link_graph)) {
(*LinkGraph::Get(ge.link_graph))[ge.node].SetDemand(amt / 8); (*LinkGraph::Get(ge.link_graph))[ge.node].SetDemand(amt / 8);
@ -3988,13 +3988,13 @@ static void UpdateStationRating(Station *st)
* Reroute cargo of type c at station st or in any vehicles unloading there. * Reroute cargo of type c at station st or in any vehicles unloading there.
* Make sure the cargo's new next hop is neither "avoid" nor "avoid2". * Make sure the cargo's new next hop is neither "avoid" nor "avoid2".
* @param st Station to be rerouted at. * @param st Station to be rerouted at.
* @param c Type of cargo. * @param cargo Type of cargo.
* @param avoid Original next hop of cargo, avoid this. * @param avoid Original next hop of cargo, avoid this.
* @param avoid2 Another station to be avoided when rerouting. * @param avoid2 Another station to be avoided when rerouting.
*/ */
void RerouteCargo(Station *st, CargoType c, StationID avoid, StationID avoid2) void RerouteCargo(Station *st, CargoType cargo, StationID avoid, StationID avoid2)
{ {
GoodsEntry &ge = st->goods[c]; GoodsEntry &ge = st->goods[cargo];
/* Reroute cargo in station. */ /* Reroute cargo in station. */
if (ge.HasData()) ge.GetData().cargo.Reroute(UINT_MAX, &ge.GetData().cargo, avoid, avoid2, &ge); if (ge.HasData()) ge.GetData().cargo.Reroute(UINT_MAX, &ge.GetData().cargo, avoid, avoid2, &ge);
@ -4002,7 +4002,7 @@ void RerouteCargo(Station *st, CargoType c, StationID avoid, StationID avoid2)
/* Reroute cargo staged to be transferred. */ /* Reroute cargo staged to be transferred. */
for (Vehicle *v : st->loading_vehicles) { for (Vehicle *v : st->loading_vehicles) {
for (Vehicle *u = v; u != nullptr; u = u->Next()) { for (Vehicle *u = v; u != nullptr; u = u->Next()) {
if (u->cargo_type != c) continue; if (u->cargo_type != cargo) continue;
u->cargo.Reroute(UINT_MAX, &u->cargo, avoid, avoid2, &ge); u->cargo.Reroute(UINT_MAX, &u->cargo, avoid, avoid2, &ge);
} }
} }
@ -4018,15 +4018,15 @@ void RerouteCargo(Station *st, CargoType c, StationID avoid, StationID avoid2)
*/ */
void DeleteStaleLinks(Station *from) void DeleteStaleLinks(Station *from)
{ {
for (CargoType c = 0; c < NUM_CARGO; ++c) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
const bool auto_distributed = (_settings_game.linkgraph.GetDistributionType(c) != DT_MANUAL); const bool auto_distributed = (_settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL);
GoodsEntry &ge = from->goods[c]; GoodsEntry &ge = from->goods[cargo];
LinkGraph *lg = LinkGraph::GetIfValid(ge.link_graph); LinkGraph *lg = LinkGraph::GetIfValid(ge.link_graph);
if (lg == nullptr) continue; if (lg == nullptr) continue;
std::vector<NodeID> to_remove{}; std::vector<NodeID> to_remove{};
for (Edge &edge : (*lg)[ge.node].edges) { for (Edge &edge : (*lg)[ge.node].edges) {
Station *to = Station::Get((*lg)[edge.dest_node].station); Station *to = Station::Get((*lg)[edge.dest_node].station);
assert(to->goods[c].node == edge.dest_node); assert(to->goods[cargo].node == edge.dest_node);
assert(TimerGameEconomy::date >= edge.LastUpdate()); assert(TimerGameEconomy::date >= edge.LastUpdate());
auto timeout = TimerGameEconomy::Date(LinkGraph::MIN_TIMEOUT_DISTANCE + (DistanceManhattan(from->xy, to->xy) >> 3)); auto timeout = TimerGameEconomy::Date(LinkGraph::MIN_TIMEOUT_DISTANCE + (DistanceManhattan(from->xy, to->xy) >> 3));
if (TimerGameEconomy::date - edge.LastUpdate() > timeout) { if (TimerGameEconomy::date - edge.LastUpdate() > timeout) {
@ -4079,14 +4079,14 @@ void DeleteStaleLinks(Station *from)
if (!updated) { if (!updated) {
/* If it's still considered dead remove it. */ /* If it's still considered dead remove it. */
to_remove.emplace_back(to->goods[c].node); to_remove.emplace_back(to->goods[cargo].node);
if (ge.HasData()) ge.GetData().flows.DeleteFlows(to->index); if (ge.HasData()) ge.GetData().flows.DeleteFlows(to->index);
RerouteCargo(from, c, to->index, from->index); RerouteCargo(from, cargo, to->index, from->index);
} }
} else if (edge.last_unrestricted_update != EconomyTime::INVALID_DATE && TimerGameEconomy::date - edge.last_unrestricted_update > timeout) { } else if (edge.last_unrestricted_update != EconomyTime::INVALID_DATE && TimerGameEconomy::date - edge.last_unrestricted_update > timeout) {
edge.Restrict(); edge.Restrict();
if (ge.HasData()) ge.GetData().flows.RestrictFlows(to->index); if (ge.HasData()) ge.GetData().flows.RestrictFlows(to->index);
RerouteCargo(from, c, to->index, from->index); RerouteCargo(from, cargo, to->index, from->index);
} else if (edge.last_restricted_update != EconomyTime::INVALID_DATE && TimerGameEconomy::date - edge.last_restricted_update > timeout) { } else if (edge.last_restricted_update != EconomyTime::INVALID_DATE && TimerGameEconomy::date - edge.last_restricted_update > timeout) {
edge.Release(); edge.Release();
} }
@ -4241,13 +4241,13 @@ void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint rad
}); });
} }
static uint UpdateStationWaiting(Station *st, CargoType type, uint amount, Source source) static uint UpdateStationWaiting(Station *st, CargoType cargo, uint amount, Source source)
{ {
/* We can't allocate a CargoPacket? Then don't do anything /* We can't allocate a CargoPacket? Then don't do anything
* at all; i.e. just discard the incoming cargo. */ * at all; i.e. just discard the incoming cargo. */
if (!CargoPacket::CanAllocateItem()) return 0; if (!CargoPacket::CanAllocateItem()) return 0;
GoodsEntry &ge = st->goods[type]; GoodsEntry &ge = st->goods[cargo];
amount += ge.amount_fract; amount += ge.amount_fract;
ge.amount_fract = GB(amount, 0, 8); ge.amount_fract = GB(amount, 0, 8);
@ -4260,7 +4260,7 @@ static uint UpdateStationWaiting(Station *st, CargoType type, uint amount, Sourc
LinkGraph *lg = nullptr; LinkGraph *lg = nullptr;
if (ge.link_graph == LinkGraphID::Invalid()) { if (ge.link_graph == LinkGraphID::Invalid()) {
if (LinkGraph::CanAllocateItem()) { if (LinkGraph::CanAllocateItem()) {
lg = new LinkGraph(type); lg = new LinkGraph(cargo);
LinkGraphSchedule::instance.Queue(lg); LinkGraphSchedule::instance.Queue(lg);
ge.link_graph = lg->index; ge.link_graph = lg->index;
ge.node = lg->AddNode(st); ge.node = lg->AddNode(st);
@ -4277,11 +4277,11 @@ static uint UpdateStationWaiting(Station *st, CargoType type, uint amount, Sourc
SetBit(ge.status, GoodsEntry::GES_RATING); SetBit(ge.status, GoodsEntry::GES_RATING);
} }
TriggerStationRandomisation(st, st->xy, SRT_NEW_CARGO, type); TriggerStationRandomisation(st, st->xy, SRT_NEW_CARGO, cargo);
TriggerStationAnimation(st, st->xy, SAT_NEW_CARGO, type); TriggerStationAnimation(st, st->xy, SAT_NEW_CARGO, cargo);
AirportAnimationTrigger(st, AAT_STATION_NEW_CARGO, type); AirportAnimationTrigger(st, AAT_STATION_NEW_CARGO, cargo);
TriggerRoadStopRandomisation(st, st->xy, RSRT_NEW_CARGO, type); TriggerRoadStopRandomisation(st, st->xy, RSRT_NEW_CARGO, cargo);
TriggerRoadStopAnimation(st, st->xy, SAT_NEW_CARGO, type); TriggerRoadStopAnimation(st, st->xy, SAT_NEW_CARGO, cargo);
SetWindowDirty(WC_STATION_VIEW, st->index); SetWindowDirty(WC_STATION_VIEW, st->index);
@ -4365,18 +4365,18 @@ const StationList &StationFinder::GetStations()
} }
static bool CanMoveGoodsToStation(const Station *st, CargoType type) static bool CanMoveGoodsToStation(const Station *st, CargoType cargo)
{ {
/* Is the station reserved exclusively for somebody else? */ /* Is the station reserved exclusively for somebody else? */
if (st->owner != OWNER_NONE && st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) return false; if (st->owner != OWNER_NONE && st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) return false;
/* Lowest possible rating, better not to give cargo anymore. */ /* Lowest possible rating, better not to give cargo anymore. */
if (st->goods[type].rating == 0) return false; if (st->goods[cargo].rating == 0) return false;
/* Selectively servicing stations, and not this one. */ /* Selectively servicing stations, and not this one. */
if (_settings_game.order.selectgoods && !st->goods[type].HasVehicleEverTriedLoading()) return false; if (_settings_game.order.selectgoods && !st->goods[cargo].HasVehicleEverTriedLoading()) return false;
if (IsCargoInClass(type, CargoClass::Passengers)) { if (IsCargoInClass(cargo, CargoClass::Passengers)) {
/* Passengers are never served by just a truck stop. */ /* Passengers are never served by just a truck stop. */
if (st->facilities == StationFacility::TruckStop) return false; if (st->facilities == StationFacility::TruckStop) return false;
} else { } else {
@ -4386,7 +4386,7 @@ static bool CanMoveGoodsToStation(const Station *st, CargoType type)
return true; return true;
} }
uint MoveGoodsToStation(CargoType type, uint amount, Source source, const StationList &all_stations, Owner exclusivity) uint MoveGoodsToStation(CargoType cargo, uint amount, Source source, const StationList &all_stations, Owner exclusivity)
{ {
/* Return if nothing to do. Also the rounding below fails for 0. */ /* Return if nothing to do. Also the rounding below fails for 0. */
if (all_stations.empty()) return 0; if (all_stations.empty()) return 0;
@ -4398,7 +4398,7 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
for (Station *st : all_stations) { for (Station *st : all_stations) {
if (exclusivity != INVALID_OWNER && exclusivity != st->owner) continue; if (exclusivity != INVALID_OWNER && exclusivity != st->owner) continue;
if (!CanMoveGoodsToStation(st, type)) continue; if (!CanMoveGoodsToStation(st, cargo)) continue;
/* Avoid allocating a vector if there is only one station to significantly /* Avoid allocating a vector if there is only one station to significantly
* improve performance in this common case. */ * improve performance in this common case. */
@ -4418,8 +4418,8 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
if (used_stations.empty()) { if (used_stations.empty()) {
/* only one station around */ /* only one station around */
amount *= first_station->goods[type].rating + 1; amount *= first_station->goods[cargo].rating + 1;
return UpdateStationWaiting(first_station, type, amount, source); return UpdateStationWaiting(first_station, cargo, amount, source);
} }
ReferenceThroughBaseContainer<std::array<uint32_t, OWNER_END.base()>> company_best = {}; // best rating for each company, including OWNER_NONE ReferenceThroughBaseContainer<std::array<uint32_t, OWNER_END.base()>> company_best = {}; // best rating for each company, including OWNER_NONE
@ -4429,7 +4429,7 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
for (auto &p : used_stations) { for (auto &p : used_stations) {
auto owner = p.first->owner; auto owner = p.first->owner;
auto rating = p.first->goods[type].rating; auto rating = p.first->goods[cargo].rating;
if (rating > company_best[owner]) { if (rating > company_best[owner]) {
best_sum += rating - company_best[owner]; // it's usually faster than iterating companies later best_sum += rating - company_best[owner]; // it's usually faster than iterating companies later
company_best[owner] = rating; company_best[owner] = rating;
@ -4447,14 +4447,14 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
Owner owner = p.first->owner; Owner owner = p.first->owner;
/* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company /* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company
* and by (station rating / sum of ratings in a company) to get the result for a single station. */ * and by (station rating / sum of ratings in a company) to get the result for a single station. */
p.second = amount * company_best[owner] * p.first->goods[type].rating / best_sum / company_sum[owner]; p.second = amount * company_best[owner] * p.first->goods[cargo].rating / best_sum / company_sum[owner];
moving += p.second; moving += p.second;
} }
/* If there is some cargo left due to rounding issues distribute it among the best rated stations. */ /* If there is some cargo left due to rounding issues distribute it among the best rated stations. */
if (amount > moving) { if (amount > moving) {
std::stable_sort(used_stations.begin(), used_stations.end(), [type](const StationInfo &a, const StationInfo &b) { std::stable_sort(used_stations.begin(), used_stations.end(), [cargo](const StationInfo &a, const StationInfo &b) {
return b.first->goods[type].rating < a.first->goods[type].rating; return b.first->goods[cargo].rating < a.first->goods[cargo].rating;
}); });
assert(amount - moving <= used_stations.size()); assert(amount - moving <= used_stations.size());
@ -4465,7 +4465,7 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
uint moved = 0; uint moved = 0;
for (auto &p : used_stations) { for (auto &p : used_stations) {
moved += UpdateStationWaiting(p.first, type, p.second, source); moved += UpdateStationWaiting(p.first, cargo, p.second, source);
} }
return moved; return moved;

View File

@ -50,7 +50,7 @@ bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrack
void IncreaseStats(Station *st, const Vehicle *v, StationID next_station_id, uint32_t time); void IncreaseStats(Station *st, const Vehicle *v, StationID next_station_id, uint32_t time);
void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes); void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes);
void RerouteCargo(Station *st, CargoType c, StationID avoid, StationID avoid2); void RerouteCargo(Station *st, CargoType cargo, StationID avoid, StationID avoid2);
/** /**
* Calculates the maintenance cost of a number of station tiles. * Calculates the maintenance cost of a number of station tiles.

View File

@ -86,14 +86,14 @@ int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad,
} }
/* Convert cargo counts to a set of cargo bits, and draw the result. */ /* Convert cargo counts to a set of cargo bits, and draw the result. */
for (CargoType i = 0; i < NUM_CARGO; i++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
switch (sct) { switch (sct) {
case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CargoClass::Passengers)) continue; break; case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(cargo, CargoClass::Passengers)) continue; break;
case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CargoClass::Passengers)) continue; break; case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(cargo, CargoClass::Passengers)) continue; break;
case SCT_ALL: break; case SCT_ALL: break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
if (cargoes[i] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, i); if (cargoes[cargo] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, cargo);
} }
} }
return DrawStringMultiLine(r, GetString(supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO, cargo_mask)); return DrawStringMultiLine(r, GetString(supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO, cargo_mask));
@ -211,16 +211,16 @@ void CheckRedrawRoadWaypointCoverage(const Window *)
* @param left left most coordinate to draw the box at * @param left left most coordinate to draw the box at
* @param right right most coordinate to draw the box at * @param right right most coordinate to draw the box at
* @param y coordinate to draw the box at * @param y coordinate to draw the box at
* @param type Cargo type * @param cargo Cargo type
* @param amount Cargo amount * @param amount Cargo amount
* @param rating ratings data for that particular cargo * @param rating ratings data for that particular cargo
*/ */
static void StationsWndShowStationRating(int left, int right, int y, CargoType type, uint amount, uint8_t rating) static void StationsWndShowStationRating(int left, int right, int y, CargoType cargo, uint amount, uint8_t rating)
{ {
static const uint units_full = 576; ///< number of units to show station as 'full' static const uint units_full = 576; ///< number of units to show station as 'full'
static const uint rating_full = 224; ///< rating needed so it is shown as 'full' static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
const CargoSpec *cs = CargoSpec::Get(type); const CargoSpec *cs = CargoSpec::Get(cargo);
if (!cs->IsValid()) return; if (!cs->IsValid()) return;
int padding = ScaleGUITrad(1); int padding = ScaleGUITrad(1);
@ -314,13 +314,13 @@ protected:
if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) { if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
bool has_rating = false; bool has_rating = false;
/* Add to the station/cargo counts. */ /* Add to the station/cargo counts. */
for (CargoType j = 0; j < NUM_CARGO; j++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (st->goods[j].HasRating()) this->stations_per_cargo_type[j]++; if (st->goods[cargo].HasRating()) this->stations_per_cargo_type[cargo]++;
} }
for (CargoType j = 0; j < NUM_CARGO; j++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (st->goods[j].HasRating()) { if (st->goods[cargo].HasRating()) {
has_rating = true; has_rating = true;
if (HasBit(this->filter.cargoes, j)) { if (HasBit(this->filter.cargoes, cargo)) {
this->stations.push_back(st); this->stations.push_back(st);
break; break;
} }
@ -359,8 +359,8 @@ protected:
{ {
int diff = 0; int diff = 0;
for (CargoType j : SetCargoBitIterator(cargo_filter)) { for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
diff += (a->goods[j].HasData() ? a->goods[j].GetData().cargo.TotalCount() : 0) - (b->goods[j].HasData() ? b->goods[j].GetData().cargo.TotalCount() : 0); diff += (a->goods[cargo].HasData() ? a->goods[cargo].GetData().cargo.TotalCount() : 0) - (b->goods[cargo].HasData() ? b->goods[cargo].GetData().cargo.TotalCount() : 0);
} }
return diff < 0; return diff < 0;
@ -371,8 +371,8 @@ protected:
{ {
int diff = 0; int diff = 0;
for (CargoType j : SetCargoBitIterator(cargo_filter)) { for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
diff += (a->goods[j].HasData() ? a->goods[j].GetData().cargo.AvailableCount() : 0) - (b->goods[j].HasData() ? b->goods[j].GetData().cargo.AvailableCount() : 0); diff += (a->goods[cargo].HasData() ? a->goods[cargo].GetData().cargo.AvailableCount() : 0) - (b->goods[cargo].HasData() ? b->goods[cargo].GetData().cargo.AvailableCount() : 0);
} }
return diff < 0; return diff < 0;
@ -384,9 +384,9 @@ protected:
uint8_t maxr1 = 0; uint8_t maxr1 = 0;
uint8_t maxr2 = 0; uint8_t maxr2 = 0;
for (CargoType j : SetCargoBitIterator(cargo_filter)) { for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating); if (a->goods[cargo].HasRating()) maxr1 = std::max(maxr1, a->goods[cargo].rating);
if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating); if (b->goods[cargo].HasRating()) maxr2 = std::max(maxr2, b->goods[cargo].rating);
} }
return maxr1 < maxr2; return maxr1 < maxr2;
@ -398,9 +398,9 @@ protected:
uint8_t minr1 = 255; uint8_t minr1 = 255;
uint8_t minr2 = 255; uint8_t minr2 = 255;
for (CargoType j : SetCargoBitIterator(cargo_filter)) { for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating); if (a->goods[cargo].HasRating()) minr1 = std::min(minr1, a->goods[cargo].rating);
if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating); if (b->goods[cargo].HasRating()) minr2 = std::min(minr2, b->goods[cargo].rating);
} }
return minr1 > minr2; return minr1 > minr2;
@ -851,19 +851,19 @@ static constexpr NWidgetPart _nested_station_view_widgets[] = {
/** /**
* Draws icons of waiting cargo in the StationView window * Draws icons of waiting cargo in the StationView window
* *
* @param i type of cargo * @param cargo type of cargo
* @param waiting number of waiting units * @param waiting number of waiting units
* @param left left most coordinate to draw on * @param left left most coordinate to draw on
* @param right right most coordinate to draw on * @param right right most coordinate to draw on
* @param y y coordinate * @param y y coordinate
*/ */
static void DrawCargoIcons(CargoType i, uint waiting, int left, int right, int y) static void DrawCargoIcons(CargoType cargo, uint waiting, int left, int right, int y)
{ {
int width = ScaleSpriteTrad(10); int width = ScaleSpriteTrad(10);
uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow
if (num == 0) return; if (num == 0) return;
SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon(); SpriteID sprite = CargoSpec::Get(cargo)->GetCargoIcon();
int x = _current_text_dir == TD_RTL ? left : right - num * width; int x = _current_text_dir == TD_RTL ? left : right - num * width;
do { do {
@ -1029,17 +1029,17 @@ public:
void Clear(); void Clear();
private: private:
CargoDataEntry(StationID st, uint c, CargoDataEntry *p); CargoDataEntry(StationID station, uint count, CargoDataEntry *parent);
CargoDataEntry(CargoType car, uint c, CargoDataEntry *p); CargoDataEntry(CargoType cargo, uint count, CargoDataEntry *parent);
CargoDataEntry(StationID st); CargoDataEntry(StationID station);
CargoDataEntry(CargoType car); CargoDataEntry(CargoType cargo);
CargoDataEntry *Retrieve(CargoDataSet::iterator i) const; CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
template <class Tid> template <class Tid>
CargoDataEntry *InsertOrRetrieve(Tid s); CargoDataEntry *InsertOrRetrieve(Tid s);
void Remove(CargoDataEntry *comp); void Remove(CargoDataEntry *entry);
void IncrementSize(); void IncrementSize();
CargoDataEntry *parent; ///< the parent of this entry. CargoDataEntry *parent; ///< the parent of this entry.
@ -1124,9 +1124,9 @@ void CargoDataEntry::Clear()
* which only contains the ID of the entry to be removed. In this case child is * which only contains the ID of the entry to be removed. In this case child is
* not deleted. * not deleted.
*/ */
void CargoDataEntry::Remove(CargoDataEntry *child) void CargoDataEntry::Remove(CargoDataEntry *entry)
{ {
CargoDataSet::iterator i = this->children->find(child); CargoDataSet::iterator i = this->children->find(entry);
if (i != this->children->end()) { if (i != this->children->end()) {
delete *i; delete *i;
this->children->erase(i); this->children->erase(i);
@ -1518,17 +1518,17 @@ struct StationViewWindow : public Window {
* even if we actually don't know the destination of a certain packet from just looking at it. * even if we actually don't know the destination of a certain packet from just looking at it.
* @param i Cargo to recalculate the cache for. * @param i Cargo to recalculate the cache for.
*/ */
void RecalcDestinations(CargoType i) void RecalcDestinations(CargoType cargo)
{ {
const Station *st = Station::Get(this->window_number); const Station *st = Station::Get(this->window_number);
CargoDataEntry *cargo_entry = cached_destinations.InsertOrRetrieve(i); CargoDataEntry *entry = cached_destinations.InsertOrRetrieve(cargo);
cargo_entry->Clear(); entry->Clear();
if (!st->goods[i].HasData()) return; if (!st->goods[cargo].HasData()) return;
for (const auto &it : st->goods[i].GetData().flows) { for (const auto &it : st->goods[cargo].GetData().flows) {
StationID from = it.first; StationID from = it.first;
CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from); CargoDataEntry *source_entry = entry->InsertOrRetrieve(from);
uint32_t prev_count = 0; uint32_t prev_count = 0;
for (const auto &flow_it : *it.second.GetShares()) { for (const auto &flow_it : *it.second.GetShares()) {
StationID via = flow_it.second; StationID via = flow_it.second;
@ -1536,7 +1536,7 @@ struct StationViewWindow : public Window {
if (via == this->window_number) { if (via == this->window_number) {
via_entry->InsertOrRetrieve(via)->Update(flow_it.first - prev_count); via_entry->InsertOrRetrieve(via)->Update(flow_it.first - prev_count);
} else { } else {
EstimateDestinations(i, from, via, flow_it.first - prev_count, via_entry); EstimateDestinations(cargo, from, via, flow_it.first - prev_count, via_entry);
} }
prev_count = flow_it.first; prev_count = flow_it.first;
} }
@ -1604,13 +1604,13 @@ struct StationViewWindow : public Window {
/** /**
* Build up the cargo view for PLANNED mode and a specific cargo. * Build up the cargo view for PLANNED mode and a specific cargo.
* @param i Cargo to show. * @param cargo Cargo to show.
* @param flows The current station's flows for that cargo. * @param flows The current station's flows for that cargo.
* @param cargo The CargoDataEntry to save the results in. * @param entry The CargoDataEntry to save the results in.
*/ */
void BuildFlowList(CargoType i, const FlowStatMap &flows, CargoDataEntry *cargo) void BuildFlowList(CargoType cargo, const FlowStatMap &flows, CargoDataEntry *entry)
{ {
const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i); const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(cargo);
for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) { for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
StationID from = it->first; StationID from = it->first;
const CargoDataEntry *source_entry = source_dest->Retrieve(from); const CargoDataEntry *source_entry = source_dest->Retrieve(from);
@ -1619,7 +1619,7 @@ struct StationViewWindow : public Window {
const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second); const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second);
for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) { for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
CargoDataEntry *dest_entry = *dest_it; CargoDataEntry *dest_entry = *dest_it;
ShowCargo(cargo, i, from, flow_it->second, dest_entry->GetStation(), dest_entry->GetCount()); ShowCargo(entry, cargo, from, flow_it->second, dest_entry->GetStation(), dest_entry->GetCount());
} }
} }
} }
@ -1627,26 +1627,26 @@ struct StationViewWindow : public Window {
/** /**
* Build up the cargo view for WAITING mode and a specific cargo. * Build up the cargo view for WAITING mode and a specific cargo.
* @param i Cargo to show. * @param cargo Cargo to show.
* @param packets The current station's cargo list for that cargo. * @param packets The current station's cargo list for that cargo.
* @param cargo The CargoDataEntry to save the result in. * @param entry The CargoDataEntry to save the result in.
*/ */
void BuildCargoList(CargoType i, const StationCargoList &packets, CargoDataEntry *cargo) void BuildCargoList(CargoType cargo, const StationCargoList &packets, CargoDataEntry *entry)
{ {
const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i); const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(cargo);
for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) { for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) {
const CargoPacket *cp = *it; const CargoPacket *cp = *it;
StationID next = it.GetKey(); StationID next = it.GetKey();
const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation()); const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation());
if (source_entry == nullptr) { if (source_entry == nullptr) {
this->ShowCargo(cargo, i, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count()); this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count());
continue; continue;
} }
const CargoDataEntry *via_entry = source_entry->Retrieve(next); const CargoDataEntry *via_entry = source_entry->Retrieve(next);
if (via_entry == nullptr) { if (via_entry == nullptr) {
this->ShowCargo(cargo, i, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count()); this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count());
continue; continue;
} }
@ -1667,50 +1667,50 @@ struct StationViewWindow : public Window {
val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount())); val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount()));
remaining -= val; remaining -= val;
} }
this->ShowCargo(cargo, i, cp->GetFirstStation(), next, dest_entry->GetStation(), val); this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, dest_entry->GetStation(), val);
} }
} }
this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount()); this->ShowCargo(entry, cargo, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
} }
/** /**
* Build up the cargo view for all cargoes. * Build up the cargo view for all cargoes.
* @param cargo The root cargo entry to save all results in. * @param entry The root cargo entry to save all results in.
* @param st The station to calculate the cargo view from. * @param st The station to calculate the cargo view from.
*/ */
void BuildCargoList(CargoDataEntry *cargo, const Station *st) void BuildCargoList(CargoDataEntry *entry, const Station *st)
{ {
for (CargoType i = 0; i < NUM_CARGO; i++) { for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (this->cached_destinations.Retrieve(i) == nullptr) { if (this->cached_destinations.Retrieve(cargo) == nullptr) {
this->RecalcDestinations(i); this->RecalcDestinations(cargo);
} }
const GoodsEntry &ge = st->goods[i]; const GoodsEntry &ge = st->goods[cargo];
if (!ge.HasData()) continue; if (!ge.HasData()) continue;
if (this->current_mode == MODE_WAITING) { if (this->current_mode == MODE_WAITING) {
this->BuildCargoList(i, ge.GetData().cargo, cargo); this->BuildCargoList(cargo, ge.GetData().cargo, entry);
} else { } else {
this->BuildFlowList(i, ge.GetData().flows, cargo); this->BuildFlowList(cargo, ge.GetData().flows, entry);
} }
} }
} }
/** /**
* Mark a specific row, characterized by its CargoDataEntry, as expanded. * Mark a specific row, characterized by its CargoDataEntry, as expanded.
* @param data The row to be marked as expanded. * @param entry The row to be marked as expanded.
*/ */
void SetDisplayedRow(const CargoDataEntry *data) void SetDisplayedRow(const CargoDataEntry *entry)
{ {
std::list<StationID> stations; std::list<StationID> stations;
const CargoDataEntry *parent = data->GetParent(); const CargoDataEntry *parent = entry->GetParent();
if (parent->GetParent() == nullptr) { if (parent->GetParent() == nullptr) {
this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, data->GetCargo())); this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, entry->GetCargo()));
return; return;
} }
StationID next = data->GetStation(); StationID next = entry->GetStation();
while (parent->GetParent()->GetParent() != nullptr) { while (parent->GetParent()->GetParent() != nullptr) {
stations.push_back(parent->GetStation()); stations.push_back(parent->GetStation());
parent = parent->GetParent(); parent = parent->GetParent();

View File

@ -535,7 +535,7 @@ static void AdvanceHouseConstruction(TileIndex tile)
* @param stations Available stations for this house. * @param stations Available stations for this house.
* @param affected_by_recession Is this cargo halved during recessions? * @param affected_by_recession Is this cargo halved during recessions?
*/ */
static void TownGenerateCargo(Town *t, CargoType ct, uint amount, StationFinder &stations, bool affected_by_recession) static void TownGenerateCargo(Town *t, CargoType cargo, uint amount, StationFinder &stations, bool affected_by_recession)
{ {
if (amount == 0) return; if (amount == 0) return;
@ -548,8 +548,8 @@ static void TownGenerateCargo(Town *t, CargoType ct, uint amount, StationFinder
amount = ScaleByCargoScale(amount, true); amount = ScaleByCargoScale(amount, true);
/* Actually generate cargo and update town statistics. */ /* Actually generate cargo and update town statistics. */
t->supplied[ct].new_max += amount; t->supplied[cargo].new_max += amount;
t->supplied[ct].new_act += MoveGoodsToStation(ct, amount, {t->index, SourceType::Town}, stations.GetStations());; t->supplied[cargo].new_act += MoveGoodsToStation(cargo, amount, {t->index, SourceType::Town}, stations.GetStations());;
} }
/** /**