Files
OpenRCT2-Web/src/openrct2/object/Object.cpp
T

170 lines
3.9 KiB
C++
Raw Normal View History

/*****************************************************************************
2018-06-15 14:07:34 +02:00
* Copyright (c) 2014-2018 OpenRCT2 developers
*
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
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-06-22 23:03:20 +02:00
#include "Object.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"
#include "../localisation/StringIds.h"
2018-01-02 20:36:42 +01:00
#include "ObjectLimits.h"
2018-06-22 23:03:20 +02:00
#include <algorithm>
Object::Object(const rct_object_entry& entry)
{
2016-06-25 14:44:04 +01:00
_objectEntry = entry;
2016-07-04 18:53:35 +01:00
2018-01-02 20:36:42 +01:00
char name[DAT_NAME_LENGTH + 1] = { 0 };
2018-02-01 12:52:39 +00:00
std::copy_n(entry.name, DAT_NAME_LENGTH, name);
2016-07-04 18:53:35 +01:00
_identifier = String::Duplicate(name);
2018-06-29 16:03:42 +02:00
_secondSourceGame = OBJECT_SOURCE_CUSTOM;
2018-01-31 13:07:20 +01:00
2018-06-29 12:52:13 +02:00
if (IsOpenRCT2OfficialObject())
2018-01-31 13:07:20 +01:00
{
SetSourceGame(OBJECT_SOURCE_OPENRCT2_OFFICIAL);
}
2016-07-04 18:53:35 +01:00
}
Object::~Object()
{
Memory::Free(_identifier);
}
std::string Object::GetOverrideString(uint8_t index) const
2016-07-04 18:53:35 +01:00
{
2018-06-22 23:03:20 +02:00
const char* identifier = GetIdentifier();
2016-07-04 18:53:35 +01:00
rct_string_id stringId = language_get_object_override_string_id(identifier, index);
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
}
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
}
std::string Object::GetString(int32_t language, uint8_t index) const
2018-04-27 18:23:39 +01:00
{
return GetStringTable().GetString(language, index);
}
rct_object_entry Object::GetScgWallsHeader()
{
return Object::CreateHeader("SCGWALLS", 207140231, 3518650219);
}
rct_object_entry Object::GetScgPathXHeader()
{
return Object::CreateHeader("SCGPATHX", 207140231, 890227440);
}
rct_object_entry Object::CreateHeader(const char name[DAT_NAME_LENGTH + 1], uint32_t flags, uint32_t checksum)
{
rct_object_entry header = {};
header.flags = flags;
2018-02-01 12:52:39 +00:00
std::copy_n(name, DAT_NAME_LENGTH, header.name);
header.checksum = checksum;
return header;
}
void Object::SetSourceGame(const uint8_t sourceGame)
2018-01-31 13:07:20 +01:00
{
// FIXME: Temporary disabled because it breaks exporting to vanilla.
/*_objectEntry.flags &= 0x0F;
_objectEntry.flags |= (sourceGame << 4);*/
2018-01-31 13:07:20 +01:00
}
2018-06-30 10:55:59 +01:00
uint8_t Object::GetSecondSourceGame()
2018-06-29 16:03:42 +02:00
{
return _secondSourceGame;
}
void Object::SetSecondSourceGame(const uint8_t sourceGame)
{
_secondSourceGame = sourceGame;
}
2018-01-31 13:07:20 +01:00
bool Object::IsOpenRCT2OfficialObject()
{
2018-06-22 23:03:20 +02:00
static const char _openRCT2OfficialObjects[][9] = {
2018-01-31 13:07:20 +01:00
// Offical extended scenery set
"XXBBBR01",
"TTRFTL02",
"TTRFTL03",
"TTRFTL04",
"TTRFTL07",
"TTRFTL08",
"TTPIRF02",
"TTPIRF03",
"TTPIRF04",
"TTPIRF05",
"TTPIRF07",
"TTPIRF08",
"MG-PRAR ",
"TTRFWD01",
"TTRFWD02",
"TTRFWD03",
"TTRFWD04",
"TTRFWD05",
"TTRFWD06",
"TTRFWD07",
"TTRFWD08",
"TTRFGL01",
"TTRFGL02",
"TTRFGL03",
"ACWW33 ",
"ACWWF32 ",
// Official DLC
"BIGPANDA",
"LITTERPA",
"PANDAGR ",
"SCGPANDA",
"WTRPINK ",
"ZPANDA ",
};
for (const auto entry : _openRCT2OfficialObjects)
{
if (String::Equals(_identifier, entry))
return true;
}
return false;
}
#ifdef __WARN_SUGGEST_FINAL_METHODS__
2018-07-21 16:17:06 +02:00
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wsuggest-final-methods"
#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);
}
std::string Object::GetName(int32_t language) const
2018-04-27 18:23:39 +01:00
{
return GetString(language, OBJ_STRING_ID_NAME);
}
#ifdef __WARN_SUGGEST_FINAL_METHODS__
2018-07-21 16:17:06 +02:00
# pragma GCC diagnostic pop
#endif