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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user