8fd28a2de2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
4.6 KiB
Rust
146 lines
4.6 KiB
Rust
//! The raid the player orders from the menu: how many of each kind, from
|
|
//! where, how far out and at what; and ready-made raids to start from.
|
|
use crate::sim::{Aim, Approach, DroneKind, RaidOrder};
|
|
|
|
/// The kinds a raid can have, in the menu's order.
|
|
pub const KINDS: [DroneKind; 11] = [
|
|
DroneKind::Gerbera,
|
|
DroneKind::Shahed,
|
|
DroneKind::Geran3,
|
|
DroneKind::Lancet,
|
|
DroneKind::Kh101,
|
|
DroneKind::Kalibr,
|
|
DroneKind::Kh22,
|
|
DroneKind::Zircon,
|
|
DroneKind::Iskander,
|
|
DroneKind::Kinzhal,
|
|
DroneKind::Oreshnik,
|
|
];
|
|
|
|
/// What a click on a kind's row steps its number through.
|
|
const STEPS: [u32; 12] = [0, 1, 2, 3, 4, 6, 8, 10, 15, 20, 30, 40];
|
|
pub const DISTANCES: [f64; 4] = [200.0, 300.0, 500.0, 800.0];
|
|
|
|
pub struct Preset {
|
|
pub name: &'static str,
|
|
kinds: &'static [(DroneKind, u32)],
|
|
approach: Approach,
|
|
aim: Aim,
|
|
}
|
|
|
|
pub const PRESETS: [Preset; 7] = [
|
|
Preset {
|
|
name: "Рой Шахедов",
|
|
kinds: &[(DroneKind::Gerbera, 10), (DroneKind::Shahed, 20), (DroneKind::Geran3, 4)],
|
|
approach: Approach::TwoSectors,
|
|
aim: Aim::Objects,
|
|
},
|
|
Preset {
|
|
name: "Массированный удар",
|
|
kinds: &[
|
|
(DroneKind::Gerbera, 8),
|
|
(DroneKind::Shahed, 12),
|
|
(DroneKind::Geran3, 4),
|
|
(DroneKind::Kh101, 4),
|
|
(DroneKind::Kalibr, 4),
|
|
(DroneKind::Kh22, 2),
|
|
(DroneKind::Iskander, 2),
|
|
],
|
|
approach: Approach::AllSides,
|
|
aim: Aim::Smart,
|
|
},
|
|
Preset {
|
|
name: "Баллистика",
|
|
kinds: &[(DroneKind::Gerbera, 4), (DroneKind::Iskander, 4), (DroneKind::Kinzhal, 2)],
|
|
approach: Approach::Sector,
|
|
aim: Aim::ObjectsAndSams,
|
|
},
|
|
Preset {
|
|
name: "Гиперзвук",
|
|
kinds: &[(DroneKind::Kh22, 3), (DroneKind::Zircon, 4), (DroneKind::Kinzhal, 3)],
|
|
approach: Approach::TwoSectors,
|
|
aim: Aim::Smart,
|
|
},
|
|
Preset {
|
|
name: "Орешник с прикрытием",
|
|
kinds: &[(DroneKind::Gerbera, 6), (DroneKind::Shahed, 10), (DroneKind::Iskander, 2), (DroneKind::Oreshnik, 1)],
|
|
approach: Approach::Sector,
|
|
aim: Aim::Smart,
|
|
},
|
|
Preset {
|
|
name: "Подавление ПВО",
|
|
kinds: &[(DroneKind::Gerbera, 8), (DroneKind::Lancet, 8), (DroneKind::Shahed, 8), (DroneKind::Kh22, 4)],
|
|
approach: Approach::AllSides,
|
|
aim: Aim::Smart,
|
|
},
|
|
Preset { name: "Пусто", kinds: &[], approach: Approach::Sector, aim: Aim::Objects },
|
|
];
|
|
|
|
pub struct WaveConfig {
|
|
pub counts: [u32; KINDS.len()],
|
|
pub approach: Approach,
|
|
pub dist: f64,
|
|
pub aim: Aim,
|
|
/// The last preset applied.
|
|
pub preset: usize,
|
|
}
|
|
|
|
impl Default for WaveConfig {
|
|
fn default() -> Self {
|
|
let mut w = WaveConfig { counts: [0; KINDS.len()], approach: Approach::Sector, dist: 300.0, aim: Aim::Smart, preset: 1 };
|
|
w.apply(1);
|
|
w
|
|
}
|
|
}
|
|
|
|
impl WaveConfig {
|
|
pub fn apply(&mut self, preset: usize) {
|
|
let p = &PRESETS[preset % PRESETS.len()];
|
|
self.preset = preset % PRESETS.len();
|
|
self.counts = [0; KINDS.len()];
|
|
for &(kind, n) in p.kinds {
|
|
if let Some(i) = KINDS.iter().position(|k| *k == kind) {
|
|
self.counts[i] = n;
|
|
}
|
|
}
|
|
self.approach = p.approach;
|
|
self.aim = p.aim;
|
|
}
|
|
/// The next number for kind `i`, back to 0 after the last.
|
|
pub fn step(&mut self, i: usize) {
|
|
let n = self.counts[i];
|
|
self.counts[i] = STEPS.iter().copied().find(|&s| s > n).unwrap_or(0);
|
|
}
|
|
pub fn total(&self) -> u32 {
|
|
self.counts.iter().sum()
|
|
}
|
|
pub fn order(&self) -> RaidOrder {
|
|
RaidOrder {
|
|
kinds: KINDS.iter().copied().zip(self.counts).filter(|k| k.1 > 0).collect(),
|
|
approach: self.approach,
|
|
dist: self.dist,
|
|
aim: self.aim,
|
|
}
|
|
}
|
|
/// A combined strike of about `n`, as `/airdef wave mix n` orders it.
|
|
pub fn mix(n: u32, dist: f64) -> RaidOrder {
|
|
let n = n.max(4);
|
|
let mut kinds = vec![
|
|
(DroneKind::Gerbera, n / 4 + 1),
|
|
(DroneKind::Shahed, n / 3 + 1),
|
|
(DroneKind::Geran3, n / 8 + 1),
|
|
(DroneKind::Kh101, n / 8 + 1),
|
|
(DroneKind::Kalibr, n / 10 + 1),
|
|
(DroneKind::Kh22, n / 16),
|
|
(DroneKind::Zircon, n / 20),
|
|
(DroneKind::Iskander, n / 12 + 1),
|
|
(DroneKind::Kinzhal, n / 16),
|
|
];
|
|
if n >= 30 {
|
|
kinds.push((DroneKind::Oreshnik, 1));
|
|
}
|
|
kinds.retain(|k| k.1 > 0);
|
|
RaidOrder { kinds, approach: Approach::TwoSectors, dist, aim: Aim::Objects }
|
|
}
|
|
}
|