Fixed commanded units attacking invalid targets
This commit is contained in:
@@ -409,6 +409,10 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
return controller instanceof CommandAI;
|
||||
}
|
||||
|
||||
public boolean canTarget(Unit other){
|
||||
return other != null && other.checkTarget(type.targetAir, type.targetGround);
|
||||
}
|
||||
|
||||
public CommandAI command(){
|
||||
if(controller instanceof CommandAI ai){
|
||||
return ai;
|
||||
|
||||
@@ -387,8 +387,19 @@ public class DesktopInput extends InputHandler{
|
||||
cursorType = ui.drillCursor;
|
||||
}
|
||||
|
||||
if(commandMode && selectedUnits.any() && ((cursor.build != null && !cursor.build.inFogTo(player.team()) && cursor.build.team != player.team()) || (selectedEnemyUnit(input.mouseWorldX(), input.mouseWorldY()) != null))){
|
||||
cursorType = ui.targetCursor;
|
||||
if(commandMode && selectedUnits.any()){
|
||||
boolean canAttack = (cursor.build != null && !cursor.build.inFogTo(player.team()) && cursor.build.team != player.team());
|
||||
|
||||
if(!canAttack){
|
||||
var unit = selectedEnemyUnit(input.mouseWorldX(), input.mouseWorldY());
|
||||
if(unit != null){
|
||||
canAttack = selectedUnits.contains(u -> u.canTarget(unit));
|
||||
}
|
||||
}
|
||||
|
||||
if(canAttack){
|
||||
cursorType = ui.targetCursor;
|
||||
}
|
||||
}
|
||||
|
||||
if(getPlan(cursor.x, cursor.y) != null && mode == none){
|
||||
|
||||
@@ -225,6 +225,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
|
||||
Teamc teamTarget = buildTarget == null ? unitTarget : buildTarget;
|
||||
boolean anyCommandedTarget = false;
|
||||
|
||||
for(int id : unitIds){
|
||||
Unit unit = Groups.unit.getByID(id);
|
||||
@@ -235,12 +236,15 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
ai.command(UnitCommand.moveCommand);
|
||||
}
|
||||
|
||||
if(teamTarget != null && teamTarget.team() != player.team()){
|
||||
ai.commandTarget(teamTarget);
|
||||
if(teamTarget != null && teamTarget.team() != player.team() &&
|
||||
!(teamTarget instanceof Unit u && !unit.canTarget(u)) && !(teamTarget instanceof Building && !unit.type.targetGround)){
|
||||
|
||||
anyCommandedTarget = true;
|
||||
ai.commandTarget(teamTarget);
|
||||
}else if(posTarget != null){
|
||||
ai.commandPosition(posTarget);
|
||||
}
|
||||
|
||||
unit.lastCommanded = player.coloredName();
|
||||
|
||||
//remove when other player command
|
||||
@@ -251,7 +255,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
|
||||
if(unitIds.length > 0 && player == Vars.player && !state.isPaused()){
|
||||
if(teamTarget != null){
|
||||
if(anyCommandedTarget){
|
||||
Fx.attackCommand.at(teamTarget);
|
||||
}else{
|
||||
Fx.moveCommand.at(posTarget);
|
||||
|
||||
@@ -601,6 +601,8 @@ public class UnitType extends UnlockableContent implements Senseable{
|
||||
stats.add(Stat.size, StatValues.squared(hitSize / tilesize, StatUnit.blocks));
|
||||
stats.add(Stat.itemCapacity, itemCapacity);
|
||||
stats.add(Stat.range, (int)(maxRange / tilesize), StatUnit.blocks);
|
||||
stats.add(Stat.targetsAir, targetAir);
|
||||
stats.add(Stat.targetsGround, targetGround);
|
||||
|
||||
if(abilities.any()){
|
||||
stats.add(Stat.abilities, StatValues.abilities(abilities));
|
||||
|
||||
Reference in New Issue
Block a user