From 5e28586a1c7439462e83c5f5c129b4a77e446f46 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 14 Apr 2021 14:56:28 +0200 Subject: [PATCH] Create ProvisionalFootpath struct --- src/openrct2-ui/windows/Footpath.cpp | 16 +++++------ src/openrct2-ui/windows/RideConstruction.cpp | 2 +- src/openrct2/world/Footpath.cpp | 29 +++++++++----------- src/openrct2/world/Footpath.h | 13 ++++++--- src/openrct2/world/Map.cpp | 10 +++---- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 8f758ad743..bde13f05b1 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -465,14 +465,14 @@ static void window_footpath_update_provisional_path_for_bridge_mode(rct_window* } // Recheck area for construction. Set by ride_construction window - if (gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_2) + if (gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_2) { footpath_provisional_remove(); - gFootpathProvisionalFlags &= ~PROVISIONAL_PATH_FLAG_2; + gProvisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_2; } // Update provisional bridge mode path - if (!(gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1)) + if (!(gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1)) { CoordsXYZ footpathLoc; footpath_get_next_path_info(&type, footpathLoc, &slope); @@ -487,12 +487,12 @@ static void window_footpath_update_provisional_path_for_bridge_mode(rct_window* { _footpathConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; - gFootpathProvisionalFlags ^= PROVISIONAL_PATH_FLAG_SHOW_ARROW; + gProvisionalFootpath.Flags ^= PROVISIONAL_PATH_FLAG_SHOW_ARROW; CoordsXYZ footpathLoc; footpath_get_next_path_info(&type, footpathLoc, &slope); gMapSelectArrowPosition = footpathLoc; gMapSelectArrowDirection = _footpathConstructDirection; - if (gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_SHOW_ARROW) + if (gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_SHOW_ARROW) { gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW; } @@ -725,8 +725,8 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& else { // Check for change - if ((gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) - && gFootpathProvisionalPosition == CoordsXYZ{ info.Loc, info.Element->GetBaseZ() }) + if ((gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1) + && gProvisionalFootpath.Position == CoordsXYZ{ info.Loc, info.Element->GetBaseZ() }) { return; } @@ -941,7 +941,7 @@ static void window_footpath_start_bridge_at_point(const ScreenCoordsXY& screenCo tool_cancel(); gFootpathConstructFromPosition = { mapCoords, z }; _footpathConstructDirection = direction; - gFootpathProvisionalFlags = 0; + gProvisionalFootpath.Flags = 0; gFootpathConstructSlope = 0; _footpathConstructionMode = PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL; _footpathConstructValidDirections = INVALID_DIRECTION; diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 28ad735e53..d66407bd92 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -650,7 +650,7 @@ static void window_ride_construction_mouseup(rct_window* w, rct_widgetindex widg case WIDX_CONSTRUCT: window_ride_construction_construct(w); // Force any footpath construction to recheck the area. - gFootpathProvisionalFlags |= PROVISIONAL_PATH_FLAG_2; + gProvisionalFootpath.Flags |= PROVISIONAL_PATH_FLAG_2; break; case WIDX_DEMOLISH: window_ride_construction_mouseup_demolish(w); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 1e99af5b0c..0008fdd356 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -40,10 +40,7 @@ void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElement* tileElement); -uint8_t gFootpathProvisionalFlags; -CoordsXYZ gFootpathProvisionalPosition; -uint8_t gFootpathProvisionalType; -uint8_t gFootpathProvisionalSlope; +ProvisionalFootpath gProvisionalFootpath; uint16_t gFootpathSelectedId; CoordsXYZ gFootpathConstructFromPosition; uint8_t gFootpathConstructSlope; @@ -153,10 +150,10 @@ money32 footpath_provisional_set(int32_t type, const CoordsXYZ& footpathLoc, int cost = res->Error == GameActions::Status::Ok ? res->Cost : MONEY32_UNDEFINED; if (res->Error == GameActions::Status::Ok) { - gFootpathProvisionalType = type; - gFootpathProvisionalPosition = footpathLoc; - gFootpathProvisionalSlope = slope; - gFootpathProvisionalFlags |= PROVISIONAL_PATH_FLAG_1; + gProvisionalFootpath.Type = type; + gProvisionalFootpath.Position = footpathLoc; + gProvisionalFootpath.Slope = slope; + gProvisionalFootpath.Flags |= PROVISIONAL_PATH_FLAG_1; if (gFootpathGroundFlags & ELEMENT_IS_UNDERGROUND) { @@ -180,15 +177,15 @@ money32 footpath_provisional_set(int32_t type, const CoordsXYZ& footpathLoc, int } else if ( gFootpathConstructSlope == TILE_ELEMENT_SLOPE_FLAT - || gFootpathProvisionalPosition.z < gFootpathConstructFromPosition.z) + || gProvisionalFootpath.Position.z < gFootpathConstructFromPosition.z) { // Going either straight on, or down. - virtual_floor_set_height(gFootpathProvisionalPosition.z); + virtual_floor_set_height(gProvisionalFootpath.Position.z); } else { // Going up in the world! - virtual_floor_set_height(gFootpathProvisionalPosition.z + LAND_HEIGHT_STEP); + virtual_floor_set_height(gProvisionalFootpath.Position.z + LAND_HEIGHT_STEP); } } @@ -201,12 +198,12 @@ money32 footpath_provisional_set(int32_t type, const CoordsXYZ& footpathLoc, int */ void footpath_provisional_remove() { - if (gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) + if (gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1) { - gFootpathProvisionalFlags &= ~PROVISIONAL_PATH_FLAG_1; + gProvisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_1; footpath_remove( - gFootpathProvisionalPosition, + gProvisionalFootpath.Position, GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); } @@ -218,9 +215,9 @@ void footpath_provisional_remove() */ void footpath_provisional_update() { - if (gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_SHOW_ARROW) + if (gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_SHOW_ARROW) { - gFootpathProvisionalFlags &= ~PROVISIONAL_PATH_FLAG_SHOW_ARROW; + gProvisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_SHOW_ARROW; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; map_invalidate_tile_full(gFootpathConstructFromPosition); diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 79c9ad5283..98318556fd 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -72,6 +72,14 @@ struct PathRailingsEntry uint8_t scrolling_mode; }; +struct ProvisionalFootpath +{ + ObjectEntryIndex Type; + CoordsXYZ Position; + uint8_t Slope; + uint8_t Flags; +}; + // Masks for values stored in TileElement.type enum { @@ -158,10 +166,7 @@ enum FOOTPATH_CONNECTED_MAP_EDGE_IGNORE_NO_ENTRY = (1 << 7) }; -extern uint8_t gFootpathProvisionalFlags; -extern CoordsXYZ gFootpathProvisionalPosition; -extern uint8_t gFootpathProvisionalType; -extern uint8_t gFootpathProvisionalSlope; +extern ProvisionalFootpath gProvisionalFootpath; extern uint16_t gFootpathSelectedId; extern CoordsXYZ gFootpathConstructFromPosition; extern uint8_t gFootpathConstructSlope; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index c11694c9c3..6f312bceb1 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1515,10 +1515,10 @@ void map_update_tiles() void map_remove_provisional_elements() { - if (gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) + if (gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1) { footpath_provisional_remove(); - gFootpathProvisionalFlags |= PROVISIONAL_PATH_FLAG_1; + gProvisionalFootpath.Flags |= PROVISIONAL_PATH_FLAG_1; } if (window_find_by_class(WC_RIDE_CONSTRUCTION) != nullptr) { @@ -1536,10 +1536,10 @@ void map_remove_provisional_elements() void map_restore_provisional_elements() { - if (gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) + if (gProvisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1) { - gFootpathProvisionalFlags &= ~PROVISIONAL_PATH_FLAG_1; - footpath_provisional_set(gFootpathProvisionalType, gFootpathProvisionalPosition, gFootpathProvisionalSlope); + gProvisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_1; + footpath_provisional_set(gProvisionalFootpath.Type, gProvisionalFootpath.Position, gProvisionalFootpath.Slope); } if (window_find_by_class(WC_RIDE_CONSTRUCTION) != nullptr) {