2018-12-05 20:33:45 +00:00
|
|
|
/*****************************************************************************
|
2026-01-05 14:42:59 +01:00
|
|
|
* Copyright (c) 2014-2026 OpenRCT2 developers
|
2018-12-05 20:33:45 +00:00
|
|
|
*
|
|
|
|
|
* 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 "StationObject.h"
|
|
|
|
|
|
2024-10-15 17:39:54 +02:00
|
|
|
#include "../core/Guard.hpp"
|
2020-10-02 11:31:20 +01:00
|
|
|
#include "../core/Json.hpp"
|
2018-12-05 20:33:45 +00:00
|
|
|
#include "../drawing/Drawing.h"
|
2026-01-11 19:18:53 +01:00
|
|
|
#include "../drawing/ScrollingText.h"
|
2026-08-19 18:20:50 +01:00
|
|
|
#include "../interface/ScreenCoords.hpp"
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
namespace OpenRCT2
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2026-05-01 11:42:00 +02:00
|
|
|
constexpr std::array kAllowedStationIDs = std::to_array<u8string_view>({
|
|
|
|
|
"rct2.station.abstract",
|
|
|
|
|
"rct2.station.canvas_tent",
|
|
|
|
|
"rct2.station.castle_brown",
|
|
|
|
|
"rct2.station.castle_grey",
|
|
|
|
|
"rct2.station.classical",
|
|
|
|
|
"rct2.station.jungle",
|
|
|
|
|
"rct2.station.log",
|
|
|
|
|
"rct2.station.pagoda",
|
|
|
|
|
"rct2.station.plain",
|
|
|
|
|
"rct2.station.snow",
|
|
|
|
|
"rct2.station.space",
|
|
|
|
|
"rct2.station.wooden",
|
|
|
|
|
"openrct2.station.noentrance",
|
|
|
|
|
"openrct2.station.noplatformnoentrance",
|
2026-09-20 20:24:23 +00:00
|
|
|
"tygrysek90.station.abstract-open",
|
2026-05-01 11:42:00 +02:00
|
|
|
"tygrysek90.station.abstract_open",
|
|
|
|
|
"tygrysek90.station.canvas_tent_open",
|
|
|
|
|
"tygrysek90.station.castle_brown_open",
|
|
|
|
|
"tygrysek90.station.castle_grey",
|
|
|
|
|
"tygrysek90.station.castle_grey_open",
|
|
|
|
|
"tygrysek90.station.classical_open",
|
|
|
|
|
"tygrysek90.station.jungle_open",
|
|
|
|
|
"tygrysek90.station.log_open",
|
|
|
|
|
"tygrysek90.station.pagoda_open",
|
|
|
|
|
"tygrysek90.station.snow_open",
|
|
|
|
|
"tygrysek90.station.space_open",
|
|
|
|
|
"tygrysek90.station.wooden_open",
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
void StationObject::Load()
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
GetStringTable().Sort();
|
|
|
|
|
NameStringId = LanguageAllocateObjectString(GetName());
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
auto numImages = GetImageTable().GetCount();
|
2026-02-23 23:53:56 +01:00
|
|
|
if (numImages == 0)
|
|
|
|
|
return;
|
2025-08-17 11:46:03 +02:00
|
|
|
|
2026-02-23 23:53:56 +01:00
|
|
|
baseImageIndex = LoadImages();
|
|
|
|
|
|
2026-02-17 15:14:35 +01:00
|
|
|
// An odd number of images suggests there is an icon present
|
|
|
|
|
auto iconOffset = numImages & 1;
|
|
|
|
|
if (iconOffset == 1)
|
|
|
|
|
{
|
|
|
|
|
iconIndex = baseImageIndex;
|
|
|
|
|
if (numImages == 1)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entranceBackIndex = baseImageIndex + iconOffset;
|
2026-02-23 23:53:56 +01:00
|
|
|
entranceFrontIndex = entranceBackIndex + 4;
|
|
|
|
|
|
|
|
|
|
exitBackIndex = entranceBackIndex + 8;
|
|
|
|
|
exitFrontIndex = entranceBackIndex + 12;
|
|
|
|
|
|
2026-08-28 23:26:03 +01:00
|
|
|
if (!Flags.has(StationObjectFlag::isTransparent))
|
2026-02-23 23:53:56 +01:00
|
|
|
{
|
2026-02-17 15:14:35 +01:00
|
|
|
if (numImages > iconOffset + 16)
|
2026-02-23 23:53:56 +01:00
|
|
|
shelterIndex = entranceBackIndex + 16;
|
|
|
|
|
|
|
|
|
|
return;
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
2026-02-23 23:53:56 +01:00
|
|
|
|
|
|
|
|
entranceBackGlassIndex = entranceBackIndex + 16;
|
|
|
|
|
entranceFrontGlassIndex = entranceBackIndex + 20;
|
|
|
|
|
|
|
|
|
|
exitBackGlassIndex = entranceBackIndex + 24;
|
|
|
|
|
exitFrontGlassIndex = entranceBackIndex + 28;
|
|
|
|
|
|
2026-02-17 15:14:35 +01:00
|
|
|
if (numImages > iconOffset + 32)
|
2026-02-23 23:53:56 +01:00
|
|
|
shelterIndex = entranceBackIndex + 32;
|
|
|
|
|
|
2026-02-17 15:14:35 +01:00
|
|
|
if (numImages > iconOffset + 44)
|
2026-02-23 23:53:56 +01:00
|
|
|
shelterGlassIndex = entranceBackIndex + 44;
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
void StationObject::Unload()
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
LanguageFreeObjectString(NameStringId);
|
|
|
|
|
UnloadImages();
|
|
|
|
|
|
|
|
|
|
NameStringId = 0;
|
2026-02-23 23:53:56 +01:00
|
|
|
baseImageIndex = kImageIndexUndefined;
|
|
|
|
|
|
|
|
|
|
entranceBackIndex = kImageIndexUndefined;
|
|
|
|
|
entranceFrontIndex = kImageIndexUndefined;
|
|
|
|
|
exitBackIndex = kImageIndexUndefined;
|
|
|
|
|
exitFrontIndex = kImageIndexUndefined;
|
|
|
|
|
|
|
|
|
|
entranceBackGlassIndex = kImageIndexUndefined;
|
|
|
|
|
entranceFrontGlassIndex = kImageIndexUndefined;
|
|
|
|
|
exitBackGlassIndex = kImageIndexUndefined;
|
|
|
|
|
exitFrontGlassIndex = kImageIndexUndefined;
|
|
|
|
|
|
|
|
|
|
shelterIndex = kImageIndexUndefined;
|
|
|
|
|
shelterGlassIndex = kImageIndexUndefined;
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-26 12:58:33 +01:00
|
|
|
void StationObject::DrawPreview(Drawing::RenderTarget& rt, int32_t width, int32_t height) const
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
auto screenCoords = ScreenCoordsXY{ width / 2, (height / 2) + 16 };
|
|
|
|
|
|
2026-01-28 10:06:45 +01:00
|
|
|
auto colour0 = Drawing::Colour::lightBlue;
|
|
|
|
|
auto colour1 = Drawing::Colour::bordeauxRed;
|
2025-08-17 11:46:03 +02:00
|
|
|
auto tcolour0 = colour0;
|
|
|
|
|
|
2026-02-23 23:53:56 +01:00
|
|
|
// Draw back sprite
|
|
|
|
|
auto backImageId = ImageId(entranceBackIndex, colour0, colour1);
|
|
|
|
|
GfxDrawSprite(rt, backImageId, screenCoords);
|
2026-08-28 23:26:03 +01:00
|
|
|
if (Flags.has(StationObjectFlag::isTransparent))
|
2025-08-17 11:46:03 +02:00
|
|
|
{
|
2026-02-23 23:53:56 +01:00
|
|
|
auto tImageId = ImageId(entranceBackGlassIndex).WithTransparency(tcolour0);
|
2025-08-17 11:46:03 +02:00
|
|
|
GfxDrawSprite(rt, tImageId, screenCoords);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 23:53:56 +01:00
|
|
|
// Draw front sprite
|
|
|
|
|
auto frontImageId = ImageId(entranceFrontIndex, colour0, colour1);
|
|
|
|
|
GfxDrawSprite(rt, frontImageId, screenCoords);
|
2026-08-28 23:26:03 +01:00
|
|
|
if (Flags.has(StationObjectFlag::isTransparent))
|
2025-08-17 11:46:03 +02:00
|
|
|
{
|
2026-02-23 23:53:56 +01:00
|
|
|
auto frontGlassImageId = ImageId(entranceFrontGlassIndex).WithTransparency(tcolour0);
|
|
|
|
|
GfxDrawSprite(rt, frontGlassImageId, screenCoords);
|
2025-08-17 11:46:03 +02:00
|
|
|
}
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 11:42:00 +02:00
|
|
|
static bool isKnownStationStyle(u8string_view identifier)
|
|
|
|
|
{
|
|
|
|
|
for (const auto& entry : kAllowedStationIDs)
|
|
|
|
|
{
|
|
|
|
|
if (entry == identifier)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
void StationObject::ReadJson(IReadObjectContext* context, json_t& root)
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
Guard::Assert(root.is_object(), "StationObject::ReadJson expects parameter root to be object");
|
2026-05-01 11:42:00 +02:00
|
|
|
if (!isKnownStationStyle(GetIdentifier()))
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Unknown station style");
|
|
|
|
|
}
|
2025-08-17 11:46:03 +02:00
|
|
|
|
|
|
|
|
auto properties = root["properties"];
|
|
|
|
|
|
|
|
|
|
if (properties.is_object())
|
|
|
|
|
{
|
|
|
|
|
Height = Json::GetNumber<int32_t>(properties["height"]);
|
|
|
|
|
ScrollingMode = Json::GetNumber<uint8_t>(properties["scrollingMode"], kScrollingModeNone);
|
2026-08-28 23:26:03 +01:00
|
|
|
Flags = Json::GetFlagHolder<StationObjectFlags, StationObjectFlag>(
|
2025-08-17 11:46:03 +02:00
|
|
|
properties,
|
|
|
|
|
{
|
2026-08-28 23:26:03 +01:00
|
|
|
{ "hasPrimaryColour", StationObjectFlag::hasPrimaryColour },
|
|
|
|
|
{ "hasSecondaryColour", StationObjectFlag::hasSecondaryColour },
|
|
|
|
|
{ "isTransparent", StationObjectFlag::isTransparent },
|
|
|
|
|
{ "noPlatforms", StationObjectFlag::noPlatforms },
|
|
|
|
|
{ "hasShelter", StationObjectFlag::hasShelter },
|
2025-08-17 11:46:03 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PopulateTablesFromJson(context, root);
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
2025-08-17 11:46:03 +02:00
|
|
|
} // namespace OpenRCT2
|