1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-22 19:54:06 +01:00

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

Rename CargoType variables and parameters using short or meaningless names.
This commit is contained in:
Peter Nelson
2025-03-24 18:18:21 +00:00
committed by GitHub
parent bdea29c414
commit b96b26ef15
15 changed files with 163 additions and 163 deletions

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;