Unit payload enter command snapping
This commit is contained in:
@@ -24,6 +24,8 @@ public class UnitCommand extends MappableContent{
|
|||||||
public boolean drawTarget = false;
|
public boolean drawTarget = false;
|
||||||
/** Whether to reset targets when switching to or from this command. */
|
/** Whether to reset targets when switching to or from this command. */
|
||||||
public boolean resetTarget = true;
|
public boolean resetTarget = true;
|
||||||
|
/** Whether to snap the command destination to ally buildings. */
|
||||||
|
public boolean snapToBuilding = false;
|
||||||
/** */
|
/** */
|
||||||
public boolean exactArrival = false;
|
public boolean exactArrival = false;
|
||||||
/** If true, this command refreshes the list of stances when selected TODO: do not use, this will likely be removed later!*/
|
/** If true, this command refreshes the list of stances when selected TODO: do not use, this will likely be removed later!*/
|
||||||
@@ -90,6 +92,7 @@ public class UnitCommand extends MappableContent{
|
|||||||
switchToMove = false;
|
switchToMove = false;
|
||||||
drawTarget = true;
|
drawTarget = true;
|
||||||
resetTarget = false;
|
resetTarget = false;
|
||||||
|
snapToBuilding = true;
|
||||||
}};
|
}};
|
||||||
loadUnitsCommand = new UnitCommand("loadUnits", "upload", Binding.unit_command_load_units, null){{
|
loadUnitsCommand = new UnitCommand("loadUnits", "upload", Binding.unit_command_load_units, null){{
|
||||||
switchToMove = false;
|
switchToMove = false;
|
||||||
|
|||||||
@@ -501,6 +501,12 @@ public class CommandAI extends AIController{
|
|||||||
|
|
||||||
//this is an allocation, but it's relatively rarely called anyway, and outside mutations must be prevented
|
//this is an allocation, but it's relatively rarely called anyway, and outside mutations must be prevented
|
||||||
targetPos = lastTargetPos = pos.cpy();
|
targetPos = lastTargetPos = pos.cpy();
|
||||||
|
if(command != null && command.snapToBuilding){
|
||||||
|
var build = world.buildWorld(targetPos.x, targetPos.y);
|
||||||
|
if(build != null && build.team == unit.team){
|
||||||
|
targetPos.set(build);
|
||||||
|
}
|
||||||
|
}
|
||||||
attackTarget = null;
|
attackTarget = null;
|
||||||
this.stopWhenInRange = stopWhenInRange;
|
this.stopWhenInRange = stopWhenInRange;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -394,6 +394,16 @@ public class Drawf{
|
|||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cross(float x, float y, float radius, Color color){
|
||||||
|
Lines.stroke(3f, Pal.gray.write(Tmp.c3).a(color.a));
|
||||||
|
Lines.lineAngleCenter(x, y, 45f, radius + 1f);
|
||||||
|
Lines.lineAngleCenter(x, y, 135f, radius + 1f);
|
||||||
|
Lines.stroke(1f, color);
|
||||||
|
Lines.lineAngleCenter(x, y, 45f, radius + 1f);
|
||||||
|
Lines.lineAngleCenter(x, y, 135f, radius + 1f);
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
|
||||||
public static void poly(float x, float y, int sides, float radius, float rotation, Color color){
|
public static void poly(float x, float y, int sides, float radius, float rotation, Color color){
|
||||||
Lines.stroke(3f, Pal.gray);
|
Lines.stroke(3f, Pal.gray);
|
||||||
Lines.poly(x, y, sides, radius + 1f, rotation);
|
Lines.poly(x, y, sides, radius + 1f, rotation);
|
||||||
|
|||||||
@@ -1123,26 +1123,29 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
Position lastPos = null;
|
Position lastPos = null;
|
||||||
|
|
||||||
if(unit.controller() instanceof CommandAI ai){
|
if(unit.controller() instanceof CommandAI ai){
|
||||||
|
var cmd = ai.currentCommand();
|
||||||
lastPos = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
|
lastPos = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
|
||||||
|
|
||||||
if(flying && ai.attackTarget != null && ai.currentCommand().drawTarget){
|
if(flying && ai.attackTarget != null && cmd.drawTarget){
|
||||||
Drawf.target(ai.attackTarget.getX(), ai.attackTarget.getY(), 6f, Pal.remove);
|
Drawf.target(ai.attackTarget.getX(), ai.attackTarget.getY(), 6f, Pal.remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unit.isFlying() != flying) continue;
|
if(unit.isFlying() != flying) continue;
|
||||||
|
|
||||||
//draw target line
|
//draw target line
|
||||||
if(ai.targetPos != null && ai.currentCommand().drawTarget){
|
if(ai.targetPos != null && cmd.drawTarget){
|
||||||
Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
|
Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
|
||||||
Drawf.limitLine(unit, lineDest, unit.hitSize / unitSelectRadScl + 1f, lineLimit, color.write(Tmp.c1).a(alpha));
|
Drawf.limitLine(unit, lineDest, unit.hitSize / unitSelectRadScl + 1f, lineLimit, color.write(Tmp.c1).a(alpha));
|
||||||
|
|
||||||
if(ai.attackTarget == null){
|
if(ai.attackTarget == null){
|
||||||
Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f, color.write(Tmp.c1).a(alpha));
|
Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f, color.write(Tmp.c1).a(alpha));
|
||||||
|
|
||||||
if(ai.currentCommand() == UnitCommand.enterPayloadCommand){
|
if(cmd == UnitCommand.enterPayloadCommand){
|
||||||
var build = world.buildWorld(lineDest.getX(), lineDest.getY());
|
var build = world.buildWorld(lineDest.getX(), lineDest.getY());
|
||||||
if(build != null && build.block.acceptsUnitPayloads && build.team == unit.team){
|
if(build != null && build.block.acceptsUnitPayloads && build.team == unit.team){
|
||||||
Drawf.selected(build, color);
|
Drawf.selected(build, color);
|
||||||
|
}else{
|
||||||
|
Drawf.cross(lineDest.getX(), lineDest.getY(), 7f, Pal.remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user