Improved unit commands
This commit is contained in:
@@ -23,6 +23,7 @@ import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.units.CommandCenter.CommandCenterEntity;
|
||||
import io.anuke.mindustry.world.blocks.units.UnitFactory.UnitFactoryEntity;
|
||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -40,6 +41,7 @@ import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Base class for AI units.*/
|
||||
public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
protected static int timerIndex = 0;
|
||||
|
||||
@@ -94,6 +96,17 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public boolean isCommanded(){
|
||||
return !isWave && world.indexer().getAllied(team, BlockFlag.comandCenter).size != 0;
|
||||
}
|
||||
|
||||
public UnitCommand getCommand(){
|
||||
if(isCommanded()){
|
||||
return world.indexer().getAllied(team, BlockFlag.comandCenter).first().<CommandCenterEntity>entity().command;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UnitType getType(){
|
||||
return type;
|
||||
}
|
||||
@@ -379,6 +392,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
state.set(getStartState());
|
||||
|
||||
health(maxHealth());
|
||||
|
||||
if(isCommanded()){
|
||||
onCommand(getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,14 +46,16 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
|
||||
idle = new UnitState(){
|
||||
public void update(){
|
||||
retarget(() -> {
|
||||
targetClosest();
|
||||
targetClosestEnemyFlag(BlockFlag.target);
|
||||
if(!isCommanded()){
|
||||
retarget(() -> {
|
||||
targetClosest();
|
||||
targetClosestEnemyFlag(BlockFlag.target);
|
||||
|
||||
if(target != null){
|
||||
setState(attack);
|
||||
}
|
||||
});
|
||||
if(target != null){
|
||||
setState(attack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
target = getClosestCore();
|
||||
if(target != null){
|
||||
@@ -106,7 +108,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(health >= maxHealth()){
|
||||
if(health >= maxHealth() && !isCommanded()){
|
||||
state.set(attack);
|
||||
}else if(!targetHasFlag(BlockFlag.repair)){
|
||||
retarget(() -> {
|
||||
@@ -128,7 +130,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
public void onCommand(UnitCommand command){
|
||||
state.set(command == UnitCommand.retreat ? retreat :
|
||||
(command == UnitCommand.attack ? attack :
|
||||
(command == UnitCommand.idle ? resupply :
|
||||
(command == UnitCommand.idle ? idle :
|
||||
(null))));
|
||||
}
|
||||
|
||||
@@ -176,8 +178,8 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
|
||||
@Override
|
||||
public void behavior(){
|
||||
if(health <= health * type.retreatPercent && !isWave &&
|
||||
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
|
||||
if(health <= health * type.retreatPercent && !isCommanded() &&
|
||||
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
|
||||
setState(retreat);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(health >= health){
|
||||
if(health >= health && !isCommanded()){
|
||||
state.set(attack);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
@Override
|
||||
public void behavior(){
|
||||
if(health <= health * type.retreatPercent && !isWave){
|
||||
if(health <= health * type.retreatPercent && !isCommanded()){
|
||||
setState(retreat);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user