2016-06-25 23:47:09 +02:00
|
|
|
#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 "LargeSceneryObject.h"
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#include "../drawing/drawing.h"
|
|
|
|
#include "../localisation/localisation.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
LargeSceneryObject::~LargeSceneryObject()
|
|
|
|
{
|
|
|
|
Memory::Free(_3dFont);
|
|
|
|
Memory::Free(_tiles);
|
|
|
|
}
|
|
|
|
|
2016-07-01 22:01:06 +02:00
|
|
|
void LargeSceneryObject::ReadLegacy(IReadObjectContext * context, IStream * stream)
|
2016-06-25 23:47:09 +02:00
|
|
|
{
|
2016-07-03 19:02:18 +02:00
|
|
|
stream->Seek(6, STREAM_SEEK_CURRENT);
|
2016-06-25 23:47:09 +02:00
|
|
|
_legacyType.large_scenery.tool_id = stream->ReadValue<uint8>();
|
|
|
|
_legacyType.large_scenery.flags = stream->ReadValue<uint8>();
|
|
|
|
_legacyType.large_scenery.price = stream->ReadValue<sint16>();
|
|
|
|
_legacyType.large_scenery.removal_price = stream->ReadValue<sint16>();
|
2016-07-10 01:15:27 +02:00
|
|
|
stream->Seek(5, STREAM_SEEK_CURRENT);
|
2016-06-25 23:47:09 +02:00
|
|
|
_legacyType.large_scenery.scenery_tab_id = 0xFF;
|
|
|
|
_legacyType.large_scenery.var_11 = stream->ReadValue<uint8>();
|
2016-07-10 01:15:27 +02:00
|
|
|
stream->Seek(4, STREAM_SEEK_CURRENT);
|
2016-06-25 23:47:09 +02:00
|
|
|
|
2016-07-01 22:01:06 +02:00
|
|
|
GetStringTable()->Read(context, stream, OBJ_STRING_ID_NAME);
|
2016-06-25 23:47:09 +02:00
|
|
|
|
2016-07-09 20:16:38 +02:00
|
|
|
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
|
|
|
|
SetPrimarySceneryGroup(&sgEntry);
|
2016-06-25 23:47:09 +02:00
|
|
|
|
2017-02-04 09:12:44 +01:00
|
|
|
if (_legacyType.large_scenery.flags & LARGE_SCENERY_FLAG_3D_TEXT)
|
2016-06-25 23:47:09 +02:00
|
|
|
{
|
|
|
|
_3dFont = Memory::Allocate<rct_large_scenery_text>();
|
|
|
|
stream->Read(_3dFont);
|
|
|
|
_legacyType.large_scenery.text = _3dFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
_tiles = ReadTiles(stream);
|
|
|
|
|
2016-07-01 22:01:06 +02:00
|
|
|
GetImageTable()->Read(context, stream);
|
2016-07-02 18:23:06 +02:00
|
|
|
|
|
|
|
// Validate properties
|
|
|
|
if (_legacyType.large_scenery.price <= 0)
|
|
|
|
{
|
|
|
|
context->LogError(OBJECT_ERROR_INVALID_PROPERTY, "Price can not be free or negative.");
|
|
|
|
}
|
|
|
|
if (_legacyType.large_scenery.removal_price <= 0)
|
|
|
|
{
|
|
|
|
// Make sure you don't make a profit when placing then removing.
|
|
|
|
money16 reimbursement = _legacyType.large_scenery.removal_price;
|
|
|
|
if (reimbursement > _legacyType.large_scenery.price)
|
|
|
|
{
|
|
|
|
context->LogError(OBJECT_ERROR_INVALID_PROPERTY, "Sell price can not be more than buy price.");
|
|
|
|
}
|
|
|
|
}
|
2016-06-25 23:47:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LargeSceneryObject::Load()
|
|
|
|
{
|
2016-07-11 23:50:55 +02:00
|
|
|
GetStringTable()->Sort();
|
2016-06-25 23:47:09 +02:00
|
|
|
_legacyType.name = language_allocate_object_string(GetName());
|
2016-07-03 20:48:21 +02:00
|
|
|
_baseImageId = gfx_object_allocate_images(GetImageTable()->GetImages(), GetImageTable()->GetCount());
|
|
|
|
_legacyType.image = _baseImageId;
|
2016-06-25 23:47:09 +02:00
|
|
|
|
2016-06-26 17:55:46 +02:00
|
|
|
_legacyType.large_scenery.tiles = _tiles;
|
|
|
|
|
2017-02-04 09:12:44 +01:00
|
|
|
if (_legacyType.large_scenery.flags & LARGE_SCENERY_FLAG_3D_TEXT)
|
2016-06-25 23:47:09 +02:00
|
|
|
{
|
|
|
|
_legacyType.large_scenery.text_image = _legacyType.image;
|
2017-02-04 09:12:44 +01:00
|
|
|
if (_3dFont->flags & LARGE_SCENERY_TEXT_FLAG_VERTICAL)
|
2016-06-25 23:47:09 +02:00
|
|
|
{
|
2017-02-04 09:12:44 +01:00
|
|
|
_legacyType.image += _3dFont->var_D * 2;
|
2016-06-25 23:47:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-04 09:12:44 +01:00
|
|
|
_legacyType.image += _3dFont->var_D * 4;
|
2016-06-25 23:47:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LargeSceneryObject::Unload()
|
|
|
|
{
|
|
|
|
language_free_object_string(_legacyType.name);
|
2016-07-03 20:48:21 +02:00
|
|
|
gfx_object_free_images(_baseImageId, GetImageTable()->GetCount());
|
2016-07-03 19:02:18 +02:00
|
|
|
|
|
|
|
_legacyType.name = 0;
|
|
|
|
_legacyType.image = 0;
|
2016-06-25 23:47:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-11 23:09:15 +02:00
|
|
|
void LargeSceneryObject::DrawPreview(rct_drawpixelinfo * dpi, sint32 width, sint32 height) const
|
2016-07-02 13:29:13 +02:00
|
|
|
{
|
2016-07-11 23:09:15 +02:00
|
|
|
sint32 x = width / 2;
|
|
|
|
sint32 y = (height / 2) - 39;
|
2016-07-02 13:29:13 +02:00
|
|
|
|
|
|
|
uint32 imageId = 0xB2D00000 | _legacyType.image;
|
|
|
|
gfx_draw_sprite(dpi, imageId, x, y, 0);
|
|
|
|
}
|
|
|
|
|
2016-06-25 23:47:09 +02:00
|
|
|
rct_large_scenery_tile * LargeSceneryObject::ReadTiles(IStream * stream)
|
|
|
|
{
|
|
|
|
auto tiles = std::vector<rct_large_scenery_tile>();
|
|
|
|
|
|
|
|
uint16 tilesEndMarker;
|
|
|
|
while ((tilesEndMarker = stream->ReadValue<uint16>()) != 0xFFFF)
|
|
|
|
{
|
|
|
|
stream->Seek(-2, STREAM_SEEK_CURRENT);
|
|
|
|
auto tile = stream->ReadValue<rct_large_scenery_tile>();
|
|
|
|
tiles.push_back(tile);
|
|
|
|
}
|
2016-07-07 18:55:07 +02:00
|
|
|
tiles.push_back({ -1, -1, -1, 255, 0xFFFF });
|
2016-06-25 23:47:09 +02:00
|
|
|
|
|
|
|
return Memory::DuplicateArray(tiles.data(), tiles.size());
|
|
|
|
}
|