The player's picture and the enemy's intel apart from the truth (#93); world answers carry their context, worlds told apart by seed, a drone that can't reach its aim gives up (#90)
build / mod (push) Successful in 8m25s
build / mod (push) Successful in 8m25s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,7 +162,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
fn track(pos: DVec3, vel: DVec3) -> Track {
|
||||
Track { id: 1, pos, vel, tick: 0, own_tick: 0, ttl: 100, hits: 3, locked: false }
|
||||
Track { id: 1, kind: DroneKind::Shahed, pos, vel, tick: 0, own_tick: 0, ttl: 100, hits: 3, locked: false }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -145,6 +145,12 @@ impl Sim {
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether the enemy has this unit in its intelligence: a radar emits, so it is known; the rest only once
|
||||
/// they gave themselves away (a launch, jamming) and are in `known`.
|
||||
pub(super) fn enemy_knows(s: &Sam, known: &[(u32, DVec3)]) -> bool {
|
||||
s.alive() && (s.kind == SamKind::Radar || known.iter().any(|k| k.0 == s.id))
|
||||
}
|
||||
|
||||
/// During a smart raid: its drones not yet launched go for what just gave itself away (a jamming station
|
||||
/// first, then systems that fired), and drones whose system target is gone pick another.
|
||||
pub(super) fn adapt(&mut self) {
|
||||
|
||||
@@ -36,7 +36,7 @@ mod regress;
|
||||
mod sensor_tests;
|
||||
pub use ew::EW_RADIUS;
|
||||
pub use damage::{Comps, Part, PartState};
|
||||
pub use sight::{Ident, LowSensor, Track, RIM_RAYS};
|
||||
pub use sight::{AirPicture, Ident, LowSensor, Track, RIM_RAYS};
|
||||
use damage::dice;
|
||||
use outcome::{Impact, Outcome};
|
||||
pub use units::{Family, SamKind};
|
||||
@@ -245,10 +245,19 @@ pub struct Ground {
|
||||
swept: u64,
|
||||
/// The tick of the last answer round: what the heights' ages are measured against.
|
||||
now: u64,
|
||||
/// The world's epoch when the last questions went out: an answer to them is of that world or dimension, or of none.
|
||||
asked_epoch: Option<u32>,
|
||||
/// The blocks themselves (issues #42, #43): what stops a flight.
|
||||
pub world: world::WorldCache,
|
||||
}
|
||||
|
||||
/// What `render.ground` answers where the chunk is not loaded (and never will be, unless asked for).
|
||||
pub const NO_LAND: i32 = -64;
|
||||
/// A height the game answered as a land height: none where it had no chunk. The one place that reads `NO_LAND`.
|
||||
pub(crate) fn land_height(y: i32) -> Option<f64> {
|
||||
(y > NO_LAND).then_some(f64::from(y))
|
||||
}
|
||||
|
||||
/// 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.
|
||||
@@ -279,7 +288,7 @@ impl Ground {
|
||||
if (when == STALE || now.saturating_sub(when) > 200) && self.wanted.len() < 64 && self.asked.insert(key) {
|
||||
self.wanted.push(key);
|
||||
}
|
||||
(y > -64).then_some(f64::from(y))
|
||||
land_height(y)
|
||||
}
|
||||
None => {
|
||||
if self.wanted.len() < 256 && self.asked.insert(key) {
|
||||
@@ -289,8 +298,18 @@ impl Ground {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The game's answers to the questions of `take_wanted`. Each is a height (`land_height`), "no land" or
|
||||
/// "loading"; one to a question of another world or dimension than the one open now is dropped (it is
|
||||
/// asked again when needed), not taken as this one's.
|
||||
pub fn answer(&mut self, answers: Vec<(i32, i32, i32)>, now: u64) {
|
||||
self.now = now;
|
||||
let answers = match self.asked_epoch.take() {
|
||||
Some(e) if e != 0 && e != self.world.epoch() => {
|
||||
self.world.stats.late_dropped += answers.len() as u64;
|
||||
Vec::new()
|
||||
}
|
||||
_ => answers,
|
||||
};
|
||||
for (x, z, y) in answers {
|
||||
if y == PENDING {
|
||||
self.loading.insert((x, z), now);
|
||||
@@ -304,6 +323,12 @@ impl Ground {
|
||||
self.loading.retain(|_, t| now.saturating_sub(*t) < 400);
|
||||
}
|
||||
self.age_heights();
|
||||
// Blasts the game did not report in the blocks: the land there is looked at again.
|
||||
for at in self.world.overdue_blasts(now) {
|
||||
let how = if self.peek(at).is_some() { world::Settled::Unchanged } else { world::Settled::Unloaded };
|
||||
self.world.note_settled(how);
|
||||
self.forget(at, 8);
|
||||
}
|
||||
if self.known.len() > 300_000 && now.saturating_sub(self.swept) >= SWEEP_EVERY {
|
||||
self.swept = now;
|
||||
self.known.retain(|_, (_, when)| now.saturating_sub(*when) < 2000);
|
||||
@@ -312,6 +337,13 @@ impl Ground {
|
||||
/// Heights over blocks that changed (the block cache's notes of changes, chunk replacements and a new world)
|
||||
/// are marked old (`when` = STALE): still used, asked again within the budget. #64.
|
||||
fn age_heights(&mut self) {
|
||||
// Another world or dimension: nothing known, asked or loading belongs to this one.
|
||||
if std::mem::take(&mut self.world.epoch_reset) {
|
||||
self.known.clear();
|
||||
self.loading.clear();
|
||||
self.wanted.clear();
|
||||
self.asked.clear();
|
||||
}
|
||||
let all = std::mem::take(&mut self.world.changed_all);
|
||||
let cols = std::mem::take(&mut self.world.changed_cols);
|
||||
if !all && cols.is_empty() {
|
||||
@@ -359,14 +391,14 @@ impl Ground {
|
||||
// What was answered as "no chunk" there is asked again: the chunk is being loaded now.
|
||||
for x in c.0 * 16..c.0 * 16 + 16 {
|
||||
for z in c.1 * 16..c.1 * 16 + 16 {
|
||||
if self.known.get(&(x, z)).is_some_and(|v| v.0 <= -64) {
|
||||
if self.known.get(&(x, z)).is_some_and(|v| land_height(v.0).is_none()) {
|
||||
self.known.remove(&(x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
for x in (c.0 * 16..c.0 * 16 + 16).step_by(8) {
|
||||
for z in (c.1 * 16..c.1 * 16 + 16).step_by(8) {
|
||||
if self.known.get(&(x + 4, z + 4)).is_some_and(|v| v.0 <= -64) {
|
||||
if self.known.get(&(x + 4, z + 4)).is_some_and(|v| land_height(v.0).is_none()) {
|
||||
self.known.remove(&(x + 4, z + 4));
|
||||
}
|
||||
}
|
||||
@@ -383,6 +415,7 @@ impl Ground {
|
||||
}
|
||||
pub fn take_wanted(&mut self) -> Vec<(i32, i32)> {
|
||||
self.asked.clear();
|
||||
self.asked_epoch = Some(self.world.epoch());
|
||||
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).
|
||||
@@ -926,6 +959,40 @@ pub struct Drone {
|
||||
err: DVec3,
|
||||
/// Ticks held at the edge of blocks the game has not told of (#61); reset by a clear step.
|
||||
hold: u16,
|
||||
/// Its progress towards the aim: a flight that stops getting nearer runs out of fuel (see `Pace`).
|
||||
pace: Pace,
|
||||
}
|
||||
|
||||
/// Ticks a cruise flight may go without getting nearer its aim or passing a route point before it is out of fuel:
|
||||
/// long enough for a detour round a radar, far short of `MAX_FLIGHT`. It stops a drone circling an aim it
|
||||
/// cannot turn onto, or one that holds for an answer that never comes, from loitering over the map for ever.
|
||||
pub const STALL_TICKS: u32 = 3600;
|
||||
/// How much nearer counts as getting nearer (blocks).
|
||||
const STALL_GAIN: f64 = 10.0;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Pace {
|
||||
/// The least distance to the aim so far, the age it was reached at, and the route points left then.
|
||||
best: f64,
|
||||
at: u32,
|
||||
route: usize,
|
||||
}
|
||||
|
||||
impl Default for Pace {
|
||||
fn default() -> Self {
|
||||
Pace { best: f64::INFINITY, at: 0, route: usize::MAX }
|
||||
}
|
||||
}
|
||||
|
||||
impl Pace {
|
||||
/// One tick: true when the flight has gone `STALL_TICKS` without progress.
|
||||
fn stalled(&mut self, age: u32, distance: f64, route: usize) -> bool {
|
||||
if distance + STALL_GAIN < self.best || route < self.route {
|
||||
*self = Pace { best: distance.min(self.best), at: age, route };
|
||||
return false;
|
||||
}
|
||||
age.saturating_sub(self.at) > STALL_TICKS
|
||||
}
|
||||
}
|
||||
|
||||
/// A drone's terrain following: refreshed every few ticks, used every one.
|
||||
@@ -1510,6 +1577,8 @@ pub struct Sim {
|
||||
pub hits: u32,
|
||||
/// Drones that struck the land or a building short of their aim.
|
||||
pub crashes: u32,
|
||||
/// Cruise flights that ran out of fuel for making no headway (`STALL_TICKS`).
|
||||
pub stalled: u32,
|
||||
/// Systems just deployed by hand and not yet checked for standing in the land: (id, until tick).
|
||||
settling: Vec<(u32, u64)>,
|
||||
/// What crashed, where, and its aim (balance measurements only).
|
||||
@@ -1604,6 +1673,7 @@ impl Sim {
|
||||
kills: 0,
|
||||
hits: 0,
|
||||
crashes: 0,
|
||||
stalled: 0,
|
||||
settling: Vec::new(),
|
||||
#[cfg(test)]
|
||||
crashed: Vec::new(),
|
||||
@@ -1949,6 +2019,15 @@ impl Sim {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Out of fuel: no nearer its aim for a long time (it circles, or waits for what never comes): it falls
|
||||
// where it is, a wreck like any other, and the raid is not held open by it.
|
||||
if d.pace.stalled(d.age, d.pos.distance(d.target), d.route.len()) {
|
||||
d.flight = Flight::Falling;
|
||||
d.age = 0;
|
||||
d.vel *= 0.35;
|
||||
self.stalled += 1;
|
||||
continue;
|
||||
}
|
||||
// An interceptor coming: drones drop to the treetops (radars lose them sooner).
|
||||
if d.engaged > 0 && matches!(spec.class, Class::Drone | Class::Jet) {
|
||||
d.low = true;
|
||||
@@ -2162,6 +2241,7 @@ impl Sim {
|
||||
nav: Nav::default(),
|
||||
err: DVec3::ZERO,
|
||||
hold: 0,
|
||||
pace: Pace::default(),
|
||||
});
|
||||
}
|
||||
for d in &self.drones {
|
||||
@@ -2255,6 +2335,7 @@ impl Sim {
|
||||
));
|
||||
}
|
||||
ground.forget(pos, 8);
|
||||
ground.world.expect_blast(pos, 8.0, self.tick);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -512,6 +512,7 @@ impl Sim {
|
||||
nav: Nav::default(),
|
||||
err,
|
||||
hold: 0,
|
||||
pace: Pace::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,8 +561,11 @@ impl Sim {
|
||||
}
|
||||
// Smart: each kind at what it is good against; what gave itself away first (a jamming
|
||||
// station, a radar, a system that fired).
|
||||
// The planner has only what the enemy knows (#93): the radars (they emit) and the units that gave
|
||||
// themselves away; the rest of the player's layout is not in its hands.
|
||||
let known = self.known_units();
|
||||
let known_ew: Vec<&Sam> = alive.iter().copied().filter(|s| s.kind == SamKind::Ew && known.iter().any(|k| k.0 == s.id)).collect();
|
||||
let alive: Vec<&Sam> = alive.iter().copied().filter(|s| Self::enemy_knows(s, &known)).collect();
|
||||
let known_ew: Vec<&Sam> = alive.iter().copied().filter(|s| s.kind == SamKind::Ew).collect();
|
||||
if matches!(kind, DroneKind::Lancet | DroneKind::Kh22) && !known_ew.is_empty() && roll < 0.6 {
|
||||
let s = known_ew[(r * known_ew.len() as f64) as usize % known_ew.len()];
|
||||
return (s.pos, Some(s.id));
|
||||
@@ -593,6 +597,7 @@ impl Sim {
|
||||
let mut cost = 0;
|
||||
let spec = kind.spec();
|
||||
let height = spec.clearance.max(6.0);
|
||||
let known_now = self.known_units();
|
||||
let n = grid.size;
|
||||
let mut prices = vec![1.0f32; (n * n) as usize];
|
||||
// Known jamming stations: drones that navigate by satellite keep away.
|
||||
@@ -610,7 +615,8 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
}
|
||||
for s in self.sams.iter().filter(|s| s.alive() && s.roles & spec.class.bit() != 0) {
|
||||
// Only the systems the enemy knows of are priced in (#93): a hidden one is flown into.
|
||||
for s in self.sams.iter().filter(|s| s.alive() && s.roles & spec.class.bit() != 0 && Self::enemy_knows(s, &known_now)) {
|
||||
let sp = s.kind.spec();
|
||||
let (lo, hi) = sp.missile.as_ref().map_or((0.0, 0.0), |m| (m.min, m.max));
|
||||
let gun = sp.gun.as_ref().map_or(0.0, |g| g.range);
|
||||
|
||||
@@ -51,6 +51,10 @@ fn network_launcher_must_contribute_to_route_risk() {
|
||||
let id=sim.id();sim.sams.push(Sam::new(id,SamKind::P1sun,DVec3::new(0.,70.,0.),0.));
|
||||
let id=sim.id();sim.sams.push(Sam::new(id,SamKind::Radar,DVec3::new(0.,70.,0.),0.));
|
||||
let grid=Grid{min:DVec3::new(-160.,0.,-160.),cell:16.,size:20};
|
||||
// #93: the planner prices only what the enemy knows; the radar emits, the launcher is not known until it gives itself away.
|
||||
let (prices,_)=sim.price_grid(&grid,DroneKind::Shahed);
|
||||
assert!(prices.iter().all(|p|*p==1.),"an unknown launcher must not be priced");
|
||||
sim.intel.revealed.push((sim.sams[0].id,DVec3::new(0.,70.,0.),0));
|
||||
let (prices,_)=sim.price_grid(&grid,DroneKind::Shahed);
|
||||
assert!(prices.iter().any(|p|*p>1.),"armed launcher with a network radar is invisible to route risk");
|
||||
}
|
||||
@@ -1711,3 +1715,92 @@ fn over_unknown_land_a_flight_does_not_descend() {
|
||||
}
|
||||
assert!(sim.drones[0].pos.y > 245.0, "it came down over unknown land: {}", sim.drones[0].pos.y);
|
||||
}
|
||||
|
||||
/// #90: a cruise flight that stops getting nearer its aim (a turn circle wider than the distance, a hold that
|
||||
/// never ends) falls out of the sky after `STALL_TICKS`, so a raid is not held open by it.
|
||||
#[test]
|
||||
fn a_flight_that_makes_no_headway_runs_out_of_fuel() {
|
||||
let mut pace = Pace::default();
|
||||
// Nearer and nearer: never stalled.
|
||||
for age in 1..10_000u32 {
|
||||
assert!(!pace.stalled(age, 5000.0 - f64::from(age) * 0.5, 1), "a flight under way stalled at {age}");
|
||||
}
|
||||
// Circling at 40 blocks from the aim.
|
||||
let mut pace = Pace::default();
|
||||
let mut ended = None;
|
||||
for age in 1..10_000u32 {
|
||||
if pace.stalled(age, 40.0 + f64::from(age % 7), 1) {
|
||||
ended = Some(age);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let ended = ended.expect("a circling flight never ran out of fuel");
|
||||
assert!((STALL_TICKS..STALL_TICKS + 20).contains(&ended), "{ended}");
|
||||
// Passing a route point is progress, however far off the aim the way goes.
|
||||
let mut pace = Pace::default();
|
||||
for age in 1..10_000u32 {
|
||||
assert!(!pace.stalled(age, 3000.0, 10 - (age / 1000) as usize), "route points passed, still stalled at {age}");
|
||||
}
|
||||
}
|
||||
|
||||
/// #90: the same in the simulation: a drone that gets no nearer its aim (here the aim keeps its distance, as one
|
||||
/// does that it cannot turn onto) ends, falling, within the stall time, and the raid is not held open by it.
|
||||
#[test]
|
||||
fn a_drone_that_never_arrives_ends_the_raid() {
|
||||
let mut sim = Sim::new(4);
|
||||
let mut d = sim.make_drone(DroneKind::Kh101, DVec3::new(0.0, 400.0, 0.0), DVec3::X, DVec3::new(3000.0, 400.0, 0.0));
|
||||
d.low = false;
|
||||
sim.drones.push(d);
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
let mut ended = None;
|
||||
for t in 0..STALL_TICKS + 400 {
|
||||
if let Some(d) = sim.drones.first_mut() {
|
||||
d.target = d.pos + DVec3::X * 3000.0;
|
||||
}
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
if !sim.drones.iter().any(|d| d.alive()) {
|
||||
ended = Some(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let ended = ended.expect("still airborne after the stall time");
|
||||
assert!(ended >= STALL_TICKS, "ended early: {ended}");
|
||||
assert_eq!(sim.stalled, 1);
|
||||
}
|
||||
|
||||
/// #90: an answer says which world it is of. Heights of another dimension are not this one's, and an answer to a
|
||||
/// question asked before the world changed is dropped, not read as the new world's.
|
||||
#[test]
|
||||
fn heights_of_another_world_are_void_and_late_answers_are_dropped() {
|
||||
let mut ground = Ground::default();
|
||||
ground.world.changed_rev(1, 0, false, &[]);
|
||||
ground.answer(vec![(4, 4, 70), (12, 4, NO_LAND)], 1);
|
||||
assert_eq!(ground.land_state(DVec3::new(4.5, 80.0, 4.5)), Some(Some(70.0)));
|
||||
assert_eq!(ground.land_state(DVec3::new(12.5, 80.0, 4.5)), Some(None), "no land is an answer too");
|
||||
// A question goes out in world 1; the dimension changes before the answer comes.
|
||||
let _ = ground.land(DVec3::new(100.5, 80.0, 100.5));
|
||||
assert_eq!(ground.take_wanted().len(), 1);
|
||||
ground.world.changed_rev(2, 0, false, &[]);
|
||||
ground.answer(vec![(100, 100, 55)], 2);
|
||||
assert_eq!(ground.world.stats.late_dropped, 1);
|
||||
assert_eq!(ground.land_state(DVec3::new(4.5, 80.0, 4.5)), None, "the old dimension's height is gone, asked again");
|
||||
assert_eq!(ground.land_state(DVec3::new(100.5, 80.0, 100.5)), None, "the late answer was not taken");
|
||||
}
|
||||
|
||||
/// #90: a blast asked of the game in the blocks is confirmed by the game's own report of blocks changed there; one
|
||||
/// that is not reported is told apart by whether the land was there.
|
||||
#[test]
|
||||
fn a_blast_in_the_blocks_waits_for_the_games_word() {
|
||||
let mut ground = Ground::default();
|
||||
ground.answer(vec![(4, 4, 70)], 1);
|
||||
let near = DVec3::new(4.5, 70.0, 4.5);
|
||||
let far = DVec3::new(900.5, 70.0, 900.5);
|
||||
ground.world.expect_blast(near, 8.0, 1);
|
||||
ground.world.expect_blast(near + DVec3::X * 200.0, 8.0, 1);
|
||||
ground.world.expect_blast(far, 8.0, 1);
|
||||
ground.world.changed_rev(1, 1, false, &[(0, 4, 0)]);
|
||||
assert_eq!(ground.world.stats.blasts_confirmed, 1);
|
||||
ground.answer(vec![], 1 + world::CONFIRM_TICKS);
|
||||
let s = ground.world.stats;
|
||||
assert_eq!((s.blasts_asked, s.blasts_confirmed, s.blasts_unchanged, s.blasts_unloaded), (3, 1, 0, 2));
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ impl Ground {
|
||||
let hit = self.known.get(&k).or_else(|| {
|
||||
self.known.get(&(k.0.div_euclid(LAT) * LAT + LAT / 2, k.1.div_euclid(LAT) * LAT + LAT / 2))
|
||||
});
|
||||
hit.and_then(|&(y, _)| (y > -64).then_some(f64::from(y)))
|
||||
hit.and_then(|&(y, _)| land_height(y))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,6 +235,8 @@ impl Ident {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Track {
|
||||
pub id: u32,
|
||||
/// What the radar made of it when it measured (the class the picture shows).
|
||||
pub kind: DroneKind,
|
||||
/// Where it was and how it went when last measured (blocks, blocks a tick).
|
||||
pub pos: DVec3,
|
||||
pub vel: DVec3,
|
||||
@@ -248,6 +250,24 @@ pub struct Track {
|
||||
pub locked: bool,
|
||||
}
|
||||
|
||||
/// What the player's side knows of the air: the network's tracks as last measured, never the drones themselves.
|
||||
pub struct AirPicture {
|
||||
pub now: u64,
|
||||
pub tracks: Vec<Track>,
|
||||
/// No system is deployed: the tracks are the sky as it is.
|
||||
pub unaided: bool,
|
||||
}
|
||||
|
||||
impl AirPicture {
|
||||
pub fn get(&self, id: u32) -> Option<&Track> {
|
||||
self.tracks.iter().find(|t| t.id == id)
|
||||
}
|
||||
/// The track nearest to a point, by its forecast place.
|
||||
pub fn nearest(&self, to: DVec3) -> Option<&Track> {
|
||||
self.tracks.iter().min_by(|a, b| a.est(self.now).distance(to).total_cmp(&b.est(self.now).distance(to)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Track {
|
||||
pub fn age(&self, now: u64) -> u64 {
|
||||
now.saturating_sub(self.tick)
|
||||
@@ -396,6 +416,7 @@ impl Sim {
|
||||
let noise = DVec3::new(dice(seed, now, key, 1) - 0.5, (dice(seed, now, key, 2) - 0.5) * 0.5, dice(seed, now, key, 3) - 0.5) * 2.0 * sigma;
|
||||
fresh.push(Track {
|
||||
id: d.id,
|
||||
kind: d.kind,
|
||||
pos: d.pos + noise,
|
||||
vel: d.vel,
|
||||
tick: now,
|
||||
@@ -447,6 +468,25 @@ impl Sim {
|
||||
self.sams.iter().any(|s| s.seen.contains(&id))
|
||||
}
|
||||
|
||||
/// The air picture as the player's panel and radar read it (the only thing they read).
|
||||
pub fn air_picture(&self) -> AirPicture {
|
||||
let now = self.tick;
|
||||
// With no system deployed there is no radar to be blind: the sky as it is (the same fallback the screens
|
||||
// always had); a network's picture is only what it holds.
|
||||
let unaided = self.sams.is_empty();
|
||||
let mut tracks: Vec<Track> = if unaided {
|
||||
self.drones
|
||||
.iter()
|
||||
.filter(|d| d.alive())
|
||||
.map(|d| Track { id: d.id, kind: d.kind, pos: d.pos, vel: d.vel, tick: now, own_tick: now, ttl: 1, hits: 3, locked: false })
|
||||
.collect()
|
||||
} else {
|
||||
self.picture().into_values().collect()
|
||||
};
|
||||
tracks.sort_by_key(|t| t.id);
|
||||
AirPicture { now, tracks, unaided }
|
||||
}
|
||||
|
||||
/// The freshest track of each drone any system holds: the air picture.
|
||||
pub fn picture(&self) -> HashMap<u32, Track> {
|
||||
let mut best: HashMap<u32, Track> = HashMap::new();
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Ground {
|
||||
if self.due(when) && self.wanted.len() < ASK_MAX / 2 && self.asked.insert(key) {
|
||||
self.wanted.push(key);
|
||||
}
|
||||
if y > -64 { Rise::At(f64::from(y)) } else { Rise::Void }
|
||||
land_height(y).map_or(Rise::Void, Rise::At)
|
||||
}
|
||||
None => {
|
||||
if self.wanted.len() < ASK_MAX && self.asked.insert(key) {
|
||||
@@ -76,7 +76,7 @@ impl Ground {
|
||||
if self.due(when) && self.wanted.len() < cap / 2 && self.asked.insert((x, z)) {
|
||||
self.wanted.push((x, z));
|
||||
}
|
||||
Some((y > -64).then_some(f64::from(y)))
|
||||
Some(land_height(y))
|
||||
}
|
||||
None => {
|
||||
// A chunk the game is loading is asked about again in a few ticks, not every one.
|
||||
|
||||
@@ -640,7 +640,7 @@ mod tests {
|
||||
.drones
|
||||
.iter()
|
||||
.filter(|d| d.alive())
|
||||
.map(|d| Track { id: d.id, pos: d.pos, vel: d.vel, tick: now, own_tick: now, ttl: 400, hits: 3, locked: false })
|
||||
.map(|d| Track { id: d.id, kind: d.kind, pos: d.pos, vel: d.vel, tick: now, own_tick: now, ttl: 400, hits: 3, locked: false })
|
||||
.collect();
|
||||
for r in sim.sams.iter_mut().filter(|s| s.kind == SamKind::Radar) {
|
||||
for t in &tracks {
|
||||
|
||||
@@ -94,6 +94,13 @@ pub struct WorldStats {
|
||||
/// Sections dropped or re-read for a chunk's unload or replacement, or for age (#62).
|
||||
pub aged: u64,
|
||||
pub columns_changed: u64,
|
||||
/// Blasts asked in the blocks, and what became of them (`Settled`).
|
||||
pub blasts_asked: u64,
|
||||
pub blasts_confirmed: u64,
|
||||
pub blasts_unchanged: u64,
|
||||
pub blasts_unloaded: u64,
|
||||
/// Answers dropped for being to a question of another world or dimension.
|
||||
pub late_dropped: u64,
|
||||
}
|
||||
|
||||
/// What the game's exact ray said of a flight's step, once it answered (#63).
|
||||
@@ -182,9 +189,37 @@ pub struct WorldCache {
|
||||
/// Columns (section x, z) where blocks changed since the land heights last looked (#64); `all`: too many to say.
|
||||
pub(super) changed_cols: HashSet<(i32, i32)>,
|
||||
pub(super) changed_all: bool,
|
||||
/// Another world or dimension opened since the land heights last looked: they are all void.
|
||||
pub(super) epoch_reset: bool,
|
||||
/// Blasts the mod asked the game to make in the blocks (`Out.commands`), waiting for the game's word that
|
||||
/// blocks changed there. The game's damage (the simulation's own) and the geometry the game confirms
|
||||
/// are two things: this is the second (#90). Singleplayer: the client's world is the authority.
|
||||
expected: Vec<Expected>,
|
||||
pub stats: WorldStats,
|
||||
}
|
||||
|
||||
/// A blast asked for: the sections it reaches (lowest, highest) and the tick it was asked.
|
||||
struct Expected {
|
||||
lo: Sec,
|
||||
hi: Sec,
|
||||
at: DVec3,
|
||||
since: u64,
|
||||
}
|
||||
|
||||
/// Ticks the game has to report a block changed after a blast was asked for (the fuse is 0; commands run 64 a tick).
|
||||
pub const CONFIRM_TICKS: u64 = 100;
|
||||
|
||||
/// What became of a blast asked for in the blocks.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Settled {
|
||||
/// The game reported blocks changed in the sections it reaches.
|
||||
Confirmed,
|
||||
/// The chunk was there and nothing changed: nothing to break, a rule or the server's rights said no.
|
||||
Unchanged,
|
||||
/// There was no chunk to change.
|
||||
Unloaded,
|
||||
}
|
||||
|
||||
fn sec_of(x: i32, y: i32, z: i32) -> Sec {
|
||||
(x >> 4, y >> 4, z >> 4)
|
||||
}
|
||||
@@ -207,7 +242,7 @@ impl WorldCache {
|
||||
pub fn text(&self) -> String {
|
||||
let s = &self.stats;
|
||||
format!(
|
||||
"мир: {} секций ({} КБ), запросов {}, неизвестно {}, лучей {} (ударов {}, неизв. {}), клеток {}",
|
||||
"мир: {} секций ({} КБ), запросов {}, неизвестно {}, лучей {} (ударов {}, неизв. {}), клеток {}; взрывы в блоках: {} (подтверждено {}, без перемен {}, нет чанка {}), чужих ответов {}",
|
||||
self.len(),
|
||||
self.bytes() / 1024,
|
||||
s.sections_asked,
|
||||
@@ -215,7 +250,12 @@ impl WorldCache {
|
||||
s.sweeps,
|
||||
s.hits,
|
||||
s.unknown_sweeps,
|
||||
s.cells
|
||||
s.cells,
|
||||
s.blasts_asked,
|
||||
s.blasts_confirmed,
|
||||
s.blasts_unchanged,
|
||||
s.blasts_unloaded,
|
||||
s.late_dropped
|
||||
)
|
||||
}
|
||||
|
||||
@@ -241,6 +281,8 @@ impl WorldCache {
|
||||
if epoch != self.epoch {
|
||||
self.rays = RayDesk { next: self.rays.next, ..RayDesk::default() };
|
||||
if self.epoch != 0 {
|
||||
self.epoch_reset = true;
|
||||
self.expected.clear();
|
||||
self.secs.clear();
|
||||
self.urgent.clear();
|
||||
self.ahead.clear();
|
||||
@@ -264,6 +306,11 @@ impl WorldCache {
|
||||
let set: HashSet<Sec> = sections.iter().copied().collect();
|
||||
self.drop_rays(|b| set.contains(&sec_of(b[0], b[1], b[2])));
|
||||
}
|
||||
if !self.expected.is_empty() {
|
||||
let before = self.expected.len();
|
||||
self.expected.retain(|e| !sections.iter().any(|s| (e.lo.0..=e.hi.0).contains(&s.0) && (e.lo.1..=e.hi.1).contains(&s.1) && (e.lo.2..=e.hi.2).contains(&s.2)));
|
||||
self.stats.blasts_confirmed += (before - self.expected.len()) as u64;
|
||||
}
|
||||
for s in sections {
|
||||
self.note_column(s.0, s.2);
|
||||
if let Some(e) = self.secs.get_mut(s) {
|
||||
@@ -274,6 +321,37 @@ impl WorldCache {
|
||||
self.stats.world_changes += sections.len() as u64;
|
||||
}
|
||||
|
||||
/// The game's epoch as last told: another world or dimension opening changes it.
|
||||
pub fn epoch(&self) -> u32 {
|
||||
self.epoch
|
||||
}
|
||||
|
||||
/// A blast of `radius` blocks was asked of the game at `at`: expect the game to report blocks changed there.
|
||||
pub fn expect_blast(&mut self, at: DVec3, radius: f64, now: u64) {
|
||||
let (lo, hi) = (at - DVec3::splat(radius), at + DVec3::splat(radius));
|
||||
let sec = |p: DVec3| sec_of(p.x.floor() as i32, p.y.floor() as i32, p.z.floor() as i32);
|
||||
if self.expected.len() < 256 {
|
||||
self.expected.push(Expected { lo: sec(lo), hi: sec(hi), at, since: now });
|
||||
}
|
||||
self.stats.blasts_asked += 1;
|
||||
}
|
||||
|
||||
/// The blasts that the game did not report in `CONFIRM_TICKS`, taken: where each was.
|
||||
pub fn overdue_blasts(&mut self, now: u64) -> Vec<DVec3> {
|
||||
let (late, keep): (Vec<_>, Vec<_>) = std::mem::take(&mut self.expected).into_iter().partition(|e| now.saturating_sub(e.since) >= CONFIRM_TICKS);
|
||||
self.expected = keep;
|
||||
late.into_iter().map(|e| e.at).collect()
|
||||
}
|
||||
|
||||
/// What became of a blast that was not reported.
|
||||
pub fn note_settled(&mut self, how: Settled) {
|
||||
match how {
|
||||
Settled::Confirmed => self.stats.blasts_confirmed += 1,
|
||||
Settled::Unchanged => self.stats.blasts_unchanged += 1,
|
||||
Settled::Unloaded => self.stats.blasts_unloaded += 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn note_column(&mut self, sx: i32, sz: i32) {
|
||||
if self.changed_cols.len() >= 4096 {
|
||||
self.changed_all = true;
|
||||
|
||||
Reference in New Issue
Block a user