mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-30 02:05:13 +01:00
Add ability to shift map
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
#include "../actions/WallRemoveAction.h"
|
||||
#include "../audio/audio.h"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../entity/Duck.h"
|
||||
#include "../entity/PatrolArea.h"
|
||||
#include "../entity/Staff.h"
|
||||
#include "../interface/Cursors.h"
|
||||
#include "../interface/Viewport.h"
|
||||
#include "../interface/Window.h"
|
||||
@@ -45,6 +48,7 @@
|
||||
#include "../world/tile_element/Slope.h"
|
||||
#include "Banner.h"
|
||||
#include "Climate.h"
|
||||
#include "Entrance.h"
|
||||
#include "Footpath.h"
|
||||
#include "MapAnimation.h"
|
||||
#include "Park.h"
|
||||
@@ -2231,3 +2235,142 @@ MapRange ClampRangeWithinMap(const MapRange& range)
|
||||
MapRange validRange = MapRange{ aX, aY, bX, bY };
|
||||
return validRange;
|
||||
}
|
||||
|
||||
void ShiftMap(const TileCoordsXY& amount)
|
||||
{
|
||||
if (amount.x == 0 || amount.y == 0)
|
||||
return;
|
||||
|
||||
auto amountToMove = amount.ToCoordsXY();
|
||||
|
||||
// Tile elements
|
||||
auto newElements = std::vector<TileElement>();
|
||||
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||
{
|
||||
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
||||
{
|
||||
auto srcX = x - amount.x;
|
||||
auto srcY = y - amount.y;
|
||||
if (x >= 0 && y >= 0 && x < gMapSize.x && y < gMapSize.y && srcX >= 0 && srcY >= 0 && srcX < gMapSize.x
|
||||
&& srcY < gMapSize.y)
|
||||
{
|
||||
auto srcTile = _tileIndex.GetFirstElementAt(TileCoordsXY(srcX, srcY));
|
||||
do
|
||||
{
|
||||
newElements.push_back(*srcTile);
|
||||
} while (!(srcTile++)->IsLastForTile());
|
||||
}
|
||||
else if (x == 0 || y == 0 || x == gMapSize.x - 1 || y == gMapSize.y - 1)
|
||||
{
|
||||
auto surface = GetDefaultSurfaceElement();
|
||||
surface.SetBaseZ(MINIMUM_LAND_HEIGHT_BIG);
|
||||
surface.SetClearanceZ(MINIMUM_LAND_HEIGHT_BIG);
|
||||
surface.AsSurface()->SetSlope(0);
|
||||
surface.AsSurface()->SetWaterHeight(0);
|
||||
newElements.push_back(surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
newElements.push_back(GetDefaultSurfaceElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
SetTileElements(std::move(newElements));
|
||||
MapRemoveOutOfRangeElements();
|
||||
|
||||
for (auto& spawn : gPeepSpawns)
|
||||
spawn += amountToMove;
|
||||
|
||||
for (auto& entrance : gParkEntrances)
|
||||
entrance += amountToMove;
|
||||
|
||||
// Entities
|
||||
for (auto i = 0; i < EnumValue(EntityType::Count); i++)
|
||||
{
|
||||
auto entityType = static_cast<EntityType>(i);
|
||||
auto& list = GetEntityList(entityType);
|
||||
for (const auto& entityId : list)
|
||||
{
|
||||
auto entity = GetEntity(entityId);
|
||||
auto location = entity->GetLocation();
|
||||
location += amountToMove;
|
||||
entity->MoveTo(location);
|
||||
|
||||
switch (entityType)
|
||||
{
|
||||
case EntityType::Guest:
|
||||
case EntityType::Staff:
|
||||
{
|
||||
auto peep = entity->As<Peep>();
|
||||
peep->NextLoc += amountToMove;
|
||||
peep->DestinationX += amountToMove.x;
|
||||
peep->DestinationY += amountToMove.y;
|
||||
peep->PathfindGoal += amount;
|
||||
for (auto& h : peep->PathfindHistory)
|
||||
h += amount;
|
||||
break;
|
||||
}
|
||||
case EntityType::Vehicle:
|
||||
{
|
||||
auto vehicle = entity->As<Vehicle>();
|
||||
vehicle->TrackLocation += amountToMove;
|
||||
vehicle->BoatLocation += amountToMove;
|
||||
break;
|
||||
}
|
||||
case EntityType::Duck:
|
||||
{
|
||||
auto duck = entity->As<Duck>();
|
||||
duck->target_x += amountToMove.x;
|
||||
duck->target_y += amountToMove.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entityType == EntityType::Staff)
|
||||
{
|
||||
auto staff = entity->As<Staff>();
|
||||
auto patrol = staff->PatrolInfo;
|
||||
if (patrol != nullptr)
|
||||
{
|
||||
auto positions = patrol->ToVector();
|
||||
for (auto& p : positions)
|
||||
p += amount;
|
||||
patrol->Clear();
|
||||
patrol->Union(positions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rides
|
||||
for (auto& ride : GetRideManager())
|
||||
{
|
||||
auto& stations = ride.GetStations();
|
||||
for (auto& station : stations)
|
||||
{
|
||||
station.Start += amountToMove;
|
||||
station.Entrance += amount;
|
||||
station.Exit += amount;
|
||||
}
|
||||
|
||||
ride.overall_view += amountToMove;
|
||||
ride.boat_hire_return_position += amount;
|
||||
ride.CurTestTrackLocation += amount;
|
||||
ride.ChairliftBullwheelLocation[0] += amount;
|
||||
ride.ChairliftBullwheelLocation[1] += amount;
|
||||
ride.CableLiftLoc += amountToMove;
|
||||
}
|
||||
|
||||
// Banners
|
||||
auto numBanners = GetNumBanners();
|
||||
auto id = BannerIndex::FromUnderlying(0);
|
||||
size_t count = 0;
|
||||
while (count < numBanners)
|
||||
{
|
||||
auto* banner = GetBanner(id);
|
||||
if (banner != nullptr)
|
||||
{
|
||||
banner->position += amount;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user