From 6912c537bb83485df60b792524cae2c83f7de528 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 26 Jun 2016 00:06:55 +0100 Subject: [PATCH] add scenery group object loading --- openrct2.vcxproj | 2 + src/object/ObjectFactory.cpp | 4 ++ src/object/SceneryGroupObject.cpp | 107 ++++++++++++++++++++++++++++++ src/object/SceneryGroupObject.h | 47 +++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 src/object/SceneryGroupObject.cpp create mode 100644 src/object/SceneryGroupObject.h diff --git a/openrct2.vcxproj b/openrct2.vcxproj index 361dc624e3..f6e3e10429 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -128,6 +128,7 @@ + @@ -442,6 +443,7 @@ + diff --git a/src/object/ObjectFactory.cpp b/src/object/ObjectFactory.cpp index 4f7c0041d2..667019af33 100644 --- a/src/object/ObjectFactory.cpp +++ b/src/object/ObjectFactory.cpp @@ -25,6 +25,7 @@ #include "Object.h" #include "ObjectFactory.h" #include "RideObject.h" +#include "SceneryGroupObject.h" #include "SmallSceneryObject.h" #include "StexObject.h" #include "WallObject.h" @@ -90,6 +91,9 @@ namespace ObjectFactory case OBJECT_TYPE_PATH_BITS: result = new FootpathItemObject(entry); break; + case OBJECT_TYPE_SCENERY_SETS: + result = new SceneryGroupObject(entry); + break; case OBJECT_TYPE_PARK_ENTRANCE: result = new EntranceObject(entry); break; diff --git a/src/object/SceneryGroupObject.cpp b/src/object/SceneryGroupObject.cpp new file mode 100644 index 0000000000..ab9c6d555f --- /dev/null +++ b/src/object/SceneryGroupObject.cpp @@ -0,0 +1,107 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#include "../core/IStream.hpp" +#include "../core/Memory.hpp" +#include "SceneryGroupObject.h" + +extern "C" +{ + #include "../drawing/drawing.h" + #include "../localisation/localisation.h" +} + +enum OBJ_STRING_ID +{ + OBJ_STRING_ID_NAME, +}; + +SceneryGroupObject::~SceneryGroupObject() +{ + Memory::Free(_items); +} + +void SceneryGroupObject::ReadLegacy(IStream * stream) +{ + _legacyType.name = stream->ReadValue(); + _legacyType.image = stream->ReadValue(); + stream->Seek(0x80 * 2, STREAM_SEEK_CURRENT); + _legacyType.entry_count = stream->ReadValue(); + _legacyType.var_107 = stream->ReadValue(); + _legacyType.var_108 = stream->ReadValue(); + _legacyType.pad_109 = stream->ReadValue(); + _legacyType.var_10A = stream->ReadValue(); + + StringTable.Read(stream, OBJ_STRING_ID_NAME); + ReadItems(stream); + ImageTable.Read(stream); + + _legacyType.var_107 = _numItems; +} + +void SceneryGroupObject::Load() +{ + _legacyType.name = language_allocate_object_string(GetName()); + _legacyType.image = gfx_object_allocate_images(ImageTable.GetImages(), ImageTable.GetCount()); + + _legacyType.entry_count = 0; + for (uint32 i = 0; i < _numItems; i++) + { + uint8 entryType; + uint8 entryIndex; + if (find_object_in_entry_group(&_items[i], &entryType, &entryIndex)) + { + uint16 sceneryEntry = entryIndex; + switch (entryType) { + case OBJECT_TYPE_SMALL_SCENERY: break; + case OBJECT_TYPE_LARGE_SCENERY: sceneryEntry |= 0x300; break; + case OBJECT_TYPE_WALLS: sceneryEntry |= 0x200; break; + case OBJECT_TYPE_PATH_BITS: sceneryEntry |= 0x100; break; + default: sceneryEntry |= 0x400; break; + } + + _legacyType.scenery_entries[_legacyType.entry_count] = sceneryEntry; + _legacyType.entry_count++; + } + } +} + +void SceneryGroupObject::Unload() +{ + language_free_object_string(_legacyType.name); + gfx_object_free_images(_legacyType.image, ImageTable.GetCount()); +} + +const utf8 * SceneryGroupObject::GetName() +{ + return StringTable.GetString(OBJ_STRING_ID_NAME); +} + +void SceneryGroupObject::ReadItems(IStream * stream) +{ + auto items = std::vector(); + + uint8 endMarker; + while ((endMarker = stream->ReadValue()) != 0xFF) + { + stream->Seek(-1, STREAM_SEEK_CURRENT); + rct_object_entry entry = stream->ReadValue(); + items.push_back(entry); + } + + _numItems = items.size(); + _items = Memory::DuplicateArray(items.data(), items.size()); +} diff --git a/src/object/SceneryGroupObject.h b/src/object/SceneryGroupObject.h new file mode 100644 index 0000000000..8f8b45ae48 --- /dev/null +++ b/src/object/SceneryGroupObject.h @@ -0,0 +1,47 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#pragma once + +#include "Object.h" + +extern "C" +{ + #include "../world/scenery.h" +} + +class SceneryGroupObject : public Object +{ +private: + rct_scenery_set_entry _legacyType; + uint32 _numItems; + rct_object_entry * _items; + +public: + explicit SceneryGroupObject(const rct_object_entry &entry) : Object(entry) { }; + ~SceneryGroupObject(); + + void * GetLegacyData() override { return &_legacyType; } + + void ReadLegacy(IStream * stream) override; + void Load() override; + void Unload() override; + + const utf8 * GetName() override; + +private: + void ReadItems(IStream * stream); +};