Codechange: Use EnumBitSet for GoodsEntry status. (#13899)

This commit is contained in:
Peter Nelson
2025-03-26 21:22:33 +00:00
committed by GitHub
parent 5331389765
commit 325f7f9767
10 changed files with 52 additions and 45 deletions

View File

@@ -501,7 +501,7 @@ CargoTypes GetAcceptanceMask(const Station *st)
CargoTypes mask = 0;
for (auto it = std::begin(st->goods); it != std::end(st->goods); ++it) {
if (HasBit(it->status, GoodsEntry::GES_ACCEPTANCE)) SetBit(mask, std::distance(std::begin(st->goods), it));
if (it->status.Test(GoodsEntry::State::Acceptance)) SetBit(mask, std::distance(std::begin(st->goods), it));
}
return mask;
}
@@ -641,7 +641,7 @@ void UpdateStationAcceptance(Station *st, bool show_msg)
}
GoodsEntry &ge = st->goods[cargo];
SB(ge.status, GoodsEntry::GES_ACCEPTANCE, 1, amt >= 8);
ge.status.Set(GoodsEntry::State::Acceptance, amt >= 8);
if (LinkGraph::IsValidID(ge.link_graph)) {
(*LinkGraph::Get(ge.link_graph))[ge.node].SetDemand(amt / 8);
}
@@ -3753,7 +3753,7 @@ void TriggerWatchedCargoCallbacks(Station *st)
/* Collect cargoes accepted since the last big tick. */
CargoTypes cargoes = 0;
for (CargoType cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
if (HasBit(st->goods[cargo_type].status, GoodsEntry::GES_ACCEPTED_BIGTICK)) SetBit(cargoes, cargo_type);
if (st->goods[cargo_type].status.Test(GoodsEntry::State::AcceptedBigtick)) SetBit(cargoes, cargo_type);
}
/* Anything to do? */
@@ -3785,7 +3785,7 @@ static bool StationHandleBigTick(BaseStation *st)
TriggerWatchedCargoCallbacks(Station::From(st));
for (GoodsEntry &ge : Station::From(st)->goods) {
ClrBit(ge.status, GoodsEntry::GES_ACCEPTED_BIGTICK);
ge.status.Reset(GoodsEntry::State::AcceptedBigtick);
}
}
@@ -3845,7 +3845,7 @@ static void UpdateStationRating(Station *st)
if (ge->HasRating()) {
byte_inc_sat(&ge->time_since_pickup);
if (ge->time_since_pickup == 255 && _settings_game.order.selectgoods) {
ClrBit(ge->status, GoodsEntry::GES_RATING);
ge->status.Reset(GoodsEntry::State::Rating);
ge->last_speed = 0;
TruncateCargo(cs, ge);
waiting_changed = true;
@@ -4222,8 +4222,8 @@ static IntervalTimer<TimerGameEconomy> _economy_stations_monthly({TimerGameEcono
{
for (Station *st : Station::Iterate()) {
for (GoodsEntry &ge : st->goods) {
SB(ge.status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge.status, GoodsEntry::GES_CURRENT_MONTH, 1));
ClrBit(ge.status, GoodsEntry::GES_CURRENT_MONTH);
ge.status.Set(GoodsEntry::State::LastMonth, ge.status.Test(GoodsEntry::State::CurrentMonth));
ge.status.Reset(GoodsEntry::State::CurrentMonth);
}
}
});
@@ -4233,7 +4233,7 @@ void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint rad
ForAllStationsRadius(tile, radius, [&](Station *st) {
if (st->owner == owner && DistanceManhattan(tile, st->xy) <= radius) {
for (GoodsEntry &ge : st->goods) {
if (ge.status != 0) {
if (ge.status.Any()) {
ge.rating = ClampTo<uint8_t>(ge.rating + amount);
}
}
@@ -4274,7 +4274,7 @@ static uint UpdateStationWaiting(Station *st, CargoType cargo, uint amount, Sour
if (!ge.HasRating()) {
InvalidateWindowData(WC_STATION_LIST, st->owner);
SetBit(ge.status, GoodsEntry::GES_RATING);
ge.status.Set(GoodsEntry::State::Rating);
}
TriggerStationRandomisation(st, st->xy, SRT_NEW_CARGO, cargo);