add small scenery object

This commit is contained in:
Ted John 2016-06-25 18:58:04 +01:00
parent 7e206d1a85
commit daa5a0c506
5 changed files with 156 additions and 1 deletions

View File

@ -125,6 +125,7 @@
<ClCompile Include="src\object\Object.cpp" />
<ClCompile Include="src\object\ObjectFactory.cpp" />
<ClCompile Include="src\object\ObjectRepository.cpp" />
<ClCompile Include="src\object\SmallSceneryObject.cpp" />
<ClCompile Include="src\object\StexObject.cpp" />
<ClCompile Include="src\object\StringTable.cpp" />
<ClCompile Include="src\object_list.c" />
@ -434,6 +435,7 @@
<ClInclude Include="src\object\Object.h" />
<ClInclude Include="src\object\ObjectFactory.h" />
<ClInclude Include="src\object\ObjectRepository.h" />
<ClInclude Include="src\object\SmallSceneryObject.h" />
<ClInclude Include="src\object\StexObject.h" />
<ClInclude Include="src\object\StringTable.h" />
<ClInclude Include="src\object_list.h" />

View File

@ -37,7 +37,6 @@ void FootpathItemObject::ReadLegacy(IStream * stream)
_legacyType.path_bit.tool_id = stream->ReadValue<uint8>();
_legacyType.path_bit.price = stream->ReadValue<sint16>();
_legacyType.path_bit.scenery_tab_id = stream->ReadValue<uint8>();
stream->Seek(0, STREAM_SEEK_BEGIN);
StringTable.Read(stream, OBJ_STRING_ID_NAME);

View File

@ -22,6 +22,7 @@
#include "FootpathObject.h"
#include "Object.h"
#include "ObjectFactory.h"
#include "SmallSceneryObject.h"
#include "StexObject.h"
extern "C"
@ -64,6 +65,9 @@ namespace ObjectFactory
uint8 objectType = entry.flags & 0x0F;
switch (objectType) {
case OBJECT_TYPE_SMALL_SCENERY:
result = new SmallSceneryObject(entry);
break;
case OBJECT_TYPE_PATHS:
result = new FootpathObject(entry);
break;

View File

@ -0,0 +1,103 @@
#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 "../core/Memory.hpp"
#include "SmallSceneryObject.h"
extern "C"
{
#include "../drawing/drawing.h"
#include "../localisation/localisation.h"
}
enum OBJ_STRING_ID
{
OBJ_STRING_ID_NAME,
};
SmallSceneryObject::~SmallSceneryObject()
{
Memory::Free(_var10data);
}
void SmallSceneryObject::ReadLegacy(IStream * stream)
{
_legacyType.name = stream->ReadValue<rct_string_id>();
_legacyType.image = stream->ReadValue<uint32>();
_legacyType.small_scenery.flags = stream->ReadValue<uint32>();
_legacyType.small_scenery.height = stream->ReadValue<uint8>();
_legacyType.small_scenery.tool_id = stream->ReadValue<uint8>();
_legacyType.small_scenery.price = stream->ReadValue<sint16>();
_legacyType.small_scenery.removal_price = stream->ReadValue<sint16>();
_legacyType.small_scenery.var_10 = stream->ReadValue<uint32>();
_legacyType.small_scenery.var_14 = stream->ReadValue<uint16>();
_legacyType.small_scenery.var_16 = stream->ReadValue<uint16>();
_legacyType.small_scenery.var_18 = stream->ReadValue<uint16>();
_legacyType.small_scenery.scenery_tab_id = 0xFF;
StringTable.Read(stream, OBJ_STRING_ID_NAME);
_sceneryTabEntry = stream->ReadValue<rct_object_entry>();
if (_legacyType.small_scenery.flags & SMALL_SCENERY_FLAG16)
{
_var10data = ReadVar10(stream);
}
ImageTable.Read(stream);
}
void SmallSceneryObject::Load()
{
_legacyType.name = language_allocate_object_string(GetName());
_legacyType.image = gfx_object_allocate_images(ImageTable.GetImages(), ImageTable.GetCount());
_legacyType.small_scenery.scenery_tab_id = 0xFF;
if ((_sceneryTabEntry.flags & 0xFF) != 0xFF)
{
uint8 entryType, entryIndex;
if (find_object_in_entry_group(&_sceneryTabEntry, &entryType, &entryIndex))
{
_legacyType.small_scenery.scenery_tab_id = entryIndex;
}
}
}
void SmallSceneryObject::Unload()
{
language_free_object_string(_legacyType.name);
gfx_object_free_images(_legacyType.image, ImageTable.GetCount());
}
const utf8 * SmallSceneryObject::GetName()
{
return StringTable.GetString(OBJ_STRING_ID_NAME);
}
uint8 * SmallSceneryObject::ReadVar10(IStream * stream)
{
uint8 b;
auto data = std::vector<uint8>();
data.push_back(stream->ReadValue<uint8>());
while ((b = stream->ReadValue<uint8>()) != 0xFF)
{
data.push_back(b);
}
data.push_back(b);
return Memory::Duplicate(data.data(), data.size());
}

View File

@ -0,0 +1,47 @@
#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/scenery.h"
}
class SmallSceneryObject : public Object
{
private:
rct_scenery_entry _legacyType;
rct_object_entry _sceneryTabEntry;
uint8 * _var10data = nullptr;
public:
explicit SmallSceneryObject(const rct_object_entry &entry) : Object(entry) { };
~SmallSceneryObject();
void * GetLegacyData() override { return &_legacyType; }
void ReadLegacy(IStream * stream) override;
void Load() override;
void Unload() override;
const utf8 * GetName() override;
private:
static uint8 * ReadVar10(IStream * stream);
};