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

@@ -70,7 +70,7 @@ public class ControlPathfinder implements Runnable{
//}
for(var entry : requests){
entry.value.update(maxUpdate / requests.size);
}
}

View File

@@ -7,29 +7,45 @@ import mindustry.gen.*;
public class CommandAI extends AIController{
public @Nullable Vec2 targetPos;
public @Nullable Teamc attackTarget;
@Override
public void updateUnit(){
updateVisuals();
updateTargeting();
//TODO
if(attackTarget != null){
if(targetPos == null) targetPos = new Vec2();
targetPos.set(attackTarget);
}
if(targetPos != null){
//if(unit.isFlying()){
moveTo(targetPos, 5f);
//}
moveTo(targetPos, attackTarget != null ? unit.type.range - 10f : 5f);
if(unit.isFlying()){
unit.lookAt(targetPos);
}else{
faceTarget();
}
}else if(target != null){
faceTarget();
}
}
@Override
public Teamc findMainTarget(float x, float y, float range, boolean air, boolean ground){
return attackTarget == null ? super.findMainTarget(x, y, range, air, ground) : attackTarget;
}
public void commandPosition(Vec2 pos){
targetPos = pos;
attackTarget = null;
}
public void commandTarget(Teamc moveTo){
//TODO
attackTarget = moveTo;
}
}

View File

@@ -183,11 +183,17 @@ public class Fx{
}
}),
moveCommand = new Effect(15, e -> {
moveCommand = new Effect(20, e -> {
color(Pal.command);
stroke(e.fout() * 5f);
Lines.circle(e.x, e.y, 6f + e.fin() * 2f);
}).layer(Layer.effect - 20f),
}).layer(Layer.overlayUI),
attackCommand = new Effect(20, e -> {
color(Pal.remove);
stroke(e.fout() * 5f);
poly(e.x, e.y, 4, 7f + e.fin() * 2f);
}).layer(Layer.overlayUI),
commandSend = new Effect(28, e -> {
color(Pal.command);

View File

@@ -3269,6 +3269,7 @@ public class UnitTypes{
health = 700f;
armor = 3f;
hitSize = 12f;
buildBeamOffset = 8f;
engineOffset = 7.5f;
engineSize = 3.4f;

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();