diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index e6de644bf1..9446e72aa3 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -55,7 +55,7 @@ public class CommandAI extends AIController{ /** Attempts to assign a command to this unit. If not supported by the unit type, does nothing. */ public void command(UnitCommand command){ - if(Structs.contains(unit.type.commands, command)){ + if(unit.type.commands.contains(command)){ //clear old state. unit.mineTile = null; unit.clearBuilding(); @@ -88,8 +88,8 @@ public class CommandAI extends AIController{ } //assign defaults - if(command == null && unit.type.commands.length > 0){ - command = unit.type.defaultCommand == null ? unit.type.commands[0] : unit.type.defaultCommand; + if(command == null && unit.type.commands.size > 0){ + command = unit.type.defaultCommand == null ? unit.type.commands.first() : unit.type.defaultCommand; } //update command controller based on index. diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 9e498b65be..e8c4cb6138 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -303,11 +303,11 @@ public class UnitType extends UnlockableContent implements Senseable{ /** A value of false is used to hide command changing UI in unit factories. */ public boolean allowChangeCommands = true; /** Commands available to this unit through RTS controls. An empty array means commands will be assigned based on unit capabilities in init(). */ - public UnitCommand[] commands = {}; + public Seq commands = new Seq<>(); /** Command to assign to this unit upon creation. Null indicates the first command in the array. */ public @Nullable UnitCommand defaultCommand; /** Stances this unit can have. An empty array means stances will be assigned based on unit capabilities in init(). */ - public UnitStance[] stances = {}; + public Seq stances = new Seq<>(); /** color for outline generated around sprites */ public Color outlineColor = Pal.darkerMetal; @@ -828,53 +828,49 @@ public class UnitType extends UnlockableContent implements Senseable{ canAttack = weapons.contains(w -> !w.noAttack); //assign default commands. - if(commands.length == 0){ - Seq cmds = new Seq<>(UnitCommand.class); + if(commands.size == 0){ - cmds.add(UnitCommand.moveCommand, UnitCommand.enterPayloadCommand); + commands.add(UnitCommand.moveCommand, UnitCommand.enterPayloadCommand); if(canBoost){ - cmds.add(UnitCommand.boostCommand); + commands.add(UnitCommand.boostCommand); if(buildSpeed > 0f){ - cmds.add(UnitCommand.rebuildCommand, UnitCommand.assistCommand); + commands.add(UnitCommand.rebuildCommand, UnitCommand.assistCommand); } } //healing, mining and building is only supported for flying units; pathfinding to ambiguously reachable locations is hard. if(flying){ if(canHeal){ - cmds.add(UnitCommand.repairCommand); + commands.add(UnitCommand.repairCommand); } if(buildSpeed > 0){ - cmds.add(UnitCommand.rebuildCommand, UnitCommand.assistCommand); + commands.add(UnitCommand.rebuildCommand, UnitCommand.assistCommand); } if(mineTier > 0){ - cmds.add(UnitCommand.mineCommand); + commands.add(UnitCommand.mineCommand); } if(example instanceof Payloadc){ - cmds.addAll(UnitCommand.loadUnitsCommand, UnitCommand.loadBlocksCommand, UnitCommand.unloadPayloadCommand, UnitCommand.loopPayloadCommand); + commands.addAll(UnitCommand.loadUnitsCommand, UnitCommand.loadBlocksCommand, UnitCommand.unloadPayloadCommand, UnitCommand.loopPayloadCommand); } } - - commands = cmds.toArray(); } - if(defaultCommand == null && commands.length > 0){ - defaultCommand = commands[0]; + if(defaultCommand == null && commands.size > 0){ + defaultCommand = commands.first(); } - if(stances.length == 0){ + if(stances.size == 0){ if(canAttack){ - Seq seq = Seq.with(UnitStance.stop, UnitStance.shoot, UnitStance.holdFire, UnitStance.pursueTarget, UnitStance.patrol); + stances.addAll(UnitStance.stop, UnitStance.shoot, UnitStance.holdFire, UnitStance.pursueTarget, UnitStance.patrol); if(!flying){ - seq.add(UnitStance.ram); + stances.add(UnitStance.ram); } - stances = seq.toArray(UnitStance.class); }else{ - stances = new UnitStance[]{UnitStance.stop, UnitStance.patrol}; + stances.addAll(UnitStance.stop, UnitStance.patrol); } } diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index a5a1063bd3..0fac1453cf 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -525,7 +525,7 @@ public class PlacementFragment{ firstCommand = true; }else{ //remove commands that this next unit type doesn't have - commands.removeAll(com -> !Structs.contains(type.commands, com)); + commands.removeAll(com -> !type.commands.contains(com)); } if(!firstStance){ @@ -533,7 +533,7 @@ public class PlacementFragment{ firstStance = true; }else{ //remove commands that this next unit type doesn't have - stances.removeAll(st -> !Structs.contains(type.stances, st)); + stances.removeAll(st -> !type.stances.contains(st)); } } } diff --git a/core/src/mindustry/world/blocks/units/Reconstructor.java b/core/src/mindustry/world/blocks/units/Reconstructor.java index 023270260b..8c243d878c 100644 --- a/core/src/mindustry/world/blocks/units/Reconstructor.java +++ b/core/src/mindustry/world/blocks/units/Reconstructor.java @@ -168,7 +168,7 @@ public class Reconstructor extends UnitBlock{ public boolean canSetCommand(){ var output = unit(); - return output != null && output.commands.length > 1 && output.allowChangeCommands; + return output != null && output.commands.size > 1 && output.allowChangeCommands; } @Override diff --git a/core/src/mindustry/world/blocks/units/UnitFactory.java b/core/src/mindustry/world/blocks/units/UnitFactory.java index 4120ac278d..c058016d91 100644 --- a/core/src/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/mindustry/world/blocks/units/UnitFactory.java @@ -54,7 +54,7 @@ public class UnitFactory extends UnitBlock{ if(build.currentPlan == i) return; build.currentPlan = i < 0 || i >= plans.size ? -1 : i; build.progress = 0; - if(build.command != null && !Structs.contains(build.unit().commands, build.command)){ + if(build.command != null && !build.unit().commands.contains(build.command)){ build.command = null; } }); @@ -66,7 +66,7 @@ public class UnitFactory extends UnitBlock{ if(build.currentPlan == next) return; build.currentPlan = next; build.progress = 0; - if(build.command != null && !Structs.contains(val.commands, build.command)){ + if(build.command != null && !val.commands.contains(build.command)){ build.command = null; } }); @@ -197,9 +197,9 @@ public class UnitFactory extends UnitBlock{ public boolean canSetCommand(){ var output = unit(); - return output != null && output.commands.length > 1 && output.allowChangeCommands && + return output != null && output.commands.size > 1 && output.allowChangeCommands && //to avoid cluttering UI, don't show command selection for "standard" units that only have two commands. - !(output.commands.length == 2 && output.commands[1] == UnitCommand.enterPayloadCommand); + !(output.commands.size == 2 && output.commands.get(1) == UnitCommand.enterPayloadCommand); } @Override @@ -275,8 +275,8 @@ public class UnitFactory extends UnitBlock{ } } - if(list.length < columns){ - for(int j = 0; j < (columns - list.length); j++){ + if(list.size < columns){ + for(int j = 0; j < (columns - list.size); j++){ commands.add().size(40f); } }