Made boosting a stance

This commit is contained in:
Anuken
2026-03-05 23:54:35 -05:00
parent 70c2010ea5
commit 79a991a2a0
6 changed files with 44 additions and 18 deletions
+1 -6
View File
@@ -13,7 +13,7 @@ import mindustry.input.*;
/** Defines a pattern of behavior that an RTS-controlled unit should follow. Shows up in the command UI. */
public class UnitCommand extends MappableContent{
public static UnitCommand moveCommand, repairCommand, rebuildCommand, assistCommand, mineCommand, boostCommand, enterPayloadCommand, loadUnitsCommand, loadBlocksCommand, unloadPayloadCommand, loopPayloadCommand;
public static UnitCommand moveCommand, repairCommand, rebuildCommand, assistCommand, mineCommand, enterPayloadCommand, loadUnitsCommand, loadBlocksCommand, unloadPayloadCommand, loopPayloadCommand;
/** Name of UI icon (from Icon class). */
public final String icon;
@@ -84,11 +84,6 @@ public class UnitCommand extends MappableContent{
mineCommand = new UnitCommand("mine", "production", Binding.unitCommandMine, u -> new MinerAI()){{
refreshOnSelect = true;
}};
boostCommand = new UnitCommand("boost", "up", Binding.unitCommandBoost, u -> new BoostAI()){{
switchToMove = false;
drawTarget = true;
resetTarget = false;
}};
enterPayloadCommand = new UnitCommand("enterPayload", "downOpen", Binding.unitCommandEnterPayload, u -> new BoostAI()){{
switchToMove = false;
drawTarget = true;
+19 -5
View File
@@ -12,19 +12,22 @@ import mindustry.input.*;
import mindustry.type.*;
public class UnitStance extends MappableContent{
public static UnitStance stop, holdFire, pursueTarget, patrol, ram, mineAuto;
public static UnitStance stop, holdFire, pursueTarget, patrol, ram, boost, mineAuto;
/** Name of UI icon (from Icon class). */
public String icon;
/** Key to press for this stance. */
public @Nullable KeyBind keybind;
/** Commands that are mutually exclusive to this stance. This is used for convenience, for writing only! */
public Seq<UnitCommand> incompatibleCommands = new Seq<>();
/** Stances that are mutually exclusive to this stance. This is used for convenience, for writing only! */
public Seq<UnitStance> incompatibleStances = new Seq<>();
/** Incompatible stances as a bitset for easier operations. This is where incompatibility is actually stored. */
public Bits incompatibleBits = new Bits(32);
/** If true, this stance can be toggled on or off. */
public boolean toggle = true;
/** Incompatible stances as a bitset for easier operations. This is where incompatibility is actually stored. */
public Bits incompatibleStanceBits = new Bits(32), incompatibleCommandBits = new Bits(32);
public UnitStance(String name, String icon, KeyBind keybind, boolean toggle){
super(name);
this.icon = icon;
@@ -42,9 +45,17 @@ public class UnitStance extends MappableContent{
for(var stance : incompatibleStances){
if(stance == this) continue;
incompatibleBits.set(stance.id);
stance.incompatibleBits.set(id);
incompatibleStanceBits.set(stance.id);
stance.incompatibleStanceBits.set(id);
}
for(var command : incompatibleCommands){
incompatibleCommandBits.set(command.id);
}
}
public boolean isCompatible(@Nullable UnitCommand other){
return other == null || !incompatibleCommandBits.get(other.id);
}
public String localized(){
@@ -75,6 +86,9 @@ public class UnitStance extends MappableContent{
pursueTarget = new UnitStance("pursuetarget", "right", Binding.unitStancePursueTarget);
patrol = new UnitStance("patrol", "refresh", Binding.unitStancePatrol);
ram = new UnitStance("ram", "rightOpen", Binding.unitStanceRam);
boost = new UnitStance("boost", "up", Binding.unitStanceBoost){{
incompatibleCommands.addAll(UnitCommand.rebuildCommand, UnitCommand.repairCommand, UnitCommand.assistCommand);
}};
mineAuto = new UnitStance("mineauto", "settings", null, false);
//Only vanilla items are supported for now
+12 -3
View File
@@ -79,7 +79,7 @@ public class CommandAI extends AIController{
//this happens when an older save reads the default "shoot" stance, or any other removed stance
if(stance == UnitStance.stop) return;
stances.andNot(stance.incompatibleBits);
stances.andNot(stance.incompatibleStanceBits);
stances.set(stance.id);
stanceChanged();
}
@@ -156,8 +156,17 @@ public class CommandAI extends AIController{
commandController.updateUnit();
}else{
defaultBehavior();
//boosting control is not supported, so just don't.
unit.updateBoosting(false);
if(hasStance(UnitStance.boost) && unit.type.canBoost){
//auto land when near target
if(attackTarget != null && unit.within(attackTarget, unit.range())){
unit.updateBoosting(false);
}else{
unit.updateBoosting(true, true);
}
}else{
//boosting control is not supported, so just don't.
unit.updateBoosting(false);
}
}
}