Sunsets, volumetric clouds and fog in HD (fork patch 23, #53); missiles and drones collide with the world through new world queries (patch 24, API level 12; #42, #43); a direct hit destroys a system, strikes scatter by kind with a small miss chance (#49, #59)
build / mod (push) Successful in 3m24s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 21:44:59 +03:00
parent a8551b5c28
commit 8065f2225c
33 changed files with 4010 additions and 37 deletions
+93 -6
View File
@@ -19,6 +19,7 @@ mod logistics;
mod orders;
mod units;
mod why;
pub mod world;
#[cfg(test)]
mod regress;
pub use ew::EW_RADIUS;
@@ -211,6 +212,8 @@ pub struct Ground {
asked: std::collections::HashSet<(i32, i32)>,
/// The tick of the last full clean-up (a big cache would otherwise be scanned on every answer).
swept: u64,
/// The blocks themselves (issues #42, #43): what stops a flight.
pub world: world::WorldCache,
}
/// Ticks between full clean-ups of a big ground cache.
@@ -251,10 +254,32 @@ impl Ground {
self.asked.clear();
std::mem::take(&mut self.wanted)
}
/// The first solid block on the way from `a` to `b` (the real blocks, not the height of the land).
pub fn sweep(&mut self, a: DVec3, b: DVec3, skip_start: bool, now: u64) -> world::Sweep {
self.world.sweep(a, b, skip_start, now)
}
/// Has the sections along a flight read before it gets there.
pub fn ahead(&mut self, pos: DVec3, vel: DVec3, ticks: f64, now: u64) {
self.world.look_ahead(pos, vel, ticks, now);
}
/// Whether `pos` is in the land by the column's height (`below`, as `at` gave it), given what the sweep
/// of this step saw: over blocks known and open, the height only counts where its top block is known
/// to be open, a fluid's surface (not a roof or a bridge deck above the flight, nor a block unread).
pub fn ground_hit(&mut self, below: Option<f64>, pos: DVec3, offset: f64, sweep: &world::Sweep, now: u64) -> bool {
let Some(g) = below else { return false };
if pos.y > g + offset {
return false;
}
match sweep {
world::Sweep::Clear => self.world.is_known_open(pos.x.floor() as i32, g.floor() as i32 - 1, pos.z.floor() as i32, now),
_ => true,
}
}
/// Explosions change the land: forget what was known round them.
fn forget(&mut self, at: DVec3, radius: i32) {
let (cx, cz) = (at.x.floor() as i32, at.z.floor() as i32);
self.known.retain(|&(x, z), _| (x - cx).abs() > radius || (z - cz).abs() > radius);
self.world.touched(at, f64::from(radius) + 2.0);
}
}
@@ -1172,6 +1197,8 @@ pub struct Sim {
pub tick: u64,
pub kills: u32,
pub hits: u32,
/// Drones that struck the land or a building short of their aim.
pub crashes: u32,
pub launched: u32,
/// Explosions damage the land (primed TNT through commands).
pub damage: bool,
@@ -1225,6 +1252,7 @@ impl Sim {
tick: 0,
kills: 0,
hits: 0,
crashes: 0,
launched: 0,
damage: true,
shader: false,
@@ -1289,6 +1317,8 @@ impl Sim {
fn add_drone(&mut self, kind: DroneKind, from: DVec3, dir: DVec3, target: DVec3) {
let id = self.id();
let spec = kind.spec();
// Its navigation error: it flies to, and strikes at, a point off the aim it was given.
let target = target + self.aim_error(kind);
let (vel, flight) = if spec.ballistic.is_some() {
// An arc from `from` to `target` at the kind's horizontal speed.
let flat = horizontal(target - from);
@@ -1373,7 +1403,7 @@ impl Sim {
self.update_sight(ground);
self.step_lights(out);
self.step_sams(out);
self.step_missiles(out);
self.step_missiles(ground, out);
self.step_fx(ground, out);
self.draw_targets(out);
self.step_wrecks(out);
@@ -1394,10 +1424,14 @@ impl Sim {
// Warheads that reached their aim (for the replays): drone, kind, where, TNT; and splits.
let mut impacts: Vec<(u32, DroneKind, DVec3, u32)> = Vec::new();
let mut splits: Vec<(u32, DVec3)> = Vec::new();
// Drones that struck the land or a building short of their aim: drone, kind, where, TNT.
let mut crashes: Vec<(u32, DroneKind, DVec3, u32)> = Vec::new();
for d in &mut self.drones {
d.age += 1;
let spec = d.kind.spec();
let below = ground.at(d.pos, now);
let from = d.pos;
ground.ahead(d.pos, d.vel, 20.0, now);
// Near its aim it looks at the land there again: a platform or hilltop blown away
// meanwhile, it goes for what is left below, not for the air where it stood.
if d.flight != Flight::Falling
@@ -1412,11 +1446,15 @@ impl Sim {
d.vel *= 0.985;
d.spin += 0.35;
d.pos += d.vel;
let sweep = ground.sweep(from, d.pos, d.age <= 3, now);
if let Some((_, p)) = sweep.hit() {
d.pos = p;
}
if self.rng.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);
if below.is_some_and(|g| d.pos.y <= g + 0.3) || d.age > 600 {
if sweep.hit().is_some() || ground.ground_hit(below, d.pos, 0.3, &sweep, now) || d.age > 600 {
// The wreck's warhead may still go off where it lands.
let warhead = if spec.decoy || !self.rng.chance(0.35) { 0 } else { spec.warhead.min(2) };
boom.push((d.pos, warhead, true));
@@ -1439,13 +1477,24 @@ impl Sim {
d.vel = turn(d.vel, d.target - d.pos, spec.turn) * sp;
}
d.pos += d.vel;
let sweep = ground.sweep(from, d.pos, d.age <= 3, now);
if let Some((_, p)) = sweep.hit() {
d.pos = p;
}
let speed = d.vel.length();
let landed = sweep.hit().is_some() || ground.ground_hit(below, d.pos, 0.2, &sweep, now);
let hit = d.pos.distance(d.target) < speed.max(2.0)
|| below.is_some_and(|g| d.pos.y <= g + 0.2)
|| landed
|| (d.vel.y < 0.0 && d.pos.y < d.target.y - 1.0 && horizontal(d.target - d.pos).length() < speed * 2.0)
|| d.age > 4000;
if hit {
boom.push((d.pos, spec.warhead, false));
// Into the land or a building short of its aim: a crash, not a hit.
if landed && d.pos.distance(d.target) >= speed.max(2.0) + 6.0 {
crashes.push((d.id, d.kind, d.pos, spec.warhead));
removed.push(d.id);
continue;
}
impacts.push((d.id, d.kind, d.pos, spec.warhead));
removed.push(d.id);
self.hits += 1;
@@ -1546,10 +1595,22 @@ impl Sim {
let speed = if d.flight == Flight::Dive { spec.speed * 1.35 } else { spec.speed };
d.vel = new * speed;
d.pos += d.vel;
let sweep = ground.sweep(from, d.pos, d.age <= 3, now);
if let Some((_, p)) = sweep.hit() {
d.pos = p;
}
let at_target = d.pos.distance(d.target) < speed.max(1.5);
let in_ground = below.is_some_and(|g| d.pos.y <= g + 0.2);
let in_ground = sweep.hit().is_some() || ground.ground_hit(below, d.pos, 0.2, &sweep, now);
if at_target || in_ground || d.age > 8000 {
boom.push((d.pos, spec.warhead, spec.decoy));
// Into the land or a building short of its aim: a crash, not a hit.
if in_ground && d.pos.distance(d.target) >= speed.max(1.5) + 3.0 {
if !spec.decoy {
crashes.push((d.id, d.kind, d.pos, spec.warhead));
}
removed.push(d.id);
continue;
}
if !spec.decoy {
impacts.push((d.id, d.kind, d.pos, spec.warhead));
}
@@ -1580,6 +1641,17 @@ impl Sim {
for (drone, pos) in splits {
self.log(pos, record::EventKind::Split { drone });
}
for (drone, kind, pos, tnt) in crashes {
self.crashes += 1;
let power = match tnt {
0 => 0,
1 | 2 => 1,
3..=5 => 2,
6 | 7 => 3,
_ => 4,
};
self.log(pos, record::EventKind::Crash { drone, kind, power });
}
for (drone, kind, pos, tnt) in impacts {
if let Some(sector) = self.drones.iter().find(|x| x.id == drone).map(|x| x.sector as usize) {
self.learn(sector, false);
@@ -1594,6 +1666,8 @@ impl Sim {
let object = self.targets.iter().position(|t| t.distance(pos) < 16.0);
let sam = self.sams.iter().enumerate().find(|(_, s)| s.alive() && s.pos.distance(pos) < 12.0).map(|(i, s)| (s.kind, i));
self.log(pos, record::EventKind::Hit { drone, kind, power, object, sam });
let vel = self.drones.iter().find(|x| x.id == drone).map_or(DVec3::ZERO, |x| x.vel);
self.direct_hit(pos, vel, tnt, out);
}
for (pos, warhead, small) in boom {
self.explode(pos, warhead, small, ground, player, out);
@@ -2061,9 +2135,11 @@ impl Sim {
// ------------------------------------------------ interceptors
fn step_missiles(&mut self, out: &mut Out) {
fn step_missiles(&mut self, ground: &mut Ground, out: &mut Out) {
let now = self.tick;
let mut done: Vec<(u32, Option<u32>, bool, u32)> = Vec::new(); // (missile, target, kill, sam)
let (mut missed, mut expired, mut orphaned) = (0u32, 0u32, 0u32);
let mut blocked = 0u32;
let sams_fit: HashMap<u32, f64> = self.sams.iter().map(|s| (s.id, s.fitness())).collect();
for m in &mut self.missiles {
m.age += 1;
@@ -2091,13 +2167,16 @@ impl Sim {
let before = m.pos;
m.vel = new * speed;
m.pos += m.vel;
// 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 world = ground.sweep(before, m.pos, m.age <= 12, now).hit();
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;
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 {
if (rel0 + delta * k).length() < spec.fuse && world.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);
@@ -2107,6 +2186,13 @@ impl Sim {
continue;
}
}
if let Some((_, p)) = world {
// The land or a building is in the way: the interceptor is lost there.
m.pos = p;
blocked += 1;
done.push((m.id, None, false, m.sam));
continue;
}
if m.age > spec.life || (target.is_none() && m.age > 30) {
// Its target gone (shot down by another, or lost), or its life spent chasing one.
if target.is_none() {
@@ -2151,6 +2237,7 @@ impl Sim {
t.missed += missed;
t.expired += expired;
t.orphaned += orphaned;
t.blocked += blocked;
});
for (mid, target, kill, sam) in done {
if let Some(i) = self.missiles.iter().position(|m| m.id == mid) {