Combat fixes: exact-ray answers tied to their segment and block (#73), no fuse kill through a wall while waiting (#74), seeker needs confirmed sight and stops reading true velocity (#75), combat RNG and ids independent of graphics (#85), saved layouts validated whole before the scene is touched, refused autosave kept (#86)
build / mod (push) Successful in 3m48s
build / mod (push) Successful in 3m48s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+54
-24
@@ -1393,7 +1393,13 @@ pub struct Sim {
|
||||
/// The next blast's id (separate from `next`, so the other units' ids stay as they were).
|
||||
blast_seq: u32,
|
||||
next: u32,
|
||||
/// The combat randomness: what is rolled for aim, hits, damage and raids. Drawing, sound and camera never
|
||||
/// spend it (#85).
|
||||
pub rng: Rng,
|
||||
/// The decorative randomness (flicker, pitch, spin, scatter of tracers and debris), and the ids of what is
|
||||
/// only drawn: neither moves with the graphics settings of the combat.
|
||||
vis: Rng,
|
||||
fx_next: u32,
|
||||
pub tick: u64,
|
||||
/// The game's tick number (the one `tick` is called with), for a recording to know the world's time by.
|
||||
pub engine_tick: u64,
|
||||
@@ -1447,6 +1453,15 @@ pub struct Sim {
|
||||
|
||||
/// Ids: objects get multiples of 16, their parts the low bits.
|
||||
const PARTS: u32 = 16;
|
||||
/// Ids of what is only drawn (debris, fireball models, tracers) come from their own range and counter, so that
|
||||
/// the number of effects never moves the ids of the combat's objects (#85).
|
||||
const FX_IDS: u32 = 0x2000_0000;
|
||||
|
||||
/// The next id for a drawn-only thing.
|
||||
fn fx_ident(counter: &mut u32) -> u32 {
|
||||
*counter = (*counter + 1) % 0x0100_0000;
|
||||
FX_IDS + *counter * PARTS
|
||||
}
|
||||
|
||||
impl Sim {
|
||||
pub fn new(seed: u64) -> Self {
|
||||
@@ -1461,6 +1476,8 @@ impl Sim {
|
||||
blast_seq: 0,
|
||||
next: 1,
|
||||
rng: Rng::new(seed),
|
||||
vis: Rng::new(seed ^ 0x5DEE_CE66_D1CE_4E5B),
|
||||
fx_next: 0,
|
||||
tick: 0,
|
||||
engine_tick: 0,
|
||||
kills: 0,
|
||||
@@ -1491,6 +1508,14 @@ impl Sim {
|
||||
spot_hd: false,
|
||||
}
|
||||
}
|
||||
/// A scenario's start: the combat generator, the dice of stateless rolls and the decorative generator all
|
||||
/// come from `state` alone, whatever was played before. The clock and the id counter go on (what is in the
|
||||
/// world keeps its ids), so a restart repeats the draws, not the whole fight.
|
||||
pub fn reseed(&mut self, state: u64) {
|
||||
self.rng = Rng::new(state);
|
||||
self.vis = Rng::new(state ^ 0x5DEE_CE66_D1CE_4E5B);
|
||||
self.seed = state.wrapping_mul(0x2545_F491_4F6C_DD1D) | 1;
|
||||
}
|
||||
pub fn id(&mut self) -> u32 {
|
||||
self.next += 1;
|
||||
self.next * PARTS
|
||||
@@ -1645,7 +1670,7 @@ impl Sim {
|
||||
} else if let Some(t) = ground.unread(&sweep, &mut d.hold, below.is_some_and(|g| from.y < g + 12.0)) {
|
||||
d.pos = from.lerp(d.pos, t);
|
||||
}
|
||||
if self.rng.chance(0.5) {
|
||||
if self.vis.chance(0.5) {
|
||||
out.particles("minecraft:large_smoke", d.pos, 0.2, DVec3::new(0.0, 0.05, 0.0), 0.02, 1);
|
||||
}
|
||||
out.particles("minecraft:flame", d.pos, 0.25, DVec3::ZERO, 0.02, 2);
|
||||
@@ -1976,14 +2001,14 @@ impl Sim {
|
||||
}
|
||||
Engine::Jet(up, back, size) => {
|
||||
let at = d.pos + rot * DVec3::new(0.0, up * s, back * s);
|
||||
let flicker = 0.7 + 0.3 * self.rng.f();
|
||||
let flicker = 0.7 + 0.3 * self.vis.f();
|
||||
out.model(d.id + 1, "airdef:geran3_flame", at, rot, s * size * flicker, true);
|
||||
}
|
||||
Engine::Rocket(back, size) => {
|
||||
// Ballistic missiles fly far and high: their glow keeps a size on screen, so they are seen
|
||||
// all the way (the motor while it burns, then the hot body).
|
||||
let far = player.map_or(1.0, |p| (d.pos.distance(p) / 140.0).max(1.0));
|
||||
let flicker = 0.8 + 0.2 * self.rng.f();
|
||||
let flicker = 0.8 + 0.2 * self.vis.f();
|
||||
if d.flight != Flight::Ballistic || d.age < 60 {
|
||||
let size = if d.flight == Flight::Ballistic { size * far.sqrt() } else { size };
|
||||
let at = d.pos + rot * DVec3::new(0.0, 0.0, back * s + size * flicker);
|
||||
@@ -2019,7 +2044,7 @@ impl Sim {
|
||||
out.particles("minecraft:flame", pos, size as f32 * 0.3, DVec3::ZERO, 0.2, n);
|
||||
out.particles("minecraft:lava", pos, 1.0, DVec3::ZERO, 0.0, 16);
|
||||
out.particles("minecraft:campfire_signal_smoke", pos, 1.2, DVec3::new(0.0, 0.04, 0.0), 0.01, if big { 30 } else { 10 });
|
||||
let pitch = 0.9 + self.rng.f() as f32 * 0.2;
|
||||
let pitch = 0.9 + self.vis.f() as f32 * 0.2;
|
||||
let event = ["airdef:blast.air", "airdef:blast.medium", "airdef:blast.big", "airdef:blast.heavy", "airdef:blast.huge"][power];
|
||||
out.sound(event, pos, 1.0, if small { pitch * 1.15 } else { pitch });
|
||||
if power >= 3 {
|
||||
@@ -2058,8 +2083,8 @@ impl Sim {
|
||||
if self.shader {
|
||||
return;
|
||||
}
|
||||
let id = self.id();
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.rng.s() * 0.2, self.rng.s() * 0.2, self.rng.s() * 0.2);
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s() * 0.2, self.vis.s() * 0.2, self.vis.s() * 0.2);
|
||||
self.fx.push((id, Fx::Fireball { pos, size, age: 0, life, spin }));
|
||||
}
|
||||
|
||||
@@ -2095,11 +2120,11 @@ impl Sim {
|
||||
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.rng.f() as f32 * 0.2);
|
||||
out.sound("airdef:blast.air", pos, gain, 1.0 + self.vis.f() as f32 * 0.2);
|
||||
for _ in 0..5 {
|
||||
let id = self.id();
|
||||
let v = vel + DVec3::new(self.rng.s(), self.rng.f() * 0.8, self.rng.s()) * 0.35;
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.rng.s() * 0.4, self.rng.s() * 0.4, self.rng.s() * 0.4);
|
||||
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 }));
|
||||
}
|
||||
}
|
||||
@@ -2333,16 +2358,15 @@ impl Sim {
|
||||
let dir = (lead - muzzle).normalize_or(DVec3::NEG_Z);
|
||||
let len = muzzle.distance(lead).min(gun.range * 1.2);
|
||||
// Every round is a red tracer flying out at the shell's speed.
|
||||
let scatter = DVec3::new(self.rng.s(), self.rng.s(), self.rng.s()) * 0.012;
|
||||
let id = self.next * PARTS + 0x0800_0000;
|
||||
self.next += 1;
|
||||
let scatter = DVec3::new(self.vis.s(), self.vis.s(), self.vis.s()) * 0.012;
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
tracers.push((id, muzzle + dir * 1.5, (dir + scatter).normalize() * gun.shell, (len / gun.shell) as u32 + 2));
|
||||
out.particles("minecraft:smoke", muzzle, 0.1, dir * 0.05, 0.01, 2);
|
||||
}
|
||||
// A gun sound holds a few shots: one every other burst.
|
||||
if sam.bursts % 2 == 0 {
|
||||
let event = if sam.kind == SamKind::Pantsir { "airdef:gun.pantsir" } else { "airdef:gun.gepard" };
|
||||
out.sound(event, mount, 1.0, 0.95 + self.rng.f() as f32 * 0.1);
|
||||
out.sound(event, mount, 1.0, 0.95 + self.vis.f() as f32 * 0.1);
|
||||
}
|
||||
// At night a gun sees what is lit (a searchlight, a flare) and little else.
|
||||
let dark = if self.night && !self.lit.contains(&t.id) { lights::DARK_HITS } else { 1.0 };
|
||||
@@ -2448,7 +2472,7 @@ impl Sim {
|
||||
out.particles("minecraft:cloud", muzzle - dir * 2.0, 1.4, DVec3::new(0.0, 0.02, 0.0), 0.06, 70);
|
||||
out.particles("minecraft:campfire_cosy_smoke", muzzle - dir * 3.0, 1.2, DVec3::ZERO, 0.02, 20);
|
||||
let event = if kind == MissileKind::M57e6 { "airdef:launch.pantsir" } else { "airdef:launch.patriot" };
|
||||
out.sound(event, muzzle, 1.0, 0.95 + self.rng.f() as f32 * 0.1);
|
||||
out.sound(event, muzzle, 1.0, 0.95 + self.vis.f() as f32 * 0.1);
|
||||
}
|
||||
}
|
||||
for (id, pos, vel, life) in tracers {
|
||||
@@ -2478,7 +2502,7 @@ impl Sim {
|
||||
.iter()
|
||||
.filter_map(|m| {
|
||||
let s = self.sams.iter().find(|s| s.id == m.sam)?;
|
||||
(s.alive() && !s.moving()).then_some(())?;
|
||||
(s.alive() && !s.moving() && s.link_range() > 0.0).then_some(())?;
|
||||
Some(((m.sam, m.target), *s.track(m.target)?))
|
||||
})
|
||||
.collect();
|
||||
@@ -2507,12 +2531,12 @@ impl Sim {
|
||||
let range = m.kind.seeker() * t.kind.rcs().powf(0.25).clamp(0.6, 1.6);
|
||||
let to = t.pos - m.pos;
|
||||
let in_view = to.length() < range && to.normalize_or_zero().dot(dir) > 0.5;
|
||||
if in_view && !matches!(ground.world.probe(m.pos, t.pos, now), world::Sweep::Hit { .. }) {
|
||||
// Only a line of sight the world has confirmed counts: blocks not read (Unknown) are not air (#75).
|
||||
if in_view && matches!(ground.world.probe(m.pos, t.pos, now), world::Sweep::Clear) {
|
||||
m.seen = now;
|
||||
}
|
||||
if m.seen > 0 && now.saturating_sub(m.seen) <= REACQUIRE {
|
||||
// The seeker measures the target (the track of its own, newer than any link's).
|
||||
m.fix = Some(Fix { pos: if m.seen == now { t.pos } else { m.fix.map_or(t.pos, |f| f.pos) }, vel: t.vel, tick: if m.seen == now { now } else { m.fix.map_or(now, |f| f.tick) }, seeker: true });
|
||||
// The seeker measures the target: position and velocity, now. Out of sight (behind a hill,
|
||||
// an unread section) nothing new is measured and the last fix is carried on as it was.
|
||||
m.fix = Some(Fix { pos: t.pos, vel: t.vel, tick: now, seeker: true });
|
||||
}
|
||||
}
|
||||
// Nothing new for too long and no seeker on it: the interceptor has lost its target.
|
||||
@@ -2544,6 +2568,9 @@ impl Sim {
|
||||
let before = m.pos;
|
||||
m.vel = new * speed;
|
||||
m.pos += m.vel;
|
||||
let end = m.pos;
|
||||
// Where the exact shape is still being asked for, the contact point (by the cube) bounds the fuse (#74).
|
||||
let mut waiting: Option<f64> = None;
|
||||
// The first block on the way this tick; a fuse that goes off earlier along the way still counts.
|
||||
ground.ahead(m.pos, m.vel, 10.0, now);
|
||||
let sweep = ground.trace(m.id | 0x8000_0000, before, m.pos, m.age <= 12, now);
|
||||
@@ -2561,16 +2588,19 @@ impl Sim {
|
||||
}
|
||||
} else if let world::Sweep::Wait { t } = sweep {
|
||||
m.pos = before.lerp(m.pos, (t - 1e-6).max(0.0));
|
||||
waiting = Some(t);
|
||||
} else if matches!(sweep, world::Sweep::Clear) {
|
||||
m.hold = 0;
|
||||
}
|
||||
if let Some(t) = target {
|
||||
// Closest approach this tick, both moving (fast targets cross a fuse in a tick).
|
||||
let rel0 = (t.pos - t.vel) - before;
|
||||
let rel1 = t.pos - m.pos;
|
||||
// Waiting for the shape: the fuse is judged on the whole step against the cube's face, as for a
|
||||
// known hit, so that a pending answer is neither a free pass nor a different outcome.
|
||||
let rel1 = t.pos - if waiting.is_some() { end } else { m.pos };
|
||||
let delta = rel1 - rel0;
|
||||
let k = (-rel0.dot(delta) / delta.length_squared().max(1e-9)).clamp(0.0, 1.0);
|
||||
if (rel0 + delta * k).length() < spec.fuse && world.is_none_or(|(w, _)| k <= w) {
|
||||
if (rel0 + delta * k).length() < spec.fuse && world.map(|w| w.0).or(waiting).is_none_or(|w| k <= w) {
|
||||
// A target faster than the interceptor is hard to hit.
|
||||
let ratio = (spec.speed / t.vel.length().max(0.1)).min(1.0).powf(1.5);
|
||||
let fit = sams_fit.get(&m.sam).copied().unwrap_or(1.0);
|
||||
@@ -2660,7 +2690,7 @@ impl Sim {
|
||||
out.model(m.id, spec.model, m.pos, rot, spec.scale, false);
|
||||
if m.age > spec.cold && spec.flame > 0.0 {
|
||||
let back = (spec.rear - 8.0) / 16.0 * spec.scale + spec.flame;
|
||||
let size = spec.flame * if m.age < 40 { 1.2 } else { 0.8 } * (0.85 + 0.15 * self.rng.f());
|
||||
let size = spec.flame * if m.age < 40 { 1.2 } else { 0.8 } * (0.85 + 0.15 * self.vis.f());
|
||||
out.model(m.id + 1, "airdef:flame", m.pos + rot * DVec3::new(0.0, 0.0, back), rot, size, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user