Keep unfinished retarget routes in a bounded job queue (#127)
A mass retarget used to clear every selected drone's route before the planner's per-tick work ran out: the rest flew straight for ever. Route jobs now carry the drone id, new aim, target unit, knowledge version and the intel snapshot, stay in a FIFO across ticks and are drained under the same WORK_PER_TICK. An old safe route is kept until its replacement is ready; a cancelled job falls back to a straight run. Jobs are replaced in place per drone, cancelled when the drone or unit is gone, and retarget routes reuse the original plan's known relief. An in-flight drone no longer turns to a unit behind its turning circle. Core release tests, adapter tests and the real WASM contract pass.
This commit is contained in:
@@ -146,6 +146,7 @@ const LONGEST_WAIT: f64 = 12_000.0;
|
||||
pub(super) const WORK_PER_TICK: usize = 40_000;
|
||||
|
||||
/// The planner's grid over a raid: its corner, its cells' size and how many a side.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) struct Grid {
|
||||
pub(super) min: DVec3,
|
||||
pub(super) cell: f64,
|
||||
@@ -157,16 +158,11 @@ impl Grid {
|
||||
let n = self.size;
|
||||
((((p.x - self.min.x) / self.cell) as i32).clamp(0, n - 1), (((p.z - self.min.z) / self.cell) as i32).clamp(0, n - 1))
|
||||
}
|
||||
fn centre(&self, (i, j): (i32, i32), y: f64) -> DVec3 {
|
||||
pub(super) fn centre(&self, (i, j): (i32, i32), y: f64) -> DVec3 {
|
||||
DVec3::new(self.min.x + (i as f64 + 0.5) * self.cell, y, self.min.z + (j as f64 + 0.5) * self.cell)
|
||||
}
|
||||
}
|
||||
|
||||
/// The cheapest way over `grid` from `from` to `to` by its prices (A*): points along it, `to` last.
|
||||
pub(super) fn plan_route(grid: &Grid, prices: &[f32], from: DVec3, to: DVec3) -> (Vec<DVec3>, usize) {
|
||||
plan_route_on(grid, prices, None, from, to)
|
||||
}
|
||||
|
||||
/// The land a route crosses: its height under each cell (NaN unknown), the climb a kind holds for long
|
||||
/// (rise a block), and the height above which the land forces a drone up from its low altitude.
|
||||
pub(super) struct Relief<'a> {
|
||||
@@ -484,6 +480,11 @@ impl Sim {
|
||||
}
|
||||
self.queue.push((now + wait.clamp(0.0, LONGEST_WAIT) as u64, d));
|
||||
}
|
||||
// Keep the land this plan was worked out over (#127): a retarget later is planned over the same
|
||||
// known relief, not over ground mapped since.
|
||||
if plan.smart && !plan.heights.is_empty() {
|
||||
self.known_relief = Some((plan.grid, std::mem::take(&mut plan.heights)));
|
||||
}
|
||||
self.wave = Some(WaveStats {
|
||||
kills: self.kills,
|
||||
hits: self.hits,
|
||||
@@ -619,6 +620,7 @@ impl Sim {
|
||||
|
||||
/// The price of each cell of `grid` for this kind flying low: 1, and much more where a
|
||||
/// system sees it there (its radar's reach for it, the land) and can shoot it.
|
||||
#[cfg(test)]
|
||||
pub(super) fn price_grid(&self, grid: &Grid, kind: DroneKind) -> (Vec<f32>, usize) {
|
||||
self.price_grid_on(grid, kind, None)
|
||||
}
|
||||
@@ -626,10 +628,16 @@ impl Sim {
|
||||
/// The same over known land: a cell's drone flies `height` over the land there, not over the system's feet,
|
||||
/// so what a radar sees and what a hill hides follow the relief.
|
||||
pub(super) fn price_grid_on(&self, grid: &Grid, kind: DroneKind, land: Option<&[f32]>) -> (Vec<f32>, usize) {
|
||||
let known_now = self.known_units();
|
||||
self.price_grid_known(grid, kind, land, &known_now)
|
||||
}
|
||||
|
||||
/// The same over a picture of the enemy: a retarget is priced on the picture its target was chosen
|
||||
/// from, so the jobs of one adaptive tick do not each see a different world (#127).
|
||||
pub(super) fn price_grid_known(&self, grid: &Grid, kind: DroneKind, land: Option<&[f32]>, known_now: &[(u32, DVec3)]) -> (Vec<f32>, usize) {
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user