From eba65b293494cc4f8cf5e7a7f3303f573f845a72 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 14 Oct 2018 11:57:37 -0400 Subject: [PATCH] Fixed units pathfinding to nonexistent cores --- .../src/io/anuke/mindustry/ai/Pathfinder.java | 21 +++++++++---------- .../io/anuke/mindustry/core/NetClient.java | 5 +++++ .../io/anuke/mindustry/core/NetServer.java | 1 + .../io/anuke/mindustry/game/EventType.java | 1 + .../ui/dialogs/CustomGameDialog.java | 7 +++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/core/src/io/anuke/mindustry/ai/Pathfinder.java b/core/src/io/anuke/mindustry/ai/Pathfinder.java index 3f52497a92..9f61cd843c 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfinder.java +++ b/core/src/io/anuke/mindustry/ai/Pathfinder.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.ai; import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.Queue; import com.badlogic.gdx.utils.TimeUtils; @@ -31,7 +30,7 @@ public class Pathfinder{ for(Team team : Team.all){ TeamData data = state.teams.get(team); - if(state.teams.isActive(team) && data.team != event.tile.getTeam() && paths[data.team.ordinal()].weights[event.tile.x][event.tile.y] >= Float.MAX_VALUE){ + if(state.teams.isActive(team) && data.team != event.tile.getTeam()){ update(event.tile, data.team); } } @@ -87,28 +86,28 @@ public class Pathfinder{ } private boolean passable(Tile tile, Team team){ - return (!tile.solid()) - || (tile.breakable() && (tile.target().getTeam() != team)); + return (!tile.solid()) || (tile.breakable() && (tile.target().getTeam() != team)); } + /**Clears the frontier, increments the search and sets up all flow sources. + * This only occurs for active teams.*/ private void update(Tile tile, Team team){ + //make sure team exists if(paths[team.ordinal()] != null){ PathData path = paths[team.ordinal()]; + //impassable tiles have a weight of float.max if(!passable(tile, team)){ path.weights[tile.x][tile.y] = Float.MAX_VALUE; } + //increment search, clear frontier path.search++; - - if(path.lastSearchTime + 1000 / 60 * 3 > TimeUtils.millis()){ - path.frontier.clear(); - } - + path.frontier.clear(); path.lastSearchTime = TimeUtils.millis(); - Array set = world.indexer.getEnemy(team, BlockFlag.target); - for(Tile other : set){ + //add all targets to the frontier + for(Tile other : world.indexer.getEnemy(team, BlockFlag.target)){ path.weights[other.x][other.y] = 0; path.searches[other.x][other.y] = path.search; path.frontier.addFirst(other); diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index 493ef8b1ca..990f6d1686 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -398,6 +398,11 @@ public class NetClient extends Module{ Net.disconnect(); } + /**When set, any disconnects will be ignored and no dialogs will be shown.*/ + public void setQuiet(){ + quiet = true; + } + public synchronized void addRemovedEntity(int id){ removed.add(id); } diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 65609c3ec3..14b8b4b0e0 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -418,6 +418,7 @@ public class NetServer extends Module{ @Remote(called = Loc.both) public static void onGameOver(Team winner){ threads.runGraphics(() -> ui.restart.show(winner)); + netClient.setQuiet(); } public boolean isWaitingForPlayers(){ diff --git a/core/src/io/anuke/mindustry/game/EventType.java b/core/src/io/anuke/mindustry/game/EventType.java index da7c7ebe31..bb66dea689 100644 --- a/core/src/io/anuke/mindustry/game/EventType.java +++ b/core/src/io/anuke/mindustry/game/EventType.java @@ -76,6 +76,7 @@ public class EventType{ } } + /**Called when block building begins. The tile's block will nearly always be a BuildBlock.*/ public static class BlockBuildEvent implements Event{ public final Tile tile; public final Team team; diff --git a/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java index dfedb5dc3d..021d87fd04 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java @@ -51,7 +51,7 @@ public class CustomGameDialog extends FloatingDialog{ if(mode.hidden) continue; modes.addButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode) - .update(b -> b.setChecked(state.mode == mode)).group(group).size(125f, 54f).padBottom(-5); + .update(b -> b.setChecked(state.mode == mode)).group(group).size(140f, 54f).padBottom(-5); if(i++ % 2 == 1) modes.row(); } selmode.add(modes); @@ -73,9 +73,8 @@ public class CustomGameDialog extends FloatingDialog{ state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]); }).width(s); - sdif.addButton("", () -> { - - }).update(t -> { + sdif.addButton("", () -> {}) + .update(t -> { t.setText(state.difficulty.toString()); t.setTouchable(Touchable.disabled); }).width(180f);