Kill outcomes: falling hull, breakup or air detonation by weapon and target, recorded for replays (#97)
build / mod (push) Successful in 3m54s
build / mod (push) Successful in 3m54s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+93
-19
@@ -20,6 +20,7 @@ mod ew;
|
||||
pub mod lights;
|
||||
mod logistics;
|
||||
mod orders;
|
||||
pub mod outcome;
|
||||
mod units;
|
||||
mod why;
|
||||
pub mod world;
|
||||
@@ -31,6 +32,7 @@ pub use ew::EW_RADIUS;
|
||||
pub use damage::{Comps, Part, PartState};
|
||||
pub use sight::{Ident, Track};
|
||||
use damage::dice;
|
||||
use outcome::{Impact, Outcome};
|
||||
pub use units::{Family, SamKind};
|
||||
use units::Muzzle;
|
||||
pub use raid::{Approach, Aim, RaidOrder};
|
||||
@@ -1375,6 +1377,8 @@ enum Fx {
|
||||
Fireball { pos: DVec3, size: f64, age: u32, life: u32, spin: DQuat },
|
||||
/// A falling piece of a drone.
|
||||
Debris { pos: DVec3, vel: DVec3, rot: DQuat, spin: DQuat, age: u32 },
|
||||
/// A piece thrown off by a breakup or an air detonation: its own drag and life.
|
||||
Piece { pos: DVec3, vel: DVec3, rot: DQuat, piece: outcome::Piece, age: u32 },
|
||||
/// A glowing red tracer round.
|
||||
Tracer { pos: DVec3, vel: DVec3, life: u32 },
|
||||
}
|
||||
@@ -2094,11 +2098,27 @@ impl Sim {
|
||||
self.fx.push((id, Fx::Fireball { pos, size, age: 0, life, spin }));
|
||||
}
|
||||
|
||||
/// A drone hit by air defence: a flash, pieces, and it falls burning.
|
||||
fn shoot_down(&mut self, idx: usize, by: u32, missile: Option<u32>, out: &mut Out) {
|
||||
/// A drone hit by the guns of system `by`.
|
||||
fn shoot_down(&mut self, idx: usize, by: u32, missile: Option<u32>, out: &mut Out) -> Option<Outcome> {
|
||||
let kind = self.sams.iter().find(|s| s.id == by).map_or(SamKind::Gepard, |s| s.kind);
|
||||
let shell = kind.spec().gun.as_ref().map_or(5.0, |g| g.shell);
|
||||
let at = self.drones[idx].pos;
|
||||
self.shoot_down_by(idx, by, missile, Impact::gun(kind, at, shell), out)
|
||||
}
|
||||
|
||||
/// A drone brought down by `imp` from system `by`: how it ends is rolled once (combat randomness, so a
|
||||
/// detonation really means no ground impact), recorded with the kill, and drawn from the visual randomness
|
||||
/// only. The kill is counted here and nowhere else.
|
||||
fn shoot_down_by(&mut self, idx: usize, by: u32, missile: Option<u32>, imp: Impact, out: &mut Out) -> Option<Outcome> {
|
||||
if !self.drones[idx].alive() {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
let dkind = self.drones[idx].kind;
|
||||
let roll = self.rng.f();
|
||||
let outcome = outcome::choose(dkind, &imp, roll);
|
||||
let spec = dkind.spec();
|
||||
// A broken-up target's warhead section may stay whole: it falls on as a wreck (and may go off on landing).
|
||||
let keeps_warhead = outcome == Outcome::Breakup && !spec.decoy && spec.warhead > 0 && self.rng.chance(outcome::WARHEAD_SURVIVES);
|
||||
let sector = self.drones[idx].sector as usize;
|
||||
self.learn(sector, true);
|
||||
let until = self.tick + 70;
|
||||
@@ -2106,33 +2126,72 @@ impl Sim {
|
||||
s.kill_view = Some((self.drones[idx].id, self.drones[idx].pos, until));
|
||||
}
|
||||
if let Some((i, s)) = self.sams.iter().enumerate().find(|(_, s)| s.id == by) {
|
||||
let (drone, kind, pos) = (self.drones[idx].id, self.drones[idx].kind, self.drones[idx].pos);
|
||||
let kill = record::EventKind::Kill { drone, kind, sam: by, sam_kind: s.kind, sam_index: i, missile };
|
||||
let (drone, kind, pos) = (self.drones[idx].id, dkind, self.drones[idx].pos);
|
||||
let kill = record::EventKind::Kill { drone, kind, sam: by, sam_kind: s.kind, sam_index: i, missile, outcome };
|
||||
self.log(pos, kill);
|
||||
}
|
||||
let d = &mut self.drones[idx];
|
||||
let before = d.vel;
|
||||
d.flight = Flight::Falling;
|
||||
d.age = 0;
|
||||
d.vel = d.vel * 0.6 + DVec3::new(0.0, 0.15, 0.0);
|
||||
d.vel = match outcome {
|
||||
Outcome::DisabledFalling => d.vel * 0.6 + DVec3::new(0.0, 0.15, 0.0),
|
||||
_ => d.vel * 0.35 + DVec3::new(0.0, 0.1, 0.0),
|
||||
};
|
||||
let pos = d.pos;
|
||||
let vel = d.vel;
|
||||
self.kills += 1;
|
||||
if let Some(s) = self.sams.iter_mut().find(|s| s.id == by) {
|
||||
s.kills += 1;
|
||||
}
|
||||
// The look of the kill goes by the warhead it blew up (replays use the same).
|
||||
let (size, life, gain) = record::kill_look(self.drones[idx].kind);
|
||||
// The look of the kill goes by the warhead it blew up and by how it ended (replays use the same).
|
||||
let (size, life, gain, sound) = outcome::look(dkind, outcome);
|
||||
self.fireball(pos, size as f64, life / 9);
|
||||
out.particles("minecraft:explosion", pos, 0.6, DVec3::ZERO, 0.0, 4);
|
||||
out.particles("minecraft:large_smoke", pos, 1.0, DVec3::ZERO, 0.06, 25);
|
||||
out.particles("minecraft:firework", pos, 0.3, DVec3::ZERO, 0.35, 30);
|
||||
out.sound("airdef:blast.air", pos, gain, 1.0 + self.vis.f() as f32 * 0.2);
|
||||
for _ in 0..5 {
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let v = vel + DVec3::new(self.vis.s(), self.vis.f() * 0.8, self.vis.s()) * 0.35;
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s() * 0.4, self.vis.s() * 0.4, self.vis.s() * 0.4);
|
||||
self.fx.push((id, Fx::Debris { pos, vel: v, rot: DQuat::IDENTITY, spin, age: 0 }));
|
||||
let pitch = 1.0 + self.vis.f() as f32 * 0.2;
|
||||
match outcome {
|
||||
Outcome::DisabledFalling => {
|
||||
out.particles("minecraft:explosion", pos, 0.6, DVec3::ZERO, 0.0, 4);
|
||||
out.particles("minecraft:large_smoke", pos, 1.0, DVec3::ZERO, 0.06, 25);
|
||||
out.particles("minecraft:firework", pos, 0.3, DVec3::ZERO, 0.35, 30);
|
||||
for _ in 0..5 {
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let v = vel + DVec3::new(self.vis.s(), self.vis.f() * 0.8, self.vis.s()) * 0.35;
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s() * 0.4, self.vis.s() * 0.4, self.vis.s() * 0.4);
|
||||
self.fx.push((id, Fx::Debris { pos, vel: v, rot: DQuat::IDENTITY, spin, age: 0 }));
|
||||
}
|
||||
}
|
||||
Outcome::Breakup => {
|
||||
out.particles("minecraft:explosion", pos, 0.8, DVec3::ZERO, 0.0, 3);
|
||||
out.particles("minecraft:large_smoke", pos, 1.4, DVec3::ZERO, 0.08, 30);
|
||||
out.particles("minecraft:firework", pos, 0.4, DVec3::ZERO, 0.3, 14);
|
||||
}
|
||||
Outcome::AirDetonation => {
|
||||
out.particles("minecraft:flash", pos, 0.0, DVec3::ZERO, 0.0, 1);
|
||||
out.particles("minecraft:explosion_emitter", pos, 0.8, DVec3::ZERO, 0.0, 2);
|
||||
out.particles("minecraft:large_smoke", pos, size * 0.3, DVec3::new(0.0, 0.05, 0.0), 0.07, if self.shader { 20 } else { 40 });
|
||||
out.particles("minecraft:firework", pos, 0.6, DVec3::ZERO, 0.5, 50);
|
||||
// The shock arrives after the flash (`boom` sounds travel); the warhead's blast hurts what is near.
|
||||
out.sound("airdef:boom.sonic", pos, 0.8, 1.2);
|
||||
self.blast_damage(pos, 0, out);
|
||||
}
|
||||
}
|
||||
out.sound(sound, pos, gain, pitch);
|
||||
let seed = self.vis.next();
|
||||
let mut alive = self.fx.iter().filter(|(_, f)| matches!(f, Fx::Piece { .. })).count();
|
||||
for p in outcome::pieces(seed, outcome, before) {
|
||||
if alive + 1 > outcome::PIECES_MAX {
|
||||
break;
|
||||
}
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let rot = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s(), self.vis.s(), self.vis.s());
|
||||
self.fx.push((id, Fx::Piece { pos, vel: p.vel, rot, piece: p, age: 0 }));
|
||||
alive += 1;
|
||||
}
|
||||
if outcome == Outcome::AirDetonation || (outcome == Outcome::Breakup && !keeps_warhead) {
|
||||
// The main mass is gone: nothing falls to the ground and nothing goes off there.
|
||||
self.drones.remove(idx);
|
||||
}
|
||||
Some(outcome)
|
||||
}
|
||||
|
||||
// ------------------------------------------------ air defence
|
||||
@@ -2486,7 +2545,7 @@ impl Sim {
|
||||
}
|
||||
for (t, by) in gun_hits {
|
||||
if let Some(i) = self.drones.iter().position(|d| d.id == t) {
|
||||
self.shoot_down(i, by, None, out);
|
||||
let _ = self.shoot_down(i, by, None, out);
|
||||
}
|
||||
}
|
||||
for i in 0..self.sams.len() {
|
||||
@@ -2679,7 +2738,8 @@ impl Sim {
|
||||
if let Some(t) = target.and_then(|t| self.drones.iter().position(|d| d.id == t)) {
|
||||
self.drones[t].engaged = self.drones[t].engaged.saturating_sub(1);
|
||||
if kill {
|
||||
self.shoot_down(t, sam, Some(mid), out);
|
||||
let (at, closing) = (self.drones[t].pos, (m.vel - self.drones[t].vel).length());
|
||||
let _ = self.shoot_down_by(t, sam, Some(mid), Impact::missile(m.kind, at, closing), out);
|
||||
}
|
||||
}
|
||||
// A missile that lost its target frees it for others.
|
||||
@@ -2730,6 +2790,20 @@ impl Sim {
|
||||
let landed = ground.at(*pos, now).is_some_and(|g| pos.y <= g);
|
||||
!landed && *age < 200
|
||||
}
|
||||
Fx::Piece { pos, vel, rot, piece, age } => {
|
||||
*age += 1;
|
||||
outcome::fly(pos, vel, piece.drag);
|
||||
*rot = piece.spin * *rot;
|
||||
out.model(id, "airdef:debris", *pos, *rot, piece.scale, false);
|
||||
if piece.burns {
|
||||
out.particles("minecraft:large_smoke", *pos, 0.1, DVec3::new(0.0, 0.03, 0.0), 0.01, 1);
|
||||
if *age % 3 == 0 {
|
||||
out.particles("minecraft:flame", *pos, 0.1, DVec3::ZERO, 0.01, 1);
|
||||
}
|
||||
}
|
||||
let landed = ground.at(*pos, now).is_some_and(|g| pos.y <= g);
|
||||
!landed && *age < piece.life
|
||||
}
|
||||
Fx::Tracer { pos, vel, life } => {
|
||||
*pos += *vel;
|
||||
vel.y -= 0.02;
|
||||
|
||||
Reference in New Issue
Block a user