Re-coded everything

This commit is contained in:
Anuken
2017-05-03 00:09:48 -04:00
parent 883610d928
commit b48c0991c7
74 changed files with 1998 additions and 1860 deletions
@@ -2,8 +2,8 @@ package io.anuke.mindustry.ai;
import com.badlogic.gdx.ai.pfa.Heuristic;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.TileType;
public class MHueristic implements Heuristic<Tile>{
//so this means that the cost of going through solids is 10x going through non solids
@@ -14,8 +14,8 @@ public class MHueristic implements Heuristic<Tile>{
float cost = Math.abs(node.worldx() - other.worldx()) + Math.abs(node.worldy() - other.worldy());
//TODO balance multiplier
if(node.artifical() && node.block().solid) cost += TileType.tilesize*multiplier;
if(other.artifical() && other.block().solid) cost += TileType.tilesize*multiplier;
if(node.artifical() && node.block().solid) cost += Vars.tilesize*multiplier;
if(other.artifical() && other.block().solid) cost += Vars.tilesize*multiplier;
return cost;
}
@@ -1,12 +1,12 @@
package io.anuke.mindustry.ai;
import static io.anuke.mindustry.Vars.worldsize;
import com.badlogic.gdx.ai.pfa.Connection;
import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Moment;
import io.anuke.mindustry.world.Tile;
/**Tilegraph that ignores player-made tiles.*/
public class PassTileGraph implements IndexedGraph<Tile>{
private Array<Connection<Tile>> tempConnections = new Array<Connection<Tile>>();
@@ -28,11 +28,11 @@ public class PassTileGraph implements IndexedGraph<Tile>{
@Override
public int getIndex(Tile node){
return node.x+node.y*Moment.i.size;
return node.x+node.y*worldsize;
}
@Override
public int getNodeCount(){
return Moment.i.size*Moment.i.size;
return worldsize*worldsize;
}
}
+7 -9
View File
@@ -1,22 +1,20 @@
package io.anuke.mindustry.ai;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Moment;
import io.anuke.mindustry.entities.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
public class Pathfind{
static MHueristic heuristic = new MHueristic();
static TileGraph graph = new TileGraph();
static PassTileGraph passgraph = new PassTileGraph();
static IndexedAStarPathFinder<Tile> pathfinder = new IndexedAStarPathFinder<Tile>(graph);
static IndexedAStarPathFinder<Tile> passpathfinder = new IndexedAStarPathFinder<Tile>(passgraph);
static IndexedAStarPathFinder<Tile> passpathfinder;
static Array<DefaultGraphPath<Tile>> paths = new Array<>();
static Vector2 vector = new Vector2();
@@ -48,11 +46,12 @@ public class Pathfind{
static public void reset(){
paths.clear();
passpathfinder = new IndexedAStarPathFinder<Tile>(passgraph);
}
static public void updatePath(){
if(paths.size == 0){
for(int i = 0; i < Moment.i.spawnpoints.size; i ++){
for(int i = 0; i < spawnpoints.size; i ++){
DefaultGraphPath<Tile> path = new DefaultGraphPath<>();
paths.add(path);
}
@@ -62,8 +61,8 @@ public class Pathfind{
for(DefaultGraphPath<Tile> path : paths){
path.clear();
passpathfinder.searchNodePath(
Moment.i.spawnpoints.get(i),
Moment.i.core, heuristic, path);
spawnpoints.get(i),
core, heuristic, path);
//for(Tile tile : path){
// Effects.effect("ind", tile.worldx(), tile.worldy());
@@ -80,7 +79,6 @@ public class Pathfind{
static void findNode(Enemy enemy){
DefaultGraphPath<Tile> path = paths.get(enemy.spawn);
Tile closest = null;
float ldst = 0f;
int cindex = -1;
@@ -1,36 +0,0 @@
package io.anuke.mindustry.ai;
import com.badlogic.gdx.ai.pfa.Connection;
import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Moment;
import io.anuke.mindustry.world.Tile;
public class TileGraph implements IndexedGraph<Tile>{
private Array<Connection<Tile>> tempConnections = new Array<Connection<Tile>>();
@Override
public Array<Connection<Tile>> getConnections(Tile fromNode){
tempConnections.clear();
if(fromNode.block().solid && fromNode != Moment.i.core)
return tempConnections;
for(Tile tile : fromNode.getNearby()){
if(tile != null && (!tile.block().solid || tile == Moment.i.core))
tempConnections.add(new TileConnection(fromNode, tile));
}
return tempConnections;
}
@Override
public int getIndex(Tile node){
return node.x+node.y*Moment.i.size;
}
@Override
public int getNodeCount(){
return Moment.i.size*Moment.i.size;
}
}