From 215633587dbd157eb41ff076d91ab11f53398286 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 16 Oct 2022 08:44:08 -0400 Subject: [PATCH] Fixed #7728 --- core/src/mindustry/core/Logic.java | 38 ++-------------------- core/src/mindustry/game/MapObjectives.java | 5 +++ core/src/mindustry/mod/ContentParser.java | 18 +++++++--- core/src/mindustry/type/SectorPreset.java | 9 +++++ 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 6c15962790..20947046ac 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -348,6 +348,7 @@ public class Logic implements ApplicationListener{ //map is over, no more world processor objective stuff state.rules.disableWorldProcessors = true; + state.rules.objectives.clear(); //save, just in case if(!headless && !net.client()){ @@ -367,9 +368,7 @@ public class Logic implements ApplicationListener{ public static void gameOver(Team winner){ state.stats.wavesLasted = state.wave; state.won = player.team() == winner; - Time.run(60f * 3f, () -> { - ui.restart.show(winner); - }); + Time.run(60f * 3f, () -> ui.restart.show(winner)); netClient.setQuiet(); } @@ -389,39 +388,6 @@ public class Logic implements ApplicationListener{ state.rules.researched.add(u.name); } - //called when the remote server runs a turn and produces something - @Remote - public static void sectorProduced(int[] amounts){ - //TODO currently disabled. - if(!state.isCampaign() || true) return; - - Planet planet = state.rules.sector.planet; - boolean any = false; - - for(Item item : content.items()){ - int am = amounts[item.id]; - if(am > 0){ - int sumMissing = planet.sectors.sum(s -> s.hasBase() ? s.info.storageCapacity - s.info.items.get(item) : 0); - if(sumMissing == 0) continue; - //how much % to add - double percent = Math.min((double)am / sumMissing, 1); - for(Sector sec : planet.sectors){ - if(sec.hasBase()){ - int added = (int)Math.ceil(((sec.info.storageCapacity - sec.info.items.get(item)) * percent)); - sec.info.items.add(item, added); - any = true; - } - } - } - } - - if(any){ - for(Sector sec : planet.sectors){ - sec.saveInfo(); - } - } - } - @Override public void dispose(){ //save the settings before quitting diff --git a/core/src/mindustry/game/MapObjectives.java b/core/src/mindustry/game/MapObjectives.java index fcc7e521f4..ff0222f938 100644 --- a/core/src/mindustry/game/MapObjectives.java +++ b/core/src/mindustry/game/MapObjectives.java @@ -139,6 +139,11 @@ public class MapObjectives implements Iterable, Eachable 0; } + public void clear(){ + if(all.size > 0) changed = true; + all.clear(); + } + /** Iterates over all qualified in-map objectives. */ public void eachRunning(Cons cons){ all.each(MapObjective::qualified, cons); diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index 3b23b140eb..37da8496f2 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -556,11 +556,21 @@ public class ContentParser{ if(!value.has("sector") || !value.get("sector").isNumber()) throw new RuntimeException("SectorPresets must have a sector number."); - SectorPreset out = new SectorPreset(name, locate(ContentType.planet, value.getString("planet", "serpulo")), value.getInt("sector")); - value.remove("sector"); - value.remove("planet"); + SectorPreset out = new SectorPreset(name); + currentContent = out; - read(() -> readFields(out, value)); + read(() -> { + Planet planet = locate(ContentType.planet, value.getString("planet", "serpulo")); + + if(planet == null) throw new RuntimeException("Planet '" + value.getString("planet") + "' not found."); + + out.initialize(planet, value.getInt("sector", 0)); + + value.remove("sector"); + value.remove("planet"); + + readFields(out, value); + }); return out; }, ContentType.planet, (TypeParser)(mod, name, value) -> { diff --git a/core/src/mindustry/type/SectorPreset.java b/core/src/mindustry/type/SectorPreset.java index 8c15999703..1015335cc4 100644 --- a/core/src/mindustry/type/SectorPreset.java +++ b/core/src/mindustry/type/SectorPreset.java @@ -29,8 +29,17 @@ public class SectorPreset extends UnlockableContent{ public boolean attackAfterWaves = false; public SectorPreset(String name, Planet planet, int sector){ + this(name); + initialize(planet, sector); + } + + /** Internal use only! */ + public SectorPreset(String name){ super(name); this.generator = new FileMapGenerator(name, this); + } + + public void initialize(Planet planet, int sector){ this.planet = planet; sector %= planet.sectors.size; this.sector = planet.sectors.get(sector);