From 5ee78213b20d37f4f0a453117ebf6003f483d515 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sun, 10 Oct 2021 11:09:26 +0100 Subject: [PATCH] Port over research == operator from NSF --- .../windows/EditorInventionsList.cpp | 4 ++-- src/openrct2/management/Research.cpp | 24 +++++++++---------- src/openrct2/management/Research.h | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index d785a8fd40..8b8eefafcb 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -162,7 +162,7 @@ static void move_research_item(ResearchItem* beforeItem, int32_t scrollIndex) { for (size_t i = 0; i < researchList.size(); i++) { - if (researchList[i].Equals(beforeItem)) + if (researchList[i] == *beforeItem) { researchList.insert((researchList.begin() + i), _editorInventionsListDraggedItem); return; @@ -610,7 +610,7 @@ static void window_editor_inventions_list_scrollpaint(rct_window* w, rct_drawpix gfx_filter_rect(dpi, 0, top, boxWidth, bottom, FilterPaletteID::PaletteDarken1); } - if (researchItem.Equals(&_editorInventionsListDraggedItem)) + if (researchItem == _editorInventionsListDraggedItem) continue; // TODO: this parameter by itself produces very light text. diff --git a/src/openrct2/management/Research.cpp b/src/openrct2/management/Research.cpp index 79d68be515..2e201a60b5 100644 --- a/src/openrct2/management/Research.cpp +++ b/src/openrct2/management/Research.cpp @@ -420,7 +420,7 @@ void research_remove(ResearchItem* researchItem) for (auto it = gResearchItemsUninvented.begin(); it != gResearchItemsUninvented.end(); it++) { auto& researchItem2 = *it; - if (researchItem2.Equals(researchItem)) + if (researchItem2 == *researchItem) { gResearchItemsUninvented.erase(it); return; @@ -429,7 +429,7 @@ void research_remove(ResearchItem* researchItem) for (auto it = gResearchItemsInvented.begin(); it != gResearchItemsInvented.end(); it++) { auto& researchItem2 = *it; - if (researchItem2.Equals(researchItem)) + if (researchItem2 == *researchItem) { gResearchItemsInvented.erase(it); return; @@ -857,23 +857,18 @@ void ResearchItem::SetNull() entryIndex = OBJECT_ENTRY_INDEX_NULL; } -bool ResearchItem::Equals(const ResearchItem* otherItem) const -{ - return (entryIndex == otherItem->entryIndex && baseRideType == otherItem->baseRideType && type == otherItem->type); -} - bool ResearchItem::Exists() const { for (auto const& researchItem : gResearchItemsUninvented) { - if (researchItem.Equals(this)) + if (researchItem == *this) { return true; } } for (auto const& researchItem : gResearchItemsInvented) { - if (researchItem.Equals(this)) + if (researchItem == *this) { return true; } @@ -919,6 +914,11 @@ rct_string_id ResearchItem::GetCategoryName() const return _researchCategoryNames[categoryValue]; } +bool ResearchItem::operator==(const ResearchItem& rhs) const +{ + return (entryIndex == rhs.entryIndex && baseRideType == rhs.baseRideType && type == rhs.type); +} + static std::bitset _seenRideType = {}; static void research_update_first_of_type(ResearchItem* researchItem) @@ -975,11 +975,11 @@ void research_determine_first_of_type() // The last research item will also be present in gResearchItemsInvented. // Avoid marking its ride type as "invented" prematurely. - if (gResearchLastItem.has_value() && !gResearchLastItem->IsNull() && researchItem.Equals(&gResearchLastItem.value())) + if (gResearchLastItem.has_value() && !gResearchLastItem->IsNull() && researchItem == gResearchLastItem.value()) continue; // The next research item is (sometimes?) also present in gResearchItemsInvented, even though it isn't invented yet(!) - if (gResearchNextItem.has_value() && !gResearchNextItem->IsNull() && researchItem.Equals(&gResearchNextItem.value())) + if (gResearchNextItem.has_value() && !gResearchNextItem->IsNull() && researchItem == gResearchNextItem.value()) continue; research_mark_ride_type_as_seen(researchItem); @@ -999,7 +999,7 @@ void research_determine_first_of_type() for (auto& researchItem : gResearchItemsUninvented) { // The next research item is (sometimes?) also present in gResearchItemsUninvented - if (gResearchNextItem.has_value() && !gResearchNextItem->IsNull() && researchItem.Equals(&gResearchNextItem.value())) + if (gResearchNextItem.has_value() && !gResearchNextItem->IsNull() && researchItem == gResearchNextItem.value()) { // Copy the "first of type" flag. researchItem.flags = gResearchNextItem->flags; diff --git a/src/openrct2/management/Research.h b/src/openrct2/management/Research.h index c3a730bb4c..ba0560a031 100644 --- a/src/openrct2/management/Research.h +++ b/src/openrct2/management/Research.h @@ -62,7 +62,6 @@ struct ResearchItem bool IsNull() const; void SetNull(); - bool Equals(const ResearchItem* otherItem) const; bool Exists() const; bool IsAlwaysResearched() const; rct_string_id GetName() const; @@ -127,6 +126,8 @@ struct ResearchItem category = static_cast(oldResearchItem.category); } } + + bool operator==(const ResearchItem& rhs) const; }; // Only used to mark as null nowadays. Deprecated. TODO: remove.