From 7c5721180718a20c03055970ef0bbe4c90fc943a Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 19 Sep 2025 23:09:37 -0400 Subject: [PATCH] Potential sector data carry-over fix --- core/src/mindustry/core/Control.java | 13 ++---------- core/src/mindustry/editor/MapEditor.java | 20 ------------------- .../src/mindustry/editor/MapEditorDialog.java | 1 - core/src/mindustry/game/SectorInfo.java | 15 ++++++++++++++ core/src/mindustry/input/MobileInput.java | 2 +- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index 87a0abd999..fa52cf2a96 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -434,19 +434,10 @@ public class Control implements ApplicationListener, Loadable{ //if there is no base, simulate a new game and place the right loadout at the spawn position if(state.rules.defaultTeam.cores().isEmpty() || hadNoCore){ - if(sector.planet.clearSectorOnLose){ + //don't carry over the spawn position and plans if the sector preset name or map size changed + if(sector.planet.clearSectorOnLose || sector.info.spawnPosition == 0 || !sector.info.sectorDataMatches(sector)){ playNewSector(origin, sector, reloader); }else{ - //no spawn set -> delete the sector save - if(sector.info.spawnPosition == 0){ - //delete old save - sector.save = null; - slot.delete(); - //play again - playSector(origin, sector, reloader); - return; - } - int spawnPos = sector.info.spawnPosition; //set spawn for sector damage to use diff --git a/core/src/mindustry/editor/MapEditor.java b/core/src/mindustry/editor/MapEditor.java index ff55266e17..c2529b8c38 100644 --- a/core/src/mindustry/editor/MapEditor.java +++ b/core/src/mindustry/editor/MapEditor.java @@ -269,26 +269,6 @@ public class MapEditor{ editor.flushOp(); } - public void addFloorCliffs(){ - for(Tile tile : world.tiles){ - if(!tile.floor().hasSurface() || tile.block() == Blocks.cliff) continue; - - int rotation = 0; - for(int i = 0; i < 8; i++){ - Tile other = world.tiles.get(tile.x + Geometry.d8[i].x, tile.y + Geometry.d8[i].y); - if(other != null && !other.floor().hasSurface()){ - rotation |= (1 << i); - } - } - - if(rotation != 0){ - tile.setBlock(Blocks.cliff); - } - - tile.data = (byte)rotation; - } - } - public void drawCircle(int x, int y, Cons drawer){ int clamped = (int)brushSize; for(int rx = -clamped; rx <= clamped; rx++){ diff --git a/core/src/mindustry/editor/MapEditorDialog.java b/core/src/mindustry/editor/MapEditorDialog.java index 2972d3de60..924e7b52da 100644 --- a/core/src/mindustry/editor/MapEditorDialog.java +++ b/core/src/mindustry/editor/MapEditorDialog.java @@ -707,7 +707,6 @@ public class MapEditorDialog extends Dialog implements Disposable{ } }).margin(0).left().growY(); - cont.table(t -> t.add(view).grow()).grow(); cont.table(this::addBlockSelection).right().growY(); diff --git a/core/src/mindustry/game/SectorInfo.java b/core/src/mindustry/game/SectorInfo.java index 7a393a8784..9d8e1c97ff 100644 --- a/core/src/mindustry/game/SectorInfo.java +++ b/core/src/mindustry/game/SectorInfo.java @@ -41,6 +41,10 @@ public class SectorInfo{ public int storageCapacity = 0; /** Whether a core is available here. */ public boolean hasCore = true; + /** Last sector preset name set to this sector. */ + public @Nullable String lastPresetName; + /** Last size of the map. */ + public int lastWidth, lastHeight; /** Whether this sector was ever fully captured. */ public boolean wasCaptured = false; /** Sector that was launched from. */ @@ -102,6 +106,14 @@ public class SectorInfo{ /** Core item storage input/output deltas. */ private @Nullable transient int[] productionDeltas; + /** @return whether the sector was last saved with the same preset. if false, this means the preset changed, and thus the spawn/plan data should be discarded. */ + public boolean sectorDataMatches(Sector sector){ + if(sector.preset != null && (sector.preset.generator.map.width != lastWidth || sector.preset.generator.map.width != lastHeight)){ + return false; + } + return Structs.eq(sector.preset == null ? null : sector.preset.name, lastPresetName); + } + /** Handles core item changes. */ public void handleCoreItem(Item item, int amount){ if(coreDeltas == null) coreDeltas = new int[content.items().size]; @@ -223,6 +235,9 @@ public class SectorInfo{ wavesPassed = 0; damage = 0; hasSpawns = spawner.countSpawns() > 0; + lastPresetName = sector.preset == null ? null : sector.preset.name; + lastWidth = world.width(); + lastHeight = world.height(); lightCoverage = 0f; for(var build : state.rules.defaultTeam.data().buildings){ diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index e445536988..a5b262c2d9 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -996,8 +996,8 @@ public class MobileInput extends InputHandler implements GestureListener{ } targetPos.set(Core.camera.position); - float attractDst = 15f; + float attractDst = 15f; float speed = unit.speed(); float range = unit.hasWeapons() ? unit.range() : 0f; float bulletSpeed = unit.hasWeapons() ? type.weapons.first().bullet.speed : 0f;