From 31ce0f20f7640aa5e355671da5e914611c7bb133 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Sun, 1 Sep 2019 16:25:50 +0100 Subject: [PATCH] Use range-based for loops for checking all directions --- src/openrct2/actions/LandSetHeightAction.hpp | 2 +- src/openrct2/actions/RideDemolishAction.hpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 14 +++++++------- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/world/Footpath.cpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2/actions/LandSetHeightAction.hpp b/src/openrct2/actions/LandSetHeightAction.hpp index 23cfd10774..e6f329542b 100644 --- a/src/openrct2/actions/LandSetHeightAction.hpp +++ b/src/openrct2/actions/LandSetHeightAction.hpp @@ -339,7 +339,7 @@ private: money32 GetSurfaceHeightChangeCost(SurfaceElement * surfaceElement) const { money32 cost{ 0 }; - for (int32_t i = 0; i < 4; i += 1) + for (Direction i : ALL_DIRECTIONS) { int32_t cornerHeight = tile_element_get_corner_height(surfaceElement, i); cornerHeight -= map_get_corner_height(_height, _style & TILE_ELEMENT_SURFACE_SLOPE_MASK, i); diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 3919e7e793..533e4a58f2 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -332,7 +332,7 @@ private: { 16, 0 }, }; - for (uint8_t dir = 0; dir < 4; dir++) + for (Direction dir : ALL_DIRECTIONS) { const LocationXY16& off = DirOffsets[dir]; money32 removePrice = MazeRemoveTrack(x + off.x, y + off.y, z, dir); diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 0155d5729b..31d2b67b16 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -344,23 +344,23 @@ static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, Direction chosenD edges &= ~(1 << direction_reverse(chosenDirection)); loc.z = tileElement->base_height; - for (direction = 0; direction < 4; direction++) + for (Direction dir : ALL_DIRECTIONS) { - if (!(edges & (1 << direction))) + if (!(edges & (1 << dir))) continue; - edges &= ~(1 << direction); + edges &= ~(1 << dir); if (edges != 0) return PATH_SEARCH_JUNCTION; if (tileElement->AsPath()->IsSloped()) { - if (tileElement->AsPath()->GetSlopeDirection() == direction) + if (tileElement->AsPath()->GetSlopeDirection() == dir) { loc.z += 2; } } - return footpath_element_dest_in_dir(loc, direction, outRideIndex, level + 1); + return footpath_element_dest_in_dir(loc, dir, outRideIndex, level + 1); } return PATH_SEARCH_DEAD_END; } @@ -1889,7 +1889,7 @@ int32_t guest_path_finding(Guest* peep) /* If this tileElement is adjacent to any non-wide paths, * remove all of the edges to wide paths. */ uint8_t adjustedEdges = edges; - for (Direction chosenDirection = 0; direction_valid(chosenDirection); chosenDirection++) + for (Direction chosenDirection : ALL_DIRECTIONS) { // If there is no path in that direction try another if (!(adjustedEdges & (1 << chosenDirection))) @@ -1971,7 +1971,7 @@ int32_t guest_path_finding(Guest* peep) if (!peep->HasFood() && (scenario_rand() & 0xFFFF) >= 2184) { uint8_t adjustedEdges = edges; - for (Direction chosenDirection = 0; direction_valid(chosenDirection); chosenDirection++) + for (Direction chosenDirection : ALL_DIRECTIONS) { // If there is no path in that direction try another if (!(adjustedEdges & (1 << chosenDirection))) diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index f0f8d97dc8..bbbb63fbbf 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -234,7 +234,7 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti uint8_t total = 0; uint8_t pathcount = 0; uint8_t widecount = 0; - for (int32_t adjac_dir = 0; adjac_dir <= 3; adjac_dir++) + for (Direction adjac_dir : ALL_DIRECTIONS) { int32_t adjac_x = x + CoordsDirectionDelta[adjac_dir].x; int32_t adjac_y = y + CoordsDirectionDelta[adjac_dir].y; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 93bf634e30..6a63bc6feb 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -741,7 +741,7 @@ static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, TileElemen return true; } - for (int32_t direction = 0; direction < 4; direction++) + for (Direction direction : ALL_DIRECTIONS) { if ((action < 0) && (direction == tileElement->AsPath()->GetSlopeDirection())) continue; @@ -980,7 +980,7 @@ void footpath_connect_edges(int32_t x, int32_t y, TileElement* tileElement, int3 neighbour_list_init(&neighbourList); footpath_update_queue_entrance_banner(x, y, tileElement); - for (int32_t direction = 0; direction < 4; direction++) + for (Direction direction : ALL_DIRECTIONS) { loc_6A6C85(x, y, direction, tileElement, flags, true, &neighbourList); }