Now with only 28 errors!

This commit is contained in:
Anuken
2018-02-05 23:38:23 -05:00
parent 55ae4c6ea5
commit 2fafb327c2
32 changed files with 206 additions and 211 deletions

View File

@@ -11,7 +11,6 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
@@ -26,6 +25,10 @@ public class Pathfind{
/**temporary vector2 for calculations*/
Vector2 vector = new Vector2();
Vector2 v1 = new Vector2();
Vector2 v2 = new Vector2();
Vector2 v3 = new Vector2();
/**Finds the position on the path an enemy should move to.
* If the path is not yet calculated, this returns the enemy's position (i. e. "don't move")
* @param enemy The enemy to find a path for
@@ -76,7 +79,7 @@ public class Pathfind{
if(projectLen < 8 || !onLine(projection, prev.worldx(), prev.worldy(), target.worldx(), target.worldy())){
canProject = false;
}else{
projection.add(Angles.translation(Angles.angle(prev.worldx(), prev.worldy(),
projection.add(v1.set(Angles.angle(prev.worldx(), prev.worldy(),
target.worldx(), target.worldy()), projectLen));
}
@@ -122,7 +125,8 @@ public class Pathfind{
public void update(){
//go through each spawnpoint, and if it's not found a path yet, update it
for(SpawnPoint point : world.getSpawns()){
for(int i = 0; i < world.getSpawns().size; i ++){
SpawnPoint point = world.getSpawns().get(i);
if(point.request == null || point.finder == null){
continue;
}
@@ -204,7 +208,7 @@ public class Pathfind{
}
/**Finds the closest tile to a position, in an array of tiles.*/
private static int findClosest(Tile[] tiles, float x, float y){
private int findClosest(Tile[] tiles, float x, float y){
int cindex = -2;
float dst = Float.MAX_VALUE;
@@ -222,23 +226,23 @@ public class Pathfind{
}
/**Returns whether a point is on a line.*/
private static boolean onLine(Vector2 vector, float x1, float y1, float x2, float y2){
private boolean onLine(Vector2 vector, float x1, float y1, float x2, float y2){
return MathUtils.isEqual(vector.dst(x1, y1) + vector.dst(x2, y2), Vector2.dst(x1, y1, x2, y2), 0.01f);
}
/**Returns distance from a point to a line segment.*/
private static float pointLineDist(float x, float y, float x2, float y2, float px, float py){
private float pointLineDist(float x, float y, float x2, float y2, float px, float py){
float l2 = Vector2.dst2(x, y, x2, y2);
float t = Math.max(0, Math.min(1, Vector2.dot(px - x, py - y, x2 - x, y2 - y) / l2));
Vector2 projection = Tmp.v1.set(x, y).add(Tmp.v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment
Vector2 projection = v1.set(x, y).add(v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment
return projection.dst(px, py);
}
//TODO documentation
private static Vector2 projectPoint(float x1, float y1, float x2, float y2, float pointx, float pointy){
private Vector2 projectPoint(float x1, float y1, float x2, float y2, float pointx, float pointy){
float px = x2-x1, py = y2-y1, dAB = px*px + py*py;
float u = ((pointx - x1) * px + (pointy - y1) * py) / dAB;
float x = x1 + u * px, y = y1 + u * py;
return Tmp.v3.set(x, y); //this is D
return v3.set(x, y); //this is D
}
}

View File

@@ -4,12 +4,13 @@ import com.badlogic.gdx.ai.utils.Collision;
import com.badlogic.gdx.ai.utils.Ray;
import com.badlogic.gdx.ai.utils.RaycastCollisionDetector;
import com.badlogic.gdx.math.Vector2;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Raycaster implements RaycastCollisionDetector<Vector2>{
private boolean found = false;
@@ -75,7 +76,8 @@ public class Raycaster implements RaycastCollisionDetector<Vector2>{
if(tile == null || tile.solid()) return true;
for(Tile near : tile.getNearby()){
for(int i = 0; i < 4; i ++){
Tile near = tile.getNearby(i);
if(near == null || near.solid()) return true;
}

View File

@@ -4,11 +4,12 @@ import io.anuke.mindustry.world.Tile;
/**Tilegraph that ignores player-made tiles.*/
public class TileGraph implements OptimizedGraph<Tile> {
private Tile[] tiles = new Tile[4];
/**Used for the OptimizedPathFinder implementation.*/
@Override
public Tile[] connectionsOf(Tile node){
Tile[] nodes = node.getNearby();
Tile[] nodes = node.getNearby(tiles);
for(int i = 0; i < 4; i ++){
if(nodes[i] != null && !nodes[i].passable()){
nodes[i] = null;