Fix raid gameplay, finite ammunition and truck routing

Check launch terrain, reserve ballistic targets for marked objectives, tune in-game reach and fallback fire, and support bounded terrain work on supply routes.

Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
2026-11-25 18:53:17 +03:00
parent 61c4fa5cee
commit aa842d8a1f
18 changed files with 606 additions and 257 deletions
+12 -31
View File
@@ -1,17 +1,7 @@
//! Logistics: once a depot stands, magazines are no longer refilled from
//! nowhere. A system out of missiles waits; one within reach of a depot
//! reloads from its stock; the reload trucks fill up at a depot and drive
//! reloads to the systems that wait, nearest first, and back.
//! Empty magazines are replenished from finite depot stock, either directly or via a truck.
use super::*;
impl Sim {
/// Whether ammunition is counted: a depot was set up (without one, magazines refill as
/// before). A destroyed depot still counts: losing the last one leaves the systems short,
/// not supplied from nowhere again.
pub fn logistics(&self) -> bool {
self.sams.iter().any(|s| s.kind == SamKind::Depot)
}
/// Prepare one explicitly typed round at a nearby living depot. Any displaced air round is retained there.
pub fn load_ground_round(&mut self, i: usize) -> Result<String, String> {
let s = self.sams.get(i).ok_or("Нет такого комплекса")?;
@@ -84,12 +74,6 @@ impl Sim {
/// Reloads from depots near the systems, and the trucks' rounds.
pub(super) fn step_supply(&mut self, out: &mut Out) {
if !self.logistics() {
for s in &mut self.sams {
s.empty = false;
}
return;
}
let now = self.tick;
// Systems by a depot reload from it.
for i in 0..self.sams.len() {
@@ -139,8 +123,7 @@ impl Sim {
if let Some((id, to)) = target {
self.sams[t].job = Some(id);
if at.distance(to) > HANDOVER {
let side = horizontal(at - to).normalize_or(DVec3::X) * (HANDOVER * 0.6);
self.order_move_near(t, to + side, 3.5);
self.order_move_near(t, to, HANDOVER - 0.75);
} else if let Some(j) = self.sams.iter().position(|s| s.id == id) {
if self.sams[t].return_cargo {
self.sams[j].ground_stock += 1;
@@ -217,8 +200,7 @@ impl Sim {
self.sams[t].job = None;
} else {
let to = self.sams[j].pos;
let side = horizontal(at - to).normalize_or(DVec3::X) * (HANDOVER * 0.6);
self.order_move_near(t, to + side, 3.5);
self.order_move_near(t, to, HANDOVER - 0.75);
continue;
}
} else { self.sams[t].job = None; }
@@ -231,15 +213,16 @@ impl Sim {
}.map(|s| (s.id, s.pos));
if let Some((id, to)) = next {
self.sams[t].job = Some(id);
let side = horizontal(at - to).normalize_or(DVec3::X) * (HANDOVER * 0.6);
if to.distance(at) > HANDOVER { self.order_move_near(t, to + side, 3.5); }
if to.distance(at) > HANDOVER { self.order_move_near(t, to, HANDOVER - 0.75); }
}
continue;
}
// Where it was going: hand over, or load up.
if let Some(job) = truck.job
&& let Some(j) = self.sams.iter().position(|s| s.id == job)
{
if let Some(job) = truck.job {
let Some(j) = self.sams.iter().position(|s| s.id == job && s.alive()) else {
self.sams[t].job = None;
continue;
};
if self.sams[j].pos.distance(at) <= HANDOVER {
if self.sams[j].kind == SamKind::Depot {
let take = TRUCK_LOAD.saturating_sub(self.sams[t].cargo).min(self.sams[j].cargo);
@@ -251,11 +234,10 @@ impl Sim {
self.reload_now(j, out);
}
self.sams[t].job = None;
} else if self.sams[j].alive() && (self.sams[j].empty || self.sams[j].kind == SamKind::Depot) {
} else if self.sams[j].empty || self.sams[j].kind == SamKind::Depot {
// Stopped short of it (it drove off meanwhile): on to where it stands now.
let to = self.sams[j].pos;
let side = horizontal(at - to).normalize_or(DVec3::X) * (HANDOVER * 0.6);
self.order_move_near(t, to + side, 3.5);
self.order_move_near(t, to, HANDOVER - 0.75);
continue;
} else {
self.sams[t].job = None;
@@ -286,9 +268,8 @@ impl Sim {
if let Some((id, to)) = next {
self.sams[t].job = Some(id);
// Stop beside it, not on it.
let side = horizontal(at - to).normalize_or(DVec3::X) * (HANDOVER * 0.6);
if to.distance(at) > HANDOVER {
self.order_move_near(t, to + side, 3.5);
self.order_move_near(t, to, HANDOVER - 0.75);
}
}
}