WIP command order system

This commit is contained in:
Anuken
2022-07-30 21:01:07 -04:00
parent a326e36bbe
commit 55edd53f84
11 changed files with 327 additions and 62 deletions

View File

@@ -14,6 +14,7 @@ import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.ai.*;
import mindustry.ai.types.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
@@ -228,6 +229,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
for(int id : unitIds){
Unit unit = Groups.unit.getByID(id);
if(unit != null && unit.team == player.team() && unit.controller() instanceof CommandAI ai){
//implicitly order it to move
ai.command(UnitCommand.moveCommand);
if(teamTarget != null && teamTarget.team() != player.team()){
ai.commandTarget(teamTarget);
}else if(posTarget != null){
@@ -246,6 +251,28 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void setUnitCommand(Player player, int[] unitIds, UnitCommand command){
if(player == null || unitIds == null || command == null) return;
if(net.server() && !netServer.admins.allowAction(player, ActionType.commandUnits, event -> {
event.unitIDs = unitIds;
})){
throw new ValidateException(player, "Player cannot command units.");
}
for(int id : unitIds){
Unit unit = Groups.unit.getByID(id);
if(unit != null && unit.team == player.team() && unit.controller() instanceof CommandAI ai){
ai.command(command);
//reset targeting
ai.targetPos = null;
ai.attackTarget = null;
unit.lastCommanded = player.coloredName();
}
}
}
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void commandBuilding(Player player, Building build, Vec2 target){
if(player == null || build == null || build.team != player.team() || !build.block.commandable || target == null) return;
@@ -814,7 +841,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
for(Unit unit : selectedUnits){
CommandAI ai = unit.command();
//draw target line
if(ai.targetPos != null){
if(ai.targetPos != null && ai.command == UnitCommand.moveCommand){
Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
Drawf.limitLine(unit, lineDest, unit.hitSize / 2f, 3.5f);
@@ -825,7 +852,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Drawf.square(unit.x, unit.y, unit.hitSize / 1.4f + 1f);
if(ai.attackTarget != null){
//TODO when to draw, when to not?
if(ai.attackTarget != null && ai.command == UnitCommand.moveCommand){
Drawf.target(ai.attackTarget.getX(), ai.attackTarget.getY(), 6f, Pal.remove);
}
}