Attack command support, still no pathfinding

This commit is contained in:
Anuken
2022-02-08 20:55:21 -05:00
parent d1eae2d1a2
commit c3c0b95024
6 changed files with 62 additions and 10 deletions

View File

@@ -675,15 +675,30 @@ public class DesktopInput extends InputHandler{
}
}else if(selectedUnits.size > 0){
//move to location - TODO right click instead?
//TODO all this needs to be synced, done with packets, etc
Vec2 target = input.mouseWorld().cpy();
for(var sel : selectedUnits){
((CommandAI)sel.controller()).commandPosition(target);
Teamc build = world.buildWorld(target.x, target.y);
if(build == null || build.team() == player.team()){
build = selectedEnemyUnit(target.x, target.y);
}
Fx.moveCommand.at(target);
if(build != null && build.team() != player.team()){
for(var sel : selectedUnits){
((CommandAI)sel.controller()).commandTarget(build);
}
Fx.attackCommand.at(build);
}else{
for(var sel : selectedUnits){
((CommandAI)sel.controller()).commandPosition(target);
}
Fx.moveCommand.at(target);
}
}
return super.tap(x, y, count, button);

View File

@@ -1199,6 +1199,20 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return tmpUnits.min(u -> u.isCommandable(), u -> u.dst(x, y) - u.hitSize/2f);
}
public @Nullable Unit selectedEnemyUnit(float x, float y){
tmpUnits.clear();
float rad = 4f;
Seq<TeamData> data = state.teams.present;
for(int i = 0; i < data.size; i++){
if(data.items[i].team != player.team()){
data.items[i].tree().intersect(x - rad / 2f, y - rad / 2f, rad, rad, tmpUnits);
}
}
return tmpUnits.min(u -> u.dst(x, y) - u.hitSize/2f);
}
public Seq<Unit> selectedCommandUnits(float x, float y, float w, float h){
var tree = player.team().data().tree();
tmpUnits.clear();