From 51a9876d959e0ab601584ea916f73faaeafd91f0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 8 May 2022 10:18:09 -0400 Subject: [PATCH] WIP game-over core pan --- core/src/mindustry/core/Control.java | 2 +- core/src/mindustry/core/GameState.java | 8 ++++-- core/src/mindustry/core/Logic.java | 6 +++- .../mindustry/entities/comp/BuilderComp.java | 28 +++++++++++++------ core/src/mindustry/game/Teams.java | 8 +++++- core/src/mindustry/input/DesktopInput.java | 5 +++- core/src/mindustry/type/UnitType.java | 2 +- .../mindustry/ui/dialogs/PausedDialog.java | 2 +- 8 files changed, 44 insertions(+), 17 deletions(-) diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index c3e94de43c..49dad084be 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -504,7 +504,7 @@ public class Control implements ApplicationListener, Loadable{ @Override public void dispose(){ //try to save when exiting - if(saves != null && saves.getCurrent() != null && saves.getCurrent().isAutosave() && !net.client() && !state.isMenu()){ + if(saves != null && saves.getCurrent() != null && saves.getCurrent().isAutosave() && !net.client() && !state.isMenu() && !state.gameOver){ try{ SaveIO.save(control.saves.getCurrent().file); Log.info("Saved on exit."); diff --git a/core/src/mindustry/core/GameState.java b/core/src/mindustry/core/GameState.java index ecd3a0e253..668fbd0b71 100644 --- a/core/src/mindustry/core/GameState.java +++ b/core/src/mindustry/core/GameState.java @@ -21,7 +21,11 @@ public class GameState{ /** Continuously ticks up every non-paused update. */ public long updateId; /** Whether the game is in game over state. */ - public boolean gameOver = false, serverPaused = false; + public boolean gameOver = false; + /** Whether the player's team won the match. */ + public boolean won = false; + /** If true, the server has been put into the paused state on multiplayer. This is synced. */ + public boolean serverPaused = false; /** Server ticks/second. Only valid in multiplayer. */ public int serverTps = -1; /** Map that is currently being played on. */ @@ -77,7 +81,7 @@ public class GameState{ } public boolean isPaused(){ - return (is(State.paused) && !net.active()) || (gameOver && (!net.active() || isCampaign())) || (serverPaused && !isMenu()); + return (is(State.paused) && !net.active()) || (serverPaused && !isMenu()); } public boolean isPlaying(){ diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 5c1e84721c..28d0e16ab6 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -402,12 +402,16 @@ public class Logic implements ApplicationListener{ @Remote(called = Loc.both) public static void updateGameOver(Team winner){ state.gameOver = true; + state.won = player.team() == winner; } @Remote(called = Loc.both) public static void gameOver(Team winner){ state.stats.wavesLasted = state.wave; - ui.restart.show(winner); + state.won = player.team() == winner; + Time.run(60f * 3f, () -> { + ui.restart.show(winner); + }); netClient.setQuiet(); } diff --git a/core/src/mindustry/entities/comp/BuilderComp.java b/core/src/mindustry/entities/comp/BuilderComp.java index 360419ad18..b6536ce704 100644 --- a/core/src/mindustry/entities/comp/BuilderComp.java +++ b/core/src/mindustry/entities/comp/BuilderComp.java @@ -47,6 +47,19 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{ updateBuildLogic(); } + public void validatePlans(){ + if(plans.size > 0){ + Iterator it = plans.iterator(); + while(it.hasNext()){ + BuildPlan plan = it.next(); + Tile tile = world.tile(plan.x, plan.y); + if(tile == null || (plan.breaking && tile.block() == Blocks.air) || (!plan.breaking && ((tile.build != null && tile.build.rotation == plan.rotation) || !plan.block.rotate) && tile.block() == plan.block)){ + it.remove(); + } + } + } + } + public void updateBuildLogic(){ if(type.buildSpeed <= 0f) return; @@ -59,7 +72,11 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{ buildAlpha = Mathf.lerpDelta(buildAlpha, activelyBuilding() ? 1f : 0f, 0.15f); } - if(!updateBuilding || !canBuild()) return; + //validate regardless of whether building is enabled. + if(!updateBuilding || !canBuild()){ + validatePlans(); + return; + } float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange; boolean infinite = state.rules.infiniteResources || team().rules().infiniteResources; @@ -69,14 +86,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{ while(buildCounter >= 1){ buildCounter -= 1f; - Iterator it = plans.iterator(); - while(it.hasNext()){ - BuildPlan plan = it.next(); - Tile tile = world.tile(plan.x, plan.y); - if(tile == null || (plan.breaking && tile.block() == Blocks.air) || (!plan.breaking && ((tile.build != null && tile.build.rotation == plan.rotation) || !plan.block.rotate) && tile.block() == plan.block)){ - it.remove(); - } - } + validatePlans(); var core = core(); diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index 290f40bb26..bd5f794a64 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -160,6 +160,9 @@ public class Teams{ data.unitCount = 0; data.units.clear(); data.players.clear(); + if(data.cores.size > 0){ + data.lastCore = data.cores.first(); + } if(data.unitTree != null){ data.unitTree.clear(); } @@ -236,7 +239,6 @@ public class Teams{ } public static class TeamData{ - public final Seq cores = new Seq<>(); public final Team team; /** Handles RTS unit control. */ @@ -249,6 +251,10 @@ public class Teams{ /** Planned blocks for drones. This is usually only blocks that have been broken. */ public Queue plans = new Queue<>(); + /** List of live cores of this team. */ + public final Seq cores = new Seq<>(); + /** Last known live core of this team. */ + public @Nullable CoreBuild lastCore; /** Quadtree for all buildings of this team. Null if not active. */ public @Nullable QuadTree buildingTree; /** Turrets by range. Null if not active. */ diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 7f53983c52..fe5b5a44d6 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -225,7 +225,10 @@ public class DesktopInput extends InputHandler{ Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(camSpeed)); }else if(!player.dead() && !panning){ - Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f); + //TODO do not pan + Team corePanTeam = state.won ? state.rules.waveTeam : player.team(); + Position coreTarget = state.gameOver && !state.rules.pvp && corePanTeam.data().lastCore != null ? corePanTeam.data().lastCore : null; + Core.camera.position.lerpDelta(coreTarget != null ? coreTarget : player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f); } if(panCam){ diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 4dc8ac6ed3..ee015ad2b6 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -362,7 +362,7 @@ public class UnitType extends UnlockableContent{ //TANK UNITS - /** list of treads as rectangles in IMAGE COORDINATES. these should match the coordinates you see in an image editor*/ + /** list of treads as rectangles in IMAGE COORDINATES. these are mirrored, and should match the coordinates you see in an image editor. */ public Rect[] treadRects = {}; /** number of frames of movement in a tread */ public int treadFrames = 18; diff --git a/core/src/mindustry/ui/dialogs/PausedDialog.java b/core/src/mindustry/ui/dialogs/PausedDialog.java index afbeef28cb..a09262c614 100644 --- a/core/src/mindustry/ui/dialogs/PausedDialog.java +++ b/core/src/mindustry/ui/dialogs/PausedDialog.java @@ -124,7 +124,7 @@ public class PausedDialog extends BaseDialog{ return; } - if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave() || wasClient){ + if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave() || wasClient || state.gameOver){ logic.reset(); return; }