Fixed build errors, AI improvements
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user