prepare new object classes with EntranceObject

This commit is contained in:
Ted John 2016-06-25 02:52:58 +01:00
parent 3f65a3a383
commit 463e88583d
9 changed files with 322 additions and 0 deletions

View File

@ -117,7 +117,11 @@
<ClCompile Include="src\network\TcpSocket.cpp" />
<ClCompile Include="src\network\twitch.cpp" />
<ClCompile Include="src\object.c" />
<ClCompile Include="src\object\EntranceObject.cpp" />
<ClCompile Include="src\object\ImageTable.cpp" />
<ClCompile Include="src\object\Object.cpp" />
<ClCompile Include="src\object\ObjectRepository.cpp" />
<ClCompile Include="src\object\StringTable.cpp" />
<ClCompile Include="src\object_list.c" />
<ClCompile Include="src\openrct2.c" />
<ClCompile Include="src\paint\map_element\banner.c" />
@ -418,7 +422,11 @@
<ClInclude Include="src\network\network.h" />
<ClInclude Include="src\network\NetworkKey.h" />
<ClInclude Include="src\object.h" />
<ClInclude Include="src\object\EntranceObject.h" />
<ClInclude Include="src\object\ImageTable.h" />
<ClInclude Include="src\object\Object.h" />
<ClInclude Include="src\object\ObjectRepository.h" />
<ClInclude Include="src\object\StringTable.h" />
<ClInclude Include="src\object_list.h" />
<ClInclude Include="src\openrct2.h" />
<ClInclude Include="src\paint\map_element\map_element.h" />

View File

@ -0,0 +1,29 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "../core/IStream.hpp"
#include "EntranceObject.h"
void EntranceObject::Load(IStream * stream)
{
_legacyType.string_idx = stream->ReadValue<rct_string_id>();
_legacyType.image_id = stream->ReadValue<uint32>();
_legacyType.scrolling_mode = stream->ReadValue<uint8>();
_legacyType.text_height = stream->ReadValue<uint8>();
LoadStringTable(stream, 0);
LoadImageTable(stream);
}

View File

@ -0,0 +1,38 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include "Object.h"
extern "C"
{
#include "../world/entrance.h"
}
class EntranceObject : public Object
{
private:
rct_object_entry _objectEntry;
rct_entrance_type _legacyType;
public:
const rct_object_entry * GetObjectEntry() override { return &_objectEntry; }
void * GetLegacyData() override { return &_legacyType; }
protected:
void Load(IStream * stream) override;
};

22
src/object/ImageTable.cpp Normal file
View File

@ -0,0 +1,22 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "ImageTable.h"
void ImageTable::Read(IStream * stream)
{
// TODO
}

27
src/object/ImageTable.h Normal file
View File

@ -0,0 +1,27 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include "../common.h"
interface IStream;
class ImageTable
{
public:
void Read(IStream * stream);
};

27
src/object/Object.cpp Normal file
View File

@ -0,0 +1,27 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "Object.h"
void Object::LoadStringTable(IStream * stream, uint8 id)
{
_stringTable.Read(stream, id);
}
void Object::LoadImageTable(IStream * stream)
{
_imageTable.Read(stream);
}

49
src/object/Object.h Normal file
View File

@ -0,0 +1,49 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include "../common.h"
#include "ImageTable.h"
#include "StringTable.h"
extern "C"
{
#include "../object.h"
}
interface IStream;
class Object
{
private:
StringTable _stringTable;
ImageTable _imageTable;
public:
virtual ~Object() { }
// Legacy data structures
virtual const rct_object_entry * GetObjectEntry() abstract;
virtual void * GetLegacyData() abstract;
protected:
virtual void Load(IStream * stream) abstract;
virtual void Unload() abstract;
void LoadStringTable(IStream * stream, uint8 id);
void LoadImageTable(IStream * stream);
};

View File

@ -0,0 +1,81 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include <algorithm>
#include "../core/IStream.hpp"
#include "../core/String.hpp"
#include "../localisation/LanguagePack.h"
#include "StringTable.h"
constexpr uint8 RCT2_LANGUAGE_ID_ENGLISH_UK = 0;
constexpr uint8 RCT2_LANGUAGE_ID_BLANK = 254;
constexpr uint8 RCT2_LANGUAGE_ID_END = 255;
bool StringIsBlank(utf8 * str)
{
for (utf8 * ch = str; *ch != '\0'; ch++)
{
if (!isblank(*ch))
{
return false;
}
}
return true;
}
void StringTable::Read(IStream * stream, uint8 id)
{
uint8 languageId;
while ((languageId = stream->ReadValue<uint8>()) != RCT2_LANGUAGE_ID_END)
{
StringTableEntry entry;
entry.Id = id;
entry.LanguageId = languageId;
entry.Text = stream->ReadString();
if (StringIsBlank(entry.Text))
{
entry.LanguageId = RCT2_LANGUAGE_ID_BLANK;
}
_strings.push_back(entry);
}
Sort();
}
void StringTable::Sort()
{
std::sort(_strings.begin(), _strings.end(), [](const StringTableEntry &a, const StringTableEntry &b) -> int
{
if (a.Id == b.Id)
{
if (a.LanguageId == b.LanguageId)
{
return _strcmpi(a.Text, b.Text);
}
if (a.LanguageId == LanguagesDescriptors[gCurrentLanguage].rct2_original_id)
{
return -1;
}
if (a.LanguageId == RCT2_LANGUAGE_ID_ENGLISH_UK)
{
return -1;
}
return 1;
}
return a.Id - b.Id;
});
}

41
src/object/StringTable.h Normal file
View File

@ -0,0 +1,41 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include <vector>
#include "../common.h"
interface IStream;
struct StringTableEntry
{
uint8 Id;
uint8 LanguageId;
utf8 * Text;
};
class StringTable
{
private:
std::vector<StringTableEntry> _strings;
public:
void Read(IStream * stream, uint8 id);
private:
void Sort();
};