From 25af7d346cc31970be19d5d0b99145a4f711ced8 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 26 Jun 2016 00:31:16 +0100 Subject: [PATCH] add water object loading --- openrct2.vcxproj | 2 ++ src/object/ObjectFactory.cpp | 4 +++ src/object/WaterObject.cpp | 65 ++++++++++++++++++++++++++++++++++++ src/object/WaterObject.h | 41 +++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 src/object/WaterObject.cpp create mode 100644 src/object/WaterObject.h diff --git a/openrct2.vcxproj b/openrct2.vcxproj index f6e3e10429..f0f2277fe1 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -133,6 +133,7 @@ + @@ -448,6 +449,7 @@ + diff --git a/src/object/ObjectFactory.cpp b/src/object/ObjectFactory.cpp index 667019af33..6af113b9ba 100644 --- a/src/object/ObjectFactory.cpp +++ b/src/object/ObjectFactory.cpp @@ -29,6 +29,7 @@ #include "SmallSceneryObject.h" #include "StexObject.h" #include "WallObject.h" +#include "WaterObject.h" extern "C" { @@ -97,6 +98,9 @@ namespace ObjectFactory case OBJECT_TYPE_PARK_ENTRANCE: result = new EntranceObject(entry); break; + case OBJECT_TYPE_WATER: + result = new WaterObject(entry); + break; case OBJECT_TYPE_SCENARIO_TEXT: result = new StexObject(entry); break; diff --git a/src/object/WaterObject.cpp b/src/object/WaterObject.cpp new file mode 100644 index 0000000000..9f87be8c5b --- /dev/null +++ b/src/object/WaterObject.cpp @@ -0,0 +1,65 @@ +#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 "WaterObject.h" + +extern "C" +{ + #include "../addresses.h" + #include "../localisation/localisation.h" +} + +enum OBJ_STRING_ID +{ + OBJ_STRING_ID_NAME, +}; + +void WaterObject::ReadLegacy(IStream * stream) +{ + _legacyType.string_idx = stream->ReadValue(); + _legacyType.image_id = stream->ReadValue(); + _legacyType.var_06 = stream->ReadValue(); + _legacyType.var_0A = stream->ReadValue(); + _legacyType.var_0E = stream->ReadValue(); + + StringTable.Read(stream, OBJ_STRING_ID_NAME); + ImageTable.Read(stream); +} + +void WaterObject::Load() +{ + _legacyType.string_idx = language_allocate_object_string(GetName()); + _legacyType.image_id = gfx_object_allocate_images(ImageTable.GetImages(), ImageTable.GetCount()); + _legacyType.var_06 = _legacyType.image_id + 1; + _legacyType.var_0A = _legacyType.image_id + 4; + + if (RCT2_GLOBAL(0x009ADAFD, uint8) == 0) + { + load_palette(); + gfx_invalidate_screen(); + } +} + +void WaterObject::Unload() +{ + language_free_object_string(_legacyType.string_idx); +} + +const utf8 * WaterObject::GetName() +{ + return StringTable.GetString(OBJ_STRING_ID_NAME); +} diff --git a/src/object/WaterObject.h b/src/object/WaterObject.h new file mode 100644 index 0000000000..147ad7f570 --- /dev/null +++ b/src/object/WaterObject.h @@ -0,0 +1,41 @@ +#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/water.h" +} + +class WaterObject : public Object +{ +private: + rct_water_type _legacyType; + +public: + explicit WaterObject(const rct_object_entry &entry) : Object(entry) { }; + + void * GetLegacyData() override { return &_legacyType; } + + void ReadLegacy(IStream * stream) override; + void Load() override; + void Unload() override; + + const utf8 * GetName() override; +};