Better handling of missiles splitting to other missiles (#8603)

- Pass a shooter separate to owner into `BulletType#create`. `killShooter` kills the owner while the shooter is passed into the missile ai
- `killShooter` no longer kills already dead units
- `MissileAI` no longer aims at shooter's aim pos if the shooter is dead
This commit is contained in:
MEEPofFaith
2023-06-15 10:57:27 -07:00
committed by GitHub
parent 71caf31543
commit 40c5510205
3 changed files with 13 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ public class MissileAI extends AIController{
float time = unit instanceof TimedKillc t ? t.time() : 1000000f; float time = unit instanceof TimedKillc t ? t.time() : 1000000f;
if(time >= unit.type.homingDelay && shooter != null){ if(time >= unit.type.homingDelay && shooter != null && !shooter.dead()){
unit.lookAt(shooter.aimX, shooter.aimY); unit.lookAt(shooter.aimX, shooter.aimY);
} }

View File

@@ -554,7 +554,7 @@ public class BulletType extends Content implements Cloneable{
public void init(Bullet b){ public void init(Bullet b){
if(killShooter && b.owner() instanceof Healthc h){ if(killShooter && b.owner() instanceof Healthc h && !h.dead()){
h.kill(); h.kill();
} }
@@ -726,6 +726,10 @@ public class BulletType extends Content implements Cloneable{
} }
public @Nullable Bullet create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data, @Nullable Mover mover, float aimX, float aimY){ public @Nullable Bullet create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data, @Nullable Mover mover, float aimX, float aimY){
return create(owner, owner, team, x, y, angle, damage, velocityScl, lifetimeScl, data, mover, aimX, aimY);
}
public @Nullable Bullet create(@Nullable Entityc owner, @Nullable Entityc shooter, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data, @Nullable Mover mover, float aimX, float aimY){
if(spawnUnit != null){ if(spawnUnit != null){
//don't spawn units clientside! //don't spawn units clientside!
if(!net.client()){ if(!net.client()){
@@ -738,17 +742,19 @@ public class BulletType extends Content implements Cloneable{
} }
//assign unit owner //assign unit owner
if(spawned.controller() instanceof MissileAI ai){ if(spawned.controller() instanceof MissileAI ai){
if(owner instanceof Unit unit){ if(shooter instanceof Unit unit){
ai.shooter = unit; ai.shooter = unit;
} }
if(owner instanceof ControlBlock control){ if(shooter instanceof ControlBlock control){
ai.shooter = control.unit(); ai.shooter = control.unit();
} }
} }
spawned.add(); spawned.add();
} }
//Since bullet init is never called, handle killing shooter here
if(killShooter && owner instanceof Healthc h && !h.dead()) h.kill();
//no bullet returned //no bullet returned
return null; return null;

View File

@@ -10,6 +10,7 @@ import arc.math.geom.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.ai.types.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.audio.*; import mindustry.audio.*;
import mindustry.content.*; import mindustry.content.*;
@@ -458,7 +459,8 @@ public class Weapon implements Cloneable{
lifeScl = bullet.scaleLife ? Mathf.clamp(Mathf.dst(bulletX, bulletY, mount.aimX, mount.aimY) / bullet.range) : 1f, lifeScl = bullet.scaleLife ? Mathf.clamp(Mathf.dst(bulletX, bulletY, mount.aimX, mount.aimY) / bullet.range) : 1f,
angle = angleOffset + shootAngle + Mathf.range(inaccuracy + bullet.inaccuracy); angle = angleOffset + shootAngle + Mathf.range(inaccuracy + bullet.inaccuracy);
mount.bullet = bullet.create(unit, unit.team, bulletX, bulletY, angle, -1f, (1f - velocityRnd) + Mathf.random(velocityRnd), lifeScl, null, mover, mount.aimX, mount.aimY); Entityc shooter = unit.controller() instanceof MissileAI ai ? ai.shooter : unit; //Pass the missile's shooter down to its bullets
mount.bullet = bullet.create(unit, shooter, unit.team, bulletX, bulletY, angle, -1f, (1f - velocityRnd) + Mathf.random(velocityRnd), lifeScl, null, mover, mount.aimX, mount.aimY);
handleBullet(unit, mount, mount.bullet); handleBullet(unit, mount, mount.bullet);
if(!continuous){ if(!continuous){