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)
{
uint weight = 0;
for (CargoType c = 0; c < NUM_CARGO; c++) {
if (cap[c] != 0) {
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (cap[cargo] != 0) {
if (vtype == VEH_TRAIN) {
weight += CargoSpec::Get(c)->WeightOfNUnitsInTrain(cap[c]);
weight += CargoSpec::Get(cargo)->WeightOfNUnitsInTrain(cap[cargo]);
} 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 */
inline bool IsValidCargoType(CargoType t) { return t != INVALID_CARGO; }
inline bool IsValidCargoType(CargoType cargo) { return cargo != INVALID_CARGO; }
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?
* @param c Cargo type.
* @param cargo Cargo type.
* @param cc Cargo 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>;

View File

@ -32,7 +32,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update);
void StartupIndustryDailyChanges(bool init_counter);
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 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++) {
CargoType a = accepts_cargo[i];
if (!IsValidCargoType(a) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes
CargoType cargo = accepts_cargo[i];
if (!IsValidCargoType(cargo) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes
/* Add accepted cargo */
acceptance[a] += cargo_acceptance[i];
acceptance[cargo] += cargo_acceptance[i];
/* 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 */
if (ind->IsCargoAccepted(a)) continue;
if (ind->IsCargoAccepted(cargo)) continue;
/* 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
*
* @param ind: Industry with changed production
* @param type: Cargo type that has changed
* @param percent: Percentage of change (>0 means increase, <0 means decrease)
* @param ind Industry with changed production
* @param cargo Cargo type that has changed
* @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;
@ -2777,7 +2777,7 @@ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoType type, in
}
AddIndustryNewsItem(
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,
ind->index

View File

@ -86,12 +86,12 @@ void LinkGraphOverlay::RebuildCache()
StationLinkMap &seen_links = this->cached_links[from];
uint supply = 0;
for (CargoType c : SetCargoBitIterator(this->cargo_mask)) {
if (!CargoSpec::Get(c)->IsValid()) continue;
if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue;
const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph);
for (CargoType cargo : SetCargoBitIterator(this->cargo_mask)) {
if (!CargoSpec::Get(cargo)->IsValid()) continue;
if (!LinkGraph::IsValidID(sta->goods[cargo].link_graph)) continue;
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);
for (const Edge &edge : from_node.edges) {
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)
{
for (CargoType c : SetCargoBitIterator(this->cargo_mask)) {
if (!CargoSpec::Get(c)->IsValid()) continue;
const GoodsEntry &ge = from->goods[c];
for (CargoType cargo : SetCargoBitIterator(this->cargo_mask)) {
if (!CargoSpec::Get(cargo)->IsValid()) continue;
const GoodsEntry &ge = from->goods[cargo];
if (!LinkGraph::IsValidID(ge.link_graph) ||
ge.link_graph != to->goods[c].link_graph) {
ge.link_graph != to->goods[cargo].link_graph) {
continue;
}
const LinkGraph &lg = *LinkGraph::Get(ge.link_graph);
if (lg[ge.node].HasEdgeTo(to->goods[c].node)) {
ConstEdge &edge = lg[ge.node][to->goods[c].node];
this->AddStats(c, lg.Monthly(edge.capacity), lg.Monthly(edge.usage),
if (lg[ge.node].HasEdgeTo(to->goods[cargo].node)) {
ConstEdge &edge = lg[ge.node][to->goods[cargo].node];
this->AddStats(cargo, lg.Monthly(edge.capacity), lg.Monthly(edge.usage),
ge.HasData() ? ge.GetData().flows.GetFlowVia(to->index) : 0,
edge.TravelTime() / Ticks::DAY_TICKS,
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());
if (st != nullptr && next_station != StationID::Invalid() && next_station != st->index) {
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. */
uint cargo_quantity = this->capacities[c];
uint cargo_quantity = this->capacities[cargo];
if (cargo_quantity == 0) continue;
if (this->vehicle->GetDisplayMaxSpeed() == 0) continue;
/* If not allowed to merge link graphs, make sure the stations are
* 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;
}
@ -234,16 +234,16 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
this->vehicle->orders->GetTotalDuration() > this->vehicle->current_order_time) {
uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
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,
{EdgeUpdateMode::Increase, restricted_mode});
} 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 {
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 {
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)) {
SetBit(flags, IN_AUTOREFIT);
LinkRefresher backup(*this);
for (CargoType c = 0; c != NUM_CARGO; ++c) {
if (CargoSpec::Get(c)->IsValid() && this->HandleRefit(c)) {
for (CargoType cargo = 0; cargo != NUM_CARGO; ++cargo) {
if (CargoSpec::Get(cargo)->IsValid() && this->HandleRefit(cargo)) {
this->RefreshLinks(cur, next, flags, num_hops);
*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 */
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) {
case 0x62: return 0xFFFFFFFF;
case 0x64: return 0xFF00;
default: return 0;
}
}
const GoodsEntry *ge = &this->goods[c];
const GoodsEntry *ge = &this->goods[cargo];
switch (variable) {
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;
const Station *st = ::Station::Get(station_id);
for (CargoType i = 0; i < NUM_CARGO; i++) {
if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(i);
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (HasBit(st->goods[cargo].status, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(cargo);
}
}

View File

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

View File

@ -99,20 +99,20 @@ Station::~Station()
if (a->targetairport == this->index) a->targetairport = StationID::Invalid();
}
for (CargoType c = 0; c < NUM_CARGO; ++c) {
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[cargo].link_graph);
if (lg == nullptr) continue;
for (NodeID node = 0; node < lg->Size(); ++node) {
Station *st = Station::Get((*lg)[node].station);
if (!st->goods[c].HasData()) continue;
st->goods[c].GetData().flows.erase(this->index);
if ((*lg)[node].HasEdgeTo(this->goods[c].node) && (*lg)[node][this->goods[c].node].LastUpdate() != EconomyTime::INVALID_DATE) {
st->goods[c].GetData().flows.DeleteFlows(this->index);
RerouteCargo(st, c, this->index, st->index);
if (!st->goods[cargo].HasData()) continue;
st->goods[cargo].GetData().flows.erase(this->index);
if ((*lg)[node].HasEdgeTo(this->goods[cargo].node) && (*lg)[node][this->goods[cargo].node].LastUpdate() != EconomyTime::INVALID_DATE) {
st->goods[cargo].GetData().flows.DeleteFlows(this->index);
RerouteCargo(st, cargo, this->index, st->index);
}
}
lg->RemoveNode(this->goods[c].node);
lg->RemoveNode(this->goods[cargo].node);
if (lg->Size() == 0) {
LinkGraphSchedule::instance.Unqueue(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 */
for (CargoType i = 0; i < NUM_CARGO; i++) {
uint amt = acceptance[i];
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
uint amt = acceptance[cargo];
/* 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})) ||
(is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::BusStop, StationFacility::Airport, StationFacility::Dock}))) {
amt = 0;
}
GoodsEntry &ge = st->goods[i];
GoodsEntry &ge = st->goods[cargo];
SB(ge.status, GoodsEntry::GES_ACCEPTANCE, 1, amt >= 8);
if (LinkGraph::IsValidID(ge.link_graph)) {
(*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.
* Make sure the cargo's new next hop is neither "avoid" nor "avoid2".
* @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 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. */
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. */
for (Vehicle *v : st->loading_vehicles) {
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);
}
}
@ -4018,15 +4018,15 @@ void RerouteCargo(Station *st, CargoType c, StationID avoid, StationID avoid2)
*/
void DeleteStaleLinks(Station *from)
{
for (CargoType c = 0; c < NUM_CARGO; ++c) {
const bool auto_distributed = (_settings_game.linkgraph.GetDistributionType(c) != DT_MANUAL);
GoodsEntry &ge = from->goods[c];
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
const bool auto_distributed = (_settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL);
GoodsEntry &ge = from->goods[cargo];
LinkGraph *lg = LinkGraph::GetIfValid(ge.link_graph);
if (lg == nullptr) continue;
std::vector<NodeID> to_remove{};
for (Edge &edge : (*lg)[ge.node].edges) {
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());
auto timeout = TimerGameEconomy::Date(LinkGraph::MIN_TIMEOUT_DISTANCE + (DistanceManhattan(from->xy, to->xy) >> 3));
if (TimerGameEconomy::date - edge.LastUpdate() > timeout) {
@ -4079,14 +4079,14 @@ void DeleteStaleLinks(Station *from)
if (!updated) {
/* 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);
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) {
edge.Restrict();
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) {
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
* at all; i.e. just discard the incoming cargo. */
if (!CargoPacket::CanAllocateItem()) return 0;
GoodsEntry &ge = st->goods[type];
GoodsEntry &ge = st->goods[cargo];
amount += ge.amount_fract;
ge.amount_fract = GB(amount, 0, 8);
@ -4260,7 +4260,7 @@ static uint UpdateStationWaiting(Station *st, CargoType type, uint amount, Sourc
LinkGraph *lg = nullptr;
if (ge.link_graph == LinkGraphID::Invalid()) {
if (LinkGraph::CanAllocateItem()) {
lg = new LinkGraph(type);
lg = new LinkGraph(cargo);
LinkGraphSchedule::instance.Queue(lg);
ge.link_graph = lg->index;
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);
}
TriggerStationRandomisation(st, st->xy, SRT_NEW_CARGO, type);
TriggerStationAnimation(st, st->xy, SAT_NEW_CARGO, type);
AirportAnimationTrigger(st, AAT_STATION_NEW_CARGO, type);
TriggerRoadStopRandomisation(st, st->xy, RSRT_NEW_CARGO, type);
TriggerRoadStopAnimation(st, st->xy, SAT_NEW_CARGO, type);
TriggerStationRandomisation(st, st->xy, SRT_NEW_CARGO, cargo);
TriggerStationAnimation(st, st->xy, SAT_NEW_CARGO, cargo);
AirportAnimationTrigger(st, AAT_STATION_NEW_CARGO, cargo);
TriggerRoadStopRandomisation(st, st->xy, RSRT_NEW_CARGO, cargo);
TriggerRoadStopAnimation(st, st->xy, SAT_NEW_CARGO, cargo);
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? */
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. */
if (st->goods[type].rating == 0) return false;
if (st->goods[cargo].rating == 0) return false;
/* 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. */
if (st->facilities == StationFacility::TruckStop) return false;
} else {
@ -4386,7 +4386,7 @@ static bool CanMoveGoodsToStation(const Station *st, CargoType type)
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. */
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) {
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
* improve performance in this common case. */
@ -4418,8 +4418,8 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
if (used_stations.empty()) {
/* only one station around */
amount *= first_station->goods[type].rating + 1;
return UpdateStationWaiting(first_station, type, amount, source);
amount *= first_station->goods[cargo].rating + 1;
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
@ -4429,7 +4429,7 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
for (auto &p : used_stations) {
auto owner = p.first->owner;
auto rating = p.first->goods[type].rating;
auto rating = p.first->goods[cargo].rating;
if (rating > company_best[owner]) {
best_sum += rating - company_best[owner]; // it's usually faster than iterating companies later
company_best[owner] = rating;
@ -4447,14 +4447,14 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
Owner owner = p.first->owner;
/* 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. */
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;
}
/* If there is some cargo left due to rounding issues distribute it among the best rated stations. */
if (amount > moving) {
std::stable_sort(used_stations.begin(), used_stations.end(), [type](const StationInfo &a, const StationInfo &b) {
return b.first->goods[type].rating < a.first->goods[type].rating;
std::stable_sort(used_stations.begin(), used_stations.end(), [cargo](const StationInfo &a, const StationInfo &b) {
return b.first->goods[cargo].rating < a.first->goods[cargo].rating;
});
assert(amount - moving <= used_stations.size());
@ -4465,7 +4465,7 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
uint moved = 0;
for (auto &p : used_stations) {
moved += UpdateStationWaiting(p.first, type, p.second, source);
moved += UpdateStationWaiting(p.first, cargo, p.second, source);
}
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, 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.

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. */
for (CargoType i = 0; i < NUM_CARGO; i++) {
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
switch (sct) {
case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CargoClass::Passengers)) continue; break;
case SCT_NON_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(cargo, CargoClass::Passengers)) continue; break;
case SCT_ALL: break;
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));
@ -211,16 +211,16 @@ void CheckRedrawRoadWaypointCoverage(const Window *)
* @param left left 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 type Cargo type
* @param cargo Cargo type
* @param amount Cargo amount
* @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 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;
int padding = ScaleGUITrad(1);
@ -314,13 +314,13 @@ protected:
if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
bool has_rating = false;
/* Add to the station/cargo counts. */
for (CargoType j = 0; j < NUM_CARGO; j++) {
if (st->goods[j].HasRating()) this->stations_per_cargo_type[j]++;
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (st->goods[cargo].HasRating()) this->stations_per_cargo_type[cargo]++;
}
for (CargoType j = 0; j < NUM_CARGO; j++) {
if (st->goods[j].HasRating()) {
for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
if (st->goods[cargo].HasRating()) {
has_rating = true;
if (HasBit(this->filter.cargoes, j)) {
if (HasBit(this->filter.cargoes, cargo)) {
this->stations.push_back(st);
break;
}
@ -359,8 +359,8 @@ protected:
{
int diff = 0;
for (CargoType j : 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);
for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
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;
@ -371,8 +371,8 @@ protected:
{
int diff = 0;
for (CargoType j : 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);
for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
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;
@ -384,9 +384,9 @@ protected:
uint8_t maxr1 = 0;
uint8_t maxr2 = 0;
for (CargoType j : SetCargoBitIterator(cargo_filter)) {
if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating);
if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating);
for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
if (a->goods[cargo].HasRating()) maxr1 = std::max(maxr1, a->goods[cargo].rating);
if (b->goods[cargo].HasRating()) maxr2 = std::max(maxr2, b->goods[cargo].rating);
}
return maxr1 < maxr2;
@ -398,9 +398,9 @@ protected:
uint8_t minr1 = 255;
uint8_t minr2 = 255;
for (CargoType j : SetCargoBitIterator(cargo_filter)) {
if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating);
if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating);
for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
if (a->goods[cargo].HasRating()) minr1 = std::min(minr1, a->goods[cargo].rating);
if (b->goods[cargo].HasRating()) minr2 = std::min(minr2, b->goods[cargo].rating);
}
return minr1 > minr2;
@ -851,19 +851,19 @@ static constexpr NWidgetPart _nested_station_view_widgets[] = {
/**
* 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 left left most coordinate to draw on
* @param right right most coordinate to draw on
* @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);
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;
SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon();
SpriteID sprite = CargoSpec::Get(cargo)->GetCargoIcon();
int x = _current_text_dir == TD_RTL ? left : right - num * width;
do {
@ -1029,17 +1029,17 @@ public:
void Clear();
private:
CargoDataEntry(StationID st, uint c, CargoDataEntry *p);
CargoDataEntry(CargoType car, uint c, CargoDataEntry *p);
CargoDataEntry(StationID st);
CargoDataEntry(CargoType car);
CargoDataEntry(StationID station, uint count, CargoDataEntry *parent);
CargoDataEntry(CargoType cargo, uint count, CargoDataEntry *parent);
CargoDataEntry(StationID station);
CargoDataEntry(CargoType cargo);
CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
template <class Tid>
CargoDataEntry *InsertOrRetrieve(Tid s);
void Remove(CargoDataEntry *comp);
void Remove(CargoDataEntry *entry);
void IncrementSize();
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
* 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()) {
delete *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.
* @param i Cargo to recalculate the cache for.
*/
void RecalcDestinations(CargoType i)
void RecalcDestinations(CargoType cargo)
{
const Station *st = Station::Get(this->window_number);
CargoDataEntry *cargo_entry = cached_destinations.InsertOrRetrieve(i);
cargo_entry->Clear();
CargoDataEntry *entry = cached_destinations.InsertOrRetrieve(cargo);
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;
CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from);
CargoDataEntry *source_entry = entry->InsertOrRetrieve(from);
uint32_t prev_count = 0;
for (const auto &flow_it : *it.second.GetShares()) {
StationID via = flow_it.second;
@ -1536,7 +1536,7 @@ struct StationViewWindow : public Window {
if (via == this->window_number) {
via_entry->InsertOrRetrieve(via)->Update(flow_it.first - prev_count);
} 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;
}
@ -1604,13 +1604,13 @@ struct StationViewWindow : public Window {
/**
* 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 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) {
StationID from = it->first;
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);
for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++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.
* @param i Cargo to show.
* @param cargo Cargo to show.
* @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++) {
const CargoPacket *cp = *it;
StationID next = it.GetKey();
const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation());
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;
}
const CargoDataEntry *via_entry = source_entry->Retrieve(next);
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;
}
@ -1667,50 +1667,50 @@ struct StationViewWindow : public Window {
val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount()));
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.
* @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.
*/
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) {
this->RecalcDestinations(i);
if (this->cached_destinations.Retrieve(cargo) == nullptr) {
this->RecalcDestinations(cargo);
}
const GoodsEntry &ge = st->goods[i];
const GoodsEntry &ge = st->goods[cargo];
if (!ge.HasData()) continue;
if (this->current_mode == MODE_WAITING) {
this->BuildCargoList(i, ge.GetData().cargo, cargo);
this->BuildCargoList(cargo, ge.GetData().cargo, entry);
} 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.
* @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;
const CargoDataEntry *parent = data->GetParent();
const CargoDataEntry *parent = entry->GetParent();
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;
}
StationID next = data->GetStation();
StationID next = entry->GetStation();
while (parent->GetParent()->GetParent() != nullptr) {
stations.push_back(parent->GetStation());
parent = parent->GetParent();

View File

@ -535,7 +535,7 @@ static void AdvanceHouseConstruction(TileIndex tile)
* @param stations Available stations for this house.
* @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;
@ -548,8 +548,8 @@ static void TownGenerateCargo(Town *t, CargoType ct, uint amount, StationFinder
amount = ScaleByCargoScale(amount, true);
/* Actually generate cargo and update town statistics. */
t->supplied[ct].new_max += amount;
t->supplied[ct].new_act += MoveGoodsToStation(ct, amount, {t->index, SourceType::Town}, stations.GetStations());;
t->supplied[cargo].new_max += amount;
t->supplied[cargo].new_act += MoveGoodsToStation(cargo, amount, {t->index, SourceType::Town}, stations.GetStations());;
}
/**