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
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:
+217
-23
@@ -2,16 +2,23 @@
|
||||
//! looks for suitable ground on each side (only land the game has told of: flat, open to the sky, clear in
|
||||
//! front, away from the defence), and sets up a site there: a ramp for the drones, a launcher vehicle for the
|
||||
//! cruise missiles, a battery for the ballistic ones (at their own range). The raid's drones are jobs of the
|
||||
//! sites: each one leaves its site, one at a time, from the stock the site holds. Ground nobody has told of is
|
||||
//! never suitable, and nothing is force-loaded: a side without suitable ground waits for the game's answers
|
||||
//! for a few seconds, and is then given up with a message.
|
||||
//! sites: each one leaves its site, one at a time, from the stock the site holds.
|
||||
//!
|
||||
//! The land beyond the render distance is not there until the game loads it, so the search asks for the chunks
|
||||
//! of the places it is looking at (`render.load-chunks`, API 22: a few, never a ring; the game generates or reads
|
||||
//! them on its workers and keeps them some seconds) and waits for them: a column the game is loading is neither
|
||||
//! land nor sea, it is pending. Where nothing can be loaded (a server) or nothing suitable is found within
|
||||
//! `SEARCH_TICKS`, the raid is never cancelled for it: the side's site is *off the map* (`offmap`): no kit is drawn,
|
||||
//! nothing can be destroyed, and its drones start in the air at the ordered range, cruising over whatever is there.
|
||||
use super::*;
|
||||
|
||||
/// The most candidate places tried for one site, and how long (ticks) a raid waits for the game's answers.
|
||||
pub const MAX_TRIES: usize = 90;
|
||||
pub const SEARCH_TICKS: u32 = 300;
|
||||
pub const SEARCH_TICKS: u32 = 400;
|
||||
/// Candidates asked about ahead of the one being waited for.
|
||||
const PREFETCH: usize = 3;
|
||||
/// Prefetched candidates ask for their chunks only while fewer than this many are wanted.
|
||||
const PREFETCH_CHUNKS: usize = 24;
|
||||
/// The footprint's samples (offsets in blocks), the most the ground may differ over it, and how far from
|
||||
/// the defence and the objects a site must be.
|
||||
const FOOTPRINT: [(f64, f64); 9] = [(0.0, 0.0), (8.0, 0.0), (-8.0, 0.0), (0.0, 8.0), (0.0, -8.0), (6.0, 6.0), (6.0, -6.0), (-6.0, 6.0), (-6.0, -6.0)];
|
||||
@@ -123,6 +130,9 @@ pub struct LaunchSite {
|
||||
pub planned: u32,
|
||||
pub alive: bool,
|
||||
pub next_free: u64,
|
||||
/// Off the map: no land to stand on was found (or none can be loaded), so there is no kit; the drones
|
||||
/// start in the air at `pos`'s range.
|
||||
pub offmap: bool,
|
||||
}
|
||||
|
||||
impl LaunchSite {
|
||||
@@ -161,6 +171,8 @@ pub(super) enum Slot {
|
||||
/// Not a site's job (a manual launch, an old save): off it goes.
|
||||
Free,
|
||||
Go,
|
||||
/// An off-map site's drone: it starts in the air, without a launch.
|
||||
Air,
|
||||
/// The site launched a moment ago.
|
||||
Busy,
|
||||
/// The site is gone or empty: the job is cancelled.
|
||||
@@ -215,8 +227,9 @@ impl Sites {
|
||||
}
|
||||
s.stock -= 1;
|
||||
s.next_free = now + s.class.cadence();
|
||||
let air = s.offmap;
|
||||
self.jobs.swap_remove(j);
|
||||
Slot::Go
|
||||
if air { Slot::Air } else { Slot::Go }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +273,13 @@ pub(super) struct Want {
|
||||
pub site: u32,
|
||||
}
|
||||
|
||||
impl Want {
|
||||
/// Whether the search has nothing to show for it: the site is off the map.
|
||||
pub fn offmap(&self) -> bool {
|
||||
self.state == Search::Failed
|
||||
}
|
||||
}
|
||||
|
||||
/// The want of this side, class and range, made if there is none yet.
|
||||
pub(super) fn want_index(wants: &mut Vec<Want>, centre: DVec3, side: usize, bearing: f64, class: SiteClass, range: f64, lo: f64) -> usize {
|
||||
if let Some(i) = wants.iter().position(|w| w.side == side && w.class == class && (w.range - range).abs() < 1.0) {
|
||||
@@ -269,16 +289,19 @@ pub(super) fn want_index(wants: &mut Vec<Want>, centre: DVec3, side: usize, bear
|
||||
let lat = DVec3::new(bearing.cos(), 0.0, -bearing.sin());
|
||||
// In order: known land at the ordered range (round it for most, the ordered range for a ballistic battery),
|
||||
// known land nearer in steps, then a barge on open water at the ordered range, then on water nearer.
|
||||
// A long range retreats in steps of at most 100 blocks and tries wider rings, not a few huge gaps.
|
||||
let near = |from: f64| -> Vec<f64> {
|
||||
let min = if class == SiteClass::Battery { lo.min(from).max(80.0) } else { (from * 0.3).max(80.0) };
|
||||
let min = if class == SiteClass::Battery { lo.min(from).max(80.0) } else { (from * 0.3).max(80.0).max(from - 600.0) };
|
||||
(1..=6).map(|i| from - (from - min) * f64::from(i) / 6.0).collect()
|
||||
};
|
||||
let wide = (range / 500.0).clamp(1.0, 3.0);
|
||||
let round: Vec<f64> = if class == SiteClass::Battery {
|
||||
vec![range]
|
||||
} else {
|
||||
[0.0, 24.0, -24.0, 48.0, -48.0, 72.0, -72.0].iter().map(|d| (range + d).max(KEEP_OUT)).collect()
|
||||
[0.0, 24.0, -24.0, 48.0, -48.0, 72.0, -72.0].iter().map(|d| (range + d * wide).max(KEEP_OUT)).collect()
|
||||
};
|
||||
let laterals: &[f64] = &[0.0, 20.0, -20.0];
|
||||
// A battery may stand where another site of the side does (its range is its own): wider to the sides.
|
||||
let laterals: &[f64] = if class == SiteClass::Battery { &[0.0, 20.0, -20.0, 60.0, -60.0] } else { &[0.0, 20.0, -20.0] };
|
||||
let mut cands = Vec::new();
|
||||
for water in [false, true] {
|
||||
for r in round.iter().copied().chain(near(range)) {
|
||||
@@ -300,9 +323,25 @@ enum Verdict {
|
||||
Good(DVec3, bool),
|
||||
}
|
||||
|
||||
/// The chunks a site at `p` needs: its footprint and the way ahead, up to 14 blocks.
|
||||
fn chunks_of(p: DVec3, inward: DVec3) -> Vec<(i32, i32)> {
|
||||
let mut out: Vec<(i32, i32)> = Vec::with_capacity(6);
|
||||
for (dx, dz) in FOOTPRINT {
|
||||
for k in [0.0, 14.0] {
|
||||
let c = (((p.x + dx + inward.x * k).floor() as i32) >> 4, ((p.z + dz + inward.z * k).floor() as i32) >> 4);
|
||||
if !out.contains(&c) {
|
||||
out.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether a site fits at `p` (x, z): every sample of its footprint is land the game told of and within
|
||||
/// `FLAT` blocks of the others, the sky above is open, the way ahead is clear, and nothing of the defence is near.
|
||||
fn judge(ground: &mut Ground, p: DVec3, inward: DVec3, keep: &[DVec3], now: u64) -> Verdict {
|
||||
/// A column or chunk the game is still loading makes it `Pending`, and the chunks are asked for (unless this is
|
||||
/// a look ahead at a later candidate, `ahead`, and many are wanted already).
|
||||
fn judge(ground: &mut Ground, p: DVec3, inward: DVec3, keep: &[DVec3], now: u64, ahead: bool) -> Verdict {
|
||||
if p.x.abs() > 29_000_000.0 || p.z.abs() > 29_000_000.0 || keep.iter().any(|k| horizontal(*k - p).length() < KEEP_OUT) {
|
||||
return Verdict::Bad;
|
||||
}
|
||||
@@ -318,6 +357,22 @@ fn judge(ground: &mut Ground, p: DVec3, inward: DVec3, keep: &[DVec3], now: u64)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The way ahead must be loaded too before it is swept (an unknown stretch is answered "no chunk" and kept
|
||||
// for a while): a column in the middle of each chunk it needs says so.
|
||||
let chunks = chunks_of(p, inward);
|
||||
if !pending {
|
||||
for &(cx, cz) in &chunks {
|
||||
pending |= ground.column(cx * 16 + 8, cz * 16 + 8, 256).is_none();
|
||||
}
|
||||
}
|
||||
if pending {
|
||||
if !ahead || ground.chunks_wanted() < PREFETCH_CHUNKS {
|
||||
for c in chunks {
|
||||
ground.want_chunk(c);
|
||||
}
|
||||
}
|
||||
return Verdict::Pending;
|
||||
}
|
||||
if pending {
|
||||
return Verdict::Pending;
|
||||
}
|
||||
@@ -334,7 +389,9 @@ fn judge(ground: &mut Ground, p: DVec3, inward: DVec3, keep: &[DVec3], now: u64)
|
||||
match ground.world.sweep(c + DVec3::Y * 0.5, c - DVec3::Y * 0.5, false, now) {
|
||||
world::Sweep::Hit { .. } => solid += 1,
|
||||
world::Sweep::Clear => {}
|
||||
world::Sweep::Unknown { pending: true, .. } | world::Sweep::Wait { .. } => return Verdict::Pending,
|
||||
world::Sweep::Unknown { pending: true, .. } | world::Sweep::Wait { .. } => {
|
||||
return Verdict::Pending;
|
||||
}
|
||||
world::Sweep::Unknown { .. } => return Verdict::Bad,
|
||||
}
|
||||
}
|
||||
@@ -346,7 +403,9 @@ fn judge(ground: &mut Ground, p: DVec3, inward: DVec3, keep: &[DVec3], now: u64)
|
||||
for s in [up, ahead] {
|
||||
match s {
|
||||
world::Sweep::Clear => {}
|
||||
world::Sweep::Unknown { pending: true, .. } | world::Sweep::Wait { .. } => return Verdict::Pending,
|
||||
world::Sweep::Unknown { pending: true, .. } | world::Sweep::Wait { .. } => {
|
||||
return Verdict::Pending;
|
||||
}
|
||||
world::Sweep::Unknown { .. } | world::Sweep::Hit { .. } => return Verdict::Bad,
|
||||
}
|
||||
}
|
||||
@@ -373,7 +432,7 @@ pub(super) fn search(wants: &mut [Want], ground: &mut Ground, centre: DVec3, kee
|
||||
break;
|
||||
}
|
||||
let (cand, water) = w.cands[w.cursor];
|
||||
match judge(ground, cand, inward, &keep, now) {
|
||||
match judge(ground, cand, inward, &keep, now, false) {
|
||||
Verdict::Bad => w.cursor += 1,
|
||||
// Land when land was asked for, a barge when water was.
|
||||
Verdict::Good(_, got) if got != water => w.cursor += 1,
|
||||
@@ -387,7 +446,7 @@ pub(super) fn search(wants: &mut [Want], ground: &mut Ground, centre: DVec3, kee
|
||||
Verdict::Pending => {
|
||||
for k in 1..=PREFETCH {
|
||||
if let Some(&(c, _)) = w.cands.get(w.cursor + k) {
|
||||
let _ = judge(ground, c, inward, &keep, now);
|
||||
let _ = judge(ground, c, inward, &keep, now, true);
|
||||
}
|
||||
}
|
||||
if last {
|
||||
@@ -414,7 +473,8 @@ impl Sim {
|
||||
/// Takes site `id` out of play (destroyed): its stock is gone and its queued jobs are cancelled. Returns how
|
||||
/// many. (The counter-strike, #101, uses this.)
|
||||
pub fn destroy_site(&mut self, id: u32) -> u32 {
|
||||
let Some(s) = self.sites.list.iter_mut().find(|s| s.id == id) else { return 0 };
|
||||
// An off-map site is nowhere to be found: nothing to destroy.
|
||||
let Some(s) = self.sites.list.iter_mut().find(|s| s.id == id && !s.offmap) else { return 0 };
|
||||
s.alive = false;
|
||||
s.stock = 0;
|
||||
let ids: Vec<u32> = self.sites.jobs.iter().filter(|j| j.1 == id).map(|j| j.0).collect();
|
||||
@@ -431,7 +491,7 @@ impl Sim {
|
||||
|
||||
/// Draws every site's kit: a ramp or launcher per pad in use, turned to the way the launches go.
|
||||
pub(super) fn draw_sites(&self, out: &mut Out) {
|
||||
for s in self.sites.list.iter().filter(|s| s.alive) {
|
||||
for s in self.sites.list.iter().filter(|s| s.alive && !s.offmap) {
|
||||
let rot = DQuat::from_rotation_y(heading_of(s.inward()));
|
||||
let sc = s.class.scale();
|
||||
if s.water {
|
||||
@@ -651,6 +711,7 @@ mod tests {
|
||||
planned: 5,
|
||||
alive: true,
|
||||
next_free: 0,
|
||||
offmap: false,
|
||||
});
|
||||
for i in 0..5 {
|
||||
let site = sim.sites.get(id).unwrap().clone();
|
||||
@@ -689,9 +750,16 @@ mod tests {
|
||||
assert_eq!(sim.launched as usize + n, 14);
|
||||
}
|
||||
|
||||
/// Runs the sim `ticks` without the game answering anything, and counts what left.
|
||||
fn run_blind(sim: &mut Sim, out: &mut Out, ground: &mut Ground, ticks: u32) {
|
||||
for _ in 0..ticks {
|
||||
sim.step(ground, None, out);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_suitable_ground_means_a_clear_refusal() {
|
||||
// Never answered: unknown ground is not suitable, and nothing is launched.
|
||||
fn no_suitable_ground_means_the_raid_launches_off_the_map() {
|
||||
// Never answered: unknown ground is not suitable, but nothing is cancelled: every side starts off the map.
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
let mut sim = Sim::new(3);
|
||||
sim.order_raid(&order(Approach::TwoSectors, 300.0), &[DVec3::new(0.0, 70.0, 0.0)], &mut out);
|
||||
@@ -701,20 +769,146 @@ mod tests {
|
||||
n += 1;
|
||||
assert!(n <= SEARCH_TICKS + 5, "a raid waits for ever");
|
||||
}
|
||||
assert!(sim.queue.is_empty() && sim.sites.list.is_empty());
|
||||
assert!(out.messages.iter().any(|m| m.contains("площад")), "{:?}", out.messages);
|
||||
assert!(!sim.drones.iter().any(|d| d.alive()));
|
||||
// A cliff face everywhere (too steep to stand on) is refused as well, and a sea (no land) too.
|
||||
assert_eq!(sim.queue.len() + sim.launched as usize, 14);
|
||||
assert!(!sim.sites.list.is_empty() && sim.sites.list.iter().all(|s| s.offmap), "{:?}", sim.sites.list);
|
||||
let said: Vec<_> = out.messages.iter().filter(|m| m.contains("за пределами")).collect();
|
||||
assert_eq!(said.len(), 1, "{:?}", out.messages);
|
||||
assert!(!out.messages.iter().any(|m| m.contains("отмен")), "{:?}", out.messages);
|
||||
run_blind(&mut sim, &mut out, &mut ground, 400);
|
||||
assert_eq!(sim.launched, 14, "{:?}", out.messages);
|
||||
assert!(sim.queue.is_empty());
|
||||
// No kit, and nothing to destroy.
|
||||
let mut o2 = Out::default();
|
||||
sim.draw_sites(&mut o2);
|
||||
assert!(o2.models.is_empty());
|
||||
let id = sim.sites.list[0].id;
|
||||
assert_eq!(sim.destroy_site(id), 0);
|
||||
// A cliff face everywhere (too steep to stand on) and a sea (no land) launch off the map as well.
|
||||
for steep in [true, false] {
|
||||
let land = Land(move |x, _| if steep { x * 4 } else { -100 });
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
let mut sim = Sim::new(3);
|
||||
plan(&mut sim, &mut ground, &land, &order(Approach::Sector, 300.0), &mut out);
|
||||
assert!(sim.queue.is_empty() && sim.sites.list.is_empty(), "steep {steep}");
|
||||
assert!(out.messages.iter().any(|m| m.contains("площад")));
|
||||
assert!(!sim.sites.list.is_empty() && sim.sites.list.iter().all(|s| s.offmap), "steep {steep}");
|
||||
assert_eq!(sim.queue.len() + sim.launched as usize, 14, "steep {steep}");
|
||||
assert!(!out.messages.iter().any(|m| m.contains("отмен")), "{:?}", out.messages);
|
||||
}
|
||||
}
|
||||
|
||||
/// Chunks that load on request: a column of a chunk asked for answers `PENDING` until `delay` ticks
|
||||
/// after the first request, and a chunk never asked for is not there (-64).
|
||||
struct Lazy {
|
||||
height: i32,
|
||||
delay: u64,
|
||||
asked: std::cell::RefCell<HashMap<(i32, i32), u64>>,
|
||||
most: usize,
|
||||
}
|
||||
impl Lazy {
|
||||
fn loaded(&self, c: (i32, i32), now: u64) -> Option<bool> {
|
||||
self.asked.borrow().get(&c).map(|&t| now >= t + self.delay)
|
||||
}
|
||||
fn tick(&mut self, ground: &mut Ground, now: u64) {
|
||||
let chunks = ground.take_chunks();
|
||||
self.most = self.most.max(chunks.len());
|
||||
for c in chunks {
|
||||
self.asked.borrow_mut().entry(c).or_insert(now);
|
||||
}
|
||||
let cols = ground
|
||||
.take_wanted()
|
||||
.into_iter()
|
||||
.map(|(x, z)| {
|
||||
let y = match self.loaded((x >> 4, z >> 4), now) {
|
||||
Some(true) => self.height,
|
||||
Some(false) => PENDING,
|
||||
None => -64,
|
||||
};
|
||||
(x, z, y)
|
||||
})
|
||||
.collect();
|
||||
ground.answer(cols, now);
|
||||
let secs = ground.world.take_wanted(now);
|
||||
let view = Seen { lazy: self, now };
|
||||
ground.world.serve(&view, secs, now);
|
||||
}
|
||||
}
|
||||
struct Seen<'a> {
|
||||
lazy: &'a Lazy,
|
||||
now: u64,
|
||||
}
|
||||
impl world::WorldSource for Seen<'_> {
|
||||
fn solid(&self, x: i32, y: i32, z: i32) -> Option<bool> {
|
||||
self.lazy.loaded((x >> 4, z >> 4), self.now).filter(|&l| l).map(|_| y < self.lazy.height)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_column_pending_for_chunk_load_waits_then_finds_a_site() {
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
let mut lazy = Lazy { height: 64, delay: 50, asked: Default::default(), most: 0 };
|
||||
let mut sim = Sim::new(21);
|
||||
sim.order_raid(&order(Approach::TwoSectors, 1500.0), &[DVec3::new(0.0, 70.0, 0.0)], &mut out);
|
||||
let mut n = 0;
|
||||
while sim.planning() {
|
||||
lazy.tick(&mut ground, sim.tick);
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
n += 1;
|
||||
assert!(n < SEARCH_TICKS + 5, "never settled");
|
||||
}
|
||||
assert!(n > 50, "settled in {n} ticks, before any chunk could be there");
|
||||
assert!(sim.sites.list.iter().all(|s| !s.offmap), "{:?} {:?}", sim.sites.list, out.messages);
|
||||
assert!(!sim.sites.list.is_empty());
|
||||
assert!(lazy.most <= 48 && lazy.most > 0, "{} chunks wanted at once", lazy.most);
|
||||
assert!(out.messages.iter().any(|m| m.contains("готовит")), "{:?}", out.messages);
|
||||
assert!(!out.messages.iter().any(|m| m.contains("отмен") || m.contains("за пределами")), "{:?}", out.messages);
|
||||
// Far ones stand where the raid was ordered (1500 out), not nearer.
|
||||
assert!(sim.sites.list.iter().any(|s| s.range > 1400.0), "{:?}", sim.sites.list.iter().map(|s| s.range).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_game_that_never_loads_gets_the_same_launch_off_the_map() {
|
||||
// The game answers "no chunk" (-64) for what was not asked about, and never loads what was (a server).
|
||||
let (mut ground, mut out) = (Ground::default(), Out::default());
|
||||
let mut sim = Sim::new(5);
|
||||
sim.order_raid(&order(Approach::Sector, 2500.0), &[DVec3::new(0.0, 70.0, 0.0)], &mut out);
|
||||
let mut n = 0;
|
||||
while sim.planning() {
|
||||
let _ = ground.take_chunks();
|
||||
let cols = ground.take_wanted().into_iter().map(|(x, z)| (x, z, -64)).collect();
|
||||
ground.answer(cols, sim.tick);
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
n += 1;
|
||||
assert!(n < SEARCH_TICKS + 5);
|
||||
}
|
||||
assert!(sim.sites.list.iter().all(|s| s.offmap));
|
||||
assert_eq!(sim.queue.len() + sim.launched as usize, 14);
|
||||
// Where they start: at the ordered range, not at the player.
|
||||
assert!(sim.queue.iter().all(|q| horizontal(q.1.pos - DVec3::new(0.0, 70.0, 0.0)).length() > 2400.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_raid_ordered_4000_out_reaches_its_target() {
|
||||
let (land, mut ground, mut out) = (flat(), Ground::default(), Out::default());
|
||||
let mut sim = Sim::new(9);
|
||||
let o = RaidOrder { kinds: vec![(DroneKind::Shahed, 2), (DroneKind::Kh101, 1), (DroneKind::Iskander, 1)], approach: Approach::Sector, dist: 4000.0, aim: Aim::Objects };
|
||||
let target = DVec3::new(0.0, 70.0, 0.0);
|
||||
sim.order_raid(&o, &[target], &mut out);
|
||||
let mut closest = [f64::MAX; 4];
|
||||
for _ in 0..16_000 {
|
||||
step(&mut sim, &mut ground, &land, &mut out);
|
||||
for d in sim.drones.iter().filter(|d| d.alive()) {
|
||||
let k = match d.kind {
|
||||
DroneKind::Shahed => 0,
|
||||
DroneKind::Kh101 => 1,
|
||||
_ => 2,
|
||||
};
|
||||
closest[k] = closest[k].min(horizontal(d.pos - target).length());
|
||||
}
|
||||
}
|
||||
assert_eq!(sim.launched, 4, "{:?}", out.messages);
|
||||
assert!(closest.iter().take(3).all(|&c| c < 120.0), "closest approaches {closest:?}");
|
||||
assert!(sim.drones.iter().all(|d| !d.alive()), "still flying");
|
||||
}
|
||||
|
||||
/// Land inside a radius of the origin (surface 64), open water outside it (surface 63 over a floor at 50):
|
||||
/// the game's height over water is the surface, and the blocks under it are not solid.
|
||||
struct Island(f64);
|
||||
|
||||
Reference in New Issue
Block a user