2016-06-25 02:52:58 +01:00
|
|
|
/*****************************************************************************
|
2020-05-07 19:35:30 +01:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-06-25 02:52:58 +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 02:52:58 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-06-25 02:52:58 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "Object.h"
|
|
|
|
|
|
2020-05-07 19:35:30 +01:00
|
|
|
#include "../Context.h"
|
2016-07-04 18:53:35 +01:00
|
|
|
#include "../core/Memory.hpp"
|
|
|
|
|
#include "../core/String.hpp"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Language.h"
|
2020-05-07 19:35:30 +01:00
|
|
|
#include "../localisation/LocalisationService.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/StringIds.h"
|
2020-03-18 16:22:08 +01:00
|
|
|
#include "../world/Scenery.h"
|
2018-01-02 20:36:42 +01:00
|
|
|
#include "ObjectLimits.h"
|
2016-06-25 02:52:58 +01:00
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
#include <algorithm>
|
2020-05-07 19:35:30 +01:00
|
|
|
#include <cstring>
|
2018-12-05 20:33:45 +00:00
|
|
|
#include <stdexcept>
|
2018-06-22 23:03:20 +02:00
|
|
|
|
|
|
|
|
Object::Object(const rct_object_entry& entry)
|
2016-06-25 02:52:58 +01:00
|
|
|
{
|
2016-06-25 14:44:04 +01:00
|
|
|
_objectEntry = entry;
|
2016-07-04 18:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-05 20:33:45 +00:00
|
|
|
void* Object::GetLegacyData()
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Not supported.");
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 23:01:22 +02:00
|
|
|
void Object::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Not supported.");
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
std::string Object::GetOverrideString(uint8_t index) const
|
2016-07-04 18:53:35 +01:00
|
|
|
{
|
2020-05-07 19:35:30 +01:00
|
|
|
auto legacyIdentifier = GetLegacyIdentifier();
|
|
|
|
|
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
|
|
|
|
|
auto stringId = localisationService.GetObjectOverrideStringId(legacyIdentifier, index);
|
2016-07-04 18:53:35 +01:00
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
const utf8* result = nullptr;
|
2016-07-04 18:53:35 +01:00
|
|
|
if (stringId != STR_NONE)
|
|
|
|
|
{
|
|
|
|
|
result = language_get_string(stringId);
|
|
|
|
|
}
|
2017-12-05 12:55:33 +00:00
|
|
|
return String::ToStd(result);
|
2016-07-04 18:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
std::string Object::GetString(uint8_t index) const
|
2016-07-04 18:53:35 +01:00
|
|
|
{
|
2017-11-22 16:52:07 +01:00
|
|
|
auto sz = GetOverrideString(index);
|
2017-12-22 15:08:00 +01:00
|
|
|
if (sz.empty())
|
2016-07-04 18:53:35 +01:00
|
|
|
{
|
2017-12-11 13:06:59 +00:00
|
|
|
sz = GetStringTable().GetString(index);
|
2016-07-04 18:53:35 +01:00
|
|
|
}
|
2017-12-05 12:55:33 +00:00
|
|
|
return sz;
|
2016-07-04 18:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
std::string Object::GetString(int32_t language, uint8_t index) const
|
2018-04-27 18:23:39 +01:00
|
|
|
{
|
|
|
|
|
return GetStringTable().GetString(language, index);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-01 11:54:25 +01:00
|
|
|
rct_object_entry Object::GetScgWallsHeader()
|
|
|
|
|
{
|
|
|
|
|
return Object::CreateHeader("SCGWALLS", 207140231, 3518650219);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rct_object_entry Object::GetScgPathXHeader()
|
|
|
|
|
{
|
|
|
|
|
return Object::CreateHeader("SCGPATHX", 207140231, 890227440);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
rct_object_entry Object::CreateHeader(const char name[DAT_NAME_LENGTH + 1], uint32_t flags, uint32_t checksum)
|
2017-12-01 11:54:25 +01:00
|
|
|
{
|
2018-06-04 19:50:46 +02:00
|
|
|
rct_object_entry header = {};
|
2017-12-01 11:54:25 +01:00
|
|
|
header.flags = flags;
|
2018-02-01 12:52:39 +00:00
|
|
|
std::copy_n(name, DAT_NAME_LENGTH, header.name);
|
2017-12-01 11:54:25 +01:00
|
|
|
header.checksum = checksum;
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 15:15:56 +02:00
|
|
|
std::vector<uint8_t> Object::GetSourceGames()
|
2018-07-03 13:46:45 +02:00
|
|
|
{
|
2018-07-06 15:15:56 +02:00
|
|
|
return _sourceGames;
|
2018-07-03 13:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-07 21:08:31 +02:00
|
|
|
void Object::SetSourceGames(const std::vector<uint8_t>& sourceGames)
|
2018-01-31 13:07:20 +01:00
|
|
|
{
|
2018-07-06 15:15:56 +02:00
|
|
|
_sourceGames = sourceGames;
|
2018-06-29 16:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-23 10:14:28 +01:00
|
|
|
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
2018-07-21 16:17:06 +02:00
|
|
|
# pragma GCC diagnostic push
|
|
|
|
|
# pragma GCC diagnostic ignored "-Wsuggest-final-methods"
|
2017-11-23 10:14:28 +01:00
|
|
|
#endif
|
|
|
|
|
|
2017-12-05 12:55:33 +00:00
|
|
|
std::string Object::GetName() const
|
2016-07-04 18:53:35 +01:00
|
|
|
{
|
|
|
|
|
return GetString(OBJ_STRING_ID_NAME);
|
2016-06-25 02:52:58 +01:00
|
|
|
}
|
2017-11-23 10:14:28 +01:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
std::string Object::GetName(int32_t language) const
|
2018-04-27 18:23:39 +01:00
|
|
|
{
|
|
|
|
|
return GetString(language, OBJ_STRING_ID_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 19:35:30 +01:00
|
|
|
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()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 06:23:28 +01:00
|
|
|
const std::vector<std::string>& Object::GetAuthors() const
|
|
|
|
|
{
|
|
|
|
|
return _authors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::SetAuthors(const std::vector<std::string>&& authors)
|
|
|
|
|
{
|
|
|
|
|
_authors = authors;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 16:22:08 +01:00
|
|
|
std::optional<uint8_t> rct_object_entry::GetSceneryType() const
|
|
|
|
|
{
|
|
|
|
|
switch (GetType())
|
|
|
|
|
{
|
|
|
|
|
case OBJECT_TYPE_SMALL_SCENERY:
|
|
|
|
|
return SCENERY_TYPE_SMALL;
|
|
|
|
|
case OBJECT_TYPE_LARGE_SCENERY:
|
|
|
|
|
return SCENERY_TYPE_LARGE;
|
|
|
|
|
case OBJECT_TYPE_WALLS:
|
|
|
|
|
return SCENERY_TYPE_WALL;
|
|
|
|
|
case OBJECT_TYPE_BANNERS:
|
|
|
|
|
return SCENERY_TYPE_BANNER;
|
|
|
|
|
case OBJECT_TYPE_PATH_BITS:
|
|
|
|
|
return SCENERY_TYPE_PATH_ITEM;
|
|
|
|
|
default:
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 10:14:28 +01:00
|
|
|
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
2018-07-21 16:17:06 +02:00
|
|
|
# pragma GCC diagnostic pop
|
2017-11-23 10:14:28 +01:00
|
|
|
#endif
|