Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handles shrinking maxx/y #1798

Merged
merged 7 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Content.IntegrationTests/DMProject/Tests/range.dm
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
57 changes: 42 additions & 15 deletions OpenDreamRuntime/DreamMapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions TestGame/code.dm
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@
src << "showing main window"
winset(src,"mainwindow","is-visible=true")

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)
Expand Down
Loading