1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 03:53:07 +01:00

Merge pull request #11665 from IntelOrca/plugin/more-object-fields

[Plugin] Split object identifier and add more ride object fields
This commit is contained in:
Ted John
2020-05-08 20:45:30 +01:00
committed by GitHub
20 changed files with 958 additions and 106 deletions

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -125,12 +125,6 @@ void language_free_object_string(rct_string_id stringId)
localisationService.FreeObjectString(stringId);
}
rct_string_id language_get_object_override_string_id(const char* identifier, uint8_t index)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
return localisationService.GetObjectOverrideStringId(identifier, index);
}
rct_string_id language_allocate_object_string(const std::string& target)
{
auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -105,7 +105,6 @@ std::string rct2_to_utf8(const std::string_view& src, RCT2LanguageId languageId)
std::string utf8_to_rct2(const std::string_view& src);
bool language_get_localised_scenario_strings(const utf8* scenarioFilename, rct_string_id* outStringIds);
void language_free_object_string(rct_string_id stringId);
rct_string_id language_get_object_override_string_id(const char* identifier, uint8_t index);
rct_string_id language_allocate_object_string(const std::string& target);
std::string language_convert_string_to_tokens(const std::string_view& s);
std::string language_convert_string(const std::string_view& s);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -198,15 +198,14 @@ public:
}
}
rct_string_id GetObjectOverrideStringId(const char* objectIdentifier, uint8_t index) override
rct_string_id GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) override
{
Guard::ArgumentNotNull(objectIdentifier);
Guard::Assert(index < ObjectOverrideMaxStringCount);
int32_t ooIndex = 0;
for (const ObjectOverride& objectOverride : _objectOverrides)
{
if (strncmp(objectOverride.name, objectIdentifier, 8) == 0)
if (std::string_view(objectOverride.name, 8) == legacyIdentifier)
{
if (objectOverride.strings[index].empty())
{

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -12,6 +12,7 @@
#include "../common.h"
#include <string>
#include <string_view>
interface ILanguagePack
{
@@ -23,7 +24,7 @@ interface ILanguagePack
virtual void RemoveString(rct_string_id stringId) abstract;
virtual void SetString(rct_string_id stringId, const std::string& str) abstract;
virtual const utf8* GetString(rct_string_id stringId) const abstract;
virtual rct_string_id GetObjectOverrideStringId(const char* objectIdentifier, uint8_t index) abstract;
virtual rct_string_id GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) abstract;
virtual rct_string_id GetScenarioOverrideStringId(const utf8* scenarioFilename, uint8_t index) abstract;
};

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -122,13 +122,13 @@ std::tuple<rct_string_id, rct_string_id, rct_string_id> LocalisationService::Get
return std::make_tuple(result0, result1, result2);
}
rct_string_id LocalisationService::GetObjectOverrideStringId(const char* identifier, uint8_t index) const
rct_string_id LocalisationService::GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) const
{
if (_languageCurrent == nullptr)
{
return STR_NONE;
}
return _languageCurrent->GetObjectOverrideStringId(identifier, index);
return _languageCurrent->GetObjectOverrideStringId(legacyIdentifier, index);
}
rct_string_id LocalisationService::AllocateObjectString(const std::string& target)

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -14,6 +14,7 @@
#include <memory>
#include <stack>
#include <string>
#include <string_view>
#include <tuple>
interface ILanguagePack;
@@ -56,7 +57,7 @@ namespace OpenRCT2::Localisation
const char* GetString(rct_string_id id) const;
std::tuple<rct_string_id, rct_string_id, rct_string_id> GetLocalisedScenarioStrings(
const std::string& scenarioFilename) const;
rct_string_id GetObjectOverrideStringId(const char* identifier, uint8_t index) const;
rct_string_id GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) const;
std::string GetLanguagePath(uint32_t languageId) const;
void OpenLanguage(int32_t id, IObjectManager& objectManager);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -41,7 +41,7 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
// Add banners to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
auto identifier = GetIdentifier();
auto identifier = GetLegacyIdentifier();
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -45,7 +45,7 @@ void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream
// Add path bits to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
auto identifier = GetIdentifier();
auto identifier = GetLegacyIdentifier();
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -9,28 +9,22 @@
#include "Object.h"
#include "../Context.h"
#include "../core/Memory.hpp"
#include "../core/String.hpp"
#include "../localisation/Language.h"
#include "../localisation/LocalisationService.h"
#include "../localisation/StringIds.h"
#include "../world/Scenery.h"
#include "ObjectLimits.h"
#include <algorithm>
#include <cstring>
#include <stdexcept>
Object::Object(const rct_object_entry& entry)
{
_objectEntry = entry;
char name[DAT_NAME_LENGTH + 1] = { 0 };
std::copy_n(entry.name, DAT_NAME_LENGTH, name);
_identifier = String::Duplicate(name);
}
Object::~Object()
{
Memory::Free(_identifier);
}
void* Object::GetLegacyData()
@@ -45,8 +39,9 @@ void Object::ReadLegacy(IReadObjectContext* context, IStream* stream)
std::string Object::GetOverrideString(uint8_t index) const
{
const char* identifier = GetIdentifier();
rct_string_id stringId = language_get_object_override_string_id(identifier, index);
auto legacyIdentifier = GetLegacyIdentifier();
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
auto stringId = localisationService.GetObjectOverrideStringId(legacyIdentifier, index);
const utf8* result = nullptr;
if (stringId != STR_NONE)
@@ -115,6 +110,12 @@ std::string Object::GetName(int32_t language) const
return GetString(language, OBJ_STRING_ID_NAME);
}
void rct_object_entry::SetName(const std::string_view& value)
{
std::memset(name, ' ', sizeof(name));
std::memcpy(name, value.data(), std::min(sizeof(name), value.size()));
}
std::optional<uint8_t> rct_object_entry::GetSceneryType() const
{
switch (GetType())

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -13,6 +13,7 @@
#include "ImageTable.h"
#include "StringTable.h"
#include <algorithm>
#include <optional>
#include <string_view>
#include <vector>
@@ -96,19 +97,7 @@ struct rct_object_entry
return std::string_view(name, std::size(name));
}
void SetName(const char* value)
{
auto src = value;
for (size_t i = 0; i < sizeof(name); i++)
{
auto dc = ' ';
if (*src != '\0')
{
dc = *src++;
}
name[i] = dc;
}
}
void SetName(const std::string_view& value);
uint8_t GetType() const
{
@@ -155,6 +144,7 @@ interface IReadObjectContext
{
virtual ~IReadObjectContext() = default;
virtual std::string_view GetObjectIdentifier() abstract;
virtual IObjectRepository& GetObjectRepository() abstract;
virtual bool ShouldLoadImages() abstract;
virtual std::vector<uint8_t> GetData(const std::string_view& path) abstract;
@@ -171,7 +161,7 @@ interface IReadObjectContext
class Object
{
private:
char* _identifier;
std::string _identifier;
rct_object_entry _objectEntry{};
StringTable _stringTable;
ImageTable _imageTable;
@@ -198,7 +188,16 @@ protected:
public:
explicit Object(const rct_object_entry& entry);
virtual ~Object();
virtual ~Object() = default;
std::string_view GetIdentifier() const
{
return _identifier;
}
void SetIdentifier(const std::string_view& identifier)
{
_identifier = identifier;
}
void MarkAsJsonObject()
{
@@ -211,9 +210,9 @@ public:
};
// Legacy data structures
const char* GetIdentifier() const
std::string_view GetLegacyIdentifier() const
{
return _identifier;
return _objectEntry.GetName();
}
const rct_object_entry* GetObjectEntry() const
{

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -87,7 +87,7 @@ private:
IObjectRepository& _objectRepository;
const IFileDataRetriever* _fileDataRetriever;
std::string _objectName;
std::string _identifier;
bool _loadImages;
std::string _basePath;
bool _wasWarning = false;
@@ -104,15 +104,20 @@ public:
}
ReadObjectContext(
IObjectRepository& objectRepository, const std::string& objectName, bool loadImages,
IObjectRepository& objectRepository, const std::string& identifier, bool loadImages,
const IFileDataRetriever* fileDataRetriever)
: _objectRepository(objectRepository)
, _fileDataRetriever(fileDataRetriever)
, _objectName(objectName)
, _identifier(identifier)
, _loadImages(loadImages)
{
}
std::string_view GetObjectIdentifier() override
{
return _identifier;
}
IObjectRepository& GetObjectRepository() override
{
return _objectRepository;
@@ -138,7 +143,7 @@ public:
if (!String::IsNullOrEmpty(text))
{
Console::Error::WriteLine("[%s] Warning (%d): %s", _objectName.c_str(), code, text);
Console::Error::WriteLine("[%s] Warning (%d): %s", _identifier.c_str(), code, text);
}
}
@@ -148,7 +153,7 @@ public:
if (!String::IsNullOrEmpty(text))
{
Console::Error::WriteLine("[%s] Error (%d): %s", _objectName.c_str(), code, text);
Console::Error::WriteLine("[%s] Error (%d): %s", _identifier.c_str(), code, text);
}
}
};
@@ -429,6 +434,7 @@ namespace ObjectFactory
std::memcpy(entry.name, originalName.c_str(), minLength);
result = CreateObject(entry);
result->SetIdentifier(id);
result->MarkAsJsonObject();
auto readContext = ReadObjectContext(objectRepository, id, !gOpenRCT2NoGraphics, fileRetriever);
result->ReadJson(&readContext, jRoot);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -252,12 +252,10 @@ public:
return _items.data();
}
const ObjectRepositoryItem* FindObject(const utf8* name) const override
const ObjectRepositoryItem* FindObject(const std::string_view& legacyIdentifier) const override
{
rct_object_entry entry = {};
utf8 entryName[9] = { ' ' };
String::Set(entryName, sizeof(entryName), name);
std::copy_n(entryName, 8, entry.name);
entry.SetName(legacyIdentifier);
auto kvp = _itemMap.find(entry);
if (kvp != _itemMap.end())

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -67,7 +67,7 @@ interface IObjectRepository
virtual void Construct(int32_t language) abstract;
virtual size_t GetNumObjects() const abstract;
virtual const ObjectRepositoryItem* GetObjects() const abstract;
virtual const ObjectRepositoryItem* FindObject(const utf8* name) const abstract;
virtual const ObjectRepositoryItem* FindObject(const std::string_view& legacyIdentifier) const abstract;
virtual const ObjectRepositoryItem* FindObject(const rct_object_entry* objectEntry) const abstract;
virtual Object* LoadObject(const ObjectRepositoryItem* ori) abstract;

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -156,14 +156,14 @@ std::vector<uint8_t> SmallSceneryObject::ReadFrameOffsets(IStream* stream)
// clang-format off
void SmallSceneryObject::PerformFixes()
{
std::string identifier = GetIdentifier();
auto identifier = GetLegacyIdentifier();
static const rct_object_entry scgWalls = Object::GetScgWallsHeader();
// ToonTowner's base blocks. Make them allow supports on top and put them in the Walls and Roofs group.
if (String::Equals(identifier, "XXBBCL01") ||
String::Equals(identifier, "XXBBMD01") ||
String::Equals(identifier, "XXBBBR01") ||
String::Equals(identifier, "ARBASE2 "))
if (identifier == "XXBBCL01" ||
identifier == "XXBBMD01" ||
identifier == "XXBBBR01" ||
identifier == "ARBASE2 ")
{
SetPrimarySceneryGroup(&scgWalls);
@@ -171,48 +171,48 @@ void SmallSceneryObject::PerformFixes()
}
// ToonTowner's regular roofs. Put them in the Walls and Roofs group.
if (String::Equals(identifier, "TTRFTL02") ||
String::Equals(identifier, "TTRFTL03") ||
String::Equals(identifier, "TTRFTL04") ||
String::Equals(identifier, "TTRFTL07") ||
String::Equals(identifier, "TTRFTL08"))
if (identifier == "TTRFTL02" ||
identifier == "TTRFTL03" ||
identifier == "TTRFTL04" ||
identifier == "TTRFTL07" ||
identifier == "TTRFTL08")
{
SetPrimarySceneryGroup(&scgWalls);
}
// ToonTowner's Pirate roofs. Make them show up in the Pirate Theming.
if (String::Equals(identifier, "TTPIRF02") ||
String::Equals(identifier, "TTPIRF03") ||
String::Equals(identifier, "TTPIRF04") ||
String::Equals(identifier, "TTPIRF05") ||
String::Equals(identifier, "TTPIRF07") ||
String::Equals(identifier, "TTPIRF08") ||
String::Equals(identifier, "TTPRF09 ") ||
String::Equals(identifier, "TTPRF10 ") ||
String::Equals(identifier, "TTPRF11 "))
if (identifier == "TTPIRF02" ||
identifier == "TTPIRF03" ||
identifier == "TTPIRF04" ||
identifier == "TTPIRF05" ||
identifier == "TTPIRF07" ||
identifier == "TTPIRF08" ||
identifier == "TTPRF09 " ||
identifier == "TTPRF10 " ||
identifier == "TTPRF11 ")
{
static const rct_object_entry scgPirat = GetScgPiratHeader();
SetPrimarySceneryGroup(&scgPirat);
}
// ToonTowner's wooden roofs. Make them show up in the Mine Theming.
if (String::Equals(identifier, "TTRFWD01") ||
String::Equals(identifier, "TTRFWD02") ||
String::Equals(identifier, "TTRFWD03") ||
String::Equals(identifier, "TTRFWD04") ||
String::Equals(identifier, "TTRFWD05") ||
String::Equals(identifier, "TTRFWD06") ||
String::Equals(identifier, "TTRFWD07") ||
String::Equals(identifier, "TTRFWD08"))
if (identifier == "TTRFWD01" ||
identifier == "TTRFWD02" ||
identifier == "TTRFWD03" ||
identifier == "TTRFWD04" ||
identifier == "TTRFWD05" ||
identifier == "TTRFWD06" ||
identifier == "TTRFWD07" ||
identifier == "TTRFWD08")
{
static const rct_object_entry scgMine = GetScgMineHeader();
SetPrimarySceneryGroup(&scgMine);
}
// ToonTowner's glass roofs. Make them show up in the Abstract Theming.
if (String::Equals(identifier, "TTRFGL01") ||
String::Equals(identifier, "TTRFGL02") ||
String::Equals(identifier, "TTRFGL03"))
if (identifier == "TTRFGL01" ||
identifier == "TTRFGL02" ||
identifier == "TTRFGL03")
{
static const rct_object_entry scgAbstr = GetScgAbstrHeader();
SetPrimarySceneryGroup(&scgAbstr);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -43,8 +43,8 @@ void WallObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
}
// Autofix this object (will be turned into an official object later).
auto identifier = GetIdentifier();
if (String::Equals(identifier, "XXWLBR03"))
auto identifier = GetLegacyIdentifier();
if (identifier == "XXWLBR03")
{
_legacyType.wall.flags2 &= ~WALL_SCENERY_2_DOOR_SOUND_MASK;
_legacyType.wall.flags2 |= (1u << WALL_SCENERY_2_DOOR_SOUND_SHIFT) & WALL_SCENERY_2_DOOR_SOUND_MASK;

View File

@@ -193,6 +193,12 @@ namespace OpenRCT2::Scripting
template<typename T> DukValue ToDuk(duk_context* ctx, const T& value) = delete;
template<typename T> T FromDuk(const DukValue& s) = delete;
template<> inline DukValue ToDuk(duk_context* ctx, const std::nullptr_t&)
{
duk_push_null(ctx);
return DukValue::take_from_stack(ctx);
}
} // namespace OpenRCT2::Scripting
#endif

View File

@@ -82,7 +82,7 @@ namespace OpenRCT2::Scripting
{
duk_error(ctx, DUK_ERR_ERROR, "Invalid object type.");
}
return {};
return ToDuk(ctx, nullptr);
}
std::vector<DukValue> getAllObjects(const std::string& typez) const

View File

@@ -25,7 +25,7 @@ namespace OpenRCT2::Scripting
{
class ScObject
{
private:
protected:
uint8_t _type{};
int32_t _index{};
@@ -41,6 +41,7 @@ namespace OpenRCT2::Scripting
dukglue_register_property(ctx, &ScObject::type_get, nullptr, "type");
dukglue_register_property(ctx, &ScObject::index_get, nullptr, "index");
dukglue_register_property(ctx, &ScObject::identifier_get, nullptr, "identifier");
dukglue_register_property(ctx, &ScObject::legacyIdentifier_get, nullptr, "legacyIdentifier");
dukglue_register_property(ctx, &ScObject::name_get, nullptr, "name");
}
@@ -83,7 +84,17 @@ namespace OpenRCT2::Scripting
auto obj = GetObject();
if (obj != nullptr)
{
return obj->GetIdentifier();
return std::string(obj->GetIdentifier());
}
return {};
}
std::string legacyIdentifier_get() const
{
auto obj = GetObject();
if (obj != nullptr)
{
return std::string(obj->GetLegacyIdentifier());
}
return {};
}
@@ -106,6 +117,527 @@ namespace OpenRCT2::Scripting
}
};
class ScRideObjectVehicle
{
private:
OBJECT_TYPE _objectType{};
ObjectEntryIndex _objectIndex{};
size_t _vehicleIndex{};
public:
ScRideObjectVehicle(OBJECT_TYPE objectType, ObjectEntryIndex objectIndex, size_t vehicleIndex)
: _objectType(objectType)
, _objectIndex(objectIndex)
, _vehicleIndex(vehicleIndex)
{
}
static void Register(duk_context* ctx)
{
dukglue_register_property(ctx, &ScRideObjectVehicle::rotationFrameMask_get, nullptr, "rotationFrameMask");
dukglue_register_property(ctx, &ScRideObjectVehicle::numVerticalFrames_get, nullptr, "numVerticalFrames");
dukglue_register_property(ctx, &ScRideObjectVehicle::numHorizontalFrames_get, nullptr, "numHorizontalFrames");
dukglue_register_property(ctx, &ScRideObjectVehicle::spacing_get, nullptr, "spacing");
dukglue_register_property(ctx, &ScRideObjectVehicle::carMass_get, nullptr, "carMass");
dukglue_register_property(ctx, &ScRideObjectVehicle::tabHeight_get, nullptr, "tabHeight");
dukglue_register_property(ctx, &ScRideObjectVehicle::numSeats_get, nullptr, "numSeats");
dukglue_register_property(ctx, &ScRideObjectVehicle::spriteFlags_get, nullptr, "spriteFlags");
dukglue_register_property(ctx, &ScRideObjectVehicle::spriteWidth_get, nullptr, "spriteWidth");
dukglue_register_property(ctx, &ScRideObjectVehicle::spriteHeightNegative_get, nullptr, "spriteHeightNegative");
dukglue_register_property(ctx, &ScRideObjectVehicle::spriteHeightPositive_get, nullptr, "spriteHeightPositive");
dukglue_register_property(ctx, &ScRideObjectVehicle::animation_get, nullptr, "animation");
dukglue_register_property(ctx, &ScRideObjectVehicle::flags_get, nullptr, "flags");
dukglue_register_property(ctx, &ScRideObjectVehicle::baseNumFrames_get, nullptr, "baseNumFrames");
dukglue_register_property(ctx, &ScRideObjectVehicle::baseImageId_get, nullptr, "baseImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::restraintImageId_get, nullptr, "restraintImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::gentleSlopeImageId_get, nullptr, "gentleSlopeImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::steepSlopeImageId_get, nullptr, "steepSlopeImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::verticalSlopeImageId_get, nullptr, "verticalSlopeImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::diagonalSlopeImageId_get, nullptr, "diagonalSlopeImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::bankedImageId_get, nullptr, "bankedImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::inlineTwistImageId_get, nullptr, "inlineTwistImageId");
dukglue_register_property(
ctx, &ScRideObjectVehicle::flatToGentleBankImageId_get, nullptr, "flatToGentleBankImageId");
dukglue_register_property(
ctx, &ScRideObjectVehicle::diagonalToGentleSlopeBankImageId_get, nullptr, "diagonalToGentleSlopeBankImageId");
dukglue_register_property(
ctx, &ScRideObjectVehicle::gentleSlopeToBankImageId_get, nullptr, "gentleSlopeToBankImageId");
dukglue_register_property(
ctx, &ScRideObjectVehicle::gentleSlopeBankTurnImageId_get, nullptr, "gentleSlopeBankTurnImageId");
dukglue_register_property(
ctx, &ScRideObjectVehicle::flatBankToGentleSlopeImageId_get, nullptr, "flatBankToGentleSlopeImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::curvedLiftHillImageId_get, nullptr, "curvedLiftHillImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::corkscrewImageId_get, nullptr, "corkscrewImageId");
dukglue_register_property(ctx, &ScRideObjectVehicle::noVehicleImages_get, nullptr, "noVehicleImages");
dukglue_register_property(ctx, &ScRideObjectVehicle::noSeatingRows_get, nullptr, "noSeatingRows");
dukglue_register_property(ctx, &ScRideObjectVehicle::spinningInertia_get, nullptr, "spinningInertia");
dukglue_register_property(ctx, &ScRideObjectVehicle::spinningFriction_get, nullptr, "spinningFriction");
dukglue_register_property(ctx, &ScRideObjectVehicle::frictionSoundId_get, nullptr, "frictionSoundId");
dukglue_register_property(
ctx, &ScRideObjectVehicle::logFlumeReverserVehicleType_get, nullptr, "logFlumeReverserVehicleType");
dukglue_register_property(ctx, &ScRideObjectVehicle::soundRange_get, nullptr, "soundRange");
dukglue_register_property(ctx, &ScRideObjectVehicle::doubleSoundFrequency_get, nullptr, "doubleSoundFrequency");
dukglue_register_property(ctx, &ScRideObjectVehicle::poweredAcceleration_get, nullptr, "poweredAcceleration");
dukglue_register_property(ctx, &ScRideObjectVehicle::poweredMaxSpeed_get, nullptr, "poweredMaxSpeed");
dukglue_register_property(ctx, &ScRideObjectVehicle::carVisual_get, nullptr, "carVisual");
dukglue_register_property(ctx, &ScRideObjectVehicle::effectVisual_get, nullptr, "effectVisual");
dukglue_register_property(ctx, &ScRideObjectVehicle::drawOrder_get, nullptr, "drawOrder");
dukglue_register_property(
ctx, &ScRideObjectVehicle::numVerticalFramesOverride_get, nullptr, "numVerticalFramesOverride");
}
private:
uint16_t rotationFrameMask_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->rotation_frame_mask;
}
return 0;
}
uint8_t numVerticalFrames_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->num_vertical_frames;
}
return 0;
}
uint8_t numHorizontalFrames_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->num_horizontal_frames;
}
return 0;
}
uint32_t spacing_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->spacing;
}
return 0;
}
uint16_t carMass_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->car_mass;
}
return 0;
}
int8_t tabHeight_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->tab_height;
}
return 0;
}
uint8_t numSeats_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->num_seats;
}
return 0;
}
uint16_t spriteFlags_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->sprite_flags;
}
return 0;
}
uint8_t spriteWidth_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->sprite_width;
}
return 0;
}
uint8_t spriteHeightNegative_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->sprite_height_negative;
}
return 0;
}
uint8_t spriteHeightPositive_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->sprite_height_positive;
}
return 0;
}
uint8_t animation_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->animation;
}
return 0;
}
uint32_t flags_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->flags;
}
return 0;
}
uint16_t baseNumFrames_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->base_num_frames;
}
return 0;
}
uint32_t baseImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->base_image_id;
}
return 0;
}
uint32_t restraintImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->restraint_image_id;
}
return 0;
}
uint32_t gentleSlopeImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->gentle_slope_image_id;
}
return 0;
}
uint32_t steepSlopeImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->steep_slope_image_id;
}
return 0;
}
uint32_t verticalSlopeImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->vertical_slope_image_id;
}
return 0;
}
uint32_t diagonalSlopeImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->diagonal_slope_image_id;
}
return 0;
}
uint32_t bankedImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->banked_image_id;
}
return 0;
}
uint32_t inlineTwistImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->inline_twist_image_id;
}
return 0;
}
uint32_t flatToGentleBankImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->flat_to_gentle_bank_image_id;
}
return 0;
}
uint32_t diagonalToGentleSlopeBankImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->diagonal_to_gentle_slope_bank_image_id;
}
return 0;
}
uint32_t gentleSlopeToBankImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->gentle_slope_to_bank_image_id;
}
return 0;
}
uint32_t gentleSlopeBankTurnImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->gentle_slope_bank_turn_image_id;
}
return 0;
}
uint32_t flatBankToGentleSlopeImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->flat_bank_to_gentle_slope_image_id;
}
return 0;
}
uint32_t curvedLiftHillImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->curved_lift_hill_image_id;
}
return 0;
}
uint32_t corkscrewImageId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->corkscrew_image_id;
}
return 0;
}
uint32_t noVehicleImages_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->no_vehicle_images;
}
return 0;
}
uint8_t noSeatingRows_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->no_seating_rows;
}
return 0;
}
uint8_t spinningInertia_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->spinning_inertia;
}
return 0;
}
uint8_t spinningFriction_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->spinning_friction;
}
return 0;
}
int32_t frictionSoundId_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return static_cast<int32_t>(entry->friction_sound_id);
}
return 0;
}
uint8_t logFlumeReverserVehicleType_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->log_flume_reverser_vehicle_type;
}
return 0;
}
uint8_t soundRange_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->sound_range;
}
return 0;
}
uint8_t doubleSoundFrequency_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->double_sound_frequency;
}
return 0;
}
uint8_t poweredAcceleration_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->powered_acceleration;
}
return 0;
}
uint8_t poweredMaxSpeed_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->powered_max_speed;
}
return 0;
}
uint8_t carVisual_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->car_visual;
}
return 0;
}
uint8_t effectVisual_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->effect_visual;
}
return 0;
}
uint8_t drawOrder_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->draw_order;
}
return 0;
}
uint8_t numVerticalFramesOverride_get() const
{
auto entry = GetEntry();
if (entry != nullptr)
{
return entry->num_vertical_frames_override;
}
return 0;
}
Object* GetObject() const
{
auto& objManager = GetContext()->GetObjectManager();
return static_cast<RideObject*>(objManager.GetLoadedObject(_objectType, _objectIndex));
}
const rct_ride_entry_vehicle* GetEntry() const
{
auto obj = GetObject();
if (obj != nullptr)
{
auto rideEntry = static_cast<rct_ride_entry*>(obj->GetLegacyData());
if (rideEntry != nullptr && _vehicleIndex < std::size(rideEntry->vehicles))
{
return rideEntry->GetVehicle(_vehicleIndex);
}
}
return nullptr;
}
};
class ScRideObject : public ScObject
{
public:
@@ -119,6 +651,26 @@ namespace OpenRCT2::Scripting
dukglue_set_base_class<ScObject, ScRideObject>(ctx);
dukglue_register_property(ctx, &ScRideObject::description_get, nullptr, "description");
dukglue_register_property(ctx, &ScRideObject::capacity_get, nullptr, "capacity");
dukglue_register_property(ctx, &ScRideObject::firstImageId_get, nullptr, "firstImageId");
dukglue_register_property(ctx, &ScRideObject::flags_get, nullptr, "flags");
dukglue_register_property(ctx, &ScRideObject::rideType_get, nullptr, "rideType");
dukglue_register_property(ctx, &ScRideObject::minCarsInTrain_get, nullptr, "minCarsInTrain");
dukglue_register_property(ctx, &ScRideObject::maxCarsInTrain_get, nullptr, "maxCarsInTrain");
dukglue_register_property(ctx, &ScRideObject::carsPerFlatRide_get, nullptr, "carsPerFlatRide");
dukglue_register_property(ctx, &ScRideObject::zeroCars_get, nullptr, "zeroCars");
dukglue_register_property(ctx, &ScRideObject::tabVehicle_get, nullptr, "tabVehicle");
dukglue_register_property(ctx, &ScRideObject::defaultVehicle_get, nullptr, "defaultVehicle");
dukglue_register_property(ctx, &ScRideObject::frontVehicle_get, nullptr, "frontVehicle");
dukglue_register_property(ctx, &ScRideObject::secondVehicle_get, nullptr, "secondVehicle");
dukglue_register_property(ctx, &ScRideObject::rearVehicle_get, nullptr, "rearVehicle");
dukglue_register_property(ctx, &ScRideObject::thirdVehicle_get, nullptr, "thirdVehicle");
dukglue_register_property(ctx, &ScRideObject::vehicles_get, nullptr, "vehicles");
dukglue_register_property(ctx, &ScRideObject::excitementMultiplier_get, nullptr, "excitementMultiplier");
dukglue_register_property(ctx, &ScRideObject::intensityMultiplier_get, nullptr, "intensityMultiplier");
dukglue_register_property(ctx, &ScRideObject::nauseaMultiplier_get, nullptr, "nauseaMultiplier");
dukglue_register_property(ctx, &ScRideObject::maxHeight_get, nullptr, "maxHeight");
dukglue_register_property(ctx, &ScRideObject::shopItem_get, nullptr, "shopItem");
dukglue_register_property(ctx, &ScRideObject::shopItemSecondary_get, nullptr, "shopItemSecondary");
}
private:
@@ -142,11 +694,229 @@ namespace OpenRCT2::Scripting
return {};
}
uint32_t firstImageId_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->images_offset;
}
return 0;
}
uint32_t flags_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->flags;
}
return 0;
}
std::vector<uint8_t> rideType_get() const
{
std::vector<uint8_t> result;
auto entry = GetLegacyData();
if (entry != nullptr)
{
for (auto rideType : entry->ride_type)
{
result.push_back(rideType);
}
}
return result;
}
uint8_t minCarsInTrain_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->min_cars_in_train;
}
return 0;
}
uint8_t maxCarsInTrain_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->max_cars_in_train;
}
return 0;
}
uint8_t carsPerFlatRide_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->cars_per_flat_ride;
}
return 0;
}
uint8_t zeroCars_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->zero_cars;
}
return 0;
}
uint8_t tabVehicle_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->tab_vehicle;
}
return 0;
}
uint8_t defaultVehicle_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->default_vehicle;
}
return 0;
}
uint8_t frontVehicle_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->front_vehicle;
}
return 0;
}
uint8_t secondVehicle_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->second_vehicle;
}
return 0;
}
uint8_t rearVehicle_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->rear_vehicle;
}
return 0;
}
uint8_t thirdVehicle_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->third_vehicle;
}
return 0;
}
std::vector<std::shared_ptr<ScRideObjectVehicle>> vehicles_get() const
{
std::vector<std::shared_ptr<ScRideObjectVehicle>> result;
auto entry = GetLegacyData();
if (entry != nullptr)
{
for (size_t i = 0; i < std::size(entry->vehicles); i++)
{
result.push_back(std::make_shared<ScRideObjectVehicle>((OBJECT_TYPE)_type, _index, i));
}
}
return result;
}
int8_t excitementMultiplier_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->excitement_multiplier;
}
return 0;
}
int8_t intensityMultiplier_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->intensity_multiplier;
}
return 0;
}
int8_t nauseaMultiplier_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->nausea_multiplier;
}
return 0;
}
uint8_t maxHeight_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->max_height;
}
return 0;
}
uint8_t shopItem_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->shop_item;
}
return 0;
}
uint8_t shopItemSecondary_get() const
{
auto entry = GetLegacyData();
if (entry != nullptr)
{
return entry->shop_item_secondary;
}
return 0;
}
protected:
RideObject* GetObject() const
{
return static_cast<RideObject*>(ScObject::GetObject());
}
const rct_ride_entry* GetLegacyData() const
{
auto obj = GetObject();
if (obj != nullptr)
{
return static_cast<rct_ride_entry*>(obj->GetLegacyData());
}
return nullptr;
}
};
class ScSmallSceneryObject : public ScObject

View File

@@ -382,6 +382,7 @@ void ScriptEngine::Initialise()
ScPlayerGroup::Register(ctx);
ScRide::Register(ctx);
ScRideObject::Register(ctx);
ScRideObjectVehicle::Register(ctx);
ScTile::Register(ctx);
ScTileElement::Register(ctx);
ScEntity::Register(ctx);