Fix pathfind crash for closed maps
This commit is contained in:
@@ -51,6 +51,10 @@ public class Pathfind{
|
|||||||
//-1 is only possible here if both pathfindings failed, which should NOT happen
|
//-1 is only possible here if both pathfindings failed, which should NOT happen
|
||||||
//check graph code
|
//check graph code
|
||||||
|
|
||||||
|
if(enemy.node <= -1){
|
||||||
|
return vector.set(enemy.x, enemy.y);
|
||||||
|
}
|
||||||
|
|
||||||
Tile prev = path[enemy.node - 1];
|
Tile prev = path[enemy.node - 1];
|
||||||
|
|
||||||
Tile target = path[enemy.node];
|
Tile target = path[enemy.node];
|
||||||
@@ -99,10 +103,15 @@ public class Pathfind{
|
|||||||
public void update(){
|
public void update(){
|
||||||
for(SpawnPoint point : Vars.control.getSpawnPoints()){
|
for(SpawnPoint point : Vars.control.getSpawnPoints()){
|
||||||
if(!point.request.pathFound){
|
if(!point.request.pathFound){
|
||||||
if(point.finder.search(point.request, ms)){
|
try{
|
||||||
smoother.smoothPath(point.path);
|
if(point.finder.search(point.request, ms)){
|
||||||
point.pathTiles = point.path.nodes.toArray(Tile.class);
|
smoother.smoothPath(point.path);
|
||||||
point.tempTiles = point.path.nodes.toArray(Tile.class);
|
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);
|
int closest = findClosest(enemy.path, enemy.x, enemy.y);
|
||||||
|
|
||||||
closest = Mathf.clamp(closest, 1, enemy.path.length-1);
|
closest = Mathf.clamp(closest, 1, enemy.path.length-1);
|
||||||
|
if(closest == -1){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Tile end = enemy.path[closest];
|
Tile end = enemy.path[closest];
|
||||||
enemy.node = closest;
|
enemy.node = closest;
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public class MapView extends Element implements GestureListener{
|
|||||||
public boolean zoom(float initialDistance, float distance){
|
public boolean zoom(float initialDistance, float distance){
|
||||||
if(!active()) return false;
|
if(!active()) return false;
|
||||||
float nzoom = distance - initialDistance;
|
float nzoom = distance - initialDistance;
|
||||||
zoom += nzoom / 2000f / Unit.dp.scl(1f) * zoom;
|
zoom += nzoom / 5000f / Unit.dp.scl(1f) * zoom;
|
||||||
clampZoom();
|
clampZoom();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user