Multiple unit stance support

This commit is contained in:
Anuken
2025-07-01 23:23:45 -04:00
parent b6195cc31e
commit 88fc46fed2
8 changed files with 141 additions and 42 deletions

View File

@@ -372,15 +372,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
//make sure its current stance is valid with its current command
stancesOut.clear();
unit.type.getUnitStances(unit, stancesOut);
if(stancesOut.size > 0 && !stancesOut.contains(ai.stance)){
ai.stance = stancesOut.first();
for(var stance : content.unitStances()){
//disable stances that the unit does not support anymore (TODO: this is slow!)
if(ai.hasStance(stance) && !stancesOut.contains(stance)){
ai.disableStance(stance);
}
}
}
}
}
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void setUnitStance(Player player, int[] unitIds, UnitStance stance){
public static void setUnitStance(Player player, int[] unitIds, UnitStance stance, boolean enable){
if(player == null || unitIds == null || stance == null) return;
if(net.server() && !netServer.admins.allowAction(player, ActionType.commandUnits, event -> {
@@ -395,7 +398,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(stance == UnitStance.stop){ //not a real stance, just cancels orders
ai.clearCommands();
}else if(unit.type.allowStance(unit, stance)){
ai.stance = stance;
//if toggle is not allowed, the stance will always be set to true when pressed
ai.setStance(stance, !stance.toggle || enable);
}
unit.lastCommanded = player.coloredName();
}