Attack command support, still no pathfinding
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user