2016-06-25 18:05:24 +01:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2016-06-25 18:05:24 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-06-25 18:05:24 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-06-25 18:05:24 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
#include "PathAdditionObject.h"
|
2018-06-22 23:03:20 +02:00
|
|
|
|
2016-06-25 18:05:24 +01:00
|
|
|
#include "../core/IStream.hpp"
|
2020-10-02 11:31:20 +01:00
|
|
|
#include "../core/Json.hpp"
|
2018-01-05 21:17:33 +00:00
|
|
|
#include "../drawing/Drawing.h"
|
2017-12-10 17:42:39 +00:00
|
|
|
#include "../interface/Cursors.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Localisation.h"
|
2018-01-02 20:36:42 +01:00
|
|
|
#include "../object/Object.h"
|
2018-04-19 23:51:05 +01:00
|
|
|
#include "../object/ObjectRepository.h"
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "ObjectList.h"
|
2016-06-25 18:05:24 +01:00
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
void PathAdditionObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
2016-06-25 18:05:24 +01:00
|
|
|
{
|
2020-07-30 23:01:22 +02:00
|
|
|
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
|
2021-06-03 21:23:00 +01:00
|
|
|
_legacyType.flags = stream->ReadValue<uint16_t>();
|
2023-05-09 21:08:25 +02:00
|
|
|
_legacyType.draw_type = static_cast<PathAdditionDrawType>(stream->ReadValue<uint8_t>());
|
2021-06-03 21:23:00 +01:00
|
|
|
_legacyType.tool_id = static_cast<CursorID>(stream->ReadValue<uint8_t>());
|
2023-03-02 22:55:42 +01:00
|
|
|
_legacyType.price = stream->ReadValue<money16>();
|
2021-06-03 21:23:00 +01:00
|
|
|
_legacyType.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
|
2020-07-30 23:01:22 +02:00
|
|
|
stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT);
|
2016-06-25 18:05:24 +01:00
|
|
|
|
2020-08-29 04:36:58 +02:00
|
|
|
GetStringTable().Read(context, stream, ObjectStringID::NAME);
|
2016-06-25 18:05:24 +01:00
|
|
|
|
2023-01-20 05:24:44 +00:00
|
|
|
RCTObjectEntry sgEntry = stream->ReadValue<RCTObjectEntry>();
|
2021-03-12 11:04:04 +01:00
|
|
|
SetPrimarySceneryGroup(ObjectEntryDescriptor(sgEntry));
|
2016-06-25 18:05:24 +01:00
|
|
|
|
2017-12-11 13:06:59 +00:00
|
|
|
GetImageTable().Read(context, stream);
|
2016-07-02 17:23:06 +01:00
|
|
|
|
|
|
|
|
// Validate properties
|
2023-03-02 22:55:42 +01:00
|
|
|
if (_legacyType.price <= 0.00_GBP)
|
2016-07-02 17:23:06 +01:00
|
|
|
{
|
2020-10-10 12:21:07 -03:00
|
|
|
context->LogError(ObjectError::InvalidProperty, "Price can not be free or negative.");
|
2016-07-02 17:23:06 +01:00
|
|
|
}
|
2017-11-13 13:51:51 +01:00
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
// Add path additions to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
|
2017-11-13 13:51:51 +01:00
|
|
|
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
|
2020-05-07 19:35:30 +01:00
|
|
|
auto identifier = GetLegacyIdentifier();
|
2017-11-13 13:51:51 +01:00
|
|
|
|
2018-04-19 23:51:05 +01:00
|
|
|
auto& objectRepository = context->GetObjectRepository();
|
2020-11-05 21:19:43 +01:00
|
|
|
auto item = objectRepository.FindObjectLegacy(identifier);
|
2018-04-19 23:51:05 +01:00
|
|
|
if (item != nullptr)
|
2017-11-13 13:51:51 +01:00
|
|
|
{
|
2018-07-30 22:01:04 +02:00
|
|
|
auto sourceGame = item->GetFirstSourceGame();
|
2020-10-17 13:27:02 -07:00
|
|
|
if (sourceGame == ObjectSourceGame::WackyWorlds || sourceGame == ObjectSourceGame::TimeTwister
|
|
|
|
|
|| sourceGame == ObjectSourceGame::Custom)
|
2018-04-19 23:51:05 +01:00
|
|
|
{
|
|
|
|
|
auto scgPathX = Object::GetScgPathXHeader();
|
2021-03-12 11:04:04 +01:00
|
|
|
SetPrimarySceneryGroup(scgPathX);
|
2018-04-19 23:51:05 +01:00
|
|
|
}
|
2017-11-13 13:51:51 +01:00
|
|
|
}
|
2016-06-25 18:05:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
void PathAdditionObject::Load()
|
2016-06-25 18:05:24 +01:00
|
|
|
{
|
2017-12-11 13:06:59 +00:00
|
|
|
GetStringTable().Sort();
|
2023-01-17 00:12:35 +01:00
|
|
|
_legacyType.name = LanguageAllocateObjectString(GetName());
|
2023-04-13 15:09:15 -04:00
|
|
|
_legacyType.image = LoadImages();
|
2016-06-25 18:05:24 +01:00
|
|
|
|
2021-06-03 21:23:00 +01:00
|
|
|
_legacyType.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
|
2016-06-25 18:05:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
void PathAdditionObject::Unload()
|
2016-06-25 18:05:24 +01:00
|
|
|
{
|
2023-01-17 00:12:35 +01:00
|
|
|
LanguageFreeObjectString(_legacyType.name);
|
2023-04-13 15:09:15 -04:00
|
|
|
UnloadImages();
|
2016-07-03 18:02:18 +01:00
|
|
|
|
|
|
|
|
_legacyType.name = 0;
|
|
|
|
|
_legacyType.image = 0;
|
2016-06-25 18:05:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
void PathAdditionObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const
|
2016-07-02 12:29:13 +01:00
|
|
|
{
|
2020-06-23 23:32:34 +02:00
|
|
|
auto screenCoords = ScreenCoordsXY{ width / 2, height / 2 };
|
2023-04-03 20:38:28 +02:00
|
|
|
GfxDrawSprite(dpi, ImageId(_legacyType.image), screenCoords - ScreenCoordsXY{ 22, 24 });
|
2016-07-02 12:29:13 +01:00
|
|
|
}
|
2017-12-10 17:42:39 +00:00
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
static PathAdditionDrawType ParseDrawType(const std::string& s)
|
2017-12-10 17:42:39 +00:00
|
|
|
{
|
2018-06-22 23:03:20 +02:00
|
|
|
if (s == "lamp")
|
2023-05-09 21:08:25 +02:00
|
|
|
return PathAdditionDrawType::Light;
|
2018-06-22 23:03:20 +02:00
|
|
|
if (s == "bin")
|
2023-05-09 21:08:25 +02:00
|
|
|
return PathAdditionDrawType::Bin;
|
2018-06-22 23:03:20 +02:00
|
|
|
if (s == "bench")
|
2023-05-09 21:08:25 +02:00
|
|
|
return PathAdditionDrawType::Bench;
|
2018-06-22 23:03:20 +02:00
|
|
|
if (s == "fountain")
|
2023-05-09 21:08:25 +02:00
|
|
|
return PathAdditionDrawType::JumpingFountain;
|
|
|
|
|
return PathAdditionDrawType::Light;
|
2017-12-10 17:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-09 21:08:25 +02:00
|
|
|
void PathAdditionObject::ReadJson(IReadObjectContext* context, json_t& root)
|
2017-12-10 17:42:39 +00:00
|
|
|
{
|
2023-05-09 21:08:25 +02:00
|
|
|
Guard::Assert(root.is_object(), "PathAdditionObject::ReadJson expects parameter root to be object");
|
2017-12-10 17:42:39 +00:00
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
json_t properties = root["properties"];
|
2017-12-10 17:42:39 +00:00
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
if (properties.is_object())
|
2018-04-08 18:45:38 +01:00
|
|
|
{
|
2021-06-03 21:23:00 +01:00
|
|
|
_legacyType.draw_type = ParseDrawType(Json::GetString(properties["renderAs"]));
|
|
|
|
|
_legacyType.tool_id = Cursor::FromString(Json::GetString(properties["cursor"]), CursorID::LamppostDown);
|
2023-03-02 22:55:42 +01:00
|
|
|
_legacyType.price = Json::GetNumber<money64>(properties["price"]);
|
2020-08-12 23:05:23 +01:00
|
|
|
|
2021-03-12 11:04:04 +01:00
|
|
|
SetPrimarySceneryGroup(ObjectEntryDescriptor(Json::GetString(properties["sceneryGroup"])));
|
2020-08-12 23:05:23 +01:00
|
|
|
|
|
|
|
|
// clang-format off
|
2021-06-03 21:23:00 +01:00
|
|
|
_legacyType.flags = Json::GetFlags<uint16_t>(
|
2020-08-12 23:05:23 +01:00
|
|
|
properties,
|
|
|
|
|
{
|
2023-05-09 21:08:25 +02:00
|
|
|
{ "isBin", PATH_ADDITION_FLAG_IS_BIN, Json::FlagType::Normal },
|
|
|
|
|
{ "isBench", PATH_ADDITION_FLAG_IS_BENCH, Json::FlagType::Normal },
|
|
|
|
|
{ "isBreakable", PATH_ADDITION_FLAG_BREAKABLE, Json::FlagType::Normal },
|
|
|
|
|
{ "isLamp", PATH_ADDITION_FLAG_LAMP, Json::FlagType::Normal },
|
|
|
|
|
{ "isJumpingFountainWater", PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER, Json::FlagType::Normal },
|
|
|
|
|
{ "isJumpingFountainSnow", PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW, Json::FlagType::Normal },
|
|
|
|
|
{ "isAllowedOnQueue", PATH_ADDITION_FLAG_DONT_ALLOW_ON_QUEUE, Json::FlagType::Inverted },
|
|
|
|
|
{ "isAllowedOnSlope", PATH_ADDITION_FLAG_DONT_ALLOW_ON_SLOPE, Json::FlagType::Inverted },
|
|
|
|
|
{ "isTelevision", PATH_ADDITION_FLAG_IS_QUEUE_SCREEN, Json::FlagType::Normal },
|
2020-08-12 23:05:23 +01:00
|
|
|
});
|
|
|
|
|
// clang-format on
|
2018-04-08 18:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
PopulateTablesFromJson(context, root);
|
2017-12-10 17:42:39 +00:00
|
|
|
}
|