diff --git a/Content.IntegrationTests/DMProject/Tests/range.dm b/Content.IntegrationTests/DMProject/Tests/range.dm index f61303e78e..31b66ad051 100644 --- a/Content.IntegrationTests/DMProject/Tests/range.dm +++ b/Content.IntegrationTests/DMProject/Tests/range.dm @@ -1,5 +1,6 @@ //Tests that /proc/range() is iterating along the correct, wonky path /proc/test_range() + world.maxx = world.maxy = 5 //Test that it goes in the right order var/list/correctCoordinates = list( list(3,3), diff --git a/OpenDreamRuntime/DreamMapManager.cs b/OpenDreamRuntime/DreamMapManager.cs index 701f443496..f9e2f166a6 100644 --- a/OpenDreamRuntime/DreamMapManager.cs +++ b/OpenDreamRuntime/DreamMapManager.cs @@ -221,27 +221,54 @@ private DreamObjectArea GetOrCreateArea(MapObjectJson prototype) { } public void SetWorldSize(Vector2i size) { - if (size.X < Size.X || size.Y < Size.Y) { - return; - } + Vector2i oldSize = Size; + + var newX = Math.Max(oldSize.X, size.X); + var newY = Math.Max(oldSize.Y, size.Y); DreamObjectArea defaultArea = GetOrCreateArea(_defaultArea); - Vector2i oldSize = Size; - Size = size; - foreach (Level existingLevel in _levels) { - var oldCells = existingLevel.Cells; + Size = (newX, newY); + + if(Size.X > oldSize.X || Size.Y > oldSize.Y) { + foreach (Level existingLevel in _levels) { + var oldCells = existingLevel.Cells; + + existingLevel.Cells = new Cell[Size.X, Size.Y]; + for (var x = 1; x <= Size.X; x++) { + for (var y = 1; y <= Size.Y; y++) { + if (x <= oldSize.X && y <= oldSize.Y) { + existingLevel.Cells[x - 1, y - 1] = oldCells[x - 1, y - 1]; + continue; + } - existingLevel.Cells = new Cell[size.X, size.Y]; - for (int x = 1; x <= size.X; x++) { - for (int y = 1; y <= size.Y; y++) { - if (x <= oldSize.X && y <= oldSize.Y) { - existingLevel.Cells[x - 1, y - 1] = oldCells[x - 1, y - 1]; - continue; + existingLevel.Cells[x - 1, y - 1] = new Cell(defaultArea); + SetTurf(new Vector2i(x, y), existingLevel.Z, _defaultTurf.ObjectDefinition, new()); } + } + } + } - existingLevel.Cells[x - 1, y - 1] = new Cell(defaultArea); - SetTurf(new Vector2i(x, y), existingLevel.Z, _defaultTurf.ObjectDefinition, new()); + if (Size.X > size.X || Size.Y > size.Y) { + Size = size; + + foreach (Level existingLevel in _levels) { + var oldCells = existingLevel.Cells; + + existingLevel.Cells = new Cell[size.X, size.Y]; + for (var x = 1; x <= oldSize.X; x++) { + for (var y = 1; y <= oldSize.Y; y++) { + if (x > size.X || y > size.Y) { + var deleteCell = oldCells[x - 1, y - 1]; + deleteCell.Turf?.Delete(); + _mapSystem.SetTile(existingLevel.Grid, new Vector2i(x, y), Tile.Empty); + foreach (var movableToDelete in deleteCell.Movables) { + movableToDelete.Delete(); + } + } else { + existingLevel.Cells[x - 1, y - 1] = oldCells[x - 1, y - 1]; + } + } } } } diff --git a/TestGame/code.dm b/TestGame/code.dm index 4f4e22560b..e9811a0147 100644 --- a/TestGame/code.dm +++ b/TestGame/code.dm @@ -207,6 +207,16 @@ world.ODHotReloadInterface() src << "done hot reload of interface!" + verb/manipulate_world_size() + var/x = input("New World X?", "World Size", 0) as num|null + var/y = input("New World Y?", "World Size", 0) as num|null + + if(!x || !y) + return + + world.maxx = x + world.maxy = y + /mob/Stat() if (statpanel("Status")) stat("tick_usage", world.tick_usage)