2021-09-29 17:46:03 +02:00
|
|
|
/*****************************************************************************
|
2024-01-01 12:52:28 +01:00
|
|
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
2021-09-29 17:46:03 +02:00
|
|
|
*
|
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
*
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
#include "MapChangeSizeAction.h"
|
2021-09-29 17:46:03 +02:00
|
|
|
|
|
|
|
#include "../Context.h"
|
2024-02-12 22:32:08 +01:00
|
|
|
#include "../GameState.h"
|
2021-09-29 17:46:03 +02:00
|
|
|
#include "../drawing/IDrawingEngine.h"
|
|
|
|
#include "../ui/UiContext.h"
|
|
|
|
#include "../ui/WindowManager.h"
|
|
|
|
#include "../windows/Intent.h"
|
2022-05-07 15:41:15 +02:00
|
|
|
#include "../world/Park.h"
|
2021-09-29 17:46:03 +02:00
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize)
|
2021-09-29 17:46:03 +02:00
|
|
|
: _targetSize(targetSize)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
uint16_t MapChangeSizeAction::GetActionFlags() const
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
|
|
|
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
|
|
|
|
}
|
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
void MapChangeSizeAction::Serialise(DataSerialiser& stream)
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
|
|
|
GameAction::Serialise(stream);
|
|
|
|
stream << DS_TAG(_targetSize);
|
|
|
|
}
|
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
GameActions::Result MapChangeSizeAction::Query() const
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
2024-03-17 14:41:36 +01:00
|
|
|
if (_targetSize.x > kMaximumMapSizeTechnical || _targetSize.y > kMaximumMapSizeTechnical)
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
2024-03-17 08:48:36 +01:00
|
|
|
return GameActions::Result(
|
|
|
|
GameActions::Status::InvalidParameters, STR_CANT_INCREASE_MAP_SIZE_ANY_FURTHER, STR_ERR_VALUE_OUT_OF_RANGE);
|
2021-09-29 17:46:03 +02:00
|
|
|
}
|
2024-03-17 14:38:21 +01:00
|
|
|
if (_targetSize.x < kMinimumMapSizeTechnical || _targetSize.y < kMinimumMapSizeTechnical)
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
2024-03-17 08:48:36 +01:00
|
|
|
return GameActions::Result(
|
|
|
|
GameActions::Status::InvalidParameters, STR_CANT_DECREASE_MAP_SIZE_ANY_FURTHER, STR_ERR_VALUE_OUT_OF_RANGE);
|
2021-09-29 17:46:03 +02:00
|
|
|
}
|
2021-11-24 08:35:08 +01:00
|
|
|
return GameActions::Result();
|
2021-09-29 17:46:03 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
GameActions::Result MapChangeSizeAction::Execute() const
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
2024-02-12 22:32:08 +01:00
|
|
|
auto& gameState = OpenRCT2::GetGameState();
|
2021-12-17 19:25:46 +01:00
|
|
|
// Expand map
|
2024-02-12 22:32:08 +01:00
|
|
|
while (_targetSize.x > gameState.MapSize.x)
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
2024-02-12 22:32:08 +01:00
|
|
|
gameState.MapSize.x++;
|
2022-10-12 14:14:45 +02:00
|
|
|
MapExtendBoundarySurfaceX();
|
2021-12-17 19:25:46 +01:00
|
|
|
}
|
2024-02-12 22:32:08 +01:00
|
|
|
while (_targetSize.y > gameState.MapSize.y)
|
2021-12-17 19:25:46 +01:00
|
|
|
{
|
2024-02-12 22:32:08 +01:00
|
|
|
gameState.MapSize.y++;
|
2022-10-12 14:14:45 +02:00
|
|
|
MapExtendBoundarySurfaceY();
|
2021-12-17 19:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shrink map
|
2024-02-12 22:32:08 +01:00
|
|
|
if (_targetSize.x < gameState.MapSize.x || _targetSize.y < gameState.MapSize.y)
|
2021-12-17 19:25:46 +01:00
|
|
|
{
|
2024-02-12 22:32:08 +01:00
|
|
|
gameState.MapSize = _targetSize;
|
2022-10-12 14:14:45 +02:00
|
|
|
MapRemoveOutOfRangeElements();
|
2021-09-29 17:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* ctx = OpenRCT2::GetContext();
|
|
|
|
auto uiContext = ctx->GetUiContext();
|
|
|
|
auto* windowManager = uiContext->GetWindowManager();
|
2024-03-26 21:35:55 +01:00
|
|
|
OpenRCT2::Park::UpdateSize(gameState);
|
2021-09-29 17:46:03 +02:00
|
|
|
|
|
|
|
windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP));
|
2023-01-16 14:50:43 +01:00
|
|
|
GfxInvalidateScreen();
|
2021-11-24 08:35:08 +01:00
|
|
|
return GameActions::Result();
|
2021-09-29 17:46:03 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 13:52:38 +01:00
|
|
|
void MapChangeSizeAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
2021-09-29 17:46:03 +02:00
|
|
|
{
|
2021-12-17 19:25:46 +01:00
|
|
|
visitor.Visit("targetSizeX", _targetSize.x);
|
|
|
|
visitor.Visit("targetSizeY", _targetSize.y);
|
2021-09-29 17:46:03 +02:00
|
|
|
}
|