diff options
author | glx22 <glx@openttd.org> | 2021-06-13 04:29:24 +0200 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-07-09 21:36:09 +0200 |
commit | a543a4b7bb0d869800591ec1504b3934b68ecd8f (patch) | |
tree | b3c63e456cf0e544c2ec6301d85f34c7dea9d6d2 /src | |
parent | 89ab8b79a51b4963da55dce195ea1ab520c73b50 (diff) | |
download | openttd-a543a4b7bb0d869800591ec1504b3934b68ecd8f.tar.xz |
Codechange: Remove FOR_EACH_SET_CARGO_ID
Diffstat (limited to 'src')
-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); } |