From bcba227430f0b669077c6ddac769a945177d2321 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 29 Aug 2021 17:07:38 +0200 Subject: [PATCH] Add footpath surface and railings objects from NSF --- OpenRCT2.xcodeproj/project.pbxproj | 12 +++ src/openrct2/interface/Colour.h | 4 +- src/openrct2/libopenrct2.vcxproj | 6 +- .../object/FootpathRailingsObject.cpp | 94 +++++++++++++++++++ src/openrct2/object/FootpathRailingsObject.h | 41 ++++++++ src/openrct2/object/FootpathSurfaceObject.cpp | 69 ++++++++++++++ src/openrct2/object/FootpathSurfaceObject.h | 36 +++++++ src/openrct2/object/Object.h | 2 + src/openrct2/object/ObjectFactory.cpp | 12 +++ src/openrct2/object/ObjectRepository.h | 4 + src/openrct2/world/Footpath.h | 1 + 11 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 src/openrct2/object/FootpathRailingsObject.cpp create mode 100644 src/openrct2/object/FootpathRailingsObject.h create mode 100644 src/openrct2/object/FootpathSurfaceObject.cpp create mode 100644 src/openrct2/object/FootpathSurfaceObject.h diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index 5733a6f091..f0fdda19f7 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -60,6 +60,8 @@ 4C8BB68525533DB9005C8830 /* ZoomLevel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C8BB68425533DB9005C8830 /* ZoomLevel.cpp */; }; 4C91FD5F25AE476700CA5DA4 /* MusicObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C91FD5D25AE476700CA5DA4 /* MusicObject.cpp */; }; 4C91FD6225AE483700CA5DA4 /* RideAudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C91FD6025AE483600CA5DA4 /* RideAudio.cpp */; }; + 4C976BC5263976F0002DEBD5 /* FootpathSurfaceObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C976BC1263976F0002DEBD5 /* FootpathSurfaceObject.cpp */; }; + 4C976BC6263976F0002DEBD5 /* FootpathRailingsObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C976BC2263976F0002DEBD5 /* FootpathRailingsObject.cpp */; }; 4CA23D64263C91D800077AA1 /* ChecksumStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CA23D62263C91D700077AA1 /* ChecksumStream.cpp */; }; 4CA23DB2263C920900077AA1 /* Entity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CA23DB1263C920900077AA1 /* Entity.cpp */; }; 4CA39E512513F8A00094066B /* RTL.ICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CA39E4E2513F8A00094066B /* RTL.ICU.cpp */; }; @@ -1189,6 +1191,10 @@ 4C93F1B71F8E185600A9330D /* NewsItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewsItem.h; sourceTree = ""; }; 4C93F1B81F8E185600A9330D /* Research.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Research.cpp; sourceTree = ""; }; 4C93F1B91F8E185600A9330D /* Research.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Research.h; sourceTree = ""; }; + 4C976BC1263976F0002DEBD5 /* FootpathSurfaceObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FootpathSurfaceObject.cpp; sourceTree = ""; }; + 4C976BC2263976F0002DEBD5 /* FootpathRailingsObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FootpathRailingsObject.cpp; sourceTree = ""; }; + 4C976BC3263976F0002DEBD5 /* FootpathRailingsObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FootpathRailingsObject.h; sourceTree = ""; }; + 4C976BC4263976F0002DEBD5 /* FootpathSurfaceObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FootpathSurfaceObject.h; sourceTree = ""; }; 4CA23D62263C91D700077AA1 /* ChecksumStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ChecksumStream.cpp; sourceTree = ""; }; 4CA23D63263C91D700077AA1 /* ChecksumStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChecksumStream.h; sourceTree = ""; }; 4CA23DAF263C920900077AA1 /* Entity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Entity.h; sourceTree = ""; }; @@ -2739,6 +2745,10 @@ F76C84171EC4E7CC00FA49E2 /* FootpathItemObject.h */, F76C84181EC4E7CC00FA49E2 /* FootpathObject.cpp */, F76C84191EC4E7CC00FA49E2 /* FootpathObject.h */, + 4C976BC2263976F0002DEBD5 /* FootpathRailingsObject.cpp */, + 4C976BC3263976F0002DEBD5 /* FootpathRailingsObject.h */, + 4C976BC1263976F0002DEBD5 /* FootpathSurfaceObject.cpp */, + 4C976BC4263976F0002DEBD5 /* FootpathSurfaceObject.h */, F76C841A1EC4E7CC00FA49E2 /* ImageTable.cpp */, F76C841B1EC4E7CC00FA49E2 /* ImageTable.h */, F76C841C1EC4E7CC00FA49E2 /* LargeSceneryObject.cpp */, @@ -3980,6 +3990,7 @@ 4CA23DB2263C920900077AA1 /* Entity.cpp in Sources */, C64644F91F3FA4120026AC2D /* EditorInventionsList.cpp in Sources */, C68878C720289B710084B384 /* OpenGLShaderProgram.cpp in Sources */, + 4C976BC5263976F0002DEBD5 /* FootpathSurfaceObject.cpp in Sources */, 4CA39E512513F8A00094066B /* RTL.ICU.cpp in Sources */, 93CBA4C420A7502E00867D56 /* Imaging.cpp in Sources */, C6D2BEE61F9BAACE008B557C /* TrackList.cpp in Sources */, @@ -3993,6 +4004,7 @@ C68878C520289B710084B384 /* OpenGLDrawingEngine.cpp in Sources */, C6D2BEE71F9BAACE008B557C /* MapTooltip.cpp in Sources */, C666EE7B1F37ACB10061AA04 /* TitleExit.cpp in Sources */, + 4C976BC6263976F0002DEBD5 /* FootpathRailingsObject.cpp in Sources */, F7D7747F1EC61E5100BE6EBC /* UiContext.macOS.mm in Sources */, F76C887E1EC5324E00FA49E2 /* CursorRepository.cpp in Sources */, C654DF331F69C0430040F43D /* LoadSave.cpp in Sources */, diff --git a/src/openrct2/interface/Colour.h b/src/openrct2/interface/Colour.h index 3dab46bc72..e4f79b65dc 100644 --- a/src/openrct2/interface/Colour.h +++ b/src/openrct2/interface/Colour.h @@ -51,7 +51,9 @@ enum : colour_t COLOUR_BRIGHT_PINK, COLOUR_LIGHT_PINK, - COLOUR_COUNT + COLOUR_COUNT, + + COLOUR_NULL = 255, }; /** diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 8d336d6de6..344bada47a 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -256,6 +256,8 @@ + + @@ -696,6 +698,8 @@ + + @@ -918,4 +922,4 @@ - \ No newline at end of file + diff --git a/src/openrct2/object/FootpathRailingsObject.cpp b/src/openrct2/object/FootpathRailingsObject.cpp new file mode 100644 index 0000000000..ee16825968 --- /dev/null +++ b/src/openrct2/object/FootpathRailingsObject.cpp @@ -0,0 +1,94 @@ +/***************************************************************************** + * Copyright (c) 2014-2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "FootpathRailingsObject.h" + +#include "../core/IStream.hpp" +#include "../core/Json.hpp" + +void FootpathRailingsObject::Load() +{ + GetStringTable().Sort(); + NameStringId = language_allocate_object_string(GetName()); + + auto numImages = GetImageTable().GetCount(); + if (numImages != 0) + { + PreviewImageId = gfx_object_allocate_images(GetImageTable().GetImages(), GetImageTable().GetCount()); + BridgeImageId = PreviewImageId + 37; + RailingsImageId = PreviewImageId + 1; + } +} + +void FootpathRailingsObject::Unload() +{ + language_free_object_string(NameStringId); + gfx_object_free_images(PreviewImageId, GetImageTable().GetCount()); + + NameStringId = 0; + PreviewImageId = 0; + BridgeImageId = 0; + RailingsImageId = 0; +} + +void FootpathRailingsObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const +{ + auto x = width / 2; + auto y = height / 2; + if (SupportType == RailingEntrySupportType::Pole) + { + auto img = ImageId(BridgeImageId + 20 + 15, Colour); + for (int i = 0; i < 2; i++) + { + auto h = i * 16; + gfx_draw_sprite(dpi, img, { x - 8, y + 8 + h }); + gfx_draw_sprite(dpi, img, { x + 8, y + 16 + h }); + } + + gfx_draw_sprite(dpi, BridgeImageId + 5, { x, y - 17 }, 0); + gfx_draw_sprite(dpi, RailingsImageId + 1, { x + 4, y - 14 }, 0); + gfx_draw_sprite(dpi, RailingsImageId + 1, { x + 27, y - 2 }, 0); + } + else + { + gfx_draw_sprite(dpi, BridgeImageId + 22, { x + 0, y + 16 }, 0); + gfx_draw_sprite(dpi, BridgeImageId + 49, { x, y - 17 }, 0); + gfx_draw_sprite(dpi, RailingsImageId + 1, { x + 4, y - 14 }, 0); + gfx_draw_sprite(dpi, RailingsImageId + 1, { x + 27, y - 3 }, 0); + } +} + +void FootpathRailingsObject::ReadJson(IReadObjectContext* context, json_t& root) +{ + Guard::Assert(root.is_object(), "FootpathObject::ReadJson expects parameter root to be object"); + + auto properties = root["properties"]; + if (properties.is_object()) + { + SupportType = ParseSupportType(Json::GetString(properties["supportType"])); + ScrollingMode = Json::GetNumber(properties["scrollingMode"]); + Colour = Colour::FromString(Json::GetString(properties["colour"]), COLOUR_NULL); + Flags = Json::GetFlags( + properties, + { + { "hasSupportImages", RAILING_ENTRY_FLAG_HAS_SUPPORT_BASE_SPRITE }, + { "hasElevatedPathImages", RAILING_ENTRY_FLAG_DRAW_PATH_OVER_SUPPORTS }, + }); + } + + PopulateTablesFromJson(context, root); +} + +RailingEntrySupportType FootpathRailingsObject::ParseSupportType(std::string_view s) +{ + if (s == "pole") + return RailingEntrySupportType::Pole; + else /* if (s == "box") */ + return RailingEntrySupportType::Box; +} diff --git a/src/openrct2/object/FootpathRailingsObject.h b/src/openrct2/object/FootpathRailingsObject.h new file mode 100644 index 0000000000..2b61ec9255 --- /dev/null +++ b/src/openrct2/object/FootpathRailingsObject.h @@ -0,0 +1,41 @@ +/***************************************************************************** + * Copyright (c) 2014-2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../world/Footpath.h" +#include "Object.h" + +class FootpathRailingsObject final : public Object +{ +public: + rct_string_id NameStringId{}; + uint32_t PreviewImageId{}; + uint32_t BridgeImageId{}; + uint32_t RailingsImageId{}; + RailingEntrySupportType SupportType{}; + uint8_t Flags{}; + uint8_t ScrollingMode{}; + colour_t Colour{}; + +public: + explicit FootpathRailingsObject(const rct_object_entry& entry) + : Object(entry) + { + } + + void ReadJson(IReadObjectContext* context, json_t& root) override; + void Load() override; + void Unload() override; + + void DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const override; + +private: + RailingEntrySupportType ParseSupportType(std::string_view s); +}; diff --git a/src/openrct2/object/FootpathSurfaceObject.cpp b/src/openrct2/object/FootpathSurfaceObject.cpp new file mode 100644 index 0000000000..66b89b6727 --- /dev/null +++ b/src/openrct2/object/FootpathSurfaceObject.cpp @@ -0,0 +1,69 @@ +/***************************************************************************** + * Copyright (c) 2014-2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "FootpathSurfaceObject.h" + +#include "../core/IStream.hpp" +#include "../core/Json.hpp" +#include "../object/ObjectRepository.h" + +void FootpathSurfaceObject::Load() +{ + GetStringTable().Sort(); + NameStringId = language_allocate_object_string(GetName()); + + auto numImages = GetImageTable().GetCount(); + if (numImages != 0) + { + PreviewImageId = gfx_object_allocate_images(GetImageTable().GetImages(), GetImageTable().GetCount()); + BaseImageId = PreviewImageId + 1; + } +} + +void FootpathSurfaceObject::Unload() +{ + language_free_object_string(NameStringId); + gfx_object_free_images(PreviewImageId, GetImageTable().GetCount()); + + NameStringId = 0; + PreviewImageId = 0; + BaseImageId = 0; +} + +void FootpathSurfaceObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const +{ + auto screenCoords = ScreenCoordsXY{ width / 2 - 16, height / 2 }; + gfx_draw_sprite(dpi, BaseImageId + 3, screenCoords, 0); + gfx_draw_sprite(dpi, BaseImageId + 16, { screenCoords.x + 32, screenCoords.y - 16 }, 0); + gfx_draw_sprite(dpi, BaseImageId + 8, { screenCoords.x + 32, screenCoords.y + 16 }, 0); +} + +void FootpathSurfaceObject::ReadJson(IReadObjectContext* context, json_t& root) +{ + Guard::Assert(root.is_object(), "FootpathSurfaceObject::ReadJson expects parameter root to be object"); + + auto properties = root["properties"]; + if (properties.is_object()) + { + Flags = Json::GetFlags( + properties, + { + { "editorOnly", FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR }, + { "isQueue", FOOTPATH_ENTRY_FLAG_IS_QUEUE }, + { "noSlopeRailings", FOOTPATH_ENTRY_FLAG_NO_SLOPE_RAILINGS }, + }); + } + + PopulateTablesFromJson(context, root); +} + +void FootpathSurfaceObject::SetRepositoryItem(ObjectRepositoryItem* item) const +{ + item->FootpathSurfaceInfo.Flags = Flags; +} diff --git a/src/openrct2/object/FootpathSurfaceObject.h b/src/openrct2/object/FootpathSurfaceObject.h new file mode 100644 index 0000000000..7d5ca8c6d7 --- /dev/null +++ b/src/openrct2/object/FootpathSurfaceObject.h @@ -0,0 +1,36 @@ +/***************************************************************************** + * Copyright (c) 2014-2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../world/Footpath.h" +#include "Object.h" + +class FootpathSurfaceObject final : public Object +{ +public: + rct_string_id NameStringId{}; + uint32_t PreviewImageId{}; + uint32_t BaseImageId{}; + uint8_t Flags{}; + +public: + explicit FootpathSurfaceObject(const rct_object_entry& entry) + : Object(entry) + { + } + + void ReadJson(IReadObjectContext* context, json_t& root) override; + void Load() override; + void Unload() override; + + void DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const override; + + void SetRepositoryItem(ObjectRepositoryItem* item) const override; +}; diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 4f7ca3f8cf..6d961edba4 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -42,6 +42,8 @@ enum class ObjectType : uint8_t TerrainEdge, Station, Music, + FootpathSurface, + FootpathRailings, Count, None = 255 diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index db5865e54a..854d3ed70b 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -24,6 +24,8 @@ #include "EntranceObject.h" #include "FootpathItemObject.h" #include "FootpathObject.h" +#include "FootpathRailingsObject.h" +#include "FootpathSurfaceObject.h" #include "LargeSceneryObject.h" #include "MusicObject.h" #include "Object.h" @@ -356,6 +358,12 @@ namespace ObjectFactory case ObjectType::Music: result = std::make_unique(entry); break; + case ObjectType::FootpathSurface: + result = std::make_unique(entry); + break; + case ObjectType::FootpathRailings: + result = std::make_unique(entry); + break; default: throw std::runtime_error("Invalid object type"); } @@ -392,6 +400,10 @@ namespace ObjectFactory return ObjectType::Station; if (s == "music") return ObjectType::Music; + if (s == "footpath_surface") + return ObjectType::FootpathSurface; + if (s == "footpath_railings") + return ObjectType::FootpathRailings; return ObjectType::None; } diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 6fa5555f8d..049fb54fe0 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -54,6 +54,10 @@ struct ObjectRepositoryItem { std::vector Entries; } SceneryGroupInfo; + struct + { + uint8_t Flags{}; + } FootpathSurfaceInfo; [[nodiscard]] ObjectSourceGame GetFirstSourceGame() const { diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 532b40f95f..f31d4fea8f 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -134,6 +134,7 @@ enum { FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR = (1 << 2), FOOTPATH_ENTRY_FLAG_IS_QUEUE = (1 << 3), + FOOTPATH_ENTRY_FLAG_NO_SLOPE_RAILINGS = (1 << 4), }; enum