From 06a5201ae899f6624ff597ba921bd6c45e970594 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 22 Sep 2023 18:32:35 -0400 Subject: [PATCH] Payload stances changed to commands --- core/assets/bundles/bundle.properties | 6 +++--- core/src/mindustry/ai/UnitCommand.java | 19 +++++++++++++++++-- core/src/mindustry/ai/UnitStance.java | 5 +---- core/src/mindustry/ai/types/CommandAI.java | 6 +++--- core/src/mindustry/io/TypeIO.java | 4 ++-- core/src/mindustry/type/UnitType.java | 6 +++--- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 9291a3bbe2..bec644f4b5 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -354,15 +354,15 @@ command.rebuild = Rebuild command.assist = Assist Player command.move = Move command.boost = Boost +command.loadUnits = Load Units +command.loadBlocks = Load Blocks +command.unloadPayload = Unload Payload stance.stop = Cancel Orders stance.shoot = Stance: Shoot stance.holdfire = Stance: Hold Fire stance.pursuetarget = Stance: Pursue Target stance.patrol = Stance: Patrol Path stance.ram = Stance: Ram\n[lightgray]Straight line movement, no pathfinding -stance.loadPayload = Stance: Load Units -stance.loadBlocks = Stance: Load Blocks -stance.unloadPayload = Stance: Unload Payload openlink = Open Link copylink = Copy Link back = Back diff --git a/core/src/mindustry/ai/UnitCommand.java b/core/src/mindustry/ai/UnitCommand.java index 20cec778bd..1f048c72ec 100644 --- a/core/src/mindustry/ai/UnitCommand.java +++ b/core/src/mindustry/ai/UnitCommand.java @@ -15,7 +15,7 @@ public class UnitCommand{ public static final UnitCommand - moveCommand = new UnitCommand("move", "right", u -> null){{ + moveCommand = new UnitCommand("move", "right", null){{ drawTarget = true; resetTarget = false; }}, @@ -31,6 +31,21 @@ public class UnitCommand{ switchToMove = false; drawTarget = true; resetTarget = false; + }}, + loadUnitsCommand = new UnitCommand("loadUnits", "download", null){{ + switchToMove = false; + drawTarget = true; + resetTarget = false; + }}, + loadBlocksCommand = new UnitCommand("loadBlocks", "down", null){{ + switchToMove = false; + drawTarget = true; + resetTarget = false; + }}, + unloadPayloadCommand = new UnitCommand("unloadPayload", "upload", null){{ + switchToMove = false; + drawTarget = true; + resetTarget = false; }}; /** Unique ID number. */ @@ -51,7 +66,7 @@ public class UnitCommand{ public UnitCommand(String name, String icon, Func controller){ this.name = name; this.icon = icon; - this.controller = controller; + this.controller = controller == null ? u -> null : controller; id = all.size; all.add(this); diff --git a/core/src/mindustry/ai/UnitStance.java b/core/src/mindustry/ai/UnitStance.java index 53153b87db..5f955c6762 100644 --- a/core/src/mindustry/ai/UnitStance.java +++ b/core/src/mindustry/ai/UnitStance.java @@ -16,10 +16,7 @@ public class UnitStance{ holdFire = new UnitStance("holdfire", "none"), pursueTarget = new UnitStance("pursuetarget", "right"), patrol = new UnitStance("patrol", "refresh"), - ram = new UnitStance("ram", "rightOpen"), - loadPayload = new UnitStance("loadPayload", "download"), - loadBlocks = new UnitStance("loadBlocks", "down"), - unloadPayload = new UnitStance("unloadPayload", "upload"); + ram = new UnitStance("ram", "rightOpen"); /** Unique ID number. */ public final int id; diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index d26a2b7d29..b86345d888 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -114,12 +114,12 @@ public class CommandAI extends AIController{ if(!net.client() && unit instanceof Payloadc pay){ //auto-drop everything - if(stance == UnitStance.unloadPayload && pay.hasPayload()){ + if(command == UnitCommand.unloadPayloadCommand && pay.hasPayload()){ Call.payloadDropped(unit, unit.x, unit.y); } //try to pick up what's under it - if(stance == UnitStance.loadPayload){ + if(command == UnitCommand.loadUnitsCommand){ Unit target = Units.closest(unit.team, unit.x, unit.y, unit.type.hitSize * 2f, u -> u.isAI() && u != unit && u.isGrounded() && pay.canPickup(u) && u.within(unit, u.hitSize + unit.hitSize)); if(target != null){ Call.pickedUnitPayload(unit, target); @@ -127,7 +127,7 @@ public class CommandAI extends AIController{ } //try to pick up a block - if(stance == UnitStance.loadBlocks && (targetPos == null || unit.within(targetPos, 1f))){ + if(command == UnitCommand.loadBlocksCommand && (targetPos == null || unit.within(targetPos, 1f))){ Building build = world.buildWorld(unit.x, unit.y); if(build != null && state.teams.canInteract(unit.team, build.team)){ diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index 885ad79680..047f329d82 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -311,7 +311,7 @@ public class TypeIO{ public static @Nullable UnitCommand readCommand(Reads read){ int val = read.ub(); - return val == 255 ? null : UnitCommand.all.get(val); + return val == 255 || val >= UnitCommand.all.size ? null : UnitCommand.all.get(val); } public static void writeStance(Writes write, @Nullable UnitStance stance){ @@ -321,7 +321,7 @@ public class TypeIO{ public static UnitStance readStance(Reads read){ int val = read.ub(); //never returns null - return val == 255 ? UnitStance.shoot : UnitStance.all.get(val); + return val == 255 || val >= UnitStance.all.size ? UnitStance.shoot : UnitStance.all.get(val); } public static void writeEntity(Writes write, Entityc entity){ diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index e8a01694c5..337bdbcb5f 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -829,6 +829,9 @@ public class UnitType extends UnlockableContent implements Senseable{ if(mineTier > 0){ cmds.add(UnitCommand.mineCommand); } + if(example instanceof Payloadc){ + cmds.addAll(UnitCommand.loadUnitsCommand, UnitCommand.loadBlocksCommand, UnitCommand.unloadPayloadCommand); + } } commands = cmds.toArray(); @@ -840,9 +843,6 @@ public class UnitType extends UnlockableContent implements Senseable{ if(crushDamage > 0){ seq.add(UnitStance.ram); } - if(example instanceof Payloadc){ - seq.addAll(UnitStance.loadPayload, UnitStance.loadBlocks, UnitStance.unloadPayload); - } stances = seq.toArray(UnitStance.class); }else{ stances = new UnitStance[]{UnitStance.stop};