diff --git a/src/object.h b/src/object.h index 8c154b410d..8d4177e6d2 100644 --- a/src/object.h +++ b/src/object.h @@ -40,7 +40,7 @@ typedef enum{ OBJECT_SELECTION_FLAG_SELECTED = (1 << 0), OBJECT_SELECTION_FLAG_2 = (1 << 1), OBJECT_SELECTION_FLAG_IN_USE = (1 << 2), - OBJECT_SELECTION_FLAG_REQUIRED = (1 << 3), + // OBJECT_SELECTION_FLAG_REQUIRED = (1 << 3), // Unused feature OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED = (1 << 4), OBJECT_SELECTION_FLAG_6 = (1 << 5), OBJECT_SELECTION_FLAG_7 = (1 << 6), diff --git a/src/object/ObjectRepository.cpp b/src/object/ObjectRepository.cpp index d700dfd18c..95e00a5090 100644 --- a/src/object/ObjectRepository.cpp +++ b/src/object/ObjectRepository.cpp @@ -44,7 +44,7 @@ extern "C" #include "../util/sawyercoding.h" } -constexpr uint16 OBJECT_REPOSITORY_VERSION = 6; +constexpr uint16 OBJECT_REPOSITORY_VERSION = 7; struct ObjectRepositoryHeader { @@ -391,13 +391,6 @@ private: item.NumImages = stream->ReadValue(); item.Name = stream->ReadString(); item.ChunkSize = stream->ReadValue(); - item.NumRequiredObjects = stream->ReadValue(); - - item.RequiredObjects = Memory::AllocateArray(item.NumRequiredObjects); - for (uint16 i = 0; i < item.NumRequiredObjects; i++) - { - item.RequiredObjects[i] = stream->ReadValue(); - } switch (item.ObjectEntry.flags & 0x0F) { case OBJECT_TYPE_RIDE: @@ -430,12 +423,6 @@ private: stream->WriteValue(item.NumImages); stream->WriteString(item.Name); stream->WriteValue(item.ChunkSize); - - stream->WriteValue(item.NumRequiredObjects); - for (uint16 i = 0; i < item.NumRequiredObjects; i++) - { - stream->WriteValue(item.RequiredObjects[i]); - } switch (item.ObjectEntry.flags & 0x0F) { case OBJECT_TYPE_RIDE: @@ -463,11 +450,9 @@ private: { Memory::Free(item->Path); Memory::Free(item->Name); - Memory::Free(item->RequiredObjects); Memory::Free(item->ThemeObjects); item->Path = nullptr; item->Name = nullptr; - item->RequiredObjects = nullptr; item->ThemeObjects = nullptr; } diff --git a/src/object/ObjectRepository.h b/src/object/ObjectRepository.h index 4e1aa4e402..d35bff222c 100644 --- a/src/object/ObjectRepository.h +++ b/src/object/ObjectRepository.h @@ -34,8 +34,6 @@ typedef struct ObjectRepositoryItem uint32 NumImages; utf8 * Name; size_t ChunkSize; - uint16 NumRequiredObjects; - rct_object_entry * RequiredObjects; union { struct diff --git a/src/object/SceneryGroupObject.cpp b/src/object/SceneryGroupObject.cpp index 800516be23..c2d1094867 100644 --- a/src/object/SceneryGroupObject.cpp +++ b/src/object/SceneryGroupObject.cpp @@ -16,6 +16,7 @@ #include "../core/IStream.hpp" #include "../core/Memory.hpp" +#include "ObjectRepository.h" #include "SceneryGroupObject.h" extern "C" @@ -100,6 +101,18 @@ const utf8 * SceneryGroupObject::GetName() const return name != nullptr ? name : ""; } +void SceneryGroupObject::SetRepositoryItem(ObjectRepositoryItem * item) const +{ + Memory::Free(item->ThemeObjects); + + item->NumThemeObjects = _numItems; + item->ThemeObjects = Memory::AllocateArray(_numItems); + for (uint32 i = 0; i < _numItems; i++) + { + item->ThemeObjects[i] = _items[i]; + } +} + void SceneryGroupObject::ReadItems(IStream * stream) { auto items = std::vector(); diff --git a/src/object/SceneryGroupObject.h b/src/object/SceneryGroupObject.h index 29a60c8ee4..f2867bdc1b 100644 --- a/src/object/SceneryGroupObject.h +++ b/src/object/SceneryGroupObject.h @@ -23,6 +23,8 @@ extern "C" #include "../world/scenery.h" } +struct ObjectRepositoryItem; + class SceneryGroupObject : public Object { private: @@ -44,6 +46,8 @@ public: const utf8 * GetName() const override; + void SetRepositoryItem(ObjectRepositoryItem * item) const override; + private: void ReadItems(IStream * stream); }; diff --git a/src/windows/editor_object_selection.c b/src/windows/editor_object_selection.c index 23f1ecf00e..bee24b36dc 100644 --- a/src/windows/editor_object_selection.c +++ b/src/windows/editor_object_selection.c @@ -231,7 +231,6 @@ static bool filter_chunks(const ObjectRepositoryItem * item); static void filter_update_counts(); void reset_selected_object_count_and_size(); -void reset_required_object_flags(); static int sub_6AB211(); static rct_object_entry RequiredSelectedObjects[] = { @@ -673,7 +672,6 @@ static int sub_6AB211() } } - reset_required_object_flags(); reset_selected_object_count_and_size(); return 1; } @@ -1420,7 +1418,7 @@ static void window_editor_object_selection_scrollpaint(rct_window *w, rct_drawpi x = 2; gCurrentFontSpriteBase = colour == 14 ? -2 : -1; colour2 = w->colours[1] & 0x7F; - if (*listItem->flags & (OBJECT_SELECTION_FLAG_IN_USE | OBJECT_SELECTION_FLAG_REQUIRED | OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED)) + if (*listItem->flags & (OBJECT_SELECTION_FLAG_IN_USE | OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED)) colour2 |= 0x40; gfx_draw_string(dpi, (char*)CheckBoxMarkString, colour2, x, y); @@ -1537,53 +1535,6 @@ void reset_selected_object_count_and_size() } } -/** - * - * rct2: 0x006AB863 - */ -void set_required_object_flags(rct_object_entry* required_object) -{ - int numObjects = (int)object_repository_get_items_count(); - const ObjectRepositoryItem * items = object_repository_get_items(); - for (int i = 0; i < numObjects; i++) { - const ObjectRepositoryItem * item = &items[i]; - if (object_entry_compare(required_object, &item->ObjectEntry)) { - _objectSelectionFlags[i] |= OBJECT_SELECTION_FLAG_REQUIRED; - - uint16 numRequiredObjects = item->NumRequiredObjects; - for (uint16 j = 0; j < numRequiredObjects; j++) { - set_required_object_flags(&item->RequiredObjects[j]); - } - break; - } - } -} - -/** - * - * rct2: 0x006AB923 - */ -void reset_required_object_flags() -{ - int numObjects = (int)object_repository_get_items_count(); - const ObjectRepositoryItem * items = object_repository_get_items(); - - for (int i = 0; i < numObjects; i++) { - _objectSelectionFlags[i] &= ~OBJECT_SELECTION_FLAG_REQUIRED; - } - - for (int i = 0; i < numObjects; i++) { - const ObjectRepositoryItem * item = &items[i]; - - if (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED) { - uint16 numRequiredObjects = item->NumRequiredObjects; - for (uint16 j = 0; j < numRequiredObjects; j++) { - set_required_object_flags(&item->RequiredObjects[j]); - } - } - } -} - /** * Master objects are objects that are not * optional / required dependants of an @@ -1620,41 +1571,27 @@ static int window_editor_object_selection_select_object(uint8 bh, int flags, con uint8 * selectionFlags = &_objectSelectionFlags[index]; if (!(flags & 1)) { - if (!(*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED)) - { - if (bh == 0){ - reset_required_object_flags(); - } + if (!(*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED)) { return 1; } - else if (*selectionFlags & OBJECT_SELECTION_FLAG_IN_USE){ + else if (*selectionFlags & OBJECT_SELECTION_FLAG_IN_USE) { set_object_selection_error(bh, 3173); return 0; } - else if (*selectionFlags & OBJECT_SELECTION_FLAG_REQUIRED){ - set_object_selection_error(bh, 3174); - return 0; - } - else if (*selectionFlags & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED){ + else if (*selectionFlags & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED) { set_object_selection_error(bh, 3175); return 0; } - uint16 numThemeObjects = item->NumThemeObjects; - if (numThemeObjects != 0 && flags & (1 << 2)) { - rct_object_entry* theme_object = item->ThemeObjects; - for (; numThemeObjects > 0; numThemeObjects--) { - window_editor_object_selection_select_object(++bh, flags, theme_object); - theme_object++; + if (flags & (1 << 2)) { + for (int j = 0; j < item->NumThemeObjects; j++) { + window_editor_object_selection_select_object(++bh, flags, &item->ThemeObjects[j]); } } uint8 objectType = item->ObjectEntry.flags & 0xF; _numSelectedObjectsForType[objectType]--; *selectionFlags &= ~OBJECT_SELECTION_FLAG_SELECTED; - if (bh == 0) { - reset_required_object_flags(); - } return 1; } else { if (bh == 0) { @@ -1663,9 +1600,6 @@ static int window_editor_object_selection_select_object(uint8 bh, int flags, con } } if (*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED) { - if (bh == 0) { - reset_required_object_flags(); - } return 1; } @@ -1680,21 +1614,10 @@ static int window_editor_object_selection_select_object(uint8 bh, int flags, con return 0; } - for (uint16 j = 0; j < item->NumRequiredObjects; j++) { - if (!window_editor_object_selection_select_object(++bh, flags, &item->RequiredObjects[j])) { - if (bh != 0) { - reset_selected_object_count_and_size(); - } - return 0; - } - } - - if (objectType == OBJECT_TYPE_SCENERY_SETS) { + if (objectType == OBJECT_TYPE_SCENERY_SETS && (flags & (1 << 2))) { for (uint16 j = 0; j < item->NumThemeObjects; j++) { - if (flags & (1 << 2)) { - if (!window_editor_object_selection_select_object(++bh, flags, &item->ThemeObjects[j])) { - _maxObjectsWasHit = true; - } + if (!window_editor_object_selection_select_object(++bh, flags, &item->ThemeObjects[j])) { + _maxObjectsWasHit = true; } } } @@ -1714,9 +1637,6 @@ static int window_editor_object_selection_select_object(uint8 bh, int flags, con _numSelectedObjectsForType[objectType]++; *selectionFlags |= OBJECT_SELECTION_FLAG_SELECTED; - if (bh == 0) { - reset_required_object_flags(); - } return 1; } }