diff options
-rw-r--r-- | src/cargotype.h | 3 | ||||
-rw-r--r-- | src/economy.cpp | 3 | ||||
-rw-r--r-- | src/linkgraph/linkgraph_gui.cpp | 6 | ||||
-rw-r--r-- | src/newgrf.cpp | 3 | ||||
-rw-r--r-- | src/station_gui.cpp | 9 |
5 files changed, 9 insertions, 15 deletions
diff --git a/src/cargotype.h b/src/cargotype.h index c93feea75..a398d6079 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -15,6 +15,7 @@ #include "gfx_type.h" #include "strings_type.h" #include "landscape_type.h" +#include "core/bitmath_func.hpp" #include "core/span_type.hpp" #include <vector> @@ -195,6 +196,6 @@ static inline bool IsCargoInClass(CargoID c, CargoClass cc) return (CargoSpec::Get(c)->classes & cc) != 0; } -#define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, CargoTypes, cargo_bits) +using SetCargoBitIterator = SetBitIterator<CargoID, CargoTypes>; #endif /* CARGOTYPE_H */ diff --git a/src/economy.cpp b/src/economy.cpp index 0c2e73cbd..c3332c4d1 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1480,9 +1480,8 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station bool is_auto_refit = new_cid == CT_AUTO_REFIT; if (is_auto_refit) { /* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */ - CargoID cid; new_cid = v_start->cargo_type; - FOR_EACH_SET_CARGO_ID(cid, refit_mask) { + for (CargoID cid : SetCargoBitIterator(refit_mask)) { if (st->goods[cid].cargo.HasCargoFor(next_station)) { /* Try to find out if auto-refitting would succeed. In case the refit is allowed, * the returned refit capacity will be greater than zero. */ diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index e0986fdb5..056d958ce 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -65,8 +65,7 @@ void LinkGraphOverlay::RebuildCache() StationLinkMap &seen_links = this->cached_links[from]; uint supply = 0; - CargoID c; - FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) { + for (CargoID 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); @@ -192,8 +191,7 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe */ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) { - CargoID c; - FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) { + for (CargoID c : SetCargoBitIterator(this->cargo_mask)) { if (!CargoSpec::Get(c)->IsValid()) continue; const GoodsEntry &ge = from->goods[c]; if (!LinkGraph::IsValidID(ge.link_graph) || diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 15e95e4d2..023ad9890 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -8902,8 +8902,7 @@ static void CalculateRefitMasks() if (cargo_map_for_first_refittable != nullptr) { /* Use first refittable cargo from cargo translation table */ byte best_local_slot = 0xFF; - CargoID cargo_type; - FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) { + for (CargoID cargo_type : SetCargoBitIterator(ei->refit_mask)) { byte local_slot = cargo_map_for_first_refittable[cargo_type]; if (local_slot < best_local_slot) { best_local_slot = local_slot; diff --git a/src/station_gui.cpp b/src/station_gui.cpp index e36978c37..ecc7ea77c 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -273,8 +273,7 @@ protected: { int diff = 0; - CargoID j; - FOR_EACH_SET_CARGO_ID(j, cargo_filter) { + for (CargoID j : SetCargoBitIterator(cargo_filter)) { diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount(); } @@ -286,8 +285,7 @@ protected: { int diff = 0; - CargoID j; - FOR_EACH_SET_CARGO_ID(j, cargo_filter) { + for (CargoID j : SetCargoBitIterator(cargo_filter)) { diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount(); } @@ -300,8 +298,7 @@ protected: byte maxr1 = 0; byte maxr2 = 0; - CargoID j; - FOR_EACH_SET_CARGO_ID(j, cargo_filter) { + for (CargoID 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); } |