mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-20 19:42:20 -08:00
Fixed build errors, AI improvements
This commit is contained in:
parent
a116a2a553
commit
12c746a4e4
10 changed files with 71 additions and 36 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Tile> 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ public class ItemImage extends Stack {
|
|||
public ItemImage(TextureRegion region, Supplier<String> text, Color color) {
|
||||
Table t = new Table().left().bottom();
|
||||
|
||||
t.label(text).get().setFontScale(0.5f);
|
||||
|
||||
image = new Image(region);
|
||||
image.setColor(color);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue