Redesign in-game menu with tabbed canvas UI and add logistics routes, secondary detonation, and RM48U tracking
build / mod (push) Failing after 15s
build / mod (push) Failing after 15s
This commit is contained in:
+132
-14
@@ -112,6 +112,20 @@ impl AmmoKind {
|
||||
AmmoKind::P1sunMissile => (2, 6),
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn blast_charge(self) -> f64 {
|
||||
match self {
|
||||
AmmoKind::S500Missile => 2.2,
|
||||
AmmoKind::S400Missile => 1.8,
|
||||
AmmoKind::PatriotMissile => 1.4,
|
||||
AmmoKind::BukMissile => 1.1,
|
||||
AmmoKind::IrisTMissile | AmmoKind::NasamsMissile => 0.9,
|
||||
AmmoKind::TorMissile | AmmoKind::PantsirMissile => 0.8,
|
||||
AmmoKind::GepardGun => 0.35,
|
||||
AmmoKind::PantsirGun => 0.3,
|
||||
AmmoKind::P1sunMissile => 0.25,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-type air-defence reload stock stored at a depot or carried on a TZM.
|
||||
@@ -197,6 +211,14 @@ impl AmmoStock {
|
||||
let parts: Vec<String> = self.non_zero().map(|(k, n)| format!("{}={n}", k.key())).collect();
|
||||
if parts.is_empty() { "-".into() } else { parts.join(" ") }
|
||||
}
|
||||
|
||||
/// Combined secondary detonation yield for all typed ammunition packs stored in a depot or truck.
|
||||
pub fn blast_charge(self) -> f64 {
|
||||
AmmoKind::ALL
|
||||
.into_iter()
|
||||
.map(|k| f64::from(self.get(k)) * k.blast_charge())
|
||||
.sum()
|
||||
}
|
||||
}
|
||||
|
||||
impl Sim {
|
||||
@@ -330,6 +352,13 @@ impl Sim {
|
||||
for s in self.sams.iter_mut().filter(|s| s.kind == SamKind::Tzm && !s.alive()) {
|
||||
s.job = None;
|
||||
}
|
||||
let has_waiting = self.sams.iter().any(|s| s.empty && s.alive() && !s.moving() && s.reloading == 0);
|
||||
let has_truck = self.sams.iter().any(|t| t.kind == SamKind::Tzm && t.alive() && !t.moving() && t.drive_speed() > 0.0);
|
||||
let network_tracks: Vec<(DVec3, ClassEst)> = if has_waiting && has_truck {
|
||||
self.picture().values().map(|trk| (trk.est(now), trk.class)).collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
// The trucks: a job each, when idle.
|
||||
for t in 0..self.sams.len() {
|
||||
let truck = &self.sams[t];
|
||||
@@ -456,7 +485,7 @@ impl Sim {
|
||||
}
|
||||
// Priority 3: typed air-defence resupply.
|
||||
let taken: Vec<u32> = self.sams.iter().filter(|s| s.kind == SamKind::Tzm && s.alive() && s.id != truck_id).filter_map(|s| s.job).collect();
|
||||
let waiting = self.waiting_needs(truck_id, at, now, &taken);
|
||||
let waiting = self.waiting_needs(truck_id, at, now, &taken, &network_tracks);
|
||||
let demand = demand_totals(&waiting);
|
||||
if let Some(job) = truck.job {
|
||||
let Some(j) = self.sams.iter().position(|s| s.id == job && s.alive()) else {
|
||||
@@ -550,14 +579,22 @@ impl Sim {
|
||||
if truck_stock.total() < TRUCK_LOAD && any_demand {
|
||||
self.sams
|
||||
.iter()
|
||||
.filter(|d| {
|
||||
d.kind == SamKind::Depot
|
||||
&& d.alive()
|
||||
&& !self.routes.out_of_reach(truck_id, d.id, now)
|
||||
&& AmmoKind::ALL.into_iter().any(|k| demand[k.index()] > truck_stock.get(k) && d.ammo_stock.get(k) > 0)
|
||||
.filter(|d| d.kind == SamKind::Depot && d.alive() && !self.routes.out_of_reach(truck_id, d.id, now))
|
||||
.filter_map(|d| {
|
||||
let rank = waiting.iter().position(|(_, _, _, needs)| {
|
||||
needs
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.any(|k| demand[k.index()] > truck_stock.get(*k) && d.ammo_stock.get(*k) > 0)
|
||||
})?;
|
||||
Some((rank, d))
|
||||
})
|
||||
.min_by(|a, b| a.pos.distance(at).total_cmp(&b.pos.distance(at)).then(a.id.cmp(&b.id)))
|
||||
.map(|d| (d.id, d.pos))
|
||||
.min_by(|(ra, da), (rb, db)| {
|
||||
ra.cmp(rb)
|
||||
.then_with(|| da.pos.distance(at).total_cmp(&db.pos.distance(at)))
|
||||
.then_with(|| da.id.cmp(&db.id))
|
||||
})
|
||||
.map(|(_, d)| (d.id, d.pos))
|
||||
} else if truck_stock.total() >= TRUCK_LOAD && AmmoKind::ALL.into_iter().any(|k| truck_stock.get(k) > demand[k.index()]) {
|
||||
self.sams
|
||||
.iter()
|
||||
@@ -578,19 +615,46 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reachable waiting systems sorted by distance from `at`, with each system's needed weapon channels.
|
||||
fn waiting_needs(&self, truck_id: u32, at: DVec3, now: u64, taken: &[u32]) -> Vec<(u32, DVec3, f64, [Option<AmmoKind>; 2])> {
|
||||
let mut out: Vec<_> = self
|
||||
/// Reachable waiting systems prioritized by active network threat matching their roles, whether both channels are dry, and distance.
|
||||
fn waiting_needs(
|
||||
&self,
|
||||
truck_id: u32,
|
||||
at: DVec3,
|
||||
now: u64,
|
||||
taken: &[u32],
|
||||
tracks: &[(DVec3, ClassEst)],
|
||||
) -> Vec<(u32, DVec3, f64, [Option<AmmoKind>; 2])> {
|
||||
let mut ranked: Vec<_> = self
|
||||
.sams
|
||||
.iter()
|
||||
.filter(|s| s.empty && s.alive() && !s.moving() && s.reloading == 0 && !taken.contains(&s.id) && !self.routes.out_of_reach(truck_id, s.id, now))
|
||||
.filter_map(|s| {
|
||||
let (m, g) = s.needed_ammo();
|
||||
(m.is_some() || g.is_some()).then(|| (s.id, s.pos, s.pos.distance(at), [m, g]))
|
||||
if m.is_none() && g.is_none() {
|
||||
return None;
|
||||
}
|
||||
let range_limit = s.kind.range() * 1.25;
|
||||
let mut threat_tier = 2u8;
|
||||
for &(tpos, tclass) in tracks {
|
||||
let matches = match tclass {
|
||||
ClassEst::Firm(c) | ClassEst::Probable(c) => (s.roles & c.bit()) != 0,
|
||||
ClassEst::Unknown => s.roles != 0,
|
||||
};
|
||||
if !matches {
|
||||
continue;
|
||||
}
|
||||
if horizontal(tpos - s.pos).length() <= range_limit {
|
||||
threat_tier = 0;
|
||||
break;
|
||||
}
|
||||
threat_tier = threat_tier.min(1);
|
||||
}
|
||||
let dry_tier = u8::from(s.missiles > 0 || s.bursts > 0);
|
||||
Some((threat_tier, dry_tier, s.pos.distance(at), s.id, s.pos, [m, g]))
|
||||
})
|
||||
.collect();
|
||||
out.sort_by(|a, b| a.2.total_cmp(&b.2).then(a.0.cmp(&b.0)));
|
||||
out
|
||||
ranked.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.cmp(&b.1)).then_with(|| a.2.total_cmp(&b.2)).then(a.3.cmp(&b.3)));
|
||||
ranked.into_iter().map(|(_, _, d, id, pos, needs)| (id, pos, d, needs)).collect()
|
||||
}
|
||||
|
||||
/// System `i` begins reloading the specified weapon channels (`RELOAD_MISSILE | RELOAD_GUN`).
|
||||
@@ -1335,4 +1399,58 @@ mod tests {
|
||||
assert_eq!(summary.total_for(AmmoKind::TorMissile), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tzm_prioritizes_threatened_and_dry_system_over_closer_idle_unit() {
|
||||
let mut sim = Sim::new(5);
|
||||
let tzm_id = sim.id();
|
||||
sim.sams.push(Sam::new(tzm_id, SamKind::Tzm, DVec3::ZERO, 0.0));
|
||||
let radar_id = sim.id();
|
||||
sim.sams.push(Sam::new(radar_id, SamKind::Radar, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
// Closer idle Tor (no matching track).
|
||||
let tor_id = sim.id();
|
||||
let mut tor = Sam::new(tor_id, SamKind::Tor, DVec3::new(100.0, 70.0, 0.0), 0.0);
|
||||
tor.missiles = 0;
|
||||
tor.empty = true;
|
||||
sim.sams.push(tor);
|
||||
// Farther S-400 threatened by a confirmed ballistic radar track inside its reach.
|
||||
let s400_id = sim.id();
|
||||
let mut s400 = Sam::new(s400_id, SamKind::S400, DVec3::new(250.0, 70.0, 0.0), 0.0);
|
||||
s400.missiles = 0;
|
||||
s400.empty = true;
|
||||
sim.sams.push(s400);
|
||||
// Nearest depot carries Tor stock; slightly farther depot carries S-400 stock.
|
||||
let d_tor_id = sim.id();
|
||||
let mut d_tor = Sam::new(d_tor_id, SamKind::Depot, DVec3::new(20.0, 70.0, 0.0), 0.0);
|
||||
d_tor.clear_ammo();
|
||||
d_tor.set_ammo(AmmoKind::TorMissile, 2);
|
||||
sim.sams.push(d_tor);
|
||||
let d_s400_id = sim.id();
|
||||
let mut d_s400 = Sam::new(d_s400_id, SamKind::Depot, DVec3::new(40.0, 70.0, 0.0), 0.0);
|
||||
d_s400.clear_ammo();
|
||||
d_s400.set_ammo(AmmoKind::S400Missile, 2);
|
||||
sim.sams.push(d_s400);
|
||||
|
||||
sim.sams[1].tracks.push(sight::Track {
|
||||
id: 42,
|
||||
class: ClassEst::Firm(Class::Ballistic),
|
||||
pos: DVec3::new(320.0, 120.0, 0.0),
|
||||
vel: DVec3::new(-1.0, 0.0, 0.0),
|
||||
tick: 1,
|
||||
own_tick: 1,
|
||||
source: radar_id,
|
||||
product: battery::Measure::Fire,
|
||||
quality: 90,
|
||||
own_product: battery::Measure::Fire,
|
||||
own_quality: 90,
|
||||
ttl: 200,
|
||||
hits: 3,
|
||||
locked: false,
|
||||
});
|
||||
|
||||
sim.step_supply(&mut Out::default());
|
||||
assert_eq!(sim.sams[0].job, Some(d_s400_id), "TZM must fetch S-400 ammo from depot matching the threatened unit first");
|
||||
assert_eq!(sim.tzm_job_kind(0), Some("fetch"));
|
||||
assert!(!sim.unit_route(0, 16).is_empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user