Load general properties and fix entrance positions

This commit is contained in:
Ted John 2018-12-15 14:31:17 +00:00
parent 6baa70ced9
commit 2fc8e06a95
4 changed files with 65 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "object/ObjectManager.h"
#include "object/ObjectRepository.h"
#include "scenario/Scenario.h"
#include "world/Entrance.h"
#include "world/Map.h"
#include "world/Park.h"
@ -297,6 +298,7 @@ void ParkFile::Load(const std::string_view& path)
void ParkFile::Import()
{
ReadTilesChunk();
ReadGeneralChunk();
}
ParkFile::Header ParkFile::ReadHeader(std::istream& fs)
@ -358,6 +360,39 @@ std::string ParkFile::ReadString()
return buffer;
}
void ParkFile::ReadGeneralChunk()
{
if (SeekChunk(ParkFileChunkType::GENERAL))
{
gScenarioTicks = ReadValue<uint64_t>();
gDateMonthTicks = ReadValue<uint32_t>();
gDateMonthsElapsed = ReadValue<uint16_t>();
gScenarioSrand0 = ReadValue<uint32_t>();
gScenarioSrand1 = ReadValue<uint32_t>();
gInitialCash = ReadValue<money32>();
gGuestInitialCash = ReadValue<money16>();
gGuestInitialHunger = ReadValue<uint8_t>();
gGuestInitialThirst = ReadValue<uint8_t>();
size_t numPeepSpawns = ReadArray();
for (size_t i = 0; i < numPeepSpawns; i++)
{
gPeepSpawns[i].x = ReadValue<uint32_t>();
gPeepSpawns[i].y = ReadValue<uint32_t>();
gPeepSpawns[i].z = ReadValue<uint32_t>();
gPeepSpawns[i].direction = ReadValue<uint8_t>();
ReadNextArrayElement();
}
gLandPrice = ReadValue<money16>();
gConstructionRightsPrice = ReadValue<money16>();
}
else
{
throw std::runtime_error("No general chunk found.");
}
}
void ParkFile::ReadTilesChunk()
{
if (SeekChunk(ParkFileChunkType::TILES))
@ -371,6 +406,7 @@ void ParkFile::ReadTilesChunk()
ReadBuffer(gTileElements, numElements * sizeof(TileElement));
map_update_tile_pointers();
UpdateParkEntranceLocations();
}
else
{

View File

@ -70,6 +70,7 @@ namespace OpenRCT2
void WriteGeneralChunk();
void WriteTilesChunk();
void ReadGeneralChunk();
void ReadTilesChunk();
Header ReadHeader(std::istream& fs);

View File

@ -214,6 +214,33 @@ void fix_park_entrance_locations(void)
gParkEntrances.end());
}
void UpdateParkEntranceLocations()
{
reset_park_entrance();
size_t entranceIndex = 0;
tile_element_iterator it;
tile_element_iterator_begin(&it);
while (tile_element_iterator_next(&it))
{
auto entranceElement = it.element->AsEntrance();
if (entranceElement != nullptr && entranceElement->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE
&& entranceElement->GetSequenceIndex() == 0 && !entranceElement->IsGhost())
{
auto& entrance = gParkEntrances[entranceIndex];
entrance.x = it.x * 32;
entrance.y = it.y * 32;
entrance.z = it.element->base_height * 8;
entrance.direction = it.element->GetDirection();
entranceIndex++;
if (entranceIndex >= MAX_PARK_ENTRANCES)
{
break;
}
}
}
}
uint8_t EntranceElement::GetStationIndex() const
{
return StationIndex;

View File

@ -56,5 +56,6 @@ void maze_entrance_hedge_replacement(const CoordsXYE& entrance);
void maze_entrance_hedge_removal(const CoordsXYE& entrance);
void fix_park_entrance_locations();
void UpdateParkEntranceLocations();
#endif