From 2000a4b6f6d4973f139020c989ddbc6c4a5d1e81 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 20 Dec 2017 12:26:30 -0500 Subject: [PATCH] Fix pathfind crash for closed maps --- core/src/io/anuke/mindustry/ai/Pathfind.java | 21 +++++++++++++++---- .../io/anuke/mindustry/mapeditor/MapView.java | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/io/anuke/mindustry/ai/Pathfind.java b/core/src/io/anuke/mindustry/ai/Pathfind.java index 3987c0ef4c..c35a2e03d1 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfind.java +++ b/core/src/io/anuke/mindustry/ai/Pathfind.java @@ -51,6 +51,10 @@ public class Pathfind{ //-1 is only possible here if both pathfindings failed, which should NOT happen //check graph code + if(enemy.node <= -1){ + return vector.set(enemy.x, enemy.y); + } + Tile prev = path[enemy.node - 1]; Tile target = path[enemy.node]; @@ -99,10 +103,15 @@ public class Pathfind{ public void update(){ for(SpawnPoint point : Vars.control.getSpawnPoints()){ if(!point.request.pathFound){ - if(point.finder.search(point.request, ms)){ - smoother.smoothPath(point.path); - point.pathTiles = point.path.nodes.toArray(Tile.class); - point.tempTiles = point.path.nodes.toArray(Tile.class); + try{ + if(point.finder.search(point.request, ms)){ + smoother.smoothPath(point.path); + point.pathTiles = point.path.nodes.toArray(Tile.class); + point.tempTiles = point.path.nodes.toArray(Tile.class); + } + }catch (ArrayIndexOutOfBoundsException e){ + //no path + point.request.pathFound = true; } } } @@ -145,6 +154,10 @@ public class Pathfind{ int closest = findClosest(enemy.path, enemy.x, enemy.y); closest = Mathf.clamp(closest, 1, enemy.path.length-1); + if(closest == -1){ + return; + } + Tile end = enemy.path[closest]; enemy.node = closest; diff --git a/core/src/io/anuke/mindustry/mapeditor/MapView.java b/core/src/io/anuke/mindustry/mapeditor/MapView.java index 28f90440cb..5d3c53bacd 100644 --- a/core/src/io/anuke/mindustry/mapeditor/MapView.java +++ b/core/src/io/anuke/mindustry/mapeditor/MapView.java @@ -173,7 +173,7 @@ public class MapView extends Element implements GestureListener{ public boolean zoom(float initialDistance, float distance){ if(!active()) return false; float nzoom = distance - initialDistance; - zoom += nzoom / 2000f / Unit.dp.scl(1f) * zoom; + zoom += nzoom / 5000f / Unit.dp.scl(1f) * zoom; clampZoom(); return false; }