Added unit stances

This commit is contained in:
Anuken
2023-09-20 21:55:06 -04:00
parent 0d1c56fb60
commit 3e15f70efa
11 changed files with 206 additions and 30 deletions

View File

@@ -0,0 +1,49 @@
package mindustry.ai;
import arc.*;
import arc.scene.style.*;
import arc.struct.*;
import mindustry.gen.*;
public class UnitStance{
/** List of all stances by ID. */
public static final Seq<UnitStance> all = new Seq<>();
public static final UnitStance
stopStance = new UnitStance("stop", "cancel"), //not a real stance, cannot be selected, just cancels ordewrs
shootStance = new UnitStance("shoot", "commandAttack"),
holdFireStance = new UnitStance("holdfire", "none");
/** Unique ID number. */
public final int id;
/** Named used for tooltip/description. */
public final String name;
/** Name of UI icon (from Icon class). */
public final String icon;
public UnitStance(String name, String icon){
this.name = name;
this.icon = icon;
id = all.size;
all.add(this);
}
public String localized(){
return Core.bundle.get("stance." + name);
}
public TextureRegionDrawable getIcon(){
return Icon.icons.get(icon, Icon.cancel);
}
public char getEmoji() {
return (char) Iconc.codes.get(icon, Iconc.cancel);
}
@Override
public String toString(){
return "UnitStance:" + name;
}
}

View File

@@ -30,6 +30,8 @@ public class CommandAI extends AIController{
protected Seq<Unit> local = new Seq<>(false);
protected boolean flocked;
/** Stance, usually related to firing mode. */
public UnitStance stance = UnitStance.shootStance;
/** Current command this unit is following. */
public @Nullable UnitCommand command;
/** Current controller instance based on command. */
@@ -62,6 +64,8 @@ public class CommandAI extends AIController{
@Override
public void updateUnit(){
//this should not be possible
if(stance == UnitStance.stopStance) stance = UnitStance.shootStance;
//remove invalid targets
if(commandQueue.any()){
@@ -91,6 +95,12 @@ public class CommandAI extends AIController{
}
}
public void clearCommands(){
commandQueue.clear();
targetPos = null;
attackTarget = null;
}
public void defaultBehavior(){
//acquiring naval targets isn't supported yet, so use the fallback dumb AI
@@ -256,6 +266,11 @@ public class CommandAI extends AIController{
}
}
@Override
public boolean shouldFire(){
return stance != UnitStance.holdFireStance;
}
@Override
public void hit(Bullet bullet){
if(unit.team.isAI() && bullet.owner instanceof Teamc teamc && teamc.team() != unit.team && attackTarget == null &&