Move gMapSize to GameState_t

This commit is contained in:
Harry-Hopkinson 2024-02-12 21:32:08 +00:00
parent 72ca04633e
commit b755c873e5
25 changed files with 128 additions and 90 deletions

View File

@ -15,6 +15,7 @@
#include <openrct2/Cheats.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/LandSetRightsAction.h>
@ -162,7 +163,8 @@ public:
CentreMapOnViewPoint();
FootpathSelectDefault();
_mapWidthAndHeightLinked = gMapSize.x == gMapSize.y;
auto& gameState = OpenRCT2::GetGameState();
_mapWidthAndHeightLinked = gameState.MapSize.x == gameState.MapSize.y;
// Reset land rights tool size
_landRightsToolSize = 1;
@ -630,7 +632,7 @@ public:
size += 2;
size = std::clamp(size, MINIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL);
TileCoordsXY newMapSize = gMapSize;
TileCoordsXY newMapSize = OpenRCT2::GetGameState().MapSize;
if (_resizeDirection != ResizeDirection::X)
newMapSize.y = size;
if (_resizeDirection != ResizeDirection::Y)
@ -755,7 +757,8 @@ public:
pressed_widgets |= (1uLL << WIDX_CONSTRUCTION_RIGHTS_OWNED_CHECKBOX);
// Set disabled widgets
SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gMapSize.x != gMapSize.y);
auto& gameState = OpenRCT2::GetGameState();
SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gameState.MapSize.x != gameState.MapSize.y);
// Resize widgets to window size
ResizeFrameWithPage();
@ -971,7 +974,7 @@ private:
void IncreaseMapSize()
{
auto newMapSize = gMapSize;
auto newMapSize = OpenRCT2::GetGameState().MapSize;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::Y)
newMapSize.y++;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X)
@ -983,7 +986,7 @@ private:
void DecreaseMapSize()
{
auto newMapSize = gMapSize;
auto newMapSize = OpenRCT2::GetGameState().MapSize;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::Y)
newMapSize.y--;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X)
@ -1312,9 +1315,10 @@ private:
widgets[WIDX_MAP_GENERATOR].type = WindowWidgetType::Button;
// Push width (Y) and height (X) to the common formatter arguments for the map size spinners to use
auto& gameState = OpenRCT2::GetGameState();
auto ft = Formatter::Common();
ft.Add<uint16_t>(gMapSize.y - 2);
ft.Add<uint16_t>(gMapSize.x - 2);
ft.Add<uint16_t>(gameState.MapSize.y - 2);
ft.Add<uint16_t>(gameState.MapSize.x - 2);
}
void InputLandSize()

View File

@ -2591,9 +2591,10 @@ private:
return;
}
auto preserveMapSize = gMapSize;
auto& gameState = OpenRCT2::GetGameState();
auto preserveMapSize = gameState.MapSize;
gMapSize = { MAXIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL };
gameState.MapSize = { MAXIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL };
// Setup non changing parts of the temporary track tile element
tempTrackTileElement.SetType(TileElementType::Track);
@ -2660,7 +2661,7 @@ private:
trackBlock++;
}
gMapSize = preserveMapSize;
gameState.MapSize = preserveMapSize;
PaintSessionArrange(*session);
PaintDrawStructs(*session);

View File

@ -205,8 +205,9 @@ namespace Editor
*/
static void SetAllLandOwned()
{
MapRange range = { 2 * COORDS_XY_STEP, 2 * COORDS_XY_STEP, (gMapSize.x - 3) * COORDS_XY_STEP,
(gMapSize.y - 3) * COORDS_XY_STEP };
auto& gameState = GetGameState();
MapRange range = { 2 * COORDS_XY_STEP, 2 * COORDS_XY_STEP, (gameState.MapSize.x - 3) * COORDS_XY_STEP,
(gameState.MapSize.y - 3) * COORDS_XY_STEP };
auto landSetRightsAction = LandSetRightsAction(range, LandSetRightSetting::SetForSale);
landSetRightsAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND);
GameActions::Execute(&landSetRightsAction);

View File

@ -469,7 +469,8 @@ static void FixInvalidSurfaces()
// Fix the invisible border tiles.
// At this point, we can be sure that surfaceElement is not NULL.
if (x == 0 || x == gMapSize.x - 1 || y == 0 || y == gMapSize.y - 1)
auto& gameState = GetGameState();
if (x == 0 || x == gameState.MapSize.x - 1 || y == 0 || y == gameState.MapSize.y - 1)
{
surfaceElement->SetBaseZ(MINIMUM_LAND_HEIGHT_BIG);
surfaceElement->SetClearanceZ(MINIMUM_LAND_HEIGHT_BIG);

View File

@ -63,6 +63,7 @@ namespace OpenRCT2
money64 ScenarioCompanyValueRecord;
random_engine_t ScenarioRand;
int32_t MapBaseZ;
TileCoordsXY MapSize;
SCENARIO_CATEGORY ScenarioCategory;
std::string ScenarioName;

View File

@ -419,9 +419,10 @@ ParametersRange CheatSetAction::GetParameterRange(CheatType cheatType) const
void CheatSetAction::SetGrassLength(int32_t length) const
{
for (int32_t y = 0; y < gMapSize.y; y++)
auto& gameState = GetGameState();
for (int32_t y = 0; y < gameState.MapSize.y; y++)
{
for (int32_t x = 0; x < gMapSize.x; x++)
for (int32_t x = 0; x < gameState.MapSize.x; x++)
{
auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y });
if (surfaceElement == nullptr)

View File

@ -10,6 +10,7 @@
#include "ClearAction.h"
#include "../Context.h"
#include "../GameState.h"
#include "../core/MemoryStream.h"
#include "../drawing/Drawing.h"
#include "../localisation/StringIds.h"
@ -216,10 +217,11 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin
void ClearAction::ResetClearLargeSceneryFlag()
{
auto& gameState = OpenRCT2::GetGameState();
// TODO: Improve efficiency of this
for (int32_t y = 0; y < gMapSize.y; y++)
for (int32_t y = 0; y < gameState.MapSize.y; y++)
{
for (int32_t x = 0; x < gMapSize.x; x++)
for (int32_t x = 0; x < gameState.MapSize.x; x++)
{
auto tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y });
do

View File

@ -10,6 +10,7 @@
#include "FootpathPlaceAction.h"
#include "../Cheats.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../core/MemoryStream.h"
#include "../interface/Window.h"

View File

@ -10,6 +10,7 @@
#include "MapChangeSizeAction.h"
#include "../Context.h"
#include "../GameState.h"
#include "../drawing/IDrawingEngine.h"
#include "../ui/UiContext.h"
#include "../ui/WindowManager.h"
@ -47,22 +48,23 @@ GameActions::Result MapChangeSizeAction::Query() const
GameActions::Result MapChangeSizeAction::Execute() const
{
auto& gameState = OpenRCT2::GetGameState();
// Expand map
while (_targetSize.x > gMapSize.x)
while (_targetSize.x > gameState.MapSize.x)
{
gMapSize.x++;
gameState.MapSize.x++;
MapExtendBoundarySurfaceX();
}
while (_targetSize.y > gMapSize.y)
while (_targetSize.y > gameState.MapSize.y)
{
gMapSize.y++;
gameState.MapSize.y++;
MapExtendBoundarySurfaceY();
}
// Shrink map
if (_targetSize.x < gMapSize.x || _targetSize.y < gMapSize.y)
if (_targetSize.x < gameState.MapSize.x || _targetSize.y < gameState.MapSize.y)
{
gMapSize = _targetSize;
gameState.MapSize = _targetSize;
MapRemoveOutOfRangeElements();
}

View File

@ -10,6 +10,7 @@
#include "PeepSpawnPlaceAction.h"
#include "../Cheats.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../core/MemoryStream.h"
#include "../localisation/StringIds.h"

View File

@ -195,10 +195,11 @@ money64 RideDemolishAction::DemolishTracks() const
uint8_t oldpaused = gGamePaused;
gGamePaused = 0;
auto& gameState = GetGameState();
for (TileCoordsXY tilePos = {}; tilePos.x < gMapSize.x; ++tilePos.x)
for (TileCoordsXY tilePos = {}; tilePos.x < gameState.MapSize.x; ++tilePos.x)
{
for (tilePos.y = 0; tilePos.y < gMapSize.y; ++tilePos.y)
for (tilePos.y = 0; tilePos.y < gameState.MapSize.y; ++tilePos.y)
{
const auto tileCoords = tilePos.ToCoordsXY();
// Loop over all elements of the tile until there are no more items to remove

View File

@ -280,22 +280,25 @@ static void ReleaseDPI(DrawPixelInfo& dpi)
static Viewport GetGiantViewport(int32_t rotation, ZoomLevel zoom)
{
auto& gameState = GetGameState();
// Get the tile coordinates of each corner
const TileCoordsXY cornerCoords[2][4] = {
{
// Map corners
{ 1, 1 },
{ gMapSize.x - 2, gMapSize.y - 2 },
{ 1, gMapSize.y - 2 },
{ gMapSize.x - 2, 1 },
{ gameState.MapSize.x - 2, gameState.MapSize.y - 2 },
{ 1, gameState.MapSize.y - 2 },
{ gameState.MapSize.x - 2, 1 },
},
{
// Horizontal view clipping corners
TileCoordsXY{ CoordsXY{ std::max(gClipSelectionA.x, 32), std::max(gClipSelectionA.y, 32) } },
TileCoordsXY{ CoordsXY{ std::min(gClipSelectionB.x, (gMapSize.x - 2) * 32),
std::min(gClipSelectionB.y, (gMapSize.y - 2) * 32) } },
TileCoordsXY{ CoordsXY{ std::max(gClipSelectionA.x, 32), std::min(gClipSelectionB.y, (gMapSize.y - 2) * 32) } },
TileCoordsXY{ CoordsXY{ std::min(gClipSelectionB.x, (gMapSize.x - 2) * 32), std::max(gClipSelectionA.y, 32) } },
TileCoordsXY{ CoordsXY{ std::min(gClipSelectionB.x, (gameState.MapSize.x - 2) * 32),
std::min(gClipSelectionB.y, (gameState.MapSize.y - 2) * 32) } },
TileCoordsXY{
CoordsXY{ std::max(gClipSelectionA.x, 32), std::min(gClipSelectionB.y, (gameState.MapSize.y - 2) * 32) } },
TileCoordsXY{
CoordsXY{ std::min(gClipSelectionB.x, (gameState.MapSize.x - 2) * 32), std::max(gClipSelectionA.y, 32) } },
},
};
@ -522,7 +525,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti
customRotation = std::atoi(argv[7]) & 3;
}
const auto& mapSize = gMapSize;
const auto& mapSize = GetGameState().MapSize;
if (resolutionWidth == 0 || resolutionHeight == 0)
{
resolutionWidth = (mapSize.x * COORDS_XY_STEP * 2) >> customZoom;

View File

@ -303,7 +303,7 @@ private:
const auto& gameState = GetGameState();
const auto& date = GetDate();
json_t mapSize = { { "x", gMapSize.x - 2 }, { "y", gMapSize.y - 2 } };
json_t mapSize = { { "x", gameState.MapSize.x - 2 }, { "y", gameState.MapSize.y - 2 } };
json_t gameInfo = {
{ "mapSize", mapSize },
{ "day", date.GetMonthTicks() },

View File

@ -1062,14 +1062,14 @@ namespace OpenRCT2
auto found = os.ReadWriteChunk(
ParkFileChunkType::TILES,
[pathToSurfaceMap, pathToQueueSurfaceMap, pathToRailingsMap, &os](OrcaStream::ChunkStream& cs) {
cs.ReadWrite(gMapSize.x);
cs.ReadWrite(gMapSize.y);
[pathToSurfaceMap, pathToQueueSurfaceMap, pathToRailingsMap, &os, &gameState](OrcaStream::ChunkStream& cs) {
cs.ReadWrite(gameState.MapSize.x);
cs.ReadWrite(gameState.MapSize.y);
if (cs.GetMode() == OrcaStream::Mode::READING)
{
// TODO: Use the passed gameState instead of the global one.
OpenRCT2::GetContext()->GetGameState()->InitAll(gMapSize);
OpenRCT2::GetContext()->GetGameState()->InitAll(gameState.MapSize);
auto numElements = cs.Read<uint32_t>();
@ -1151,9 +1151,10 @@ namespace OpenRCT2
void UpdateTrackElementsRideType()
{
for (int32_t y = 0; y < gMapSize.y; y++)
auto& gameState = GetGameState();
for (int32_t y = 0; y < gameState.MapSize.y; y++)
{
for (int32_t x = 0; x < gMapSize.x; x++)
for (int32_t x = 0; x < gameState.MapSize.x; x++)
{
TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y });
if (tileElement == nullptr)

View File

@ -402,7 +402,7 @@ namespace RCT2
gameState.Cash = ToMoney64(DECRYPT_MONEY(_s6.Cash));
// Pad013587FC
gParkRatingCasualtyPenalty = _s6.ParkRatingCasualtyPenalty;
gMapSize = { _s6.MapSize, _s6.MapSize };
gameState.MapSize = { _s6.MapSize, _s6.MapSize };
gSamePriceThroughoutPark = _s6.SamePriceThroughout | (static_cast<uint64_t>(_s6.SamePriceThroughoutExtended) << 32);
gameState.SuggestedGuestMaximum = _s6.SuggestedMaxGuests;
gameState.ScenarioParkRatingWarningDays = _s6.ParkRatingWarningDays;

View File

@ -5599,9 +5599,10 @@ void DetermineRideEntranceAndExitLocations()
// Search the map to find it. Skip the outer ring of invisible tiles.
bool alreadyFoundEntrance = false;
bool alreadyFoundExit = false;
for (int32_t y = 1; y < gMapSize.y - 1; y++)
auto& gameState = GetGameState();
for (int32_t y = 1; y < gameState.MapSize.y - 1; y++)
{
for (int32_t x = 1; x < gMapSize.x - 1; x++)
for (int32_t x = 1; x < gameState.MapSize.x - 1; x++)
{
TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y });
@ -5685,9 +5686,10 @@ void DetermineRideEntranceAndExitLocations()
void RideClearLeftoverEntrances(const Ride& ride)
{
for (TileCoordsXY tilePos = {}; tilePos.x < gMapSize.x; ++tilePos.x)
auto& gameState = GetGameState();
for (TileCoordsXY tilePos = {}; tilePos.x < gameState.MapSize.x; ++tilePos.x)
{
for (tilePos.y = 0; tilePos.y < gMapSize.y; ++tilePos.y)
for (tilePos.y = 0; tilePos.y < gameState.MapSize.y; ++tilePos.y)
{
for (auto* entrance : TileElementsView<EntranceElement>(tilePos.ToCoordsXY()))
{
@ -5764,9 +5766,10 @@ void Ride::IncreaseNumShelteredSections()
void Ride::UpdateRideTypeForAllPieces()
{
for (int32_t y = 0; y < gMapSize.y; y++)
auto& gameState = GetGameState();
for (int32_t y = 0; y < gameState.MapSize.y; y++)
{
for (int32_t x = 0; x < gMapSize.x; x++)
for (int32_t x = 0; x < gameState.MapSize.x; x++)
{
auto* tileElement = MapGetFirstElementAt(TileCoordsXY(x, y));
if (tileElement == nullptr)

View File

@ -10,6 +10,7 @@
#include "RideConstruction.h"
#include "../Context.h"
#include "../GameState.h"
#include "../Input.h"
#include "../actions/MazeSetTrackAction.h"
#include "../actions/RideEntranceExitRemoveAction.h"
@ -340,9 +341,10 @@ void Ride::RemovePeeps()
void RideClearBlockedTiles(const Ride& ride)
{
for (TileCoordsXY tilePos = {}; tilePos.x < gMapSize.x; ++tilePos.x)
auto& gameState = GetGameState();
for (TileCoordsXY tilePos = {}; tilePos.x < gameState.MapSize.x; ++tilePos.x)
{
for (tilePos.y = 0; tilePos.y < gMapSize.y; ++tilePos.y)
for (tilePos.y = 0; tilePos.y < gameState.MapSize.y; ++tilePos.y)
{
for (auto* trackElement : TileElementsView<TrackElement>(tilePos.ToCoordsXY()))
{

View File

@ -11,6 +11,7 @@
#include "../Cheats.h"
#include "../Context.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../interface/Window.h"
#include "../localisation/Date.h"
@ -1793,9 +1794,10 @@ static int32_t ride_ratings_get_scenery_score(const Ride& ride)
// Count surrounding scenery items
int32_t numSceneryItems = 0;
auto tileLocation = TileCoordsXY(location);
for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, gMapSize.y - 1); yy++)
auto& gameState = GetGameState();
for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, gameState.MapSize.y - 1); yy++)
{
for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, gMapSize.x - 1); xx++)
for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, gameState.MapSize.x - 1); xx++)
{
// Count scenery items on this tile
TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ xx, yy });

View File

@ -1944,7 +1944,7 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon
uint8_t backup_rotation = _currentTrackPieceDirection;
uint32_t backup_park_flags = gameState.ParkFlags;
gameState.ParkFlags &= ~PARK_FLAGS_FORBID_HIGH_CONSTRUCTION;
auto mapSize = TileCoordsXY{ gMapSize.x * 16, gMapSize.y * 16 };
auto mapSize = TileCoordsXY{ gameState.MapSize.x * 16, gameState.MapSize.y * 16 };
_currentTrackPieceDirection = 0;
int32_t z = TrackDesignGetZPlacement(
@ -2101,7 +2101,7 @@ static void TrackDesignPreviewClearMap()
{
auto numTiles = MAXIMUM_MAP_SIZE_TECHNICAL * MAXIMUM_MAP_SIZE_TECHNICAL;
gMapSize = TRACK_DESIGN_PREVIEW_MAP_SIZE;
GetGameState().MapSize = TRACK_DESIGN_PREVIEW_MAP_SIZE;
// Reserve ~8 elements per tile
std::vector<TileElement> tileElements;

View File

@ -434,8 +434,9 @@ bool ScenarioCreateDucks()
constexpr int32_t SquareRadiusSize = SquareCentre * 32;
CoordsXY centrePos;
centrePos.x = SquareRadiusSize + (ScenarioRandMax(gMapSize.x - SquareCentre) * 32);
centrePos.y = SquareRadiusSize + (ScenarioRandMax(gMapSize.y - SquareCentre) * 32);
auto& gameState = GetGameState();
centrePos.x = SquareRadiusSize + (ScenarioRandMax(gameState.MapSize.x - SquareCentre) * 32);
centrePos.y = SquareRadiusSize + (ScenarioRandMax(gameState.MapSize.y - SquareCentre) * 32);
Guard::Assert(MapIsLocationValid(centrePos));

View File

@ -11,6 +11,7 @@
# include "ScMap.hpp"
# include "../../../GameState.h"
# include "../../../common.h"
# include "../../../entity/Balloon.h"
# include "../../../entity/Duck.h"
@ -43,7 +44,7 @@ namespace OpenRCT2::Scripting
DukValue ScMap::size_get() const
{
return ToDuk(_context, gMapSize);
return ToDuk(_context, GetGameState().MapSize);
}
int32_t ScMap::numRides_get() const

View File

@ -251,10 +251,11 @@ struct BannerElementWithPos
// Returns a list of BannerElement's with the tile position.
static std::vector<BannerElementWithPos> GetAllBannerElementsOnMap()
{
auto& gameState = GetGameState();
std::vector<BannerElementWithPos> banners;
for (int y = 0; y < gMapSize.y; y++)
for (int y = 0; y < gameState.MapSize.y; y++)
{
for (int x = 0; x < gMapSize.x; x++)
for (int x = 0; x < gameState.MapSize.x; x++)
{
const auto tilePos = TileCoordsXY{ x, y };
for (auto* bannerElement : OpenRCT2::TileElementsView<BannerElement>(tilePos.ToCoordsXY()))

View File

@ -91,8 +91,6 @@ uint8_t gMapSelectArrowDirection;
TileCoordsXY gWidePathTileLoopPosition;
uint16_t gGrassSceneryTileLoopPosition;
TileCoordsXY gMapSize;
std::vector<CoordsXY> gMapSelectionTiles;
std::vector<PeepSpawn> gPeepSpawns;
@ -120,7 +118,7 @@ void StashMap()
{
_tileIndexStash = std::move(_tileIndex);
_tileElementsStash = std::move(_tileElements);
_mapSizeStash = gMapSize;
_mapSizeStash = GetGameState().MapSize;
_currentRotationStash = gCurrentRotation;
_tileElementsInUseStash = _tileElementsInUse;
}
@ -129,11 +127,27 @@ void UnstashMap()
{
_tileIndex = std::move(_tileIndexStash);
_tileElements = std::move(_tileElementsStash);
gMapSize = _mapSizeStash;
GetGameState().MapSize = _mapSizeStash;
gCurrentRotation = _currentRotationStash;
_tileElementsInUse = _tileElementsInUseStash;
}
CoordsXY GetMapSizeUnits()
{
auto& gameState = OpenRCT2::GetGameState();
return { (gameState.MapSize.x - 1) * COORDS_XY_STEP, (gameState.MapSize.y - 1) * COORDS_XY_STEP };
}
CoordsXY GetMapSizeMinus2()
{
auto& gameState = OpenRCT2::GetGameState();
return { (gameState.MapSize.x * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2),
(gameState.MapSize.y * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2) };
}
CoordsXY GetMapSizeMaxXY()
{
return GetMapSizeUnits() - CoordsXY{ 1, 1 };
}
const std::vector<TileElement>& GetTileElements()
{
return _tileElements;
@ -449,7 +463,7 @@ void MapInit(const TileCoordsXY& size)
gGrassSceneryTileLoopPosition = 0;
gWidePathTileLoopPosition = {};
gMapSize = size;
gameState.MapSize = size;
gameState.MapBaseZ = 7;
MapRemoveOutOfRangeElements();
MapAnimationAutoCreate();
@ -467,10 +481,11 @@ void MapCountRemainingLandRights()
{
gLandRemainingOwnershipSales = 0;
gLandRemainingConstructionSales = 0;
auto& gameState = GetGameState();
for (int32_t y = 0; y < gMapSize.y; y++)
for (int32_t y = 0; y < gameState.MapSize.y; y++)
{
for (int32_t x = 0; x < gMapSize.x; x++)
for (int32_t x = 0; x < gameState.MapSize.x; x++)
{
auto* surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y });
// Surface elements are sometimes hacked out to save some space for other map elements
@ -1240,6 +1255,8 @@ void MapUpdateTiles()
if (gScreenFlags & ignoreScreenFlags)
return;
auto& gameState = GetGameState();
// Update 43 more tiles (for each 256x256 block)
for (int32_t j = 0; j < 43; j++)
{
@ -1256,9 +1273,9 @@ void MapUpdateTiles()
}
// Repeat for each 256x256 block on the map
for (int32_t blockY = 0; blockY < gMapSize.y; blockY += 256)
for (int32_t blockY = 0; blockY < gameState.MapSize.y; blockY += 256)
{
for (int32_t blockX = 0; blockX < gMapSize.x; blockX += 256)
for (int32_t blockX = 0; blockX < gameState.MapSize.x; blockX += 256)
{
auto mapPos = TileCoordsXY{ blockX + x, blockY + y }.ToCoordsXY();
if (MapIsEdge(mapPos))
@ -1405,7 +1422,7 @@ static void MapExtendBoundarySurfaceExtendTile(const SurfaceElement& sourceTile,
*/
void MapExtendBoundarySurfaceY()
{
auto y = gMapSize.y - 2;
auto y = GetGameState().MapSize.y - 2;
for (auto x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{
auto existingTileElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y - 1 });
@ -1425,7 +1442,7 @@ void MapExtendBoundarySurfaceY()
*/
void MapExtendBoundarySurfaceX()
{
auto x = gMapSize.x - 2;
auto x = GetGameState().MapSize.x - 2;
for (auto y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
{
auto existingTileElement = MapGetSurfaceElementAt(TileCoordsXY{ x - 1, y });

View File

@ -106,21 +106,9 @@ extern const TileCoordsXY TileDirectionDelta[];
extern TileCoordsXY gWidePathTileLoopPosition;
extern uint16_t gGrassSceneryTileLoopPosition;
extern TileCoordsXY gMapSize;
inline CoordsXY GetMapSizeUnits()
{
return { (gMapSize.x - 1) * COORDS_XY_STEP, (gMapSize.y - 1) * COORDS_XY_STEP };
}
inline CoordsXY GetMapSizeMinus2()
{
return { (gMapSize.x * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2),
(gMapSize.y * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2) };
}
inline CoordsXY GetMapSizeMaxXY()
{
return GetMapSizeUnits() - CoordsXY{ 1, 1 };
}
CoordsXY GetMapSizeUnits();
CoordsXY GetMapSizeMinus2();
CoordsXY GetMapSizeMaxXY();
extern uint16_t gMapSelectFlags;
extern uint16_t gMapSelectType;

View File

@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../common.h"
#include "../core/Guard.hpp"
#include "../core/Imaging.h"
@ -335,9 +336,10 @@ static void MapGenPlaceTrees()
// Place trees
CoordsXY pos;
float treeToLandRatio = (10 + (UtilRand() % 30)) / 100.0f;
for (int32_t y = 1; y < gMapSize.y - 1; y++)
auto& gameState = OpenRCT2::GetGameState();
for (int32_t y = 1; y < gameState.MapSize.y - 1; y++)
{
for (int32_t x = 1; x < gMapSize.x - 1; x++)
for (int32_t x = 1; x < gameState.MapSize.x - 1; x++)
{
pos.x = x * COORDS_XY_STEP;
pos.y = y * COORDS_XY_STEP;
@ -366,8 +368,8 @@ static void MapGenPlaceTrees()
// Get map coord, clamped to the edges
const auto offset = CoordsXY{ offsetX * COORDS_XY_STEP, offsetY * COORDS_XY_STEP };
auto neighbourPos = pos + offset;
neighbourPos.x = std::clamp(neighbourPos.x, COORDS_XY_STEP, COORDS_XY_STEP * (gMapSize.x - 1));
neighbourPos.y = std::clamp(neighbourPos.y, COORDS_XY_STEP, COORDS_XY_STEP * (gMapSize.y - 1));
neighbourPos.x = std::clamp(neighbourPos.x, COORDS_XY_STEP, COORDS_XY_STEP * (gameState.MapSize.x - 1));
neighbourPos.y = std::clamp(neighbourPos.y, COORDS_XY_STEP, COORDS_XY_STEP * (gameState.MapSize.y - 1));
const auto neighboutSurface = MapGetSurfaceElementAt(neighbourPos);
if (neighboutSurface != nullptr && neighboutSurface->GetWaterHeight() > 0)
@ -415,9 +417,10 @@ static void MapGenPlaceTrees()
*/
static void MapGenSetWaterLevel(int32_t waterLevel)
{
for (int32_t y = 1; y < gMapSize.y - 1; y++)
auto& gameState = OpenRCT2::GetGameState();
for (int32_t y = 1; y < gameState.MapSize.y - 1; y++)
{
for (int32_t x = 1; x < gMapSize.x - 1; x++)
for (int32_t x = 1; x < gameState.MapSize.x - 1; x++)
{
auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y });
if (surfaceElement != nullptr && surfaceElement->BaseHeight < waterLevel)