Add ability to shift map

This commit is contained in:
Ted John 2023-05-21 01:23:58 +01:00 committed by Gymnasiast
parent 4e2f546d14
commit abc67f09e6
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
5 changed files with 160 additions and 0 deletions

View File

@ -939,6 +939,8 @@ declare global {
interface MapChangeSizeArgs extends GameActionArgs {
targetSizeX: number;
targetSizeY: number;
shiftX: number;
shiftY: number;
}
interface MazePlaceTrackArgs extends GameActionArgs {

View File

@ -18,7 +18,13 @@
#include "../world/Park.h"
MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize)
: MapChangeSizeAction(targetSize, TileCoordsXY())
{
}
MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize, const TileCoordsXY& shift)
: _targetSize(targetSize)
, _shift(shift)
{
}
@ -31,6 +37,7 @@ void MapChangeSizeAction::Serialise(DataSerialiser& stream)
{
GameAction::Serialise(stream);
stream << DS_TAG(_targetSize);
stream << DS_TAG(_shift);
}
GameActions::Result MapChangeSizeAction::Query() const
@ -63,6 +70,9 @@ GameActions::Result MapChangeSizeAction::Execute() const
MapExtendBoundarySurfaceY();
}
// Shift the map (allows increasing the map at the 0,0 position
ShiftMap(_shift);
// Shrink map
if (_targetSize.x < gameState.MapSize.x || _targetSize.y < gameState.MapSize.y)
{
@ -84,4 +94,6 @@ void MapChangeSizeAction::AcceptParameters(GameActionParameterVisitor& visitor)
{
visitor.Visit("targetSizeX", _targetSize.x);
visitor.Visit("targetSizeY", _targetSize.y);
visitor.Visit("shiftX", _shift.x);
visitor.Visit("shiftY", _shift.y);
}

View File

@ -17,6 +17,7 @@ class MapChangeSizeAction final : public GameActionBase<GameCommand::ChangeMapSi
public:
MapChangeSizeAction() = default;
MapChangeSizeAction(const TileCoordsXY& targetSize);
MapChangeSizeAction(const TileCoordsXY& targetSize, const TileCoordsXY& shift);
void AcceptParameters(GameActionParameterVisitor& visitor) override;
uint16_t GetActionFlags() const override;
@ -27,4 +28,5 @@ public:
private:
TileCoordsXY _targetSize;
TileCoordsXY _shift;
};

View File

@ -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++;
}
}
}

View File

@ -246,3 +246,4 @@ void FixLandOwnershipTiles(std::initializer_list<TileCoordsXY> tiles);
void FixLandOwnershipTilesWithOwnership(
std::initializer_list<TileCoordsXY> tiles, uint8_t ownership, bool doNotDowngrade = false);
MapRange ClampRangeWithinMap(const MapRange& range);
void ShiftMap(const TileCoordsXY& amount);