Add const where possible

This commit is contained in:
duncanspumpkin 2021-10-01 11:52:16 +01:00
parent fea69cc86c
commit 9e227c1e2f
3 changed files with 72 additions and 77 deletions

View File

@ -87,7 +87,7 @@ validate_global_widx(WC_SCENERY, WIDX_SCENERY_TAB_1);
validate_global_widx(WC_SCENERY, WIDX_SCENERY_ROTATE_OBJECTS_BUTTON); validate_global_widx(WC_SCENERY, WIDX_SCENERY_ROTATE_OBJECTS_BUTTON);
validate_global_widx(WC_SCENERY, WIDX_SCENERY_EYEDROPPER_BUTTON); validate_global_widx(WC_SCENERY, WIDX_SCENERY_EYEDROPPER_BUTTON);
static rct_widget window_scenery_widgets[] = { static rct_widget WindowSceneryBaseWidgets[] = {
WINDOW_SHIM(WINDOW_TITLE, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT), WINDOW_SHIM(WINDOW_TITLE, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT),
MakeWidget ({ 0, 43}, {634, 99}, WindowWidgetType::Resize, WindowColour::Secondary ), // 8 0x009DE2C8 MakeWidget ({ 0, 43}, {634, 99}, WindowWidgetType::Resize, WindowColour::Secondary ), // 8 0x009DE2C8
MakeWidget ({ 2, 47}, {607, 80}, WindowWidgetType::Scroll, WindowColour::Secondary, SCROLL_VERTICAL ), // 1000000 0x009DE418 MakeWidget ({ 2, 47}, {607, 80}, WindowWidgetType::Scroll, WindowColour::Secondary, SCROLL_VERTICAL ), // 1000000 0x009DE418
@ -114,13 +114,12 @@ struct SceneryTabInfo
return SceneryGroupIndex == OBJECT_ENTRY_INDEX_NULL; return SceneryGroupIndex == OBJECT_ENTRY_INDEX_NULL;
} }
bool Contains(ScenerySelection entry) const bool Contains(const ScenerySelection& entry) const
{ {
auto it = std::find(Entries.begin(), Entries.end(), entry); return std::find(std::begin(Entries), std::end(Entries), entry) != std::end(Entries);
return it != Entries.end();
} }
void AddEntry(ScenerySelection entry) void AddEntry(const ScenerySelection& entry)
{ {
if (!Contains(entry)) if (!Contains(entry))
{ {
@ -148,7 +147,7 @@ static std::vector<rct_widget> _widgets;
static ScenerySelection _selectedScenery; static ScenerySelection _selectedScenery;
static int16_t _hoverCounter; static int16_t _hoverCounter;
static ScenerySelection GetSelectedScenery(size_t tabIndex) static const ScenerySelection GetSelectedScenery(const size_t tabIndex)
{ {
if (gWindowSceneryTabSelections.size() > tabIndex) if (gWindowSceneryTabSelections.size() > tabIndex)
{ {
@ -157,7 +156,7 @@ static ScenerySelection GetSelectedScenery(size_t tabIndex)
return {}; return {};
} }
static void SetSelectedScenery(size_t tabIndex, ScenerySelection value) static void SetSelectedScenery(const size_t tabIndex, const ScenerySelection& value)
{ {
if (gWindowSceneryTabSelections.size() <= tabIndex) if (gWindowSceneryTabSelections.size() <= tabIndex)
{ {
@ -166,7 +165,7 @@ static void SetSelectedScenery(size_t tabIndex, ScenerySelection value)
gWindowSceneryTabSelections[tabIndex] = value; gWindowSceneryTabSelections[tabIndex] = value;
} }
static SceneryTabInfo* GetSceneryTabInfoForGroup(ObjectEntryIndex sceneryGroupIndex) static SceneryTabInfo* GetSceneryTabInfoForGroup(const ObjectEntryIndex sceneryGroupIndex)
{ {
if (sceneryGroupIndex == OBJECT_ENTRY_INDEX_NULL) if (sceneryGroupIndex == OBJECT_ENTRY_INDEX_NULL)
{ {
@ -187,30 +186,27 @@ static std::optional<size_t> window_scenery_find_tab_with_scenery(const SceneryS
for (size_t i = 0; i < _tabEntries.size(); i++) for (size_t i = 0; i < _tabEntries.size(); i++)
{ {
const auto& tabInfo = _tabEntries[i]; const auto& tabInfo = _tabEntries[i];
for (const auto& entry : tabInfo.Entries) if (tabInfo.Contains(scenery))
{
if (entry == scenery)
{ {
return i; return i;
} }
} }
} return std::nullopt;
return {};
} }
static void init_scenery_entry(const ScenerySelection& selection, ObjectEntryIndex sceneryGroupIndex) static void init_scenery_entry(const ScenerySelection& selection, const ObjectEntryIndex sceneryGroupIndex)
{ {
Guard::ArgumentInRange<int32_t>(selection.EntryIndex, 0, OBJECT_ENTRY_INDEX_NULL); Guard::ArgumentInRange<int32_t>(selection.EntryIndex, 0, OBJECT_ENTRY_INDEX_NULL);
if (IsSceneryAvailableToBuild(selection)) if (IsSceneryAvailableToBuild(selection))
{ {
// Get current tab // Get current tab
auto tabIndex = window_scenery_find_tab_with_scenery(selection); const auto tabIndex = window_scenery_find_tab_with_scenery(selection);
// Add scenery to primary group (usually trees or path additions) // Add scenery to primary group (usually trees or path additions)
if (sceneryGroupIndex != OBJECT_ENTRY_INDEX_NULL) if (sceneryGroupIndex != OBJECT_ENTRY_INDEX_NULL)
{ {
auto tabInfo = GetSceneryTabInfoForGroup(sceneryGroupIndex); auto* tabInfo = GetSceneryTabInfoForGroup(sceneryGroupIndex);
if (tabInfo != nullptr) if (tabInfo != nullptr)
{ {
tabInfo->AddEntry(selection); tabInfo->AddEntry(selection);
@ -219,9 +215,9 @@ static void init_scenery_entry(const ScenerySelection& selection, ObjectEntryInd
} }
// If scenery is no tab, add it to misc // If scenery is no tab, add it to misc
if (!tabIndex) if (!tabIndex.has_value())
{ {
auto tabInfo = GetSceneryTabInfoForGroup(OBJECT_ENTRY_INDEX_NULL); auto* tabInfo = GetSceneryTabInfoForGroup(OBJECT_ENTRY_INDEX_NULL);
if (tabInfo != nullptr) if (tabInfo != nullptr)
{ {
tabInfo->AddEntry(selection); tabInfo->AddEntry(selection);
@ -241,16 +237,17 @@ static void window_scenery_sort_tabs()
if (b.SceneryGroupIndex == OBJECT_ENTRY_INDEX_NULL) if (b.SceneryGroupIndex == OBJECT_ENTRY_INDEX_NULL)
return true; return true;
auto entryA = a.GetSceneryGroupEntry(); const auto* entryA = a.GetSceneryGroupEntry();
auto entryB = b.GetSceneryGroupEntry(); const auto* entryB = b.GetSceneryGroupEntry();
return entryA->priority < entryB->priority; return entryA->priority < entryB->priority;
}); });
} }
static void window_scenery_prepare_widgets(rct_window* w) static void window_scenery_prepare_widgets(rct_window* w)
{ {
// Add the base widgets
_widgets.clear(); _widgets.clear();
for (const auto& widget : window_scenery_widgets) for (const auto& widget : WindowSceneryBaseWidgets)
{ {
_widgets.push_back(widget); _widgets.push_back(widget);
} }
@ -272,7 +269,7 @@ static void window_scenery_prepare_widgets(rct_window* w)
} }
else else
{ {
auto sceneryGroupEntry = get_scenery_group_entry(tabInfo.SceneryGroupIndex); const auto* sceneryGroupEntry = get_scenery_group_entry(tabInfo.SceneryGroupIndex);
if (sceneryGroupEntry != nullptr) if (sceneryGroupEntry != nullptr)
{ {
widget.image = sceneryGroupEntry->image | IMAGE_TYPE_REMAP; widget.image = sceneryGroupEntry->image | IMAGE_TYPE_REMAP;
@ -314,7 +311,7 @@ static void window_scenery_init(rct_window* w)
tabInfo.SceneryGroupIndex = scenerySetIndex; tabInfo.SceneryGroupIndex = scenerySetIndex;
for (size_t i = 0; i < sceneryGroupEntry->entry_count; i++) for (size_t i = 0; i < sceneryGroupEntry->entry_count; i++)
{ {
auto sceneryEntry = sceneryGroupEntry->scenery_entries[i]; const auto& sceneryEntry = sceneryGroupEntry->scenery_entries[i];
if (IsSceneryAvailableToBuild(sceneryEntry)) if (IsSceneryAvailableToBuild(sceneryEntry))
{ {
tabInfo.Entries.push_back(sceneryEntry); tabInfo.Entries.push_back(sceneryEntry);
@ -393,7 +390,7 @@ static void window_scenery_init(rct_window* w)
void window_scenery_init() void window_scenery_init()
{ {
auto w = window_find_by_class(WC_SCENERY); auto* w = window_find_by_class(WC_SCENERY);
if (w != nullptr) if (w != nullptr)
{ {
window_scenery_init(w); window_scenery_init(w);
@ -424,7 +421,7 @@ void window_scenery_set_default_placement_configuration()
rct_window* window_scenery_open() rct_window* window_scenery_open()
{ {
// Check if window is already open // Check if window is already open
auto window = window_bring_to_front_by_class(WC_SCENERY); auto* window = window_bring_to_front_by_class(WC_SCENERY);
if (window != nullptr) if (window != nullptr)
return window; return window;
@ -457,10 +454,10 @@ rct_window* window_scenery_open()
return window; return window;
} }
static int32_t window_scenery_get_num_columns(rct_window* w) static int32_t window_scenery_get_num_columns(const rct_window* w)
{ {
const auto* listWidget = &w->widgets[WIDX_SCENERY_LIST]; const auto* listWidget = &w->widgets[WIDX_SCENERY_LIST];
auto contentWidth = listWidget->width() - SCROLLBAR_WIDTH; const auto contentWidth = listWidget->width() - SCROLLBAR_WIDTH;
return contentWidth / SCENERY_BUTTON_WIDTH; return contentWidth / SCENERY_BUTTON_WIDTH;
} }
@ -481,23 +478,23 @@ void window_scenery_close(rct_window* w)
tool_cancel(); tool_cancel();
} }
template<typename T> constexpr static T window_scenery_count_rows(rct_window* w, T items) template<typename T> constexpr static T window_scenery_count_rows(const rct_window* w, T items)
{ {
auto rows = items / window_scenery_get_num_columns(w); const auto rows = items / window_scenery_get_num_columns(w);
return rows; return rows;
} }
static size_t window_scenery_count_rows(rct_window* w) static size_t window_scenery_count_rows(const rct_window* w)
{ {
auto tabIndex = gWindowSceneryActiveTabIndex; const auto tabIndex = gWindowSceneryActiveTabIndex;
if (tabIndex >= _tabEntries.size()) if (tabIndex >= _tabEntries.size())
{ {
return 0; return 0;
} }
auto totalItems = _tabEntries[tabIndex].Entries.size(); const auto totalItems = _tabEntries[tabIndex].Entries.size();
auto numColumns = window_scenery_get_num_columns(w); const auto numColumns = window_scenery_get_num_columns(w);
auto rows = window_scenery_count_rows(w, totalItems + numColumns - 1); const auto rows = window_scenery_count_rows(w, totalItems + numColumns - 1);
return rows; return rows;
} }
@ -508,10 +505,10 @@ struct scenery_item
ScenerySelection scenerySelection; ScenerySelection scenerySelection;
}; };
static scenery_item window_scenery_count_rows_with_selected_item(rct_window* w, size_t tabIndex) static scenery_item window_scenery_count_rows_with_selected_item(rct_window* w, const size_t tabIndex)
{ {
scenery_item sceneryItem = { 0, 0, ScenerySelection() }; scenery_item sceneryItem = { 0, 0, ScenerySelection() };
const auto& scenerySelection = GetSelectedScenery(tabIndex); const auto scenerySelection = GetSelectedScenery(tabIndex);
const auto& tabInfo = _tabEntries[tabIndex]; const auto& tabInfo = _tabEntries[tabIndex];
for (size_t i = 0; i < tabInfo.Entries.size(); i++) for (size_t i = 0; i < tabInfo.Entries.size(); i++)
{ {
@ -526,7 +523,7 @@ static scenery_item window_scenery_count_rows_with_selected_item(rct_window* w,
return sceneryItem; return sceneryItem;
} }
static int32_t window_scenery_rows_height(size_t rows) static int32_t window_scenery_rows_height(const size_t rows)
{ {
return static_cast<int32_t>(rows * SCENERY_BUTTON_HEIGHT); return static_cast<int32_t>(rows * SCENERY_BUTTON_HEIGHT);
} }
@ -591,23 +588,23 @@ static void window_scenery_mouseup(rct_window* w, rct_widgetindex widgetIndex)
*/ */
void window_scenery_update_scroll(rct_window* w) void window_scenery_update_scroll(rct_window* w)
{ {
auto tabIndex = gWindowSceneryActiveTabIndex; const auto tabIndex = gWindowSceneryActiveTabIndex;
if (tabIndex >= _tabEntries.size()) if (tabIndex >= _tabEntries.size())
{ {
return; return;
} }
int32_t listHeight = w->height - 14 - w->widgets[WIDX_SCENERY_LIST].top - 1; const int32_t listHeight = w->height - 14 - w->widgets[WIDX_SCENERY_LIST].top - 1;
scenery_item sceneryItem = window_scenery_count_rows_with_selected_item(w, tabIndex); const auto sceneryItem = window_scenery_count_rows_with_selected_item(w, tabIndex);
w->scrolls[0].v_bottom = window_scenery_rows_height(sceneryItem.allRows) + 1; w->scrolls[0].v_bottom = window_scenery_rows_height(sceneryItem.allRows) + 1;
int32_t maxTop = std::max(0, w->scrolls[0].v_bottom - listHeight); const int32_t maxTop = std::max(0, w->scrolls[0].v_bottom - listHeight);
auto rowSelected = window_scenery_count_rows(w, sceneryItem.selected_item); auto rowSelected = window_scenery_count_rows(w, sceneryItem.selected_item);
if (sceneryItem.scenerySelection.IsUndefined()) if (sceneryItem.scenerySelection.IsUndefined())
{ {
rowSelected = 0; rowSelected = 0;
auto& scenery = _tabEntries[tabIndex].Entries[0]; const auto& scenery = _tabEntries[tabIndex].Entries[0];
if (!scenery.IsUndefined()) if (!scenery.IsUndefined())
{ {
SetSelectedScenery(tabIndex, scenery); SetSelectedScenery(tabIndex, scenery);
@ -758,12 +755,12 @@ static void window_scenery_update(rct_window* w)
else else
{ {
const auto& listWidget = w->widgets[WIDX_SCENERY_LIST]; const auto& listWidget = w->widgets[WIDX_SCENERY_LIST];
auto nonListHeight = w->height - listWidget.height() + 2; const auto nonListHeight = w->height - listWidget.height() + 2;
auto numRows = static_cast<int32_t>(window_scenery_count_rows(w)); const auto numRows = static_cast<int32_t>(window_scenery_count_rows(w));
auto maxContentHeight = numRows * SCENERY_BUTTON_HEIGHT; const auto maxContentHeight = numRows * SCENERY_BUTTON_HEIGHT;
auto maxWindowHeight = maxContentHeight + nonListHeight; const auto maxWindowHeight = maxContentHeight + nonListHeight;
auto windowHeight = std::clamp(maxWindowHeight, WINDOW_SCENERY_HEIGHT, 463); const auto windowHeight = std::clamp(maxWindowHeight, WINDOW_SCENERY_HEIGHT, 463);
w->min_width = WINDOW_SCENERY_WIDTH; w->min_width = WINDOW_SCENERY_WIDTH;
w->max_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH;
@ -803,8 +800,8 @@ static void window_scenery_update(rct_window* w)
} }
else else
{ {
auto tabIndex = gWindowSceneryActiveTabIndex; const auto tabIndex = gWindowSceneryActiveTabIndex;
auto tabSelectedScenery = GetSelectedScenery(tabIndex); const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
if (!tabSelectedScenery.IsUndefined()) if (!tabSelectedScenery.IsUndefined())
{ {
if (tabSelectedScenery.SceneryType == SCENERY_TYPE_BANNER) if (tabSelectedScenery.SceneryType == SCENERY_TYPE_BANNER)
@ -845,13 +842,13 @@ static ScenerySelection get_scenery_id_by_cursor_pos(rct_window* w, const Screen
{ {
ScenerySelection scenery{}; ScenerySelection scenery{};
auto numColumns = window_scenery_get_num_columns(w); const auto numColumns = window_scenery_get_num_columns(w);
auto colIndex = screenCoords.x / SCENERY_BUTTON_WIDTH; const auto colIndex = screenCoords.x / SCENERY_BUTTON_WIDTH;
auto rowIndex = screenCoords.y / SCENERY_BUTTON_HEIGHT; const auto rowIndex = screenCoords.y / SCENERY_BUTTON_HEIGHT;
if (colIndex >= 0 && colIndex < numColumns && rowIndex >= 0) if (colIndex >= 0 && colIndex < numColumns && rowIndex >= 0)
{ {
auto tabSceneryIndex = static_cast<size_t>((rowIndex * numColumns) + colIndex); const auto tabSceneryIndex = static_cast<size_t>((rowIndex * numColumns) + colIndex);
auto tabIndex = gWindowSceneryActiveTabIndex; const auto tabIndex = gWindowSceneryActiveTabIndex;
if (tabIndex < _tabEntries.size()) if (tabIndex < _tabEntries.size())
{ {
auto& tabInfo = _tabEntries[tabIndex]; auto& tabInfo = _tabEntries[tabIndex];
@ -870,7 +867,7 @@ static ScenerySelection get_scenery_id_by_cursor_pos(rct_window* w, const Screen
*/ */
void window_scenery_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords) void window_scenery_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
{ {
ScenerySelection scenery = get_scenery_id_by_cursor_pos(w, screenCoords); const auto scenery = get_scenery_id_by_cursor_pos(w, screenCoords);
if (scenery.IsUndefined()) if (scenery.IsUndefined())
return; return;
@ -906,7 +903,7 @@ OpenRCT2String window_scenery_tooltip(rct_window* w, const rct_widgetindex widge
{ {
if (widgetIndex >= WIDX_SCENERY_TAB_1) if (widgetIndex >= WIDX_SCENERY_TAB_1)
{ {
auto tabIndex = static_cast<size_t>(widgetIndex - WIDX_SCENERY_TAB_1); const auto tabIndex = static_cast<size_t>(widgetIndex - WIDX_SCENERY_TAB_1);
if (_tabEntries.size() > tabIndex) if (_tabEntries.size() > tabIndex)
{ {
const auto& tabInfo = _tabEntries[tabIndex]; const auto& tabInfo = _tabEntries[tabIndex];
@ -917,7 +914,7 @@ OpenRCT2String window_scenery_tooltip(rct_window* w, const rct_widgetindex widge
return { fallback, ft }; return { fallback, ft };
} }
auto sceneryEntry = tabInfo.GetSceneryGroupEntry(); const auto* sceneryEntry = tabInfo.GetSceneryGroupEntry();
if (sceneryEntry != nullptr) if (sceneryEntry != nullptr)
{ {
auto ft = Formatter(); auto ft = Formatter();
@ -937,7 +934,7 @@ void window_scenery_invalidate(rct_window* w)
{ {
// Set the window title // Set the window title
rct_string_id titleStringId = STR_MISCELLANEOUS; rct_string_id titleStringId = STR_MISCELLANEOUS;
auto tabIndex = gWindowSceneryActiveTabIndex; const auto tabIndex = gWindowSceneryActiveTabIndex;
if (tabIndex < _tabEntries.size()) if (tabIndex < _tabEntries.size())
{ {
const auto& tabInfo = _tabEntries[tabIndex]; const auto& tabInfo = _tabEntries[tabIndex];
@ -967,7 +964,7 @@ void window_scenery_invalidate(rct_window* w)
w->widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].type = WindowWidgetType::FlatBtn; w->widgets[WIDX_SCENERY_EYEDROPPER_BUTTON].type = WindowWidgetType::FlatBtn;
} }
auto tabSelectedScenery = GetSelectedScenery(tabIndex); const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
if (!tabSelectedScenery.IsUndefined()) if (!tabSelectedScenery.IsUndefined())
{ {
if (tabSelectedScenery.SceneryType == SCENERY_TYPE_SMALL) if (tabSelectedScenery.SceneryType == SCENERY_TYPE_SMALL)
@ -1061,7 +1058,7 @@ void window_scenery_invalidate(rct_window* w)
auto windowWidth = w->width; auto windowWidth = w->width;
if (_tabEntries.size() > 0) if (_tabEntries.size() > 0)
{ {
auto lastTabIndex = _tabEntries.size() - 1; const auto lastTabIndex = _tabEntries.size() - 1;
const auto lastTabWidget = &w->widgets[WIDX_SCENERY_TAB_1 + lastTabIndex]; const auto lastTabWidget = &w->widgets[WIDX_SCENERY_TAB_1 + lastTabIndex];
windowWidth = std::max<int32_t>(windowWidth, lastTabWidget->right + 3); windowWidth = std::max<int32_t>(windowWidth, lastTabWidget->right + 3);
} }
@ -1170,7 +1167,7 @@ void window_scenery_paint(rct_window* w, rct_drawpixelinfo* dpi)
{ {
WindowDrawWidgets(w, dpi); WindowDrawWidgets(w, dpi);
auto tabIndex = gWindowSceneryActiveTabIndex; const auto tabIndex = gWindowSceneryActiveTabIndex;
if (tabIndex < _tabEntries.size()) if (tabIndex < _tabEntries.size())
{ {
auto selectedWidgetId = static_cast<rct_widgetindex>(WIDX_SCENERY_TAB_1 + tabIndex); auto selectedWidgetId = static_cast<rct_widgetindex>(WIDX_SCENERY_TAB_1 + tabIndex);
@ -1337,7 +1334,7 @@ void window_scenery_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t s
for (size_t sceneryTabItemIndex = 0; sceneryTabItemIndex < tabInfo.Entries.size(); sceneryTabItemIndex++) for (size_t sceneryTabItemIndex = 0; sceneryTabItemIndex < tabInfo.Entries.size(); sceneryTabItemIndex++)
{ {
const auto& currentSceneryGlobal = tabInfo.Entries[sceneryTabItemIndex]; const auto& currentSceneryGlobal = tabInfo.Entries[sceneryTabItemIndex];
auto tabSelectedScenery = GetSelectedScenery(tabIndex); const auto tabSelectedScenery = GetSelectedScenery(tabIndex);
if (gWindowSceneryPaintEnabled == 1 || gWindowSceneryEyedropperEnabled) if (gWindowSceneryPaintEnabled == 1 || gWindowSceneryEyedropperEnabled)
{ {
if (_selectedScenery == currentSceneryGlobal) if (_selectedScenery == currentSceneryGlobal)

View File

@ -284,7 +284,7 @@ int32_t wall_entry_get_door_sound(const WallSceneryEntry* wallEntry)
return (wallEntry->flags2 & WALL_SCENERY_2_DOOR_SOUND_MASK) >> WALL_SCENERY_2_DOOR_SOUND_SHIFT; return (wallEntry->flags2 & WALL_SCENERY_2_DOOR_SOUND_MASK) >> WALL_SCENERY_2_DOOR_SOUND_SHIFT;
} }
bool IsSceneryAvailableToBuild(ScenerySelection item) bool IsSceneryAvailableToBuild(const ScenerySelection& item)
{ {
if (!gCheatsIgnoreResearchStatus) if (!gCheatsIgnoreResearchStatus)
{ {
@ -305,7 +305,7 @@ bool IsSceneryAvailableToBuild(ScenerySelection item)
return true; return true;
} }
static size_t GetMaxObjectsForSceneryType(uint8_t sceneryType) static size_t GetMaxObjectsForSceneryType(const uint8_t sceneryType)
{ {
switch (sceneryType) switch (sceneryType)
{ {
@ -324,7 +324,7 @@ static size_t GetMaxObjectsForSceneryType(uint8_t sceneryType)
} }
} }
static SceneryEntryBase* GetSceneryEntry(ScenerySelection item) static SceneryEntryBase* GetSceneryEntry(const ScenerySelection& item)
{ {
switch (item.SceneryType) switch (item.SceneryType)
{ {
@ -343,10 +343,9 @@ static SceneryEntryBase* GetSceneryEntry(ScenerySelection item)
} }
} }
bool IsSceneryItemRestricted(ScenerySelection item) bool IsSceneryItemRestricted(const ScenerySelection& item)
{ {
auto it = std::find(_restrictedScenery.begin(), _restrictedScenery.end(), item); return std::find(std::begin(_restrictedScenery), std::end(_restrictedScenery), item) != std::end(_restrictedScenery);
return it != _restrictedScenery.end();
} }
void ClearRestrictedScenery() void ClearRestrictedScenery()
@ -364,7 +363,7 @@ void RestrictAllMiscScenery()
std::vector<ScenerySelection> nonMiscScenery; std::vector<ScenerySelection> nonMiscScenery;
for (ObjectEntryIndex i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++) for (ObjectEntryIndex i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
{ {
auto sgEntry = get_scenery_group_entry(i); const auto* sgEntry = get_scenery_group_entry(i);
if (sgEntry != nullptr) if (sgEntry != nullptr)
{ {
for (size_t j = 0; j < sgEntry->entry_count; j++) for (size_t j = 0; j < sgEntry->entry_count; j++)
@ -375,15 +374,14 @@ void RestrictAllMiscScenery()
} }
for (uint8_t sceneryType = SCENERY_TYPE_SMALL; sceneryType < SCENERY_TYPE_COUNT; sceneryType++) for (uint8_t sceneryType = SCENERY_TYPE_SMALL; sceneryType < SCENERY_TYPE_COUNT; sceneryType++)
{ {
auto maxObjects = GetMaxObjectsForSceneryType(sceneryType); const auto maxObjects = GetMaxObjectsForSceneryType(sceneryType);
for (ObjectEntryIndex i = 0; i < maxObjects; i++) for (ObjectEntryIndex i = 0; i < maxObjects; i++)
{ {
ScenerySelection sceneryItem = { sceneryType, i }; const ScenerySelection sceneryItem = { sceneryType, i };
auto sceneryEntry = GetSceneryEntry(sceneryItem); const auto* sceneryEntry = GetSceneryEntry(sceneryItem);
if (sceneryEntry != nullptr) if (sceneryEntry != nullptr)
{ {
auto it = std::find(nonMiscScenery.begin(), nonMiscScenery.end(), sceneryItem); if (std::find(std::begin(nonMiscScenery), std::end(nonMiscScenery), sceneryItem) == std::end(nonMiscScenery))
if (it == nonMiscScenery.end())
{ {
_restrictedScenery.push_back(sceneryItem); _restrictedScenery.push_back(sceneryItem);
} }

View File

@ -295,9 +295,9 @@ rct_scenery_group_entry* get_scenery_group_entry(ObjectEntryIndex entryIndex);
int32_t wall_entry_get_door_sound(const WallSceneryEntry* wallEntry); int32_t wall_entry_get_door_sound(const WallSceneryEntry* wallEntry);
bool IsSceneryAvailableToBuild(ScenerySelection item); bool IsSceneryAvailableToBuild(const ScenerySelection& item);
bool IsSceneryItemRestricted(ScenerySelection item); bool IsSceneryItemRestricted(const ScenerySelection& item);
void ClearRestrictedScenery(); void ClearRestrictedScenery();
void RestrictAllMiscScenery(); void RestrictAllMiscScenery();
std::vector<ScenerySelection>& GetRestrictedScenery(); std::vector<ScenerySelection>& GetRestrictedScenery();