Fixed rubble-related crash, improved vtol AI

This commit is contained in:
Anuken 2018-04-29 23:34:40 -04:00
parent 9641a388e2
commit 2b96c820fd
9 changed files with 506 additions and 463 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 107 KiB

View File

@ -520,7 +520,7 @@ public class Renderer extends RendererModule{
}
if((!debug || showUI) && Settings.getBool("healthbars")){
for(TeamData ally : state.teams.getTeams(true)){
for(TeamData ally : (debug ? state.teams.getTeams() : state.teams.getTeams(true))){
for(Unit e : unitGroups[ally.team.ordinal()].all()){
drawStats(e);
}

View File

@ -57,6 +57,10 @@ public class BaseUnit extends Unit{
((TileEntity)target).tile.block().flags.contains(flag);
}
public void setState(UnitState state){
this.state.set(this, state);
}
@Override
public boolean acceptsAmmo(Item item) {
return type.ammo.containsKey(item) && inventory.canAcceptAmmo(type.ammo.get(item));

View File

@ -8,6 +8,7 @@ public class StateMachine {
}
public void set(BaseUnit unit, UnitState next){
if(next == state) return;
if(state != null) state.exited(unit);
this.state = next;
if(next != null) next.entered(unit);

View File

@ -20,6 +20,7 @@ import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.world;
public class Vtol extends FlyingUnitType {
private float retreatHealth = 10f;
public Vtol(){
super("vtol");
@ -94,6 +95,15 @@ public class Vtol extends FlyingUnitType {
}
}
@Override
public void behavior(BaseUnit unit) {
if(unit.health <= retreatHealth &&
Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, BlockFlag.repair)) != null){
unit.setState(retreat);
}
}
@Override
public UnitState getStartState(){
return resupply;
}
@ -119,7 +129,7 @@ public class Vtol extends FlyingUnitType {
if(diff > 100f && vec.len() < circleLength){
vec.setAngle(unit.velocity.angle());
}else{
vec.setAngle(Mathf.slerpDelta(unit.velocity.angle(), vec.angle(), 0.4f));
vec.setAngle(Mathf.slerpDelta(unit.velocity.angle(), vec.angle(), 0.44f));
}
vec.setLength(speed*Timers.delta());
@ -153,13 +163,12 @@ public class Vtol extends FlyingUnitType {
}
public void update(BaseUnit unit) {
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);
unit.inventory.getAmmo().getRange(), other -> other.distanceTo(unit) < 60f);
if(closest != null){
unit.target = closest;
}else {
@ -170,7 +179,7 @@ public class Vtol extends FlyingUnitType {
}else{
attack(unit, 150f);
if (unit.timer.get(timerReload, 7) && Mathf.angNear(unit.angleTo(unit.target), unit.rotation, 16f)
if (unit.timer.get(timerReload, 7) && Mathf.angNear(unit.angleTo(unit.target), unit.rotation, 13f)
&& unit.distanceTo(unit.target) < unit.inventory.getAmmo().getRange()) {
AmmoType ammo = unit.inventory.getAmmo();
unit.inventory.useAmmo();
@ -179,6 +188,24 @@ public class Vtol extends FlyingUnitType {
}
}
}
},
retreat = new UnitState() {
public void entered(BaseUnit unit) {
unit.target = null;
}
public void update(BaseUnit unit) {
if(unit.health >= health){
unit.state.set(unit, attack);
}else if(!unit.targetHasFlag(BlockFlag.repair)){
if(unit.timer.get(timerTarget, 20)) {
Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, BlockFlag.repair));
if (target != null) unit.target = target.entity;
}
}else{
circle(unit, 20f);
}
}
};
}

View File

@ -22,6 +22,10 @@ public class TeamInfo {
return ally ? allyData : enemyData;
}
public ObjectSet<TeamData> getTeams() {
return allTeamData;
}
/**Register a team.
* @param team The team type enum.
* @param ally Whether this team is an ally with the player or an enemy with the player.

View File

@ -1,5 +1,5 @@
package io.anuke.mindustry.world.flags;
public enum BlockFlag {
resupplyPoint, producer
resupplyPoint, producer, repair
}