From b6c5f202e47b5f5904a13f5d6b4e190f6d394d76 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 23 Feb 2019 20:16:32 -0500 Subject: [PATCH] Bugfixes / Pathfinding 'improvements' --- .../src/io/anuke/mindustry/ai/Pathfinder.java | 24 +++++++++-------- .../entities/effect/RubbleDecal.java | 26 ++++++++++++------- .../mindustry/ui/dialogs/DatabaseDialog.java | 2 +- .../mindustry/ui/fragments/HudFragment.java | 5 ++-- core/src/io/anuke/mindustry/world/Tile.java | 6 ++--- .../world/blocks/distribution/ItemBridge.java | 9 ++++++- .../world/blocks/storage/CoreBlock.java | 2 +- 7 files changed, 46 insertions(+), 28 deletions(-) diff --git a/core/src/io/anuke/mindustry/ai/Pathfinder.java b/core/src/io/anuke/mindustry/ai/Pathfinder.java index 024d83ed4a..9cf7db9a41 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfinder.java +++ b/core/src/io/anuke/mindustry/ai/Pathfinder.java @@ -2,7 +2,7 @@ package io.anuke.mindustry.ai; import io.anuke.arc.Events; import io.anuke.arc.collection.IntArray; -import io.anuke.arc.collection.Queue; +import io.anuke.arc.collection.IntQueue; import io.anuke.arc.math.geom.Geometry; import io.anuke.arc.math.geom.Point2; import io.anuke.arc.util.Structs; @@ -19,7 +19,7 @@ import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.world; public class Pathfinder{ - private long maxUpdate = Time.millisToNanos(4); + private static final long maxUpdate = Time.millisToNanos(4); private PathData[] paths; private IntArray blocked = new IntArray(); @@ -39,10 +39,6 @@ public class Pathfinder{ }); } - public void activateTeamPath(Team team){ - createFor(team); - } - public void update(){ if(Net.client() || paths == null) return; @@ -110,7 +106,7 @@ public class Pathfinder{ for(Tile other : world.indexer.getEnemy(team, BlockFlag.target)){ path.weights[other.x][other.y] = 0; path.searches[other.x][other.y] = (short)path.search; - path.frontier.addFirst(other); + path.frontier.addFirst(other.pos()); } } } @@ -130,7 +126,7 @@ public class Pathfinder{ if(state.teams.areEnemies(tile.getTeam(), team) && tile.block().flags.contains(BlockFlag.target)){ - path.frontier.addFirst(tile); + path.frontier.addFirst(tile.pos()); path.weights[x][y] = 0; path.searches[x][y] = (short)path.search; }else{ @@ -148,9 +144,15 @@ public class Pathfinder{ long start = Time.nanos(); while(path.frontier.size > 0 && (nsToRun < 0 || Time.timeSinceNanos(start) <= nsToRun)){ - Tile tile = path.frontier.removeLast(); + Tile tile = world.tile(path.frontier.removeLast()); float cost = path.weights[tile.x][tile.y]; + //pathfinding overflowed for some reason, time to bail. the next block update will handle this, hopefully + if(path.frontier.size >= world.width() * world.height()){ + path.frontier.clear(); + return; + } + if(cost < Float.MAX_VALUE){ for(Point2 point : Geometry.d4){ @@ -160,7 +162,7 @@ public class Pathfinder{ if(other != null && (path.weights[dx][dy] > cost + other.cost || path.searches[dx][dy] < path.search) && passable(other, team)){ if(other.cost < 0) throw new IllegalArgumentException("Tile cost cannot be negative! " + other); - path.frontier.addFirst(world.tile(dx, dy)); + path.frontier.addFirst(world.tile(dx, dy).pos()); path.weights[dx][dy] = cost + other.cost; path.searches[dx][dy] = (short)path.search; } @@ -190,6 +192,6 @@ public class Pathfinder{ short[][] searches; int search = 0; long lastSearchTime; - Queue frontier = new Queue<>(); + IntQueue frontier = new IntQueue(); } } diff --git a/core/src/io/anuke/mindustry/entities/effect/RubbleDecal.java b/core/src/io/anuke/mindustry/entities/effect/RubbleDecal.java index 51dda93718..89a727da61 100644 --- a/core/src/io/anuke/mindustry/entities/effect/RubbleDecal.java +++ b/core/src/io/anuke/mindustry/entities/effect/RubbleDecal.java @@ -2,30 +2,38 @@ package io.anuke.mindustry.entities.effect; import io.anuke.arc.Core; import io.anuke.arc.graphics.g2d.Draw; +import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.math.Mathf; public class RubbleDecal extends Decal{ - private int size; + private static TextureRegion[][] regions = new TextureRegion[16][0]; + private TextureRegion region; /** * Creates a rubble effect at a position. Provide a block size to use. */ public static void create(float x, float y, int size){ + if(regions[size].length == 0){ + int i = 0; + for(; i < 2; i++){ + if(!Core.atlas.has("rubble-" + size + "-" + i)){ + break; + } + } + regions[size] = new TextureRegion[i + 1]; + for(int j = 0; j <= i; j++){ + regions[size][j] = Core.atlas.find("rubble-" + size + "-" + j); + } + } + RubbleDecal decal = new RubbleDecal(); - decal.size = size; + decal.region = regions[size][Mathf.clamp(Mathf.randomSeed(decal.id, 0, 1), 0, regions[size].length - 1)]; decal.set(x, y); decal.add(); } @Override public void drawDecal(){ - String region = "rubble-" + size + "-" + Mathf.randomSeed(id, 0, 1); - - if(!Core.atlas.has(region)){ - remove(); - return; - } - Draw.rect(region, x, y, Mathf.randomSeed(id, 0, 4) * 90); } } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/DatabaseDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/DatabaseDialog.java index 1ef64d2c51..bb794e667a 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/DatabaseDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/DatabaseDialog.java @@ -16,7 +16,7 @@ import io.anuke.mindustry.type.ContentType; public class DatabaseDialog extends FloatingDialog{ public DatabaseDialog(){ - super("database"); + super("$database"); shouldPause = true; addCloseButton(); diff --git a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java index 07b2a1aefe..de674bf519 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java @@ -129,12 +129,13 @@ public class HudFragment extends Fragment{ Table healthTable = cont.table("button", t -> t.margin(10f).add(new Bar("boss.health", Pal.health, () -> state.boss() == null ? 0f : state.boss().healthf()).blink(Color.WHITE)).grow() - ).fillX().visible(() -> world.isZone() && state.boss() != null).height(60f).update(t -> t.getTranslation().set(wavetable.getTranslation())).get(); + ).fillX().visible(() -> world.isZone() && state.boss() != null).height(60f).update(t -> t.getTranslation().set(0, Unit.dp.scl(wavetable.getTranslation().y))).get(); cont.row(); //fps display infolabel = new Table(); + infolabel.marginLeft(10f); IntFormat fps = new IntFormat("fps"); IntFormat ping = new IntFormat("ping"); infolabel.label(() -> fps.get(Core.graphics.getFramesPerSecond())).padRight(10); @@ -144,7 +145,7 @@ public class HudFragment extends Fragment{ } infolabel.visible(() -> Core.settings.getBool("fps")).update(() -> infolabel.setPosition(0, - healthTable.isVisible() ? healthTable.getY() + healthTable.getTranslation().y : waves.isVisible() ? wavetable.getY() : Core.graphics.getHeight(), + healthTable.isVisible() ? healthTable.getY() + healthTable.getTranslation().y : waves.isVisible() ? Math.min(wavetable.getY(), Core.graphics.getHeight()) : Core.graphics.getHeight(), Align.topLeft)); infolabel.pack(); diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 9bdbe56b48..5bc7e46926 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -331,15 +331,15 @@ public class Tile implements Position, TargetTrait{ } if(occluded){ - cost += 1; + cost += 2; } if(target().synthetic()){ - cost += Mathf.clamp(target().block().health / 10f, 0, 28); + cost += Mathf.clamp(target().block().health / 10f, 0, 20); } if(floor.isLiquid){ - cost += 80; + cost += 10; } } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index 7e4bfe30d3..b6bf145b67 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -36,9 +36,10 @@ public class ItemBridge extends Block{ protected int range; protected float transportTime = 2f; protected IntArray removals = new IntArray(); - protected TextureRegion endRegion, bridgeRegion, arrowRegion; + private static int lastPlaced = Pos.invalid; + public ItemBridge(String name){ super(name); update = true; @@ -85,9 +86,15 @@ public class ItemBridge extends Block{ if(linkValid(tile, link)){ Call.linkItemBridge(null, link, tile); } + + lastPlaced = tile.pos(); } public Tile findLink(int x, int y){ + if(linkValid(world.tile(x, y), world.tile(lastPlaced))){ + return world.tile(lastPlaced); + } + for(int j = 0; j < 4; j ++){ Point2 p = Geometry.d4(j + 1); for(int i = 1; i <= range; i++){ diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index 2ade6ec0b1..7bb4946473 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -74,7 +74,7 @@ public class CoreBlock extends StorageBlock{ @Override public boolean canBreak(Tile tile){ - return state.teams.get(tile.getTeam()).cores.size > 1; + return false; } @Override