From ecd624746267117c68f044542ee63010ec6fd700 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 17:08:15 +0200 Subject: [PATCH] Replace C-style functions for checking getting path additions --- .../interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 4 +-- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- src/openrct2/Cheats.cpp | 6 ++-- src/openrct2/EditorObjectSelectionSession.cpp | 4 +-- .../paint/tile_element/Paint.Path.cpp | 9 +++--- src/openrct2/peep/Guest.cpp | 28 ++++++++--------- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/peep/Staff.cpp | 8 ++--- src/openrct2/rct1/S4Importer.cpp | 4 +-- src/openrct2/world/Footpath.cpp | 31 +++++++++++-------- src/openrct2/world/Footpath.h | 4 --- src/openrct2/world/Fountain.cpp | 4 +-- src/openrct2/world/Scenery.cpp | 4 +-- src/openrct2/world/TileElement.h | 8 ++++- 15 files changed, 63 insertions(+), 57 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 437938f21b..15a9ed8df5 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -362,7 +362,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter return info->type; case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: - sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) { diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a4aa0532a2..a6d5a49a60 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1813,9 +1813,9 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_NAME, &pathNameId, COLOUR_DARK_GREEN, x, y); // Path addition - if (footpath_element_has_path_scenery(tileElement)) + if (tileElement->AsPath()->HasAddition()) { - const uint8_t pathAdditionType = footpath_element_get_path_scenery_index(tileElement); + const uint8_t pathAdditionType = tileElement->AsPath()->GetAdditionEntryIndex(); rct_string_id additionNameId = get_footpath_item_entry(pathAdditionType)->name; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_ADDITIONS, &additionNameId, COLOUR_DARK_GREEN, x, y + 11); } diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 4bd76304e8..4f017c1fbd 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1129,7 +1129,7 @@ static void scenery_eyedropper_tool_down(int16_t x, int16_t y, rct_widgetindex w } case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: { - int32_t entryIndex = footpath_element_get_path_scenery_index(tileElement); + int32_t entryIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(entryIndex); if (sceneryEntry != nullptr) { diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index 3d1b72d946..6e0c5a54d0 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -108,7 +108,7 @@ static void cheat_fix_vandalism() if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (!footpath_element_has_path_scenery(it.element)) + if (!(it.element)->AsPath()->HasAddition()) continue; it.element->flags &= ~TILE_ELEMENT_FLAG_BROKEN; @@ -138,10 +138,10 @@ static void cheat_remove_litter() if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (!footpath_element_has_path_scenery(it.element)) + if (!(it.element)->AsPath()->HasAddition()) continue; - sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(it.element)); + sceneryEntry = it.element->AsPath()->GetAdditionEntry(); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN) it.element->properties.path.addition_status = 0xFF; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index dbeff817b8..377006cd49 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -136,9 +136,9 @@ void setup_in_use_selection_flags() assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); - if (footpath_element_has_path_scenery(iter.element)) + if (iter.element->AsPath()->HasAddition()) { - uint8_t path_additions = footpath_element_get_path_scenery_index(iter.element); + uint8_t path_additions = iter.element->AsPath()->GetAdditionEntryIndex(); Editor::SetSelectedObject(OBJECT_TYPE_PATH_BITS, path_additions, OBJECT_SELECTION_FLAG_SELECTED); } break; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 168993093f..d82d67ac24 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -682,7 +682,7 @@ static void sub_6A3F61( { if (!gTrackDesignSaveMode) { - if (footpath_element_has_path_scenery(tile_element)) + if (tile_element->AsPath()->HasAddition()) { session->InteractionType = VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM; if (sceneryImageFlags != 0) @@ -691,8 +691,7 @@ static void sub_6A3F61( } // Draw additional path bits (bins, benches, lamps, queue screens) - rct_scenery_entry* sceneryEntry = get_footpath_item_entry( - footpath_element_get_path_scenery_index(tile_element)); + rct_scenery_entry* sceneryEntry = tile_element->AsPath()->GetAdditionEntry(); if ((gCurrentViewportFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES) && !(tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) @@ -939,9 +938,9 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* #ifdef __ENABLE_LIGHTFX__ if (lightfx_is_available()) { - if (footpath_element_has_path_scenery(tile_element) && !(tile_element->flags & TILE_ELEMENT_FLAG_BROKEN)) + if (tile_element->AsPath()->HasAddition() && !(tile_element->flags & TILE_ELEMENT_FLAG_BROKEN)) { - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); + rct_scenery_entry* sceneryEntry = tile_element->AsPath()->GetAdditionEntry(); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP) { if (!(tile_element->properties.path.edges & EDGE_NE)) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 65e2cea215..0cdfa2170d 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -640,10 +640,10 @@ void rct_peep::Tick128UpdateGuest(int32_t index) continue; // Check if the footpath has a queue line TV monitor on it - if (footpath_element_has_path_scenery(tileElement) + if (tileElement->AsPath()->HasAddition() && !tileElement->AsPath()->AdditionIsGhost()) { - uint8_t pathSceneryIndex = footpath_element_get_path_scenery_index(tileElement); + uint8_t pathSceneryIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(pathSceneryIndex); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_QUEUE_SCREEN) { @@ -2718,10 +2718,10 @@ static uint8_t peep_assess_surroundings(int16_t centre_x, int16_t centre_y, int1 switch (tileElement->GetType()) { case TILE_ELEMENT_TYPE_PATH: - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) break; - scenery = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + scenery = tileElement->AsPath()->GetAdditionEntry(); if (scenery == nullptr) { return PEEP_THOUGHT_TYPE_NONE; @@ -5318,11 +5318,11 @@ void rct_peep::UpdateWalking() int32_t positions_free = 15; - if (footpath_element_has_path_scenery(tileElement)) + if (tileElement->AsPath()->HasAddition()) { if (!tileElement->AsPath()->AdditionIsGhost()) { - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry == nullptr) { return; @@ -5753,13 +5753,13 @@ void rct_peep::UpdateUsingBin() } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) { StateReset(); return; } - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN)) { StateReset(); @@ -5920,9 +5920,9 @@ bool rct_peep::UpdateWalkingFindBench() } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return false; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry == nullptr || !(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BENCH)) return false; @@ -6015,9 +6015,9 @@ bool rct_peep::UpdateWalkingFindBin() } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return false; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry == nullptr) { return false; @@ -6116,9 +6116,9 @@ static void peep_update_walking_break_scenery(rct_peep* peep) } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_BREAKABLE)) return; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 56630e49a6..ed9b00bc90 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2878,7 +2878,7 @@ static void peep_interact_with_path(rct_peep* peep, int16_t x, int16_t y, rct_ti { // 0x00F1AEE2 bool vandalism_present = false; - if (footpath_element_has_path_scenery(tile_element) && (tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) + if (tile_element->AsPath()->HasAddition() && (tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) && (tile_element->properties.path.edges & 0xF) != 0xF) { vandalism_present = true; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 0980ac8e0c..9c65db1354 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1810,13 +1810,13 @@ void rct_peep::UpdateEmptyingBin() } } - if (!footpath_element_has_path_scenery(tile_element)) + if (!tile_element->AsPath()->HasAddition()) { StateReset(); return; } - rct_scenery_entry* scenery_entry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); + rct_scenery_entry* scenery_entry = tile_element->AsPath()->GetAdditionEntry(); if (!(scenery_entry->path_bit.flags & PATH_BIT_FLAG_IS_BIN) || tile_element->flags & (1 << 5) || tile_element->AsPath()->AdditionIsGhost()) { @@ -2210,9 +2210,9 @@ static int32_t peep_update_patrolling_find_bin(rct_peep* peep) return 0; } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return 0; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN)) return 0; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 011357e4aa..9754e488a5 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2514,7 +2514,7 @@ private: tileElement->AsPath()->SetAdditionIsGhost(false); // Additions - uint8_t additionType = footpath_element_get_path_scenery(tileElement); + uint8_t additionType = tileElement->AsPath()->GetAddition(); if (additionType != RCT1_PATH_ADDITION_NONE) { uint8_t normalisedType = RCT1::NormalisePathAddition(additionType); @@ -2523,7 +2523,7 @@ private: { tileElement->flags |= TILE_ELEMENT_FLAG_BROKEN; } - footpath_element_set_path_scenery(tileElement, entryIndex + 1); + tileElement->AsPath()->SetAddition(entryIndex + 1); } break; } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 3018998592..734dbdb123 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -308,7 +308,7 @@ static money32 footpath_element_update( } else if (pathItemType != 0) { - if (!(flags & GAME_COMMAND_FLAG_GHOST) && footpath_element_get_path_scenery(tileElement) == pathItemType + if (!(flags & GAME_COMMAND_FLAG_GHOST) && tileElement->AsPath()->GetAddition() == pathItemType && !(tileElement->flags & TILE_ELEMENT_FLAG_BROKEN)) { if (flags & GAME_COMMAND_FLAG_4) @@ -357,7 +357,7 @@ static money32 footpath_element_update( if (flags & GAME_COMMAND_FLAG_GHOST) { // Check if there is something on the path already - if (footpath_element_has_path_scenery(tileElement)) + if (tileElement->AsPath()->HasAddition()) { gGameCommandErrorText = STR_NONE; return MONEY32_UNDEFINED; @@ -377,7 +377,7 @@ static money32 footpath_element_update( tileElement->AsPath()->SetAdditionIsGhost(false); } - footpath_element_set_path_scenery(tileElement, pathItemType); + tileElement->AsPath()->SetAddition(pathItemType); tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; if (pathItemType != 0) { @@ -404,7 +404,7 @@ static money32 footpath_element_update( footpath_element_set_type(tileElement, type); tileElement->type = (tileElement->type & 0xFE) | (type >> 7); - footpath_element_set_path_scenery(tileElement, pathItemType); + tileElement->AsPath()->SetAddition(pathItemType); tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; loc_6A6620(flags, x, y, tileElement); @@ -2004,25 +2004,30 @@ void PathElement::SetWide(bool isWide) type |= FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE; } -bool footpath_element_has_path_scenery(const rct_tile_element* tileElement) +bool PathElement::HasAddition() const { - return footpath_element_get_path_scenery(tileElement) != 0; + return (additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK) != 0; } -uint8_t footpath_element_get_path_scenery(const rct_tile_element* tileElement) +uint8_t PathElement::GetAddition() const { - return tileElement->properties.path.additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + return additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; } -void footpath_element_set_path_scenery(rct_tile_element* tileElement, uint8_t pathSceneryType) +uint8_t PathElement::GetAdditionEntryIndex() const { - tileElement->properties.path.additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; - tileElement->properties.path.additions |= pathSceneryType; + return GetAddition() - 1; } -uint8_t footpath_element_get_path_scenery_index(const rct_tile_element* tileElement) +rct_scenery_entry* PathElement::GetAdditionEntry() const { - return footpath_element_get_path_scenery(tileElement) - 1; + return get_footpath_item_entry(GetAdditionEntryIndex()); +} + +void PathElement::SetAddition(uint8_t newAddition) +{ + additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + additions |= newAddition; } bool PathElement::AdditionIsGhost() const diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 25dcd5e6a2..6c9bc421f1 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -159,10 +159,6 @@ uint8_t footpath_element_get_type(const rct_tile_element* tileElement); void footpath_element_set_type(rct_tile_element* tileElement, uint8_t type); uint8_t footpath_element_get_direction(const rct_tile_element* tileElement); void footpath_element_set_direction(rct_tile_element* tileElement, uint8_t direction); -bool footpath_element_has_path_scenery(const rct_tile_element* tileElement); -uint8_t footpath_element_get_path_scenery(const rct_tile_element* tileElement); -void footpath_element_set_path_scenery(rct_tile_element* tileElement, uint8_t pathSceneryType); -uint8_t footpath_element_get_path_scenery_index(const rct_tile_element* tileElement); void footpath_remove_edges_at(int32_t x, int32_t y, rct_tile_element* tileElement); int32_t entrance_get_directions(const rct_tile_element* tileElement); diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index 357e197251..8324cc4fdc 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -261,10 +261,10 @@ static bool is_jumping_fountain(int32_t type, int32_t x, int32_t y, int32_t z) continue; if (tileElement->AsPath()->AdditionIsGhost()) continue; - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) continue; - uint8_t additionIndex = footpath_element_get_path_scenery_index(tileElement); + uint8_t additionIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(additionIndex); if (sceneryEntry != reinterpret_cast(-1) && sceneryEntry->path_bit.flags & pathBitFlagMask) { diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 55ec2779e1..2fa66c9a91 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -88,9 +88,9 @@ void scenery_update_tile(int32_t x, int32_t y) } else if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (footpath_element_has_path_scenery(tileElement) && !tileElement->AsPath()->AdditionIsGhost()) + if (tileElement->AsPath()->HasAddition() && !tileElement->AsPath()->AdditionIsGhost()) { - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry != nullptr) { if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_JUMPING_FOUNTAIN_WATER) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index cc3bf86eba..eb410cdfbb 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -202,11 +202,17 @@ public: bool IsWide() const; void SetWide(bool isWide); - + bool IsQueue() const; void SetIsQueue(bool isQueue); bool HasQueueBanner() const; + bool HasAddition() const; + uint8_t GetAddition() const; + uint8_t GetAdditionEntryIndex() const; + rct_scenery_entry* GetAdditionEntry() const; + void SetAddition(uint8_t newAddition); + bool AdditionIsGhost() const; void SetAdditionIsGhost(bool isGhost);