mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-06 08:57:45 +07:00
Patrol + pursue target stances
This commit is contained in:
parent
fccf6847c1
commit
9d9d5d2e18
@ -356,6 +356,8 @@ command.boost = Boost
|
|||||||
stance.stop = Cancel Orders
|
stance.stop = Cancel Orders
|
||||||
stance.shoot = Stance: Shoot
|
stance.shoot = Stance: Shoot
|
||||||
stance.holdfire = Stance: Hold Fire
|
stance.holdfire = Stance: Hold Fire
|
||||||
|
stance.pursuetarget = Stance: Pursue Target
|
||||||
|
stance.patrol = Stance: Patrol Path
|
||||||
openlink = Open Link
|
openlink = Open Link
|
||||||
copylink = Copy Link
|
copylink = Copy Link
|
||||||
back = Back
|
back = Back
|
||||||
|
@ -13,7 +13,9 @@ public class UnitStance{
|
|||||||
|
|
||||||
stopStance = new UnitStance("stop", "cancel"), //not a real stance, cannot be selected, just cancels ordewrs
|
stopStance = new UnitStance("stop", "cancel"), //not a real stance, cannot be selected, just cancels ordewrs
|
||||||
shootStance = new UnitStance("shoot", "commandAttack"),
|
shootStance = new UnitStance("shoot", "commandAttack"),
|
||||||
holdFireStance = new UnitStance("holdfire", "none");
|
holdFireStance = new UnitStance("holdfire", "none"),
|
||||||
|
pursueTarget = new UnitStance("pursuetarget", "right"),
|
||||||
|
patrol = new UnitStance("patrol", "refresh");
|
||||||
|
|
||||||
/** Unique ID number. */
|
/** Unique ID number. */
|
||||||
public final int id;
|
public final int id;
|
||||||
|
@ -67,6 +67,10 @@ public class CommandAI extends AIController{
|
|||||||
//this should not be possible
|
//this should not be possible
|
||||||
if(stance == UnitStance.stopStance) stance = UnitStance.shootStance;
|
if(stance == UnitStance.stopStance) stance = UnitStance.shootStance;
|
||||||
|
|
||||||
|
if(stance == UnitStance.pursueTarget && target != null && attackTarget == null && targetPos == null){
|
||||||
|
commandTarget(target, false);
|
||||||
|
}
|
||||||
|
|
||||||
//remove invalid targets
|
//remove invalid targets
|
||||||
if(commandQueue.any()){
|
if(commandQueue.any()){
|
||||||
commandQueue.removeAll(e -> e instanceof Healthc h && !h.isValid());
|
commandQueue.removeAll(e -> e instanceof Healthc h && !h.isValid());
|
||||||
@ -194,11 +198,13 @@ public class CommandAI extends AIController{
|
|||||||
target = attackTarget;
|
target = attackTarget;
|
||||||
circleAttack(80f);
|
circleAttack(80f);
|
||||||
}else{
|
}else{
|
||||||
|
boolean isFinalPoint = targetPos.epsilonEquals(vecOut, 4.1f) && commandQueue.size == 0;
|
||||||
|
|
||||||
moveTo(vecOut,
|
moveTo(vecOut,
|
||||||
attackTarget != null && unit.within(attackTarget, engageRange) ? engageRange :
|
attackTarget != null && unit.within(attackTarget, engageRange) ? engageRange :
|
||||||
unit.isGrounded() ? 0f :
|
unit.isGrounded() ? 0f :
|
||||||
attackTarget != null ? engageRange :
|
attackTarget != null ? engageRange :
|
||||||
0f, unit.isFlying() ? 40f : 100f, false, null, targetPos.epsilonEquals(vecOut, 4.1f));
|
0f, unit.isFlying() ? 40f : 100f, false, null, isFinalPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,6 +249,7 @@ public class CommandAI extends AIController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void finishPath(){
|
void finishPath(){
|
||||||
|
Vec2 prev = targetPos;
|
||||||
targetPos = null;
|
targetPos = null;
|
||||||
if(commandQueue.size > 0){
|
if(commandQueue.size > 0){
|
||||||
var next = commandQueue.remove(0);
|
var next = commandQueue.remove(0);
|
||||||
@ -251,6 +258,10 @@ public class CommandAI extends AIController{
|
|||||||
}else if(next instanceof Vec2 position){
|
}else if(next instanceof Vec2 position){
|
||||||
commandPosition(position);
|
commandPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(prev != null && stance == UnitStance.patrol){
|
||||||
|
commandQueue.add(prev.cpy());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1285,6 +1285,7 @@ public class UnitTypes{
|
|||||||
lowAltitude = true;
|
lowAltitude = true;
|
||||||
|
|
||||||
ammoType = new PowerAmmoType(900);
|
ammoType = new PowerAmmoType(900);
|
||||||
|
stances = new UnitStance[]{UnitStance.stopStance, UnitStance.shootStance, UnitStance.holdFireStance};
|
||||||
|
|
||||||
mineTier = 2;
|
mineTier = 2;
|
||||||
mineSpeed = 3.5f;
|
mineSpeed = 3.5f;
|
||||||
@ -1344,6 +1345,7 @@ public class UnitTypes{
|
|||||||
isEnemy = false;
|
isEnemy = false;
|
||||||
|
|
||||||
ammoType = new PowerAmmoType(1100);
|
ammoType = new PowerAmmoType(1100);
|
||||||
|
stances = new UnitStance[]{UnitStance.stopStance, UnitStance.shootStance, UnitStance.holdFireStance};
|
||||||
|
|
||||||
weapons.add(
|
weapons.add(
|
||||||
new Weapon("heal-weapon-mount"){{
|
new Weapon("heal-weapon-mount"){{
|
||||||
|
@ -122,6 +122,18 @@ public class ContentParser{
|
|||||||
throw new IllegalArgumentException("Unit commands must be strings.");
|
throw new IllegalArgumentException("Unit commands must be strings.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
put(UnitStance.class, (type, data) -> {
|
||||||
|
if(data.isString()){
|
||||||
|
var cmd = UnitStance.all.find(u -> u.name.equals(data.asString()));
|
||||||
|
if(cmd != null){
|
||||||
|
return cmd;
|
||||||
|
}else{
|
||||||
|
throw new IllegalArgumentException("Unknown unit stance name: " + data.asString());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
throw new IllegalArgumentException("Unit stances must be strings.");
|
||||||
|
}
|
||||||
|
});
|
||||||
put(BulletType.class, (type, data) -> {
|
put(BulletType.class, (type, data) -> {
|
||||||
if(data.isString()){
|
if(data.isString()){
|
||||||
return field(Bullets.class, data);
|
return field(Bullets.class, data);
|
||||||
|
@ -836,9 +836,9 @@ public class UnitType extends UnlockableContent implements Senseable{
|
|||||||
|
|
||||||
if(stances.length == 0){
|
if(stances.length == 0){
|
||||||
if(canAttack){
|
if(canAttack){
|
||||||
stances = new UnitStance[]{UnitStance.stopStance, UnitStance.shootStance, UnitStance.holdFireStance};
|
stances = new UnitStance[]{UnitStance.stopStance, UnitStance.shootStance, UnitStance.holdFireStance, UnitStance.pursueTarget, UnitStance.patrol};
|
||||||
}else{
|
}else{
|
||||||
stances = new UnitStance[]{UnitStance.stopStance, UnitStance.shootStance};
|
stances = new UnitStance[]{UnitStance.stopStance};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,12 +524,15 @@ public class PlacementFragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//list stances
|
//list stances
|
||||||
if(stances.size > 0){
|
if(stances.size > 1){
|
||||||
u.row();
|
u.row();
|
||||||
|
|
||||||
u.table(coms -> {
|
u.table(coms -> {
|
||||||
coms.left();
|
coms.left();
|
||||||
for(var stance : stances){
|
for(var stance : stances){
|
||||||
|
//TODO: patrolling is pointless on mobile since you can't queue commands
|
||||||
|
if(stance == UnitStance.patrol && mobile) continue;
|
||||||
|
|
||||||
coms.button(Icon.icons.get(stance.icon, Icon.cancel), Styles.clearNoneTogglei, () -> {
|
coms.button(Icon.icons.get(stance.icon, Icon.cancel), Styles.clearNoneTogglei, () -> {
|
||||||
IntSeq ids = new IntSeq();
|
IntSeq ids = new IntSeq();
|
||||||
for(var unit : units){
|
for(var unit : units){
|
||||||
|
Loading…
Reference in New Issue
Block a user