Skip to content

Commit

Permalink
Tower section is centered with base
Browse files Browse the repository at this point in the history
  • Loading branch information
frutiemax92 committed May 14, 2023
1 parent 60f01d1 commit aec45e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/openrct2/ride/RideBaseBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RideBaseBuilder.h"
#include <algorithm>

RideBaseBuilder::RideBaseBuilder(uint8_t sizeX, uint8_t sizeY)
: _sizeX(sizeX)
Expand All @@ -20,13 +21,29 @@ RideBaseBuilder::RideBaseBuilder(uint8_t sizeX, uint8_t sizeY)

void RideBaseBuilder::SwapTiles(uint8_t index0, uint8_t index1)
{
//swap the blocks
auto block0 = std::find_if(_blocks.begin(), _blocks.end(), [index0](const auto& block) { return block.index == index0; });
auto block1 = std::find_if(_blocks.begin(), _blocks.end(), [index1](const auto& block) { return block.index == index1; });

block0->index = index1;
block1->index = index0;
std::iter_swap(block0, block1);

//swap the edges
//std::iter_swap(_edges.begin() + index0, _edges.begin() + index1);

//change the track mapping
for (auto& mapping : _mapping)
{
std::iter_swap(mapping.begin() + index0, mapping.begin() + index1);
}
}

uint8_t RideBaseBuilder::GetTileIndex(uint8_t x, uint8_t y) const
{
std::vector<PreviewTrack>::const_iterator res = std::find_if(
_blocks.begin(), _blocks.end(), [x, y](const auto& block) { return block.x / 32 == x && block.y / 32 == y; });
if (res != _blocks.end())
auto res = std::find_if(
_blocks.cbegin(), _blocks.cend(), [x, y](const auto& block) { return block.x / 32 == x && block.y / 32 == y; });
if (res != _blocks.cend())
return res->index;
else
return 255;
Expand Down
4 changes: 4 additions & 0 deletions src/openrct2/ride/RideBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <vector>
#include "TrackData.h"

/// <summary>
/// RideBaseBuilder only supports square bases for now
/// Non-square bases requires specific handling for the track mapping
/// </summary>
class RideBaseBuilder
{
public:
Expand Down
6 changes: 6 additions & 0 deletions src/openrct2/ride/TrackData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7204,6 +7204,12 @@ namespace OpenRCT2

//build the 9x9 base
RideBaseBuilder builder(9, 9);

//swap the center tile for the last tile
auto centerTile = builder.GetTileIndex(5, 4);
auto lastTile = builder.GetTileIndex(8, 8);
builder.SwapTiles(centerTile, lastTile);

TrackBlock9x9 = builder.GetBlocks();
Sequence9x9 = builder.GetSequences();
TrackMap9x9 = builder.GetMapping();
Expand Down

0 comments on commit aec45e1

Please sign in to comment.