diff --git a/core/src/io/anuke/mindustry/ai/Pathfinder.java b/core/src/io/anuke/mindustry/ai/Pathfinder.java index 5abc79965e..d754e6dcb1 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfinder.java +++ b/core/src/io/anuke/mindustry/ai/Pathfinder.java @@ -4,7 +4,7 @@ import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.Queue; import com.badlogic.gdx.utils.async.AsyncExecutor; -import io.anuke.mindustry.entities.Units; +import io.anuke.mindustry.game.EventType.TileChangeEvent; import io.anuke.mindustry.game.EventType.WorldLoadEvent; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.TeamInfo.TeamData; @@ -14,15 +14,12 @@ import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Log; -import io.anuke.ucore.util.Mathf; import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.world; public class Pathfinder { - private static final float SQRT2 = Mathf.sqrt(2f); private static final float unitBlockCost = 4f; - private static boolean avoid = false; private AsyncExecutor executor = new AsyncExecutor(8); private float[][][] weights; @@ -30,30 +27,10 @@ public class Pathfinder { public Pathfinder(){ Events.on(WorldLoadEvent.class, this::clear); - } - public void update(){ - if(avoid) { + Events.on(TileChangeEvent.class, tile -> { - for (TeamData data : state.teams.getTeams()) { - for (int i = 0; i < blocked.size; i++) { - int c = blocked.get(i); - weights[data.team.ordinal()][c % world.width()][c / world.width()] -= unitBlockCost; - } - } - - blocked.clear(); - - Units.getAllUnits(unit -> { - if (unit.isFlying()) return; - int cx = world.toTile(unit.x), cy = world.toTile(unit.y); - for (TeamData data : state.teams.getTeams()) { - if (weights[data.team.ordinal()][cx][cy] < Float.MAX_VALUE) - weights[data.team.ordinal()][cx][cy] += unitBlockCost; - } - blocked.add(cx + cy * world.width()); - }); - } + }); } public Tile getTargetTile(Team team, Tile tile){ @@ -68,10 +45,12 @@ public class Pathfinder { for(GridPoint2 point : Geometry.d8) { int dx = tile.x + point.x, dy = tile.y + point.y; - if(!Mathf.inBounds(dx, dy, world.width(), world.height())) continue; + Tile other = world.tile(dx, dy); + if(other == null) continue; - if(values[dx][dy] < value && (target == null || values[dx][dy] < tl)){ - target = world.tile(dx, dy); + if(values[dx][dy] < value && (target == null || values[dx][dy] < tl) && + (other.getWallID() == 0 || state.teams.areEnemies(team, other.getTeam()))){ + target = other; tl = values[dx][dy]; } } @@ -83,7 +62,7 @@ public class Pathfinder { } public float getDebugValue(int x, int y){ - return weights[Team.blue.ordinal()][x][y]; + return weights[Team.red.ordinal()][x][y]; } private boolean passable(Tile tile){ @@ -138,7 +117,6 @@ public class Pathfinder { } } } - } Log.info("Elapsed calculation time: {0}", Timers.elapsedNs()); diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 83e6a6f79d..c9ea33b3e6 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -117,8 +117,6 @@ public class Logic extends Module { runWave(); } - world.pathfinder().update(); - if(!Entities.defaultGroup().isEmpty()) throw new RuntimeException("Do not add anything to the default group!"); Entities.update(bulletGroup); diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index b21295587b..724e773dec 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -319,15 +319,13 @@ public class Renderer extends RendererModule{ if(world.tile(worldx, worldy) == null) continue; float value = world.pathfinder().getDebugValue(worldx, worldy); - if(value == Float.MAX_VALUE){ - Draw.text("R", worldx*tilesize, worldy*tilesize); - }else{ - Draw.text(value + "", worldx*tilesize, worldy*tilesize); - } + Draw.color(Color.PURPLE); + Draw.alpha((value % 10f) / 10f); + Lines.square(worldx * tilesize, worldy*tilesize, 4f); } } - Draw.tscl(0.5f); + Draw.color(); } void drawPlayerNames(){ diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 96df837094..25054f7efa 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -132,7 +132,7 @@ public class BaseUnit extends Unit{ public void added(){ maxhealth = type.health; - hitbox.solid = true; + hitbox.solid = !isFlying(); hitbox.setSize(type.hitsize); hitboxTile.setSize(type.hitsizeTile); state.set(this, type.getStartState()); diff --git a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java index bcdb0186bb..130e1d5f19 100644 --- a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java @@ -177,10 +177,6 @@ public class BlockRenderer{ } } - public void clearTiles(){ - floorRenderer.clearTiles(); - } - public void beginFloor(){ floorRenderer.beginDraw(); } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/units/CommandCenter.java b/core/src/io/anuke/mindustry/world/blocks/types/units/CommandCenter.java new file mode 100644 index 0000000000..c775787442 --- /dev/null +++ b/core/src/io/anuke/mindustry/world/blocks/types/units/CommandCenter.java @@ -0,0 +1,9 @@ +package io.anuke.mindustry.world.blocks.types.units; + +import io.anuke.mindustry.world.Block; + +public class CommandCenter extends Block { + public CommandCenter(String name) { + super(name); + } +}