Compare commits
3 Commits
cd3c4ed76d
...
afe320786d
| Author | SHA1 | Date | |
|---|---|---|---|
| afe320786d | |||
| 733dc07863 | |||
| 5860c5009f |
@@ -97,7 +97,8 @@ CI: `.gitea/workflows/build.yml` на каждый пуш собирает то
|
||||
перенацеливает ещё не взлетевшие Ланцеты и Шахеды на них; если цель-комплекс уничтожен, дроны идут к
|
||||
следующему известному. Дроны под обстрелом прижимаются к земле.
|
||||
|
||||
**Ночь.** Ночью пушки попадают втрое хуже, если цель не освещена. Освещают **прожекторы** (луч ведёт ближайшую
|
||||
**Ночь.** Исправные пушки с собственным свежим радарным сопровождением не теряют точность из-за темноты.
|
||||
Цели освещают **прожекторы** (луч ведёт ближайшую
|
||||
цель из сети, приоритет — цели пушек) и **осветительные ракеты**: пушечные комплексы пускают их сами (раз в
|
||||
25 с на цель в темноте), игрок — **осветительным пистолетом** или `/airdef flare`. Ракета висит ~30 с и
|
||||
освещает всё вокруг на ~60–90 м.
|
||||
|
||||
@@ -535,10 +535,15 @@ impl Player {
|
||||
}
|
||||
}
|
||||
for tr in rec.tracks.iter().filter(|tr| (self.heard..self.t).contains(&(tr.first as f64))) {
|
||||
if let What::Missile(kind, _) = tr.what
|
||||
let event = match tr.what {
|
||||
What::Missile(kind, _) => Some(kind.launch_sound()),
|
||||
What::Strike => Some(DroneKind::Kalibr.launch_sound()),
|
||||
What::Drone(_) => None,
|
||||
};
|
||||
if let Some(event) = event
|
||||
&& let Some(p) = tr.at(rec.origin, tr.first as f64)
|
||||
{
|
||||
out.sound(kind.launch_sound(), heard(p), 1.0, 1.0);
|
||||
out.sound(event, heard(p), 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
self.heard = self.t;
|
||||
@@ -1102,6 +1107,27 @@ mod engine_tests {
|
||||
let _ = rec;
|
||||
p
|
||||
}
|
||||
#[test]
|
||||
fn counter_strike_launch_is_heard_once_and_can_be_replayed_after_seek() {
|
||||
let mut rec = Recording::blank(100);
|
||||
rec.straight(1, What::Strike, 10, 70, DVec3::ZERO, DVec3::new(300.0, 70.0, 0.0));
|
||||
let mut p = player(&rec);
|
||||
p.heard = 9.0;
|
||||
p.t = 11.0;
|
||||
let mut out = Out::default();
|
||||
p.sounds(&rec, DVec3::ZERO, &mut out);
|
||||
assert_eq!(out.sounds.len(), 1);
|
||||
assert_eq!(out.sounds[0].0, DroneKind::Kalibr.launch_sound());
|
||||
out.sounds.clear();
|
||||
p.t = 12.0;
|
||||
p.sounds(&rec, DVec3::ZERO, &mut out);
|
||||
assert!(out.sounds.is_empty(), "the loop engine must not repeat the launch");
|
||||
p.heard = 9.0; // seek/cut resets the one-shot cursor
|
||||
p.t = 11.0;
|
||||
p.sounds(&rec, DVec3::ZERO, &mut out);
|
||||
assert_eq!(out.sounds.len(), 1);
|
||||
}
|
||||
|
||||
/// A host that remembers which sources run.
|
||||
#[derive(Default)]
|
||||
struct Host(std::collections::BTreeMap<u32, [f64; 3]>);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Night fighting: guns aim by sight, and at night they hit far less unless
|
||||
//! the target is lit. Searchlights follow the network's tracks with their
|
||||
//! Night fighting: darkness penalizes aiming without fresh radar fire control,
|
||||
//! unless the target is lit. Searchlights follow the network's tracks with their
|
||||
//! beams; illumination flares (fired by the guns on their own, or by the
|
||||
//! player) hang over the sky for half a minute and light everything round.
|
||||
use super::*;
|
||||
@@ -24,6 +24,11 @@ pub const DARK_HITS: f64 = 0.4;
|
||||
/// Ticks between a gun's own flares.
|
||||
const FLARE_EVERY: u32 = 500;
|
||||
|
||||
/// Night only reduces a gun's hit chance when it has to aim by sight.
|
||||
pub(super) fn hit_factor(night: bool, lit: bool, radar_fire_control: bool) -> f64 {
|
||||
if night && !lit && !radar_fire_control { DARK_HITS } else { 1.0 }
|
||||
}
|
||||
|
||||
pub struct Flare {
|
||||
id: u32,
|
||||
pub pos: DVec3,
|
||||
|
||||
@@ -2728,8 +2728,11 @@ impl Sim {
|
||||
let event = if sam.kind == SamKind::Pantsir { "airdef:gun.pantsir" } else { "airdef:gun.gepard" };
|
||||
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 };
|
||||
// A fresh working own-radar fire-control track does not depend on seeing the target.
|
||||
// Guns without that radar picture still take the darkness penalty unless illuminated.
|
||||
let radar_fire_control = sam.radar_up()
|
||||
&& sam.track(gt).is_some_and(|tr| tr.own_within(now, sight::GUN_AGE));
|
||||
let dark = lights::hit_factor(self.night, self.lit.contains(&t.id), radar_fire_control);
|
||||
// The aim point is the track's forecast: the farther it is from the truth, the more shells miss.
|
||||
let off = est.distance(t.pos);
|
||||
let p = gun.p * sam.gun_fit() * dark / (t.kind.spec().stealth * (1.0 + (off / 8.0).powi(2))) * (1.0 - dist / (gun.range * 1.3)).max(0.35);
|
||||
|
||||
@@ -181,6 +181,34 @@ fn a_close_blast_can_leave_a_firing_but_immobile_system() {
|
||||
assert!(found, "no seed left it firing but immobile");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fresh_own_radar_track_keeps_gun_hits_equal_day_and_night() {
|
||||
fn firing(seed: u64, night: bool) -> (u32, u32) {
|
||||
let mut sim = Sim::new(seed);
|
||||
let (mut ground, mut out) = flat();
|
||||
let gun = radar_at(&mut sim, SamKind::Gepard, 0.0);
|
||||
sim.night = night;
|
||||
sim.add_drone(
|
||||
DroneKind::Shahed,
|
||||
DVec3::new(0.0, 95.0, 35.0),
|
||||
DVec3::ZERO,
|
||||
DVec3::new(5000.0, 95.0, 35.0),
|
||||
);
|
||||
let starting_bursts = sim.sams[gun].bursts;
|
||||
for _ in 0..240 {
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
}
|
||||
(starting_bursts - sim.sams[gun].bursts, sim.sams[gun].kills)
|
||||
}
|
||||
|
||||
for seed in 0..32 {
|
||||
let day = firing(seed, false);
|
||||
let night = firing(seed, true);
|
||||
assert!(day.0 > 0, "seed {seed} did not fire");
|
||||
assert_eq!(night, day, "seed {seed}: radar gun changed its fire or kills at night");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_parts_block_what_they_serve_and_repair_restores_them() {
|
||||
let mut sim = Sim::new(2);
|
||||
|
||||
@@ -587,12 +587,11 @@ impl Sim {
|
||||
let below = ground.at(DVec3::new(f.land.x, 0.0, f.land.y), now);
|
||||
let end = DVec3::new(f.land.x, below.unwrap_or(f.from.y), f.land.y);
|
||||
let t = ((now - f.start) as f64 / (f.arrive - f.start).max(1) as f64).clamp(0.0, 1.0);
|
||||
let want = f.from.lerp(end, t) + DVec3::Y * (TUNE.height * (std::f64::consts::PI * t).sin().max(0.0).sqrt());
|
||||
let planned = f.from.lerp(end, t) + DVec3::Y * (TUNE.height * (std::f64::consts::PI * t).sin().max(0.0).sqrt());
|
||||
let from = f.pos;
|
||||
if now >= f.arrive && from.distance(end) <= TUNE.speed * 1.5 + 2.0 {
|
||||
self.land_strike(f, from, ground, player, out);
|
||||
continue;
|
||||
}
|
||||
// Time spent waiting for world data must not accumulate into a faster step.
|
||||
let delta = planned - from;
|
||||
let want = from + delta.clamp_length_max(TUNE.speed);
|
||||
// A missile that never reaches its point (the world never tells of the way) ends somewhere: it does
|
||||
// not stay in the air for ever.
|
||||
if now >= f.arrive + 600 {
|
||||
@@ -605,9 +604,11 @@ impl Sim {
|
||||
}
|
||||
let sweep = ground.trace(f.key(), from, want, false, now);
|
||||
let mut pos = want;
|
||||
let mut permitted = true;
|
||||
let contact = match sweep {
|
||||
world::Sweep::Hit { point, .. } => Some(point),
|
||||
world::Sweep::Wait { t } => {
|
||||
permitted = false;
|
||||
pos = from.lerp(want, (t - 1e-6).max(0.0));
|
||||
None
|
||||
}
|
||||
@@ -616,19 +617,32 @@ impl Sim {
|
||||
// the game doesn't have (not one still loading) is passed, high over the land.
|
||||
let low = ground.at(from, now).is_some_and(|g| from.y < g + 12.0);
|
||||
if let Some(t) = ground.unread(&sweep, &mut f.hold, low) {
|
||||
permitted = false;
|
||||
pos = from.lerp(want, t);
|
||||
}
|
||||
None
|
||||
}
|
||||
world::Sweep::Clear => None,
|
||||
world::Sweep::Clear => {
|
||||
ground.unread(&sweep, &mut f.hold, false);
|
||||
None
|
||||
},
|
||||
};
|
||||
if let Some(point) = contact {
|
||||
self.crash_strike(f, point, ground, player, out);
|
||||
// A surface exactly at the intended endpoint is the landing, not an intervening wall.
|
||||
if point.distance(end) < 1e-6 {
|
||||
self.land_strike(f, point, ground, player, out);
|
||||
} else {
|
||||
self.crash_strike(f, point, ground, player, out);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if permitted && pos.distance(end) < 1e-6 {
|
||||
self.land_strike(f, pos, ground, player, out);
|
||||
continue;
|
||||
}
|
||||
// The land's height says it met the ground where the blocks were not read: the same contact.
|
||||
let here = ground.at(pos, now);
|
||||
if ground.ground_hit(here, pos, 0.2, &sweep, now) {
|
||||
if permitted && ground.ground_hit(here, pos, 0.2, &sweep, now) {
|
||||
self.crash_strike(f, pos, ground, player, out);
|
||||
continue;
|
||||
}
|
||||
@@ -641,7 +655,7 @@ impl Sim {
|
||||
out.model(id + 1, "airdef:geran3_flame", pos + rot * DVec3::new(0.0, up * spec.scale, back * spec.scale), rot, spec.scale * size * flicker, true);
|
||||
}
|
||||
if let Some((event, pitch)) = DroneKind::Kalibr.engine_voice() {
|
||||
out.engine(id, event, pos, dir * TUNE.speed, 0.8, pitch, false);
|
||||
out.engine(id, event, pos, pos - from, 0.8, pitch, false);
|
||||
}
|
||||
f.pos = pos;
|
||||
rest.push(f);
|
||||
@@ -1413,6 +1427,52 @@ mod tests {
|
||||
assert_eq!(sim.strikes.fired, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn terminal_wall_is_resolved_before_landing() {
|
||||
let mut sim = Sim::new(11);
|
||||
sim.strikes.cover_override = Some(0);
|
||||
let id = fixed_site(&mut sim, DVec3::new(0.0, 64.0, 300.0), 2);
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
sim.order_strike(id, DVec3::new(0.0, 64.0, 0.0), &mut out).unwrap();
|
||||
let f = sim.strikes.flights[0];
|
||||
let wall = Wall { at: f.land.y.floor() as i32 - 1, hole: None };
|
||||
for _ in 0..500 {
|
||||
serve(&mut ground, &wall, sim.tick);
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
if sim.strikes.flights.is_empty() { break; }
|
||||
}
|
||||
assert!(sim.strikes.flights.is_empty());
|
||||
assert_eq!((sim.strikes.destroyed, sim.strikes.missed), (0, 1));
|
||||
assert!(sim.sites.get(id).unwrap().alive);
|
||||
assert_eq!(sim.sites.pending(id), 2);
|
||||
assert!(matches!(strike_events(&sim).as_slice(), [record::EventKind::Strike { result: record::StrikeResult::Blocked, .. }]));
|
||||
assert!((sim.blasts[0].at.z - f64::from(wall.at)).abs() < 0.01);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delayed_world_answers_do_not_accelerate_the_strike() {
|
||||
let mut sim = Sim::new(11);
|
||||
sim.strikes.cover_override = Some(0);
|
||||
let id = fixed_site(&mut sim, DVec3::new(0.0, 64.0, 1000.0), 0);
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
sim.order_strike(id, DVec3::new(0.0, 64.0, 0.0), &mut out).unwrap();
|
||||
for _ in 0..20 { sim.step(&mut ground, None, &mut out); }
|
||||
let f = sim.strikes.flights[0];
|
||||
let open = Wall { at: 10_000, hole: None };
|
||||
warm(&mut ground, &open, f.from, DVec3::new(f.land.x, 110.0, f.land.y));
|
||||
let mut previous = f.pos;
|
||||
for _ in 0..500 {
|
||||
serve(&mut ground, &open, sim.tick);
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
if let Some(f) = sim.strikes.flights.first() {
|
||||
assert!(previous.distance(f.pos) <= TUNE.speed + 1e-8, "jump at tick {}", sim.tick);
|
||||
previous = f.pos;
|
||||
} else { break; }
|
||||
}
|
||||
assert!(sim.strikes.flights.is_empty(), "strike failed to arrive");
|
||||
assert_eq!(sim.strikes.destroyed, 1, "{:?}", out.messages);
|
||||
}
|
||||
|
||||
// #106: an open way works as before: the missile reaches its point, the site dies, one result, one stock spent.
|
||||
#[test]
|
||||
fn a_counter_strike_on_an_open_way_still_reaches_its_site() {
|
||||
|
||||
@@ -247,6 +247,9 @@ impl Smoke {
|
||||
self.trail((1, m.id), m.pos, tick, look);
|
||||
}
|
||||
}
|
||||
for f in &sim.strikes.flights {
|
||||
self.trail((2, f.id), f.pos, tick, drone_look(Class::Cruise, crate::sim::DroneKind::Kalibr.spec().trail_scale()));
|
||||
}
|
||||
// Forget what is gone.
|
||||
if tick % 100 == 0 {
|
||||
let alive: std::collections::HashSet<(u8, u32)> = sim
|
||||
@@ -254,6 +257,7 @@ impl Smoke {
|
||||
.iter()
|
||||
.map(|d| (0, d.id))
|
||||
.chain(sim.missiles.iter().map(|m| (1, m.id)))
|
||||
.chain(sim.strikes.flights.iter().map(|f| (2, f.id)))
|
||||
.collect();
|
||||
self.last.retain(|k, _| alive.contains(k));
|
||||
}
|
||||
@@ -286,6 +290,44 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::sim::{DroneKind, MissileKind};
|
||||
|
||||
#[test]
|
||||
fn live_counter_strike_leaves_a_trail_and_releases_its_source() {
|
||||
use crate::sim::sites::{LaunchSite, SiteClass};
|
||||
use crate::sim::strike::{Estimate, Known, SiteState};
|
||||
use glam::DVec2;
|
||||
let mut sim = Sim::new(11);
|
||||
let id = 1;
|
||||
sim.sites.list.push(LaunchSite {
|
||||
id, side: 0, sector: 0, bearing: 0.0, class: SiteClass::Ramp,
|
||||
pos: DVec3::new(0.0, 64.0, 300.0), range: 300.0, water: false,
|
||||
stock: 0, planned: 0, alive: true, next_free: 0, offmap: false,
|
||||
});
|
||||
sim.strikes.known.push(Known {
|
||||
site: id, class: SiteClass::Ramp, obs: Vec::new(),
|
||||
est: Some(Estimate { pos: DVec2::new(0.0, 300.0), radius: 5.0, fix: true,
|
||||
bearing: 0.0, bearing_err: 0.01, origin: DVec2::ZERO }),
|
||||
launches: 1, last: 0, state: SiteState::Active, cover: None, aimed: false,
|
||||
});
|
||||
sim.order_strike(id, DVec3::new(0.0, 64.0, 0.0), &mut crate::sim::Out::default()).unwrap();
|
||||
let mut smoke = Smoke::default();
|
||||
sim.tick = 1;
|
||||
smoke.update(&sim);
|
||||
let from = sim.strikes.flights[0].pos;
|
||||
sim.tick = 2;
|
||||
sim.strikes.flights[0].pos += DVec3::Z * 8.0;
|
||||
smoke.update(&sim);
|
||||
let segments = smoke.segments(&sim);
|
||||
assert_eq!(segments.len(), 1, "a live strike must emit the cruise trail also seen in replay");
|
||||
assert_eq!(segments[0].az, from.z);
|
||||
assert_eq!(segments[0].bz, from.z + 8.0);
|
||||
let expected = drone_look(Class::Cruise, DroneKind::Kalibr.spec().trail_scale());
|
||||
assert_eq!(segments[0].density, expected.density);
|
||||
sim.strikes.flights.clear();
|
||||
sim.tick = 100;
|
||||
smoke.update(&sim);
|
||||
assert!(smoke.last.is_empty(), "finished strikes must not leave source bookkeeping behind");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trails_follow_one_rule() {
|
||||
assert!(missile_look(MissileKind::P1sun).is_none());
|
||||
|
||||
Reference in New Issue
Block a user