Commandable blocks
This commit is contained in:
@@ -545,6 +545,16 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
|
||||
}
|
||||
|
||||
/** Called when this building receives a position command. Requires a commandable block. */
|
||||
public void onCommand(Vec2 target){
|
||||
|
||||
}
|
||||
|
||||
/** @return the position that this block points to for commands, or null. */
|
||||
public @Nullable Vec2 getCommandPosition(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handleUnitPayload(Unit unit, Cons<Payload> grabber){
|
||||
Fx.spawn.at(unit);
|
||||
|
||||
|
||||
@@ -281,6 +281,14 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
return controller instanceof CommandAI;
|
||||
}
|
||||
|
||||
public CommandAI command(){
|
||||
if(controller instanceof CommandAI ai){
|
||||
return ai;
|
||||
}else{
|
||||
throw new IllegalArgumentException("Unit cannot be commanded - check isCommandable() first.");
|
||||
}
|
||||
}
|
||||
|
||||
public int count(){
|
||||
return team.data().countType(type);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,13 @@ import static mindustry.Vars.*;
|
||||
|
||||
public class AIController implements UnitController{
|
||||
protected static final Vec2 vec = new Vec2();
|
||||
protected static final float rotateBackTimer = 60f * 5f;
|
||||
protected static final int timerTarget = 0, timerTarget2 = 1, timerTarget3 = 2, timerTarget4 = 3;
|
||||
|
||||
protected Unit unit;
|
||||
protected Interval timer = new Interval(4);
|
||||
protected AIController fallback;
|
||||
protected float noTargetTime;
|
||||
|
||||
/** main target that is being faced */
|
||||
protected Teamc target;
|
||||
@@ -128,8 +130,12 @@ public class AIController implements UnitController{
|
||||
target = findMainTarget(unit.x, unit.y, unit.range(), unit.type.targetAir, unit.type.targetGround);
|
||||
}
|
||||
|
||||
noTargetTime += Time.delta;
|
||||
|
||||
if(invalid(target)){
|
||||
target = null;
|
||||
}else{
|
||||
noTargetTime = 0f;
|
||||
}
|
||||
|
||||
unit.isShooting = false;
|
||||
@@ -168,6 +174,13 @@ public class AIController implements UnitController{
|
||||
|
||||
unit.isShooting |= (mount.shoot = mount.rotate = shoot);
|
||||
|
||||
if(mount.target == null && !shoot && !Angles.within(mount.rotation, 0f, 0.01f) && noTargetTime >= rotateBackTimer){
|
||||
mount.rotate = true;
|
||||
Tmp.v1.trns(unit.rotation, 5f);
|
||||
mount.aimX = mountX + Tmp.v1.x;
|
||||
mount.aimY = mountY + Tmp.v1.y;
|
||||
}
|
||||
|
||||
if(shoot){
|
||||
unit.aimX = mount.aimX;
|
||||
unit.aimY = mount.aimY;
|
||||
|
||||
Reference in New Issue
Block a user