Playtest fixes: smoke by engine, searchlights, far launch sites that load their chunks, air defence balance, last chance and radar-cued shots, radars in smart raids, echo, Windows release build from a tag
build / mod (push) Successful in 4m4s
release / windows (push) Successful in 23m13s

Smoke: one rule by engine, no heat on trails, no trail on P1-SUN. Searchlights: two lamps a target, off with an empty sky. Halos fade before their reach and their sum is limited. Launch sites load chunks through the server thread, go off-map as a last resort, and reach 4000 blocks. Air defence: ranges x1.5, shots grow with urgency, claims released, /airdef lastchance, long shots on a big radar's tracks. Build: rust-toolchain.toml, airdef.py check, generator manifest and --check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 23:44:14 +03:00
parent 5003376e70
commit ccc3e20902
67 changed files with 4573 additions and 328 deletions
+131 -13
View File
@@ -26,6 +26,8 @@ mod units;
mod why;
pub mod world;
#[cfg(test)]
mod balance;
#[cfg(test)]
mod regress;
#[cfg(test)]
mod sensor_tests;
@@ -229,6 +231,13 @@ pub struct Ground {
known: HashMap<(i32, i32), (i32, u64)>,
wanted: Vec<(i32, i32)>,
asked: std::collections::HashSet<(i32, i32)>,
/// Columns whose chunk the game is loading (it answered `PENDING`), and the tick it said so: not asked
/// again for a few ticks.
loading: HashMap<(i32, i32), u64>,
/// Chunks the search wants loaded (`render.load-chunks`), taken every tick.
chunks: Vec<(i32, i32)>,
/// The game has answered "loading" at least once: it loads chunks on request (a server doesn't).
pub loads: bool,
/// The tick of the last full clean-up (a big cache would otherwise be scanned on every answer).
swept: u64,
/// The tick of the last answer round: what the heights' ages are measured against.
@@ -237,6 +246,14 @@ pub struct Ground {
pub world: world::WorldCache,
}
/// What `render.ground` answers (`i32::MIN`) for a column whose chunk it is loading for the mod.
pub const PENDING: i32 = i32::MIN;
/// Ticks before a column that was loading is asked about again.
const LOAD_RECHECK: u64 = 6;
/// The chunks asked to load at once (the game holds 64).
const CHUNKS_MAX: usize = 48;
/// Ticks a strike drone may fly before it is lost: a Shahed at 0.6 blocks a tick needs 6700 for 4000 blocks.
const MAX_FLIGHT: u32 = 24_000;
/// The `when` of a height reported changed: due to be asked again.
const STALE: u64 = u64::MAX;
/// Ticks after which a land height used by the flights' look-ahead is asked again (#64), changes told of or not.
@@ -272,8 +289,17 @@ impl Ground {
pub fn answer(&mut self, answers: Vec<(i32, i32, i32)>, now: u64) {
self.now = now;
for (x, z, y) in answers {
if y == PENDING {
self.loading.insert((x, z), now);
self.loads = true;
continue;
}
self.loading.remove(&(x, z));
self.known.insert((x, z), (y, now));
}
if self.loading.len() > 4096 {
self.loading.retain(|_, t| now.saturating_sub(*t) < 400);
}
self.age_heights();
if self.known.len() > 300_000 && now.saturating_sub(self.swept) >= SWEEP_EVERY {
self.swept = now;
@@ -318,6 +344,25 @@ impl Ground {
fn due(&self, when: u64) -> bool {
when == STALE || self.now.saturating_sub(when) > HEIGHT_TTL
}
/// Asks the game to load the chunk (chunk x, z) for a while, if there is room; whether it did.
pub fn want_chunk(&mut self, c: (i32, i32)) -> bool {
if self.chunks.contains(&c) {
return true;
}
if self.chunks.len() >= CHUNKS_MAX {
return false;
}
self.chunks.push(c);
true
}
/// How many chunks are wanted so far this tick.
pub fn chunks_wanted(&self) -> usize {
self.chunks.len()
}
/// The chunks to ask the game to load this tick.
pub fn take_chunks(&mut self) -> Vec<(i32, i32)> {
std::mem::take(&mut self.chunks)
}
pub fn take_wanted(&mut self) -> Vec<(i32, i32)> {
self.asked.clear();
std::mem::take(&mut self.wanted)
@@ -524,6 +569,13 @@ pub struct DroneSpec {
pub ballistic: Option<f64>,
}
impl DroneSpec {
/// Its size, for how thick its smoke is.
pub fn trail_scale(&self) -> f32 {
self.scale as f32
}
}
impl DroneKind {
pub const ALL: [DroneKind; 13] = [
DroneKind::Shahed,
@@ -924,6 +976,11 @@ struct MissileSpec {
}
impl MissileKind {
/// How thick its motor smoke is (its size); `None` for an electric one.
pub fn trail_scale(self) -> Option<f32> {
let s = self.spec();
(s.flame > 0.0).then_some(s.scale as f32)
}
/// The sound of its launch.
pub fn launch_sound(self) -> &'static str {
match self {
@@ -1199,6 +1256,11 @@ pub struct Sam {
pub bursts: u32,
cooldown: u32,
gun_cooldown: u32,
/// Ticks until the system may take another long shot on a big radar's cue (`why::basis`).
far_cooldown: u32,
/// Ticks it has held its present missile target without launching, and a target it gave up (id, until when).
held: u32,
shy: Option<(u32, u64)>,
pub reloading: u32,
/// What its missiles are after, and what its guns track.
pub target: Option<u32>,
@@ -1270,6 +1332,9 @@ impl Sam {
bursts: spec.gun.as_ref().map_or(0, |g| g.bursts),
cooldown: 40,
gun_cooldown: 0,
far_cooldown: 0,
held: 0,
shy: None,
reloading: 0,
target: None,
gun_target: None,
@@ -1432,6 +1497,10 @@ pub struct Sim {
pub shader: bool,
/// Air defence holds fire.
pub hold: bool,
/// Last chance (`/airdef lastchance`): a system fires at a class outside its roles when it is about to hit.
pub last_chance: bool,
/// The heavy systems take long shots on the big radar's cue (a switch for the balance tests).
pub far_shots: bool,
/// What the land hides round each system's radar, by system id.
horizons: HashMap<u32, sight::Horizon>,
/// Blasts to come: (tick, where, TNT, small) — a magazine cooking off.
@@ -1505,6 +1574,8 @@ impl Sim {
truth: false,
shader: false,
hold: false,
last_chance: true,
far_shots: true,
horizons: HashMap::new(),
later: Vec::new(),
queue: Vec::new(),
@@ -1907,7 +1978,7 @@ impl Sim {
}
let at_target = d.pos.distance(d.target) < speed.max(1.5);
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 {
if at_target || in_ground || d.age > MAX_FLIGHT {
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 {
@@ -1929,7 +2000,7 @@ impl Sim {
let back = d.pos - d.vel.normalize_or_zero() * 1.5 * spec.scale;
match spec.engine {
Engine::Prop(..) => {
if d.age % 2 == 0 {
if d.age % 10 == 0 {
out.particles("minecraft:smoke", back, 0.05, DVec3::ZERO, 0.01, 1);
}
}
@@ -2241,6 +2312,7 @@ impl Sim {
let sam = &mut self.sams[i];
sam.cooldown = sam.cooldown.saturating_sub(1);
sam.gun_cooldown = sam.gun_cooldown.saturating_sub(1);
sam.far_cooldown = sam.far_cooldown.saturating_sub(1);
sam.flash = sam.flash.saturating_sub(1);
sam.recoil *= 0.6;
if sam.radar_up() {
@@ -2288,17 +2360,30 @@ impl Sim {
let drone = |tr: &Track| drone_at.get(&tr.id).map(|&k| &self.drones[k]);
let claimed = |d: &Drone| why::claimed(d, &missile_on, had_target);
let needed = why::needed;
let opts = why::Opts { last_chance: self.last_chance, far_shots: self.far_shots };
let target = spec.missile.as_ref().map(|load| {
let ok = |tr: &Track, k: f64| {
drone(tr).is_some_and(|d| why::allowed(roles, tr, now, d) && open(tr.id) && why::in_reach(load.min, load.max, k, pos, tr.est(now)))
// A launcher with nothing to fire (reloading, empty, failed) claims no target: others take it.
if me.missiles == 0 || me.reloading > 0 || me.part(Part::Launcher) <= 0.0 {
return None;
}
let radars: Vec<&Sam> = if me.kind.far_shooter() && opts.far_shots { self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect() } else { Vec::new() };
let cued = |id: u32| !radars.is_empty() && why::radar_cue(me, &radars, id, now);
let basis = |tr: &Track, k: f64, role_in_reach: bool| {
drone(tr).filter(|_| open(tr.id)).and_then(|d| why::basis(me, load, tr, d, now, claimed(d), k, opts, cued(tr.id), role_in_reach))
};
let keep = had_target.filter(|t| tracks.iter().any(|tr| tr.id == *t && ok(tr, 1.1)));
// A target held too long without a launch (the mount can't lay on it, the land) is let go,
// and not taken again for a while: another system gets it.
let shy = |id: u32| me.shy.is_some_and(|(s, until)| s == id && until > now);
let stuck = me.held > why::HOLD_MAX;
let keep = had_target.filter(|t| !stuck && tracks.iter().any(|tr| tr.id == *t && basis(tr, 1.1, false).is_some()));
keep.or_else(|| {
let free = |tr: &Track| drone(tr).is_some_and(|d| claimed(d) < needed(d));
// Long shots only while nothing of the system's roles is in its normal reach.
let role_in_reach = !radars.is_empty() && tracks.iter().any(|tr| free(tr) && basis(tr, 1.0, true) == Some(why::Basis::Role));
tracks
.iter()
.filter(|tr| ok(tr, 1.0))
.filter(|tr| free(tr) && !shy(tr.id) && basis(tr, 1.0, role_in_reach).is_some())
.filter_map(|tr| drone(tr).map(|d| (tr, d)))
.filter(|(_, d)| claimed(d) < needed(d))
.max_by(|a, b| a.1.threat_at(pos, a.0.est(now)).total_cmp(&b.1.threat_at(pos, b.0.est(now))))
.map(|(_, d)| d.id)
})
@@ -2330,7 +2415,16 @@ impl Sim {
tracks_lost += 1;
}
retarget(&mut missile_on, had_target, target);
self.sams[i].target = target;
let sam = &mut self.sams[i];
if target.is_some() && target == had_target {
sam.held += 1;
} else {
if let (Some(h), true) = (had_target, sam.held > why::HOLD_MAX) {
sam.shy = Some((h, now + why::SHY_TICKS));
}
sam.held = 0;
}
sam.target = target;
}
if let Some(gun_target) = gun_target {
retarget(&mut guns_on, had_gun, gun_target);
@@ -2364,8 +2458,24 @@ impl Sim {
} else {
SamState::Search
};
// Back to the rest position, under the drive's limits like any other turn.
sam.aim_towards(sam.heading, Some(spec.rest_pitch));
// Nothing to fire at: the mount watches the nearest track of its classes (a reaction a turn
// shorter), else it goes back to the rest position, under the drive's limits like any other turn.
let (mount, _) = sam.mount();
let watch = sam
.tracks
.iter()
.filter(|tr| tr.age(now) <= sight::MISSILE_AGE && drone_at.get(&tr.id).is_some_and(|&k| roles & self.drones[k].kind.spec().class.bit() != 0 && self.drones[k].alive()))
.min_by(|a, b| a.est(now).distance(mount).total_cmp(&b.est(now).distance(mount)))
.map(|tr| why::aim_wants(mount, tr.est(now), tr.vel, spec.gun.as_ref().map_or(5.0, |g| g.shell)));
match (watch, spec.family) {
(Some((_, yaw, pitch)), Family::Trainable) => {
let _ = pitch;
sam.aim_towards(yaw, None)
}
(Some((_, yaw, _)), Family::Vertical) if matches!(spec.muzzle, Muzzle::Cells) => sam.aim_towards(yaw, None),
(Some((_, yaw, pitch)), Family::Gun | Family::Turret) => sam.aim_towards(yaw, Some(pitch)),
_ => sam.aim_towards(sam.heading, Some(spec.rest_pitch)),
}
continue;
};
let (mount, _) = sam.mount();
@@ -2496,6 +2606,10 @@ impl Sim {
retarget(&mut missile_on, Some(mt), None);
sam.target = None;
} else if ready && aligned {
// Past its normal reach: a long shot, and the next waits.
if sam.kind.far_shooter() && t.is_some_and(|t| t.distance(sam.pos) >= load.max) {
sam.far_cooldown = why::FAR_COOLDOWN;
}
launches.push((load.kind, muzzle, dir, mt, sam.id));
// Its missile is on it from now, so the systems after this one this tick see
// the target taken; this one's next launch looks for another.
@@ -2546,8 +2660,10 @@ impl Sim {
out.sound(event, muzzle, 1.0, 1.0);
} else {
out.particles("minecraft:flash", muzzle, 0.0, DVec3::ZERO, 0.0, 1);
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);
if spec.flame > 0.0 {
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.vis.f() as f32 * 0.1);
}
@@ -2573,6 +2689,8 @@ impl Sim {
let (mut missed, mut expired, mut orphaned) = (0u32, 0u32, 0u32);
let (mut blocked, mut scrubbed) = (0u32, 0u32);
let sams_fit: HashMap<u32, f64> = self.sams.iter().map(|s| (s.id, 1.0 - 0.3 * (1.0 - s.health.clamp(0.0, 1.0)))).collect();
// Where each launcher stands and how far its missiles reach: a hit past that is less likely (`why::reach_fit`).
let launchers: HashMap<u32, (DVec3, f64)> = self.sams.iter().filter_map(|s| Some((s.id, (s.pos, s.kind.spec().missile.as_ref()?.max)))).collect();
// The data link (#66): the track the firing system holds of each missile's target, if it is up.
let links: HashMap<(u32, u32), Track> = self
.missiles
@@ -2680,7 +2798,7 @@ impl Sim {
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);
let fit = sams_fit.get(&m.sam).copied().unwrap_or(1.0) * launchers.get(&m.sam).map_or(1.0, |(at, max)| why::reach_fit(*max, at.distance(m.pos)));
let kill = self.rng.chance(spec.pk * fit * ratio / t.kind.spec().stealth.sqrt());
missed += u32::from(!kill);
done.push((m.id, Some(t.id), kill, m.sam));