Fix raid gameplay, finite ammunition and truck routing

Check launch terrain, reserve ballistic targets for marked objectives, tune in-game reach and fallback fire, and support bounded terrain work on supply routes.

Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
2026-11-25 18:53:17 +03:00
parent 61c4fa5cee
commit aa842d8a1f
18 changed files with 606 additions and 257 deletions
+99 -9
View File
@@ -79,7 +79,7 @@ pub(super) const SHY_TICKS: u64 = 120;
/// is about to hit, with nobody's interceptor on it, is shot at anyway; a system told to hold fire
/// (no roles) keeps to it. An unidentified track is no last-chance case: it is already a candidate
/// under the general rules (#133).
pub(super) const LAST_CHANCE_TICKS: f64 = 200.0;
pub(super) const LAST_CHANCE_TICKS: f64 = 120.0;
pub(super) fn last_chance(on: bool, roles: u8, class: ClassEst, d: &Drone, claimed: u32) -> bool {
on && roles != 0 && !class.in_roles(roles) && claimed == 0 && arrival(d) < LAST_CHANCE_TICKS
@@ -327,6 +327,54 @@ impl LaunchAudit {
}
impl Sim {
pub(super) fn last_chance_for(&self, sam: &Sam, class: ClassEst, d: &Drone, claimed: u32) -> bool {
last_chance(self.last_chance, sam.roles, class, d, claimed) && !self.has_role_cover(sam, d)
}
/// A shorter-range role weapon with a usable track and time to engage.
fn has_role_cover(&self, fallback: &Sam, d: &Drone) -> bool {
let now = self.tick;
let lead = (arrival(d) - 20.0).clamp(0.0, 40.0);
let reach = fallback.kind.range();
self.sams.iter().any(|sam| {
if sam.id == fallback.id || !sam.alive() || sam.moving() || sam.reloading > 0
|| sam.kind.range() >= reach
{
return false;
}
let Some(track) = sam.track(d.id) else { return false };
if track.class.class().is_none() || !allowed(sam.roles, track, now, d)
|| sam.doctrine.area_blocks(sam.pos, track, now) != 0
{
return false;
}
let at = track.est(now);
let soon = at + track.vel * lead;
let available = |target: Option<u32>| target.is_none_or(|id| id == d.id);
let spec = sam.kind.spec();
let gun = spec.gun.as_ref().is_some_and(|gun| {
let mount = sam.mount().0;
sam.gun_up() && sam.bursts > 0 && f64::from(sam.gun_cooldown) <= lead
&& available(sam.gun_target) && track.own_within(now, sight::GUN_PICK_AGE)
&& at.distance(mount).min(soon.distance(mount)) < gun.range
});
gun || spec.missile.as_ref().is_some_and(|load| {
let authority = if sam.mode == battery::SamMode::LauncherOnly {
self.sams.iter().any(|radar| radar_cue(sam, &[radar], d.id, now))
} else {
track.own_authorizes(now)
};
sam.missiles > 0 && f64::from(sam.cooldown) <= lead && sam.part(Part::Launcher) > 0.0
&& available(sam.target) && !sam.preparing.is_some_and(|p| p.ground)
&& sam.terrain_verdict(d.id, now).is_none_or(|v| v == 0)
&& sam.doctrine.reserve_blocks(sam.missiles, d, track.class) == 0
&& (in_reach(load.min, load.max, 1.0, sam.pos, at)
|| in_reach(load.min, load.max, 1.0, sam.pos, soon))
&& authority
})
})
}
/// The saturation audit: every armed system against every alive drone, attributed to the first
/// ground that stops the shot. Reads the tracks' estimates and provenance, never the target's
/// own class or velocity (#133).
@@ -372,7 +420,7 @@ impl Sim {
}
let est = tr.class;
let free = claimed(d, &missile_on, sam.target);
let chance = blocks & ROLE != 0 && last_chance(self.last_chance, sam.roles, est, d, free);
let chance = blocks & ROLE != 0 && self.last_chance_for(sam, est, d, free);
if blocks & ROLE != 0 && !chance {
a.role += 1;
continue;
@@ -606,7 +654,7 @@ impl Sim {
.filter(|d| {
d.alive()
&& (sam.track(d.id).is_some_and(|tr| tr.class.in_roles(sam.roles))
|| last_chance(self.last_chance, sam.roles, sam.track(d.id).map_or(ClassEst::Unknown, |tr| tr.class), d, claimed(d, &missile_on, sam.target)))
|| self.last_chance_for(sam, sam.track(d.id).map_or(ClassEst::Unknown, |tr| tr.class), d, claimed(d, &missile_on, sam.target)))
})
.max_by(|a, b| {
let area = |d: &Drone| sam.track(d.id).is_none_or(|tr| sam.doctrine.area_blocks(sam.pos, tr, now) == 0);
@@ -639,7 +687,7 @@ impl Sim {
let est = tr.class;
let blocks = target_blocks(sam.roles, Some(tr), now, t);
let claimed_now = claimed(t, &missile_on, sam.target);
let chance = blocks & ROLE != 0 && last_chance(self.last_chance, sam.roles, est, t, claimed_now);
let chance = blocks & ROLE != 0 && self.last_chance_for(sam, est, t, claimed_now);
if blocks & ROLE != 0 && !chance {
return Some(reason(BattleKind::Blocked, Some(if sam.roles == 0 { BattleBlock::Hold } else { BattleBlock::OutOfRoles }), Some(t.id), mark));
}
@@ -837,7 +885,6 @@ impl Sim {
v.push(battle_check(self.battle_reason(index)));
return v;
}
let logistics = self.logistics();
let (missile_on, guns_on) = engagement_counts(&self.sams);
let alive = self.drones.iter().filter(|d| d.alive()).count();
let now = self.tick;
@@ -881,7 +928,7 @@ impl Sim {
// Of what the system's picture holds: a track of its roles' classes (or not yet
// classified), or a known out-of-role one about to hit (the last chance) — never
// the target's own class (#133).
.filter(|d| d.alive() && (sam.track(d.id).is_some_and(|tr| tr.class.in_roles(sam.roles)) || last_chance(self.last_chance, sam.roles, sam.track(d.id).map_or(ClassEst::Unknown, |tr| tr.class), d, claimed(d, &missile_on, sam.target))))
.filter(|d| d.alive() && (sam.track(d.id).is_some_and(|tr| tr.class.in_roles(sam.roles)) || self.last_chance_for(sam, sam.track(d.id).map_or(ClassEst::Unknown, |tr| tr.class), d, claimed(d, &missile_on, sam.target))))
.max_by(|a, b| {
// What the doctrine lets the system shoot at comes first; then the most threatening.
let area = |d: &Drone| sam.track(d.id).is_none_or(|tr| sam.doctrine.area_blocks(sam.pos, tr, self.tick) == 0);
@@ -917,7 +964,7 @@ impl Sim {
let est_at = track.map_or(t.pos, |tr| tr.est(now));
let evel = track.map_or(t.vel, |tr| tr.vel);
let first_claim = claimed(t, &missile_on, sam.target);
let chance = blocks & ROLE != 0 && last_chance(self.last_chance, sam.roles, est, t, first_claim);
let chance = blocks & ROLE != 0 && self.last_chance_for(sam, est, t, first_claim);
let role_text = if blocks & ROLE == 0 {
match est {
ClassEst::Unknown => "роль: тип не определён — цель ведётся по общим правилам, классовые ограничения не применяются".to_string(),
@@ -1004,7 +1051,7 @@ impl Sim {
let supply = if sam.reloading > 0 {
format!("перезарядка, ещё {:.1} с", sam.reloading as f64 / 20.0)
} else if sam.empty {
if logistics { "пуст, ждёт машину-заряжающую (ТЗМ) со склада".into() } else { "пуст".into() }
"пуст, ждёт пополнения со склада или ТЗМ".into()
} else {
"боезапас есть".into()
};
@@ -1195,6 +1242,46 @@ mod tests {
sim.sams[0].tracks.push(Track { id: d.id, class, pos: d.pos, vel: d.vel, tick: now, own_tick: now, source, product: battery::Measure::Fire, quality: 90, own_product: battery::Measure::Fire, own_quality: 90, ttl: 400, hits: 3, locked: false });
}
#[test]
fn last_chance_leaves_a_drone_for_a_ready_short_range_battery() {
let (mut sim, _, _, _) = setup(SamKind::S500);
sim.tick = 100;
shahed_at(&mut sim, 45.0);
seed_classified(&mut sim, ClassEst::Firm(Class::Drone));
let id = sim.id();
let mut gun = Sam::new(id, SamKind::Gepard, DVec3::new(5.0, 70.0, 0.0), 0.0);
gun.tracks.push(Track { source: id, ..sim.sams[0].tracks[0] });
sim.sams.push(gun);
let chance = |s: &Sim| s.last_chance_for(&s.sams[0], ClassEst::Firm(Class::Drone), &s.drones[0], 0);
assert!(!chance(&sim));
sim.sams[1].bursts = 0;
assert!(chance(&sim), "an empty gun may not block the fallback shot");
sim.sams[1].bursts = 20;
sim.sams[1].pos.x = 500.0;
assert!(chance(&sim), "a gun outside engagement range may not block the fallback shot");
}
#[test]
fn an_empty_s400_stays_empty_until_external_stock_pays_for_a_reload() {
let (mut sim, mut ground, land, mut out) = setup(SamKind::S400);
sim.sams[0].missiles = 0;
for _ in 0..900 {
serve(&mut ground, &land, sim.tick);
sim.step(&mut ground, None, &mut out);
}
assert_eq!((sim.sams[0].missiles, sim.sams[0].reloading), (0, 0));
assert!(sim.sams[0].empty);
let id = sim.id();
let mut depot = Sam::new(id, SamKind::Depot, DVec3::new(10.0, 70.0, 0.0), 0.0);
depot.cargo = 1;
sim.sams.push(depot);
for _ in 0..450 {
serve(&mut ground, &land, sim.tick);
sim.step(&mut ground, None, &mut out);
}
assert_eq!((sim.sams[0].missiles, sim.sams[1].cargo), (4, 0));
}
#[test]
fn last_chance_fires_at_a_class_out_of_roles_only_when_it_is_about_to_hit() {
// The S-400 does not engage drones by default.
@@ -1558,7 +1645,10 @@ mod tests {
sim.add_drone(DroneKind::Kh101, DVec3::new(0.0, 300.0, -300.0), DVec3::Z, DVec3::new(0.0, 70.0, 0.0));
let target = sim.drones[0].id;
let now = 1;
sim.sams[0].tracks.push(seeded_track(target, radar, 0, battery::Measure::Search, now));
sim.sams[0].tracks.push(Track {
class: ClassEst::Firm(Class::Cruise),
..seeded_track(target, radar, 0, battery::Measure::Search, now)
});
assert_eq!(sim.battle_reason(0).expect("a reason").kind, BattleKind::AwaitingTrack);
// Каналы заняты: the supporting radar has the contact but both tracked-contact channels