diff --git a/openrct2.vcxproj b/openrct2.vcxproj index 8690833636..59adc5e95e 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -125,6 +125,7 @@ + @@ -434,6 +435,7 @@ + diff --git a/src/object/FootpathItemObject.cpp b/src/object/FootpathItemObject.cpp index 6538292425..c765f4f3a7 100644 --- a/src/object/FootpathItemObject.cpp +++ b/src/object/FootpathItemObject.cpp @@ -37,7 +37,6 @@ void FootpathItemObject::ReadLegacy(IStream * stream) _legacyType.path_bit.tool_id = stream->ReadValue(); _legacyType.path_bit.price = stream->ReadValue(); _legacyType.path_bit.scenery_tab_id = stream->ReadValue(); - stream->Seek(0, STREAM_SEEK_BEGIN); StringTable.Read(stream, OBJ_STRING_ID_NAME); diff --git a/src/object/ObjectFactory.cpp b/src/object/ObjectFactory.cpp index e91fa07d5b..b89463287b 100644 --- a/src/object/ObjectFactory.cpp +++ b/src/object/ObjectFactory.cpp @@ -22,6 +22,7 @@ #include "FootpathObject.h" #include "Object.h" #include "ObjectFactory.h" +#include "SmallSceneryObject.h" #include "StexObject.h" extern "C" @@ -64,6 +65,9 @@ namespace ObjectFactory uint8 objectType = entry.flags & 0x0F; switch (objectType) { + case OBJECT_TYPE_SMALL_SCENERY: + result = new SmallSceneryObject(entry); + break; case OBJECT_TYPE_PATHS: result = new FootpathObject(entry); break; diff --git a/src/object/SmallSceneryObject.cpp b/src/object/SmallSceneryObject.cpp new file mode 100644 index 0000000000..055b28fa4b --- /dev/null +++ b/src/object/SmallSceneryObject.cpp @@ -0,0 +1,103 @@ +#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 "SmallSceneryObject.h" + +extern "C" +{ + #include "../drawing/drawing.h" + #include "../localisation/localisation.h" +} + +enum OBJ_STRING_ID +{ + OBJ_STRING_ID_NAME, +}; + +SmallSceneryObject::~SmallSceneryObject() +{ + Memory::Free(_var10data); +} + +void SmallSceneryObject::ReadLegacy(IStream * stream) +{ + _legacyType.name = stream->ReadValue(); + _legacyType.image = stream->ReadValue(); + + _legacyType.small_scenery.flags = stream->ReadValue(); + _legacyType.small_scenery.height = stream->ReadValue(); + _legacyType.small_scenery.tool_id = stream->ReadValue(); + _legacyType.small_scenery.price = stream->ReadValue(); + _legacyType.small_scenery.removal_price = stream->ReadValue(); + _legacyType.small_scenery.var_10 = stream->ReadValue(); + _legacyType.small_scenery.var_14 = stream->ReadValue(); + _legacyType.small_scenery.var_16 = stream->ReadValue(); + _legacyType.small_scenery.var_18 = stream->ReadValue(); + _legacyType.small_scenery.scenery_tab_id = 0xFF; + + StringTable.Read(stream, OBJ_STRING_ID_NAME); + + _sceneryTabEntry = stream->ReadValue(); + + if (_legacyType.small_scenery.flags & SMALL_SCENERY_FLAG16) + { + _var10data = ReadVar10(stream); + } + + ImageTable.Read(stream); +} + +void SmallSceneryObject::Load() +{ + _legacyType.name = language_allocate_object_string(GetName()); + _legacyType.image = gfx_object_allocate_images(ImageTable.GetImages(), ImageTable.GetCount()); + + _legacyType.small_scenery.scenery_tab_id = 0xFF; + if ((_sceneryTabEntry.flags & 0xFF) != 0xFF) + { + uint8 entryType, entryIndex; + if (find_object_in_entry_group(&_sceneryTabEntry, &entryType, &entryIndex)) + { + _legacyType.small_scenery.scenery_tab_id = entryIndex; + } + } +} + +void SmallSceneryObject::Unload() +{ + language_free_object_string(_legacyType.name); + gfx_object_free_images(_legacyType.image, ImageTable.GetCount()); +} + +const utf8 * SmallSceneryObject::GetName() +{ + return StringTable.GetString(OBJ_STRING_ID_NAME); +} + +uint8 * SmallSceneryObject::ReadVar10(IStream * stream) +{ + uint8 b; + auto data = std::vector(); + data.push_back(stream->ReadValue()); + while ((b = stream->ReadValue()) != 0xFF) + { + data.push_back(b); + } + data.push_back(b); + return Memory::Duplicate(data.data(), data.size()); +} diff --git a/src/object/SmallSceneryObject.h b/src/object/SmallSceneryObject.h new file mode 100644 index 0000000000..5f0aa5e73f --- /dev/null +++ b/src/object/SmallSceneryObject.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 SmallSceneryObject : public Object +{ +private: + rct_scenery_entry _legacyType; + rct_object_entry _sceneryTabEntry; + uint8 * _var10data = nullptr; + +public: + explicit SmallSceneryObject(const rct_object_entry &entry) : Object(entry) { }; + ~SmallSceneryObject(); + + void * GetLegacyData() override { return &_legacyType; } + + void ReadLegacy(IStream * stream) override; + void Load() override; + void Unload() override; + + const utf8 * GetName() override; + +private: + static uint8 * ReadVar10(IStream * stream); +};