From 12c746a4e4e0c86f5dec6b6f3fcd83edcc82df9f Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 3 Jun 2018 00:09:41 -0400 Subject: [PATCH] Fixed build errors, AI improvements --- build.gradle | 2 +- core/src/io/anuke/mindustry/Vars.java | 2 +- .../src/io/anuke/mindustry/ai/Pathfinder.java | 6 +-- core/src/io/anuke/mindustry/core/Logic.java | 11 ++++-- .../src/io/anuke/mindustry/core/Renderer.java | 22 ++++++++++- .../mindustry/entities/units/BaseUnit.java | 6 +++ .../entities/units/FlyingUnitType.java | 7 +--- .../entities/units/GroundUnitType.java | 39 ++++++++++--------- .../mindustry/entities/units/UnitType.java | 10 ++++- core/src/io/anuke/mindustry/ui/ItemImage.java | 2 + 10 files changed, 71 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index d169e47cb2..b7ea2a18a3 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { gdxVersion = '1.9.8' roboVMVersion = '2.3.0' aiVersion = '1.8.1' - uCoreVersion = 'a8572ca' + uCoreVersion = 'ea792ea' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index bfc54e1b9a..916e57ef4d 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -63,7 +63,7 @@ public class Vars{ //whether turrets have infinite ammo (only with debug) public static boolean infiniteAmmo = true; //whether to show paths of enemies - public static boolean showPaths = false; + public static boolean showPaths = true; //if false, player is always hidden public static boolean showPlayer = true; //whether to hide ui, only on debug diff --git a/core/src/io/anuke/mindustry/ai/Pathfinder.java b/core/src/io/anuke/mindustry/ai/Pathfinder.java index 05effc78fc..a5f076ce51 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfinder.java +++ b/core/src/io/anuke/mindustry/ai/Pathfinder.java @@ -63,7 +63,7 @@ public class Pathfinder { if(other == null) continue; if(values[dx][dy] < value && (target == null || values[dx][dy] < tl) && - (other.getWallID() == 0 || state.teams.areEnemies(team, other.getTeam()))){ + (!other.solid() || state.teams.areEnemies(team, other.getTeam()))){ target = other; tl = values[dx][dy]; } @@ -79,8 +79,8 @@ public class Pathfinder { } private boolean passable(Tile tile, Team team){ - return (tile.getWallID() == 0 && !(tile.floor().liquid && (tile.floor().damageTaken > 0 || tile.floor().drownTime > 0))) || (tile.breakable() - && (tile.getTeam() != team || !tile.solid())); + return (tile.getWallID() == 0 && !(tile.floor().liquid && (tile.floor().damageTaken > 0 || tile.floor().drownTime > 0))) + || (tile.breakable() && (tile.getTeam() != team)) || !tile.solid(); } private void update(Tile tile, Team team){ diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 13648fb648..fcec340265 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -11,6 +11,7 @@ import io.anuke.mindustry.game.EventType.ResetEvent; import io.anuke.mindustry.game.EventType.WaveEvent; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.TeamInfo; +import io.anuke.mindustry.game.TeamInfo.TeamData; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemType; @@ -47,10 +48,12 @@ public class Logic extends Module { state.wavetime = wavespace * state.difficulty.timeScaling * 2; //fill inventory with items for debugging - for(Tile tile : state.teams.get(players[0].team).cores){ - for(Item item : Item.all()){ - if(item.type == ItemType.material){ - tile.entity.items.addItem(item, 1000); + for(TeamData team : state.teams.getTeams()) { + for (Tile tile : team.cores) { + for (Item item : Item.all()) { + if (item.type == ItemType.material) { + tile.entity.items.addItem(item, 1000); + } } } } diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 668f00857e..b2d7dfe97a 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.FloatArray; +import com.badlogic.gdx.utils.ObjectIntMap; import com.badlogic.gdx.utils.Pools; import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.core.GameState.State; @@ -20,6 +21,8 @@ import io.anuke.mindustry.entities.units.BaseUnit; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.world.Block; +import io.anuke.mindustry.world.BlockFlag; +import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Graphics; @@ -232,7 +235,7 @@ public class Renderer extends RendererModule{ if(pixelate) Graphics.flushSurface(); - if(showPaths) drawDebug(); + if(showPaths && debug) drawDebug(); Entities.drawWith(playerGroup, p -> !p.isLocal && !p.isDead(), Player::drawName); @@ -316,7 +319,6 @@ public class Renderer extends RendererModule{ void drawDebug(){ int rangex = (int)(Core.camera.viewportWidth/tilesize/2), rangey = (int)(Core.camera.viewportHeight/tilesize/2); - Draw.tscl(0.125f); for(int x = -rangex; x <= rangex; x++) { for (int y = -rangey; y <= rangey; y++) { @@ -332,6 +334,22 @@ public class Renderer extends RendererModule{ } } + Draw.color(Color.ORANGE); + Draw.tcolor(Color.ORANGE); + + ObjectIntMap seen = new ObjectIntMap<>(); + + for(BlockFlag flag : BlockFlag.values()){ + for(Tile tile : world.indexer().getEnemy(Team.blue, flag)){ + int index = seen.getAndIncrement(tile, 0, 1); + Draw.tscl(0.125f); + Draw.text(flag.name(), tile.drawx(), tile.drawy() + tile.block().size * tilesize/2f + 4 + index * 3); + Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize/2f); + } + } + Draw.tscl(fontScale); + Draw.tcolor(); + Draw.color(); } diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 9a8a3fb595..3ab6e3cee0 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -55,6 +55,12 @@ public class BaseUnit extends Unit{ this.state.set(this, state); } + public void retarget(Runnable run){ + if(timer.get(UnitType.timerTarget, 20)){ + run.run(); + } + } + @Override public float getArmor() { return type.armor; diff --git a/core/src/io/anuke/mindustry/entities/units/FlyingUnitType.java b/core/src/io/anuke/mindustry/entities/units/FlyingUnitType.java index 8bf22543f5..5171505297 100644 --- a/core/src/io/anuke/mindustry/entities/units/FlyingUnitType.java +++ b/core/src/io/anuke/mindustry/entities/units/FlyingUnitType.java @@ -97,10 +97,7 @@ public class FlyingUnitType extends UnitType { if(unit.inventory.totalAmmo() + 10 >= unit.inventory.ammoCapacity()){ unit.state.set(unit, attack); }else if(!unit.targetHasFlag(BlockFlag.resupplyPoint)){ - if(unit.timer.get(timerTarget, 20)) { - Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, BlockFlag.resupplyPoint)); - if (target != null) unit.target = target.entity; - } + unit.retarget(() -> targetClosestAllyFlag(unit, BlockFlag.resupplyPoint)); }else{ circle(unit, 20f); } @@ -125,7 +122,7 @@ public class FlyingUnitType extends UnitType { if(closest != null){ unit.target = closest; }else { - Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getEnemy(unit.team, BlockFlag.resupplyPoint)); + Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getEnemy(unit.team, BlockFlag.target)); if (target != null) unit.target = target.entity; } } diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnitType.java b/core/src/io/anuke/mindustry/entities/units/GroundUnitType.java index 55976fa01c..2927fdacad 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnitType.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnitType.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.entities.units; import com.badlogic.gdx.graphics.Color; -import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.Unit; import io.anuke.mindustry.entities.Units; import io.anuke.mindustry.type.AmmoType; @@ -11,7 +10,10 @@ import io.anuke.mindustry.world.blocks.types.Floor; import io.anuke.ucore.core.Timers; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Hue; -import io.anuke.ucore.util.*; +import io.anuke.ucore.util.Angles; +import io.anuke.ucore.util.Geometry; +import io.anuke.ucore.util.Mathf; +import io.anuke.ucore.util.Translator; import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.world; @@ -128,6 +130,12 @@ public abstract class GroundUnitType extends UnitType{ } public void update(BaseUnit unit) { + Tile tile = Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, BlockFlag.resupplyPoint)); + + if (tile != null && unit.distanceTo(tile) > 40) { + moveAwayFromCore(unit); + } + //TODO move toward resupply point if(unit.inventory.totalAmmo() + 10 >= unit.inventory.ammoCapacity()){ unit.state.set(unit, attack); @@ -140,32 +148,25 @@ public abstract class GroundUnitType extends UnitType{ } public void update(BaseUnit unit) { - if(unit.target != null && (unit.target instanceof TileEntity && - (((TileEntity)unit.target).tile.getTeam() == unit.team || !((TileEntity)unit.target).tile.breakable()))){ - unit.target = null; - } + unit.retarget(() -> { + Unit closest = Units.getClosestEnemy(unit.team, unit.x, unit.y, unit.inventory.getAmmo().getRange(), other -> true); + if(closest != null){ + unit.target = closest; + }else { + Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getEnemy(unit.team, BlockFlag.target)); + if (target != null) unit.target = target.entity; + } + }); if(!unit.inventory.hasAmmo()) { unit.state.set(unit, resupply); - }else if (unit.target == null){ - if(unit.timer.get(timerTarget, 20)) { - Unit closest = Units.getClosestEnemy(unit.team, unit.x, unit.y, - unit.inventory.getAmmo().getRange(), other -> true); - if(closest != null){ - unit.target = closest; - }else { - Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getEnemy(unit.team, BlockFlag.target)); - if (target != null) unit.target = target.entity; - } - } }else{ - if(unit.distanceTo(unit.target) > unit.inventory.getAmmo().getRange()){ + if(unit.distanceTo(unit.target) > unit.inventory.getAmmo().getRange() * 0.7f){ moveToCore(unit); }else{ unit.rotate(unit.angleTo(unit.target)); } - if (unit.timer.get(timerReload, reload) && Mathf.angNear(unit.angleTo(unit.target), unit.rotation, 13f) && unit.distanceTo(unit.target) < unit.inventory.getAmmo().getRange()) { AmmoType ammo = unit.inventory.getAmmo(); diff --git a/core/src/io/anuke/mindustry/entities/units/UnitType.java b/core/src/io/anuke/mindustry/entities/units/UnitType.java index 482fe2def8..8a2e8fba7b 100644 --- a/core/src/io/anuke/mindustry/entities/units/UnitType.java +++ b/core/src/io/anuke/mindustry/entities/units/UnitType.java @@ -3,16 +3,19 @@ package io.anuke.mindustry.entities.units; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import io.anuke.mindustry.content.fx.ExplosionFx; -import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.Unit; +import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.NetEvents; import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.type.Item; +import io.anuke.mindustry.world.BlockFlag; +import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Angles; +import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Mathf; import static io.anuke.mindustry.Vars.tilesize; @@ -116,6 +119,11 @@ public abstract class UnitType { unit.y + Angles.trnsy(rotation, translation), rotation, unit); } + public void targetClosestAllyFlag(BaseUnit unit, BlockFlag flag){ + Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, flag)); + if (target != null) unit.target = target.entity; + } + public void onDeath(BaseUnit unit){ //TODO other things, such as enemies? Effects.effect(ExplosionFx.explosion, unit); diff --git a/core/src/io/anuke/mindustry/ui/ItemImage.java b/core/src/io/anuke/mindustry/ui/ItemImage.java index 0692f1010f..e38ee4ac3d 100644 --- a/core/src/io/anuke/mindustry/ui/ItemImage.java +++ b/core/src/io/anuke/mindustry/ui/ItemImage.java @@ -14,6 +14,8 @@ public class ItemImage extends Stack { public ItemImage(TextureRegion region, Supplier text, Color color) { Table t = new Table().left().bottom(); + t.label(text).get().setFontScale(0.5f); + image = new Image(region); image.setColor(color);