Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d4e1682f5 | |||
| 545d4777e8 | |||
| f16bc2387f |
@@ -4,3 +4,4 @@
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.hmod binary
|
||||
*.patch -text
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
//! The `/airdef` command tree: the one description the game's chat box (colours, errors,
|
||||
//! Tab completion), the help line and the tests read (#98). The handler in `lib.rs` still
|
||||
//! splits its line itself; this tree decides what reaches it.
|
||||
use crate::sim::{DroneKind, SamKind};
|
||||
use horizon_mod_sdk::tree::{Node, Opt, Tree, Value};
|
||||
|
||||
/// The suggestion list of the saved scenarios' names (`command::set_suggestions`).
|
||||
pub const SCENARIOS: &str = "scenarios";
|
||||
|
||||
fn on_off() -> Value {
|
||||
Value::choice(["on", "off"])
|
||||
}
|
||||
|
||||
/// `/airdef ...` as `lib.rs` accepts it.
|
||||
pub fn tree() -> Tree {
|
||||
let wave_kinds: Vec<&str> = DroneKind::ALL.iter().map(|k| k.spec().key).chain(["mix"]).collect();
|
||||
let deploy_kinds: Vec<&str> = SamKind::ALL.iter().map(|k| k.key()).collect();
|
||||
let armed: Vec<&str> = SamKind::ARMED.iter().map(|k| k.key()).chain(["all"]).collect();
|
||||
let toggle = |word: &str| Node::lit(word).then(Node::arg("on/off", on_off()).runs());
|
||||
Tree::new("airdef").runs().with([
|
||||
Node::lit("menu").runs(),
|
||||
Node::lit("monitor").runs(),
|
||||
Node::lit("grid").runs(),
|
||||
Node::lit("replay").runs().with([
|
||||
Node::lit("map").runs(),
|
||||
Node::lit("full").runs(),
|
||||
Node::lit("reel").runs(),
|
||||
Node::lit("film").runs().with([
|
||||
Node::arg("режим", Value::choice(["best", "all"])).runs(),
|
||||
Node::arg("N", Value::int_from(1)).runs(),
|
||||
]),
|
||||
// The words after `export` come in any order: a name, best/all/N, key=value options.
|
||||
Node::lit("export").runs().then(
|
||||
Node::options(
|
||||
"параметры",
|
||||
vec![
|
||||
Opt::new("fps", Value::int_from(1)),
|
||||
Opt::new("size", Value::word()),
|
||||
Opt::new("crf", Value::int_from(0)),
|
||||
Opt::new("sec", Value::Number(Some(0.0), None)),
|
||||
Opt::flag("noaudio"),
|
||||
],
|
||||
Some(vec!["best".into(), "all".into()]),
|
||||
)
|
||||
.runs(),
|
||||
),
|
||||
Node::lit("stop").runs(),
|
||||
]),
|
||||
Node::lit("scenario").with([
|
||||
Node::lit("save").then(
|
||||
Node::arg("имя", Value::word()).runs().then(Node::arg("fresh", Value::choice(["fresh"])).runs()),
|
||||
),
|
||||
Node::lit("load").then(
|
||||
Node::arg("имя", Value::names(SCENARIOS)).runs().then(Node::arg("force", Value::choice(["force"])).runs()),
|
||||
),
|
||||
Node::lit("list").runs(),
|
||||
Node::lit("delete").then(Node::arg("имя", Value::names(SCENARIOS)).runs()),
|
||||
]),
|
||||
Node::lit("why").runs().then(Node::arg("номер", Value::int_from(1)).runs()),
|
||||
Node::lit("raid").runs(),
|
||||
Node::lit("repair").runs(),
|
||||
Node::lit("import").runs(),
|
||||
toggle("ew"),
|
||||
Node::lit("flare").runs(),
|
||||
Node::lit("move").then(Node::arg("номер", Value::int_from(1)).runs()),
|
||||
Node::lit("target").then(Node::lit("here").runs()),
|
||||
Node::lit("give").runs(),
|
||||
Node::lit("deploy").then(Node::arg("комплекс", Value::choice(deploy_kinds)).runs()),
|
||||
Node::lit("wave").then(
|
||||
Node::arg("тип", Value::choice(wave_kinds)).runs().then(
|
||||
Node::arg("кол-во", Value::int(1, 80)).runs().then(Node::arg("дальность", Value::number(60.0, 800.0)).runs()),
|
||||
),
|
||||
),
|
||||
Node::lit("clear").runs(),
|
||||
Node::lit("targets").then(Node::lit("clear").runs()),
|
||||
toggle("damage"),
|
||||
toggle("truth"),
|
||||
Node::lit("shader").then(Node::arg("режим", Value::choice(["on", "off", "hd"])).runs()),
|
||||
toggle("hold"),
|
||||
Node::lit("roles").runs().then(
|
||||
Node::arg("комплекс", Value::choice(armed)).then(
|
||||
Node::arg(
|
||||
"классы",
|
||||
Value::Word(["default", "all", "drone", "jet", "cruise", "supersonic", "ballistic"].map(String::from).to_vec()),
|
||||
)
|
||||
.runs(),
|
||||
),
|
||||
),
|
||||
Node::lit("stats").runs(),
|
||||
])
|
||||
}
|
||||
|
||||
/// The help line, from the same tree.
|
||||
pub fn help() -> String {
|
||||
tree().usage()
|
||||
}
|
||||
|
||||
/// The scenario names after `name` is saved (once, in the order saved).
|
||||
pub fn names_after_save(mut all: Vec<String>, name: &str) -> Vec<String> {
|
||||
if !all.iter().any(|n| n == name) {
|
||||
all.push(name.to_string());
|
||||
}
|
||||
all
|
||||
}
|
||||
|
||||
/// The scenario names after `name` is deleted.
|
||||
pub fn names_after_delete(mut all: Vec<String>, name: &str) -> Vec<String> {
|
||||
all.retain(|n| n != name);
|
||||
all
|
||||
}
|
||||
|
||||
/// Registers the tree with the game, and the scenario names it suggests.
|
||||
pub fn register(scenarios: &[String]) {
|
||||
horizon_mod_sdk::command::set_suggestions(SCENARIOS, scenarios);
|
||||
if let Err(e) = tree().register() {
|
||||
horizon_mod_sdk::warn(&format!("airdef: command tree refused: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn ok(line: &str) {
|
||||
if let Err(e) = tree().parse(line) {
|
||||
panic!("`{line}` should parse: {e}");
|
||||
}
|
||||
}
|
||||
fn bad_at(line: &str) -> usize {
|
||||
match tree().parse(line) {
|
||||
Ok(_) => panic!("`{line}` should not parse"),
|
||||
Err(e) => e.at,
|
||||
}
|
||||
}
|
||||
fn complete(line: &str, scenarios: &[&str]) -> Vec<String> {
|
||||
let names: Vec<String> = scenarios.iter().map(|s| s.to_string()).collect();
|
||||
tree().complete(line, &|_| names.clone())
|
||||
}
|
||||
|
||||
/// Every branch of the old `HELP` line and of the handler's match parses, with its
|
||||
/// options.
|
||||
#[test]
|
||||
fn every_branch_of_the_handler_parses() {
|
||||
for line in [
|
||||
"", "menu", "monitor", "grid", "give", "raid", "repair", "import", "flare", "clear", "stats", "roles",
|
||||
"replay", "replay map", "replay full", "replay reel", "replay film", "replay film best", "replay film all",
|
||||
"replay film 3", "replay export", "replay export mine", "replay export best", "replay export all", "replay export 3",
|
||||
"replay export mine all fps=30 size=1280x720 crf=18 sec=12.5 noaudio", "replay export fps=60", "replay stop",
|
||||
"scenario save a", "scenario save a fresh", "scenario load a", "scenario load a force", "scenario list",
|
||||
"scenario delete a", "why", "why 2", "ew on", "ew off", "move 4", "target here", "targets clear",
|
||||
"deploy patriot", "deploy light", "deploy s400", "wave mix", "wave shahed", "wave shahed 20", "wave kh101 80 800",
|
||||
"wave oreshnik 1 60", "damage on", "damage off", "truth on", "shader hd", "shader off", "shader on", "hold on",
|
||||
"roles all default", "roles patriot drone,jet", "roles pantsir all", "roles tor ballistic",
|
||||
] {
|
||||
ok(line);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_trees_kinds_are_the_enums_own() {
|
||||
for k in SamKind::ALL {
|
||||
ok(&format!("deploy {}", k.key()));
|
||||
}
|
||||
for k in DroneKind::ALL {
|
||||
ok(&format!("wave {}", k.spec().key));
|
||||
}
|
||||
for k in SamKind::ARMED {
|
||||
ok(&format!("roles {} all", k.key()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_and_words_outside_what_the_handler_takes_are_refused_where_they_are() {
|
||||
assert_eq!(bad_at("wave shahed 0"), 12);
|
||||
assert_eq!(bad_at("wave shahed 81"), 12);
|
||||
assert_eq!(bad_at("wave shahed 5 59"), 14);
|
||||
assert_eq!(bad_at("wave shahed 5 801"), 14);
|
||||
assert_eq!(bad_at("wave shahed x"), 12);
|
||||
assert_eq!(bad_at("wave scud"), 5);
|
||||
assert_eq!(bad_at("wave"), 4);
|
||||
assert_eq!(bad_at("deploy tank"), 7);
|
||||
assert_eq!(bad_at("deploy"), 6);
|
||||
assert_eq!(bad_at("ew maybe"), 3);
|
||||
assert_eq!(bad_at("shader ultra"), 7);
|
||||
assert_eq!(bad_at("why 0"), 4);
|
||||
assert_eq!(bad_at("why x"), 4);
|
||||
assert_eq!(bad_at("move"), 4);
|
||||
assert_eq!(bad_at("move 0"), 5);
|
||||
assert_eq!(bad_at("scenario"), 8);
|
||||
assert_eq!(bad_at("scenario load"), 13);
|
||||
assert_eq!(bad_at("scenario wipe"), 9);
|
||||
assert_eq!(bad_at("scenario save a keep"), 16);
|
||||
assert_eq!(bad_at("target there"), 7);
|
||||
assert_eq!(bad_at("roles tank all"), 6);
|
||||
assert_eq!(bad_at("roles patriot"), 13);
|
||||
assert_eq!(bad_at("replay sideways"), 7);
|
||||
assert_eq!(bad_at("replay film best now"), 17);
|
||||
assert_eq!(bad_at("nothing"), 0);
|
||||
assert_eq!(bad_at("menu 1"), 5);
|
||||
}
|
||||
|
||||
/// The key=value options of `replay export` stay what `start_export` reads.
|
||||
#[test]
|
||||
fn export_options_are_checked_by_key_and_value() {
|
||||
assert_eq!(bad_at("replay export fps=0"), 14);
|
||||
assert_eq!(bad_at("replay export fps=x"), 14);
|
||||
assert_eq!(bad_at("replay export fps"), 14);
|
||||
assert_eq!(bad_at("replay export noaudio=1"), 14);
|
||||
assert_eq!(bad_at("replay export fps=30 fps=60"), 21);
|
||||
assert_eq!(bad_at("replay export sec=-1"), 14);
|
||||
assert_eq!(bad_at("replay export crf=-2"), 14);
|
||||
assert_eq!(bad_at("replay export size="), 14);
|
||||
let p = tree().parse("replay export mine fps=30 noaudio").unwrap();
|
||||
assert_eq!(p.get("параметры"), Some("mine fps=30 noaudio"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completion_offers_the_next_word_only() {
|
||||
let top = complete("", &[]);
|
||||
for w in ["menu", "monitor", "grid", "replay", "scenario", "why", "raid", "repair", "import", "ew", "flare", "move",
|
||||
"target", "give", "deploy", "wave", "clear", "targets", "damage", "truth", "shader", "hold", "roles", "stats"] {
|
||||
assert!(top.contains(&w.to_string()), "{w} in {top:?}");
|
||||
}
|
||||
assert_eq!(top.len(), 24);
|
||||
assert_eq!(complete("rep", &[]), ["repair", "replay"]);
|
||||
assert_eq!(complete("replay ", &[]), ["export", "film", "full", "map", "reel", "stop"]);
|
||||
assert_eq!(complete("replay film ", &[]), ["all", "best"]);
|
||||
assert_eq!(complete("scenario ", &[]), ["delete", "list", "load", "save"]);
|
||||
assert_eq!(complete("wave ", &[]).len(), 14);
|
||||
assert!(complete("wave s", &[]).contains(&"shahed".to_string()));
|
||||
assert_eq!(complete("shader ", &[]), ["hd", "off", "on"]);
|
||||
assert_eq!(complete("replay export ", &[]), ["all", "best", "crf=", "fps=", "noaudio", "sec=", "size="]);
|
||||
assert_eq!(complete("replay export fps=30 no", &[]), ["noaudio"]);
|
||||
assert!(complete("menu ", &[]).is_empty());
|
||||
assert!(complete("wave nothing ", &[]).is_empty());
|
||||
}
|
||||
|
||||
/// The names follow the data: after a save the new name is offered, after a delete it is gone.
|
||||
#[test]
|
||||
fn scenario_names_follow_a_save_and_a_delete() {
|
||||
let mut all: Vec<String> = Vec::new();
|
||||
let names = |all: &[String]| -> Vec<String> { tree().complete("scenario load ", &|_| all.to_vec()) };
|
||||
assert!(names(&all).is_empty());
|
||||
all = names_after_save(all, "base");
|
||||
all = names_after_save(all, "night");
|
||||
all = names_after_save(all, "base");
|
||||
assert_eq!(names(&all), ["base", "night"]);
|
||||
let of = |all: &[String], line: &str| tree().complete(line, &|_| all.to_vec());
|
||||
assert_eq!(of(&all, "scenario delete n"), ["night"]);
|
||||
all = names_after_delete(all, "base");
|
||||
assert_eq!(names(&all), ["night"]);
|
||||
assert_eq!(of(&all, "scenario delete "), ["night"]);
|
||||
all = names_after_delete(all, "night");
|
||||
assert!(names(&all).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_help_line_is_the_trees() {
|
||||
let help = help();
|
||||
assert!(help.starts_with("/airdef menu | monitor | grid | replay "), "{help}");
|
||||
assert!(help.contains("scenario save <имя> [fresh]"), "{help}");
|
||||
assert!(help.contains("wave <тип> [<кол-во> [<дальность>]]"), "{help}");
|
||||
assert!(help.ends_with("| stats"), "{help}");
|
||||
assert!(help.contains("export [fps=… size=… crf=… sec=… noaudio]"), "{help}");
|
||||
assert!(help.contains("deploy <комплекс>"), "{help}");
|
||||
}
|
||||
|
||||
/// The nodes handed to the game are a tree the game accepts.
|
||||
#[test]
|
||||
fn the_nodes_are_flat_and_ordered() {
|
||||
let nodes = tree().nodes();
|
||||
assert!(nodes.len() < 512, "{}", nodes.len());
|
||||
assert!(nodes.iter().enumerate().all(|(i, n)| n.children.iter().all(|&c| c as usize > i)));
|
||||
}
|
||||
}
|
||||
@@ -308,10 +308,15 @@ fn plan_event(rec: &Recording, i: usize, floor: f64) -> Vec<Shot> {
|
||||
Some(Shot::new(a, b, &[(a, 1.0), (b, 1.4)], variants, head, "", i))
|
||||
};
|
||||
match e.kind {
|
||||
EventKind::Kill { drone, kind, sam, sam_kind, sam_index, missile } => {
|
||||
EventKind::Kill { drone, kind, sam, sam_kind, sam_index, missile, outcome } => {
|
||||
let sp = rec.sam(sam).map_or(pos - DVec3::new(150.0, 0.0, 0.0), |s| s.1);
|
||||
let name = format!("{} №{}", sam_kind.name(), sam_index + 1);
|
||||
let sub = format!("Перехват «{}»", kind.spec().name);
|
||||
let how = match outcome {
|
||||
crate::sim::outcome::Outcome::DisabledFalling => "",
|
||||
crate::sim::outcome::Outcome::Breakup => ": разрушение в воздухе",
|
||||
crate::sim::outcome::Outcome::AirDetonation => ": детонация в воздухе",
|
||||
};
|
||||
let sub = format!("Перехват «{}»{how}", kind.spec().name);
|
||||
let mt = missile.and_then(|m| rec.track(m).map(|t| (m, t.first as f64)));
|
||||
match mt {
|
||||
Some((m, tl)) => {
|
||||
@@ -638,7 +643,7 @@ mod tests {
|
||||
rec.events.push(Event {
|
||||
at: kill,
|
||||
pos,
|
||||
kind: EventKind::Kill { drone: 1, kind: DroneKind::Geran3, sam: 5, sam_kind: SamKind::S400, sam_index: 0, missile: missile.then_some(2) },
|
||||
kind: EventKind::Kill { drone: 1, kind: DroneKind::Geran3, sam: 5, sam_kind: SamKind::S400, sam_index: 0, missile: missile.then_some(2), outcome: Default::default() },
|
||||
});
|
||||
rec
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use horizon_mod_sdk::{
|
||||
};
|
||||
|
||||
mod cinema;
|
||||
mod commands;
|
||||
mod layout;
|
||||
mod film;
|
||||
mod monitor;
|
||||
@@ -1368,7 +1369,10 @@ impl AirDef {
|
||||
}
|
||||
}
|
||||
|
||||
const HELP: &str = "/airdef menu | monitor | grid | replay [map|full|reel|film [best|all|N]|export [имя] [best|all|N] [fps=60 size=1920x1080 crf=14 sec=N noaudio]|stop] | scenario save|load|list|delete | why [номер] | raid | repair | import | ew on|off | flare | move <номер> | target here | give | deploy <комплекс> | wave <тип|mix> [кол-во] [дальность] | clear | targets clear | damage on|off | truth on|off | shader on|off|hd | hold on|off | roles [комплекс классы] | stats";
|
||||
/// The help line: generated from the command tree (`commands.rs`), which the game checks lines with.
|
||||
fn help() -> String {
|
||||
commands::help()
|
||||
}
|
||||
|
||||
impl Mod for AirDef {
|
||||
fn init() -> Result<(Self, Registration), String> {
|
||||
@@ -1422,6 +1426,8 @@ impl Mod for AirDef {
|
||||
me.block_log = Some(render::world_log_start());
|
||||
me.sim.shader = true;
|
||||
me.apply_far();
|
||||
// Subcommands, typed arguments and the saved scenarios' names for the chat box (#98).
|
||||
commands::register(&scenario::saved_names());
|
||||
Ok((me, Registration::new().command("airdef").on_tick()))
|
||||
}
|
||||
|
||||
@@ -1946,7 +1952,7 @@ impl Mod for AirDef {
|
||||
self.sim.crashes,
|
||||
self.ground.world.text()
|
||||
)),
|
||||
_ => return Err(HELP.to_string()),
|
||||
_ => return Err(help()),
|
||||
};
|
||||
self.emit(out);
|
||||
Ok(reply)
|
||||
|
||||
@@ -125,13 +125,23 @@ fn clock(ticks: f64) -> String {
|
||||
format!("{:02}:{:04.1}", (s / 60.0) as u32, s % 60.0)
|
||||
}
|
||||
|
||||
/// How a kill ended, when it was not the plain fall.
|
||||
fn outcome_note(outcome: crate::sim::outcome::Outcome) -> &'static str {
|
||||
use crate::sim::outcome::Outcome;
|
||||
match outcome {
|
||||
Outcome::DisabledFalling => "",
|
||||
Outcome::Breakup => " (разрушение)",
|
||||
Outcome::AirDetonation => " (детонация в воздухе)",
|
||||
}
|
||||
}
|
||||
|
||||
/// What an event was, in a line.
|
||||
pub fn title(rec: &Recording, i: usize) -> String {
|
||||
let e = &rec.events[i];
|
||||
match e.kind {
|
||||
EventKind::Kill { kind, sam_kind, sam_index, missile, .. } => {
|
||||
EventKind::Kill { kind, sam_kind, sam_index, missile, outcome, .. } => {
|
||||
let how = if missile.is_some() { "ракетой" } else { "огнём пушек" };
|
||||
format!("{} №{} сбивает «{}» {how}", sam_kind.name(), sam_index + 1, kind.spec().name)
|
||||
format!("{} №{} сбивает «{}» {how}{}", sam_kind.name(), sam_index + 1, kind.spec().name, outcome_note(outcome))
|
||||
}
|
||||
EventKind::Hit { kind, object: Some(o), .. } => format!("«{}» поражает объект №{}", kind.spec().name, o + 1),
|
||||
EventKind::Hit { kind, sam: Some((sk, si)), .. } => format!("«{}» бьёт по {} №{}", kind.spec().name, sk.name(), si + 1),
|
||||
@@ -146,8 +156,8 @@ pub fn title(rec: &Recording, i: usize) -> String {
|
||||
pub fn row(rec: &Recording, i: usize) -> String {
|
||||
let e = &rec.events[i];
|
||||
let what = match e.kind {
|
||||
EventKind::Kill { kind, sam_kind, sam_index, missile, .. } => {
|
||||
format!("{}-{} > {}{}", sam_kind.name(), sam_index + 1, kind.spec().name, if missile.is_none() { " (пушки)" } else { "" })
|
||||
EventKind::Kill { kind, sam_kind, sam_index, missile, outcome, .. } => {
|
||||
format!("{}-{} > {}{}{}", sam_kind.name(), sam_index + 1, kind.spec().name, if missile.is_none() { " (пушки)" } else { "" }, outcome_note(outcome))
|
||||
}
|
||||
EventKind::Hit { kind, object: Some(o), .. } => format!("{} > объект {}", kind.spec().name, o + 1),
|
||||
EventKind::Hit { kind, sam: Some((sk, si)), .. } => format!("{} > {}-{}", kind.spec().name, sk.name(), si + 1),
|
||||
@@ -163,8 +173,9 @@ pub fn row(rec: &Recording, i: usize) -> String {
|
||||
pub fn interest(rec: &Recording, i: usize) -> f64 {
|
||||
let e = &rec.events[i];
|
||||
match e.kind {
|
||||
EventKind::Kill { kind, missile, .. } => {
|
||||
EventKind::Kill { kind, missile, outcome, .. } => {
|
||||
let spec = kind.spec();
|
||||
let bonus = if outcome == crate::sim::outcome::Outcome::AirDetonation { 2.0 } else { 0.0 };
|
||||
let class = match spec.class {
|
||||
Class::Ballistic => 10.0,
|
||||
Class::Supersonic => 7.0,
|
||||
@@ -179,7 +190,7 @@ pub fn interest(rec: &Recording, i: usize) -> f64 {
|
||||
};
|
||||
// A kill close to what it was going for.
|
||||
let close = rec.objects.iter().chain(rec.sams.iter().map(|s| &s.2)).any(|o| o.distance(e.pos) < 40.0);
|
||||
class + rare + if spec.decoy { -3.0 } else { 0.0 } + if missile.is_none() { 1.0 } else { 0.0 } + if close { 3.0 } else { 0.0 }
|
||||
bonus + class + rare + if spec.decoy { -3.0 } else { 0.0 } + if missile.is_none() { 1.0 } else { 0.0 } + if close { 3.0 } else { 0.0 }
|
||||
}
|
||||
EventKind::Hit { power, object, sam, .. } => {
|
||||
power as f64 * 1.5 + if object.is_some() { 6.0 } else if sam.is_some() { 5.0 } else { 0.0 }
|
||||
@@ -439,13 +450,16 @@ impl Player {
|
||||
let heard = |p: DVec3| listener + (p - self.eye);
|
||||
for e in rec.events.iter().filter(|e| (self.heard..self.t).contains(&(e.at as f64))) {
|
||||
let event = match e.kind {
|
||||
EventKind::Kill { .. } => "airdef:blast.air",
|
||||
EventKind::Kill { kind, outcome, .. } => crate::sim::outcome::look(kind, outcome).3,
|
||||
EventKind::Hit { power, .. } | EventKind::Crash { power, .. } => ["airdef:blast.air", "airdef:blast.medium", "airdef:blast.big", "airdef:blast.heavy", "airdef:blast.huge"][(power as usize).min(4)],
|
||||
EventKind::SamLost { .. } => "airdef:blast.big",
|
||||
EventKind::Split { .. } => "airdef:boom.sonic",
|
||||
};
|
||||
let gain = if let EventKind::Kill { kind, .. } = e.kind { crate::sim::record::kill_look(kind).2 } else { 1.0 };
|
||||
let gain = if let EventKind::Kill { kind, outcome, .. } = e.kind { crate::sim::outcome::look(kind, outcome).2 } else { 1.0 };
|
||||
out.sound(event, heard(e.pos), gain, 1.0);
|
||||
if let EventKind::Kill { outcome: crate::sim::outcome::Outcome::AirDetonation, .. } = e.kind {
|
||||
out.sound("airdef:boom.sonic", heard(e.pos), 0.8, 1.2);
|
||||
}
|
||||
}
|
||||
for tr in rec.tracks.iter().filter(|tr| (self.heard..self.t).contains(&(tr.first as f64))) {
|
||||
if let What::Missile(kind, _) = tr.what
|
||||
|
||||
@@ -20,6 +20,16 @@ fn valid(name: &str) -> Result<String, String> {
|
||||
Ok(n)
|
||||
}
|
||||
|
||||
/// The saved scenarios' names.
|
||||
pub(crate) fn saved_names() -> Vec<String> {
|
||||
names()
|
||||
}
|
||||
|
||||
/// Tells the chat box the names now saved, so Tab offers them.
|
||||
fn publish(all: &[String]) {
|
||||
command::set_suggestions(commands::SCENARIOS, all);
|
||||
}
|
||||
|
||||
fn names() -> Vec<String> {
|
||||
storage::get(INDEX).map(|b| String::from_utf8_lossy(&b).lines().map(str::to_string).filter(|l| !l.is_empty()).collect()).unwrap_or_default()
|
||||
}
|
||||
@@ -82,11 +92,12 @@ impl AirDef {
|
||||
let fresh = flags.contains(&"fresh");
|
||||
let text = self.scenario_text(&name, fresh);
|
||||
storage::set(&key(&name), text.as_bytes()).map_err(|e| format!("Не удалось сохранить: {e}"))?;
|
||||
let mut all = names();
|
||||
if !all.contains(&name) {
|
||||
all.push(name.clone());
|
||||
let before = names();
|
||||
let all = commands::names_after_save(before.clone(), &name);
|
||||
if all != before {
|
||||
storage::set(INDEX, all.join("\n").as_bytes()).map_err(|e| format!("Не удалось записать список: {e}"))?;
|
||||
}
|
||||
publish(&all);
|
||||
Ok(format!(
|
||||
"Сценарий «{name}» сохранён: комплексов {}, объектов {}{}",
|
||||
self.sim.sams.len(),
|
||||
@@ -109,13 +120,14 @@ impl AirDef {
|
||||
}
|
||||
["delete", name] => {
|
||||
let name = valid(name)?;
|
||||
let mut all = names();
|
||||
let all = names();
|
||||
if !all.contains(&name) {
|
||||
return Err(format!("Нет сценария «{name}»"));
|
||||
}
|
||||
all.retain(|n| *n != name);
|
||||
let all = commands::names_after_delete(all, &name);
|
||||
storage::delete(&key(&name));
|
||||
storage::set(INDEX, all.join("\n").as_bytes()).map_err(|e| format!("Не удалось записать список: {e}"))?;
|
||||
publish(&all);
|
||||
Ok(format!("Сценарий «{name}» удалён"))
|
||||
}
|
||||
_ => Err("/airdef scenario save <имя> [fresh] | load <имя> [force] | list | delete <имя>".into()),
|
||||
|
||||
+93
-19
@@ -20,6 +20,7 @@ mod ew;
|
||||
pub mod lights;
|
||||
mod logistics;
|
||||
mod orders;
|
||||
pub mod outcome;
|
||||
mod units;
|
||||
mod why;
|
||||
pub mod world;
|
||||
@@ -31,6 +32,7 @@ pub use ew::EW_RADIUS;
|
||||
pub use damage::{Comps, Part, PartState};
|
||||
pub use sight::{Ident, Track};
|
||||
use damage::dice;
|
||||
use outcome::{Impact, Outcome};
|
||||
pub use units::{Family, SamKind};
|
||||
use units::Muzzle;
|
||||
pub use raid::{Approach, Aim, RaidOrder};
|
||||
@@ -1375,6 +1377,8 @@ enum Fx {
|
||||
Fireball { pos: DVec3, size: f64, age: u32, life: u32, spin: DQuat },
|
||||
/// A falling piece of a drone.
|
||||
Debris { pos: DVec3, vel: DVec3, rot: DQuat, spin: DQuat, age: u32 },
|
||||
/// A piece thrown off by a breakup or an air detonation: its own drag and life.
|
||||
Piece { pos: DVec3, vel: DVec3, rot: DQuat, piece: outcome::Piece, age: u32 },
|
||||
/// A glowing red tracer round.
|
||||
Tracer { pos: DVec3, vel: DVec3, life: u32 },
|
||||
}
|
||||
@@ -2094,11 +2098,27 @@ impl Sim {
|
||||
self.fx.push((id, Fx::Fireball { pos, size, age: 0, life, spin }));
|
||||
}
|
||||
|
||||
/// A drone hit by air defence: a flash, pieces, and it falls burning.
|
||||
fn shoot_down(&mut self, idx: usize, by: u32, missile: Option<u32>, out: &mut Out) {
|
||||
/// A drone hit by the guns of system `by`.
|
||||
fn shoot_down(&mut self, idx: usize, by: u32, missile: Option<u32>, out: &mut Out) -> Option<Outcome> {
|
||||
let kind = self.sams.iter().find(|s| s.id == by).map_or(SamKind::Gepard, |s| s.kind);
|
||||
let shell = kind.spec().gun.as_ref().map_or(5.0, |g| g.shell);
|
||||
let at = self.drones[idx].pos;
|
||||
self.shoot_down_by(idx, by, missile, Impact::gun(kind, at, shell), out)
|
||||
}
|
||||
|
||||
/// A drone brought down by `imp` from system `by`: how it ends is rolled once (combat randomness, so a
|
||||
/// detonation really means no ground impact), recorded with the kill, and drawn from the visual randomness
|
||||
/// only. The kill is counted here and nowhere else.
|
||||
fn shoot_down_by(&mut self, idx: usize, by: u32, missile: Option<u32>, imp: Impact, out: &mut Out) -> Option<Outcome> {
|
||||
if !self.drones[idx].alive() {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
let dkind = self.drones[idx].kind;
|
||||
let roll = self.rng.f();
|
||||
let outcome = outcome::choose(dkind, &imp, roll);
|
||||
let spec = dkind.spec();
|
||||
// A broken-up target's warhead section may stay whole: it falls on as a wreck (and may go off on landing).
|
||||
let keeps_warhead = outcome == Outcome::Breakup && !spec.decoy && spec.warhead > 0 && self.rng.chance(outcome::WARHEAD_SURVIVES);
|
||||
let sector = self.drones[idx].sector as usize;
|
||||
self.learn(sector, true);
|
||||
let until = self.tick + 70;
|
||||
@@ -2106,33 +2126,72 @@ impl Sim {
|
||||
s.kill_view = Some((self.drones[idx].id, self.drones[idx].pos, until));
|
||||
}
|
||||
if let Some((i, s)) = self.sams.iter().enumerate().find(|(_, s)| s.id == by) {
|
||||
let (drone, kind, pos) = (self.drones[idx].id, self.drones[idx].kind, self.drones[idx].pos);
|
||||
let kill = record::EventKind::Kill { drone, kind, sam: by, sam_kind: s.kind, sam_index: i, missile };
|
||||
let (drone, kind, pos) = (self.drones[idx].id, dkind, self.drones[idx].pos);
|
||||
let kill = record::EventKind::Kill { drone, kind, sam: by, sam_kind: s.kind, sam_index: i, missile, outcome };
|
||||
self.log(pos, kill);
|
||||
}
|
||||
let d = &mut self.drones[idx];
|
||||
let before = d.vel;
|
||||
d.flight = Flight::Falling;
|
||||
d.age = 0;
|
||||
d.vel = d.vel * 0.6 + DVec3::new(0.0, 0.15, 0.0);
|
||||
d.vel = match outcome {
|
||||
Outcome::DisabledFalling => d.vel * 0.6 + DVec3::new(0.0, 0.15, 0.0),
|
||||
_ => d.vel * 0.35 + DVec3::new(0.0, 0.1, 0.0),
|
||||
};
|
||||
let pos = d.pos;
|
||||
let vel = d.vel;
|
||||
self.kills += 1;
|
||||
if let Some(s) = self.sams.iter_mut().find(|s| s.id == by) {
|
||||
s.kills += 1;
|
||||
}
|
||||
// The look of the kill goes by the warhead it blew up (replays use the same).
|
||||
let (size, life, gain) = record::kill_look(self.drones[idx].kind);
|
||||
// The look of the kill goes by the warhead it blew up and by how it ended (replays use the same).
|
||||
let (size, life, gain, sound) = outcome::look(dkind, outcome);
|
||||
self.fireball(pos, size as f64, life / 9);
|
||||
out.particles("minecraft:explosion", pos, 0.6, DVec3::ZERO, 0.0, 4);
|
||||
out.particles("minecraft:large_smoke", pos, 1.0, DVec3::ZERO, 0.06, 25);
|
||||
out.particles("minecraft:firework", pos, 0.3, DVec3::ZERO, 0.35, 30);
|
||||
out.sound("airdef:blast.air", pos, gain, 1.0 + self.vis.f() as f32 * 0.2);
|
||||
for _ in 0..5 {
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let v = vel + DVec3::new(self.vis.s(), self.vis.f() * 0.8, self.vis.s()) * 0.35;
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s() * 0.4, self.vis.s() * 0.4, self.vis.s() * 0.4);
|
||||
self.fx.push((id, Fx::Debris { pos, vel: v, rot: DQuat::IDENTITY, spin, age: 0 }));
|
||||
let pitch = 1.0 + self.vis.f() as f32 * 0.2;
|
||||
match outcome {
|
||||
Outcome::DisabledFalling => {
|
||||
out.particles("minecraft:explosion", pos, 0.6, DVec3::ZERO, 0.0, 4);
|
||||
out.particles("minecraft:large_smoke", pos, 1.0, DVec3::ZERO, 0.06, 25);
|
||||
out.particles("minecraft:firework", pos, 0.3, DVec3::ZERO, 0.35, 30);
|
||||
for _ in 0..5 {
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let v = vel + DVec3::new(self.vis.s(), self.vis.f() * 0.8, self.vis.s()) * 0.35;
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s() * 0.4, self.vis.s() * 0.4, self.vis.s() * 0.4);
|
||||
self.fx.push((id, Fx::Debris { pos, vel: v, rot: DQuat::IDENTITY, spin, age: 0 }));
|
||||
}
|
||||
}
|
||||
Outcome::Breakup => {
|
||||
out.particles("minecraft:explosion", pos, 0.8, DVec3::ZERO, 0.0, 3);
|
||||
out.particles("minecraft:large_smoke", pos, 1.4, DVec3::ZERO, 0.08, 30);
|
||||
out.particles("minecraft:firework", pos, 0.4, DVec3::ZERO, 0.3, 14);
|
||||
}
|
||||
Outcome::AirDetonation => {
|
||||
out.particles("minecraft:flash", pos, 0.0, DVec3::ZERO, 0.0, 1);
|
||||
out.particles("minecraft:explosion_emitter", pos, 0.8, DVec3::ZERO, 0.0, 2);
|
||||
out.particles("minecraft:large_smoke", pos, size * 0.3, DVec3::new(0.0, 0.05, 0.0), 0.07, if self.shader { 20 } else { 40 });
|
||||
out.particles("minecraft:firework", pos, 0.6, DVec3::ZERO, 0.5, 50);
|
||||
// The shock arrives after the flash (`boom` sounds travel); the warhead's blast hurts what is near.
|
||||
out.sound("airdef:boom.sonic", pos, 0.8, 1.2);
|
||||
self.blast_damage(pos, 0, out);
|
||||
}
|
||||
}
|
||||
out.sound(sound, pos, gain, pitch);
|
||||
let seed = self.vis.next();
|
||||
let mut alive = self.fx.iter().filter(|(_, f)| matches!(f, Fx::Piece { .. })).count();
|
||||
for p in outcome::pieces(seed, outcome, before) {
|
||||
if alive + 1 > outcome::PIECES_MAX {
|
||||
break;
|
||||
}
|
||||
let id = fx_ident(&mut self.fx_next);
|
||||
let rot = DQuat::from_euler(glam::EulerRot::XYZ, self.vis.s(), self.vis.s(), self.vis.s());
|
||||
self.fx.push((id, Fx::Piece { pos, vel: p.vel, rot, piece: p, age: 0 }));
|
||||
alive += 1;
|
||||
}
|
||||
if outcome == Outcome::AirDetonation || (outcome == Outcome::Breakup && !keeps_warhead) {
|
||||
// The main mass is gone: nothing falls to the ground and nothing goes off there.
|
||||
self.drones.remove(idx);
|
||||
}
|
||||
Some(outcome)
|
||||
}
|
||||
|
||||
// ------------------------------------------------ air defence
|
||||
@@ -2486,7 +2545,7 @@ impl Sim {
|
||||
}
|
||||
for (t, by) in gun_hits {
|
||||
if let Some(i) = self.drones.iter().position(|d| d.id == t) {
|
||||
self.shoot_down(i, by, None, out);
|
||||
let _ = self.shoot_down(i, by, None, out);
|
||||
}
|
||||
}
|
||||
for i in 0..self.sams.len() {
|
||||
@@ -2679,7 +2738,8 @@ impl Sim {
|
||||
if let Some(t) = target.and_then(|t| self.drones.iter().position(|d| d.id == t)) {
|
||||
self.drones[t].engaged = self.drones[t].engaged.saturating_sub(1);
|
||||
if kill {
|
||||
self.shoot_down(t, sam, Some(mid), out);
|
||||
let (at, closing) = (self.drones[t].pos, (m.vel - self.drones[t].vel).length());
|
||||
let _ = self.shoot_down_by(t, sam, Some(mid), Impact::missile(m.kind, at, closing), out);
|
||||
}
|
||||
}
|
||||
// A missile that lost its target frees it for others.
|
||||
@@ -2730,6 +2790,20 @@ impl Sim {
|
||||
let landed = ground.at(*pos, now).is_some_and(|g| pos.y <= g);
|
||||
!landed && *age < 200
|
||||
}
|
||||
Fx::Piece { pos, vel, rot, piece, age } => {
|
||||
*age += 1;
|
||||
outcome::fly(pos, vel, piece.drag);
|
||||
*rot = piece.spin * *rot;
|
||||
out.model(id, "airdef:debris", *pos, *rot, piece.scale, false);
|
||||
if piece.burns {
|
||||
out.particles("minecraft:large_smoke", *pos, 0.1, DVec3::new(0.0, 0.03, 0.0), 0.01, 1);
|
||||
if *age % 3 == 0 {
|
||||
out.particles("minecraft:flame", *pos, 0.1, DVec3::ZERO, 0.01, 1);
|
||||
}
|
||||
}
|
||||
let landed = ground.at(*pos, now).is_some_and(|g| pos.y <= g);
|
||||
!landed && *age < piece.life
|
||||
}
|
||||
Fx::Tracer { pos, vel, life } => {
|
||||
*pos += *vel;
|
||||
vel.y -= 0.02;
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
//! What a kill does to the air target (#97): it falls burning on, it breaks up, or its warhead goes
|
||||
//! off in the air. The chances are game profiles, all here and nowhere else; they are not the real
|
||||
//! weapons' figures. The roll is combat randomness (a detonation means no ground impact), one draw
|
||||
//! per kill; everything drawn from it (pieces, sparks) is decoration and uses only the visual RNG.
|
||||
//! The outcome is recorded with the kill, so a replay shows it and never rolls again.
|
||||
use super::*;
|
||||
|
||||
/// How an air target ended up when it was brought down.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
|
||||
pub enum Outcome {
|
||||
/// Control lost: the burning hull falls on with what momentum it had. A recording without an
|
||||
/// outcome (an old one) is read as this, which is what every kill used to be.
|
||||
#[default]
|
||||
DisabledFalling,
|
||||
/// The airframe tears into several pieces; the warhead section may survive and fall on.
|
||||
Breakup,
|
||||
/// The warhead goes off in the air: a flash and a rain of debris, nothing left to hit the ground.
|
||||
AirDetonation,
|
||||
}
|
||||
|
||||
/// What brought the target down.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum KillCause {
|
||||
/// Shells of this system's guns.
|
||||
Gun(SamKind),
|
||||
Missile(MissileKind),
|
||||
}
|
||||
|
||||
/// A hit, as far as the outcome is concerned.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Impact {
|
||||
pub cause: KillCause,
|
||||
/// Game energy of the hit (see `energy_of`).
|
||||
pub energy: f64,
|
||||
pub at: DVec3,
|
||||
/// Closing speed, blocks a tick.
|
||||
pub rel_speed: f64,
|
||||
}
|
||||
|
||||
impl Impact {
|
||||
pub fn gun(sam: SamKind, at: DVec3, rel_speed: f64) -> Self {
|
||||
Impact { cause: KillCause::Gun(sam), energy: energy_of(KillCause::Gun(sam)), at, rel_speed }
|
||||
}
|
||||
pub fn missile(kind: MissileKind, at: DVec3, rel_speed: f64) -> Self {
|
||||
Impact { cause: KillCause::Missile(kind), energy: energy_of(KillCause::Missile(kind)), at, rel_speed }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- the profiles: the one place to tune ------------------------------------------------------
|
||||
|
||||
/// Game energy of one hit: a shell is small, an interceptor's warhead is big.
|
||||
pub fn energy_of(cause: KillCause) -> f64 {
|
||||
match cause {
|
||||
KillCause::Gun(SamKind::Gepard) => 0.15,
|
||||
KillCause::Gun(_) => 0.13,
|
||||
KillCause::Missile(m) => match m {
|
||||
MissileKind::Pac3 => 1.0,
|
||||
MissileKind::M57e6 => 0.5,
|
||||
MissileKind::M48n6 => 1.2,
|
||||
MissileKind::M77n6 => 1.6,
|
||||
MissileKind::IrisT => 0.7,
|
||||
MissileKind::Amraam => 0.6,
|
||||
MissileKind::M9m317 => 0.8,
|
||||
MissileKind::M9m338 => 0.7,
|
||||
// Rams: a lot of speed, no warhead to speak of.
|
||||
MissileKind::P1sun => 0.25,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// How much a target takes before it comes apart: size, then what it carries.
|
||||
pub fn toughness(kind: DroneKind) -> f64 {
|
||||
let s = kind.spec();
|
||||
0.2 + 0.2 * s.scale + 0.03 * s.warhead as f64
|
||||
}
|
||||
|
||||
/// Chance of an air detonation: nothing without a warhead, rare for shells, likely when a strong
|
||||
/// interceptor meets a small target.
|
||||
const DET_BASE: f64 = 0.04;
|
||||
const DET_SLOPE: f64 = 0.32;
|
||||
const DET_FLOOR: f64 = 0.03;
|
||||
const DET_CEIL: f64 = 0.75;
|
||||
/// Of the rest, the share that breaks up instead of falling on.
|
||||
const BREAK_BASE: f64 = 0.12;
|
||||
const BREAK_SLOPE: f64 = 0.3;
|
||||
const BREAK_CEIL: f64 = 0.8;
|
||||
/// A broken-up target whose warhead section stays whole and falls on (and may cook off on landing).
|
||||
pub const WARHEAD_SURVIVES: f64 = 0.3;
|
||||
|
||||
/// The relative strength of the hit against the target.
|
||||
pub fn ratio(kind: DroneKind, imp: &Impact) -> f64 {
|
||||
let speed = (0.8 + 0.05 * imp.rel_speed).clamp(0.8, 1.2);
|
||||
imp.energy * speed / toughness(kind)
|
||||
}
|
||||
|
||||
/// (chance of an air detonation, chance of a breakup) of a hit on `kind`; the rest falls on.
|
||||
pub fn odds(kind: DroneKind, imp: &Impact) -> (f64, f64) {
|
||||
let s = kind.spec();
|
||||
let r = ratio(kind, imp);
|
||||
let det = if s.decoy || s.warhead == 0 { 0.0 } else { (DET_BASE + DET_SLOPE * (r - 0.4)).clamp(DET_FLOOR, DET_CEIL) };
|
||||
let share = (BREAK_BASE + BREAK_SLOPE * r).clamp(0.0, BREAK_CEIL);
|
||||
(det, (1.0 - det) * share)
|
||||
}
|
||||
|
||||
/// The outcome for a roll of 0..1.
|
||||
pub fn choose(kind: DroneKind, imp: &Impact, roll: f64) -> Outcome {
|
||||
let (det, brk) = odds(kind, imp);
|
||||
if roll < det {
|
||||
Outcome::AirDetonation
|
||||
} else if roll < det + brk {
|
||||
Outcome::Breakup
|
||||
} else {
|
||||
Outcome::DisabledFalling
|
||||
}
|
||||
}
|
||||
|
||||
/// The look of a kill by the target's warhead and the outcome: (fireball radius, ticks it burns,
|
||||
/// loudness, sound). A bare decoy pops; a detonation lights the sky. The live raid and its replay
|
||||
/// both take it from here.
|
||||
pub fn look(kind: DroneKind, outcome: Outcome) -> (f32, u32, f32, &'static str) {
|
||||
let w = kind.spec().warhead.min(8) as f32;
|
||||
let size = 3.5 * (0.85 + 0.12 * w);
|
||||
let life = (8 + (w as u32) / 2) * 9;
|
||||
let gain = 1.0 + 0.06 * w;
|
||||
match outcome {
|
||||
Outcome::DisabledFalling => (size, life, gain, "airdef:blast.air"),
|
||||
Outcome::Breakup => (size * 0.9, life, gain * 0.9, "airdef:blast.medium"),
|
||||
Outcome::AirDetonation => (size * 1.9, life * 8 / 5, gain * 1.5, "airdef:blast.big"),
|
||||
}
|
||||
}
|
||||
|
||||
// ---- pieces -----------------------------------------------------------------------------------
|
||||
|
||||
/// Most pieces alive at once; a mass battle thins them out.
|
||||
pub const PIECES_MAX: usize = 320;
|
||||
/// Longest a piece lives, ticks (a replay's pieces end here too).
|
||||
pub const PIECE_LIFE: u32 = 110;
|
||||
|
||||
/// One piece thrown off: its own velocity, spin, size, drag and life.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Piece {
|
||||
pub vel: DVec3,
|
||||
pub spin: DQuat,
|
||||
pub scale: f64,
|
||||
pub drag: f64,
|
||||
pub life: u32,
|
||||
/// Trails smoke while it falls.
|
||||
pub burns: bool,
|
||||
}
|
||||
|
||||
/// The pieces of an outcome from `seed` (decorative randomness only), moving on with `base` (the
|
||||
/// target's velocity). None for a fall.
|
||||
pub fn pieces(seed: u64, outcome: Outcome, base: DVec3) -> Vec<Piece> {
|
||||
let (n, speed, size, life) = match outcome {
|
||||
Outcome::DisabledFalling => return Vec::new(),
|
||||
Outcome::Breakup => (7, 0.35, 1.0, 70),
|
||||
Outcome::AirDetonation => (12, 0.8, 0.8, 50),
|
||||
};
|
||||
let mut rng = Rng::new(seed ^ 0x9e37_79b9_7f4a_7c15);
|
||||
(0..n)
|
||||
.map(|_| {
|
||||
let dir = DVec3::new(rng.s(), rng.s() * 0.8 + 0.2, rng.s()).normalize_or(DVec3::Y);
|
||||
let v = base * if outcome == Outcome::Breakup { 0.55 } else { 0.3 } + dir * speed * (0.4 + 0.8 * rng.f());
|
||||
let spin = DQuat::from_euler(glam::EulerRot::XYZ, rng.s() * 0.5, rng.s() * 0.5, rng.s() * 0.5);
|
||||
Piece {
|
||||
vel: v,
|
||||
spin,
|
||||
scale: size * (0.5 + 0.8 * rng.f()),
|
||||
drag: 0.96 + 0.025 * rng.f(),
|
||||
life: (life as f64 * (0.6 + 0.4 * rng.f())) as u32,
|
||||
burns: rng.chance(0.6),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// One tick of a piece's flight: gravity, then drag (the replays and the live raid move the same).
|
||||
pub fn fly(pos: &mut DVec3, vel: &mut DVec3, drag: f64) {
|
||||
vel.y -= 0.05;
|
||||
*vel *= drag;
|
||||
*pos += *vel;
|
||||
}
|
||||
|
||||
/// Where a piece is `age` ticks after it was thrown from `at`, as a pure function (for replays).
|
||||
pub fn piece_at(at: DVec3, p: &Piece, age: u32) -> DVec3 {
|
||||
let (mut pos, mut vel) = (at, p.vel);
|
||||
for _ in 0..age.min(p.life) {
|
||||
fly(&mut pos, &mut vel, p.drag);
|
||||
}
|
||||
pos
|
||||
}
|
||||
|
||||
/// How a piece is turned `age` ticks after it was thrown (a replay's, from the start).
|
||||
pub fn piece_rot(p: &Piece, age: u32) -> DQuat {
|
||||
let mut rot = DQuat::IDENTITY;
|
||||
for _ in 0..age.min(p.life) {
|
||||
rot = p.spin * rot;
|
||||
}
|
||||
rot
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn shares(kind: DroneKind, imp: Impact, seeds: u64) -> [u32; 3] {
|
||||
let mut n = [0u32; 3];
|
||||
let mut rng = Rng::new(97);
|
||||
for _ in 0..seeds {
|
||||
let roll = rng.f();
|
||||
n[match choose(kind, &imp, roll) {
|
||||
Outcome::DisabledFalling => 0,
|
||||
Outcome::Breakup => 1,
|
||||
Outcome::AirDetonation => 2,
|
||||
}] += 1;
|
||||
}
|
||||
n
|
||||
}
|
||||
|
||||
// #97: the profiles are tendencies, not laws: shells mostly leave a falling hull, a strong interceptor
|
||||
// against a small target often detonates it, and everything still can happen.
|
||||
#[test]
|
||||
fn outcomes_follow_the_weapon_and_the_target() {
|
||||
let at = DVec3::ZERO;
|
||||
let gun = shares(DroneKind::Shahed, Impact::gun(SamKind::Gepard, at, 10.0), 4000);
|
||||
assert!(gun[0] > 2400 && gun[2] < 400, "gun against a Shahed: {gun:?}");
|
||||
assert!(gun[1] > 0 && gun[2] > 0, "not a law: some break up, a few go off: {gun:?}");
|
||||
let strong = shares(DroneKind::Shahed, Impact::missile(MissileKind::M77n6, at, 6.0), 4000);
|
||||
assert!(strong[2] > 2000, "a strong interceptor against a small target: {strong:?}");
|
||||
let weak = shares(DroneKind::Shahed, Impact::missile(MissileKind::M57e6, at, 5.0), 4000);
|
||||
assert!(weak[2] < strong[2] && weak[2] > gun[2], "in between: {weak:?}");
|
||||
// A big missile is tougher than a small drone for the same interceptor.
|
||||
let big = shares(DroneKind::Iskander, Impact::missile(MissileKind::Pac3, at, 6.0), 4000);
|
||||
let small = shares(DroneKind::Shahed, Impact::missile(MissileKind::Pac3, at, 6.0), 4000);
|
||||
assert!(big[2] < small[2], "{big:?} {small:?}");
|
||||
// Without a warhead nothing goes off: a decoy or a bus breaks up or falls.
|
||||
for kind in [DroneKind::Gerbera, DroneKind::Oreshnik] {
|
||||
assert_eq!(shares(kind, Impact::missile(MissileKind::M77n6, at, 6.0), 2000)[2], 0, "{kind:?}");
|
||||
}
|
||||
}
|
||||
|
||||
fn kill(seed: u64, shader: bool, imp: impl Fn(DVec3) -> Impact) -> (Outcome, usize, u64) {
|
||||
let mut sim = Sim::new(seed);
|
||||
sim.shader = shader;
|
||||
let mut out = Out::default();
|
||||
let sam = sim.id();
|
||||
sim.sams.push(Sam::new(sam, SamKind::Patriot, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(0.0, 120.0, 300.0), DVec3::X, DVec3::new(900.0, 70.0, 0.0));
|
||||
let at = sim.drones[0].pos;
|
||||
let o = sim.shoot_down_by(0, sam, None, imp(at), &mut out).unwrap();
|
||||
(o, sim.drones.len(), sim.rng.state())
|
||||
}
|
||||
|
||||
// #97: the roll is combat randomness: the same with graphics on and off, and the drawing never moves it.
|
||||
#[test]
|
||||
fn the_outcome_is_the_same_with_graphics_on_and_off() {
|
||||
for seed in 1..40 {
|
||||
let strong = |at| Impact::missile(MissileKind::M77n6, at, 6.0);
|
||||
assert_eq!(kill(seed, true, strong), kill(seed, false, strong), "seed {seed}");
|
||||
let gun = |at| Impact::gun(SamKind::Gepard, at, 10.0);
|
||||
assert_eq!(kill(seed, true, gun), kill(seed, false, gun), "seed {seed}");
|
||||
}
|
||||
}
|
||||
|
||||
// #97: a detonated warhead is spent: no wreck falls, so no second blast on landing; the kill counts once.
|
||||
#[test]
|
||||
fn a_detonated_target_does_no_ground_damage_and_counts_once() {
|
||||
let mut found = 0;
|
||||
for seed in 1..60 {
|
||||
let mut sim = Sim::new(seed);
|
||||
sim.damage = true;
|
||||
let mut out = Out::default();
|
||||
let mut ground = Ground::default();
|
||||
ground.answer((-50..50).flat_map(|x| (-50..400).map(move |z| (x, z, 70))).collect(), 0);
|
||||
let sam = sim.id();
|
||||
sim.sams.push(Sam::new(sam, SamKind::Patriot, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(0.0, 120.0, 300.0), DVec3::X, DVec3::new(900.0, 70.0, 0.0));
|
||||
let at = sim.drones[0].pos;
|
||||
let o = sim.shoot_down_by(0, sam, Some(5), Impact::missile(MissileKind::M77n6, at, 6.0), &mut out).unwrap();
|
||||
if o != Outcome::AirDetonation {
|
||||
continue;
|
||||
}
|
||||
found += 1;
|
||||
assert!(sim.drones.is_empty(), "the main mass is gone");
|
||||
assert_eq!((sim.kills, sim.hits, sim.crashes), (1, 0, 0));
|
||||
assert_eq!(sim.sams[0].kills, 1);
|
||||
let mut cmds = out.commands.len();
|
||||
for _ in 0..400 {
|
||||
sim.tick += 1;
|
||||
let mut o = Out::default();
|
||||
sim.step_drones(&mut ground, None, &mut o);
|
||||
sim.step_fx(&mut ground, &mut o);
|
||||
cmds += o.commands.len();
|
||||
assert!(o.sounds.iter().all(|s| !s.0.starts_with("airdef:blast")), "a second blast");
|
||||
}
|
||||
assert_eq!(cmds, 0, "no primed TNT for the land from a detonated warhead");
|
||||
assert_eq!(sim.kills, 1);
|
||||
}
|
||||
assert!(found >= 10, "{found} detonations in 59 seeds");
|
||||
}
|
||||
|
||||
// #97: a breakup throws pieces that have a life: they expire, and the number alive is bounded in a mass battle.
|
||||
#[test]
|
||||
fn pieces_expire_and_a_mass_battle_keeps_them_bounded() {
|
||||
let mut sim = Sim::new(3);
|
||||
let mut out = Out::default();
|
||||
let mut ground = Ground::default();
|
||||
for i in 0..150 {
|
||||
let sam = sim.id();
|
||||
sim.sams.push(Sam::new(sam, SamKind::Patriot, DVec3::new(f64::from(i) * 500.0, 70.0, 0.0), 0.0));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(f64::from(i) * 500.0, 400.0, 300.0), DVec3::X, DVec3::new(9e5, 70.0, 0.0));
|
||||
let at = sim.drones.last().unwrap().pos;
|
||||
let idx = sim.drones.len() - 1;
|
||||
let _ = sim.shoot_down_by(idx, sam, None, Impact::missile(MissileKind::M77n6, at, 6.0), &mut out);
|
||||
}
|
||||
let pieces = |s: &Sim| s.fx.iter().filter(|(_, f)| matches!(f, Fx::Piece { .. })).count();
|
||||
let n = pieces(&sim);
|
||||
assert!(n > 0 && n <= PIECES_MAX, "{n} pieces");
|
||||
for _ in 0..PIECE_LIFE + 1 {
|
||||
sim.tick += 1;
|
||||
sim.step_fx(&mut ground, &mut Out::default());
|
||||
}
|
||||
assert_eq!(pieces(&sim), 0, "pieces expire");
|
||||
}
|
||||
|
||||
// #97: a breakup either keeps the warhead section (a wreck still falling, which may go off on landing by the
|
||||
// existing roll) or leaves nothing to fall.
|
||||
#[test]
|
||||
fn a_breakup_keeps_the_warhead_section_only_sometimes() {
|
||||
let (mut kept, mut gone) = (0, 0);
|
||||
for seed in 1..200 {
|
||||
let (o, drones, _) = kill(seed, true, |at| Impact::missile(MissileKind::M57e6, at, 5.0));
|
||||
if o == Outcome::Breakup {
|
||||
if drones == 1 {
|
||||
kept += 1;
|
||||
} else {
|
||||
gone += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(kept > 0 && gone > kept, "kept {kept} gone {gone}");
|
||||
}
|
||||
|
||||
// #97: a flight of a piece is a pure function of its age (so a replay moves it as the raid did).
|
||||
#[test]
|
||||
fn a_pieces_flight_is_the_same_stepped_or_computed() {
|
||||
let ps = pieces(5, Outcome::AirDetonation, DVec3::new(0.5, 0.0, 0.2));
|
||||
assert!(!ps.is_empty() && pieces(5, Outcome::DisabledFalling, DVec3::ZERO).is_empty());
|
||||
let (mut pos, mut vel) = (DVec3::new(1.0, 100.0, 2.0), ps[0].vel);
|
||||
for _ in 0..20 {
|
||||
fly(&mut pos, &mut vel, ps[0].drag);
|
||||
}
|
||||
assert!(pos.distance(piece_at(DVec3::new(1.0, 100.0, 2.0), &ps[0], 20)) < 1e-9);
|
||||
assert!(ps.iter().all(|p| p.life <= PIECE_LIFE));
|
||||
}
|
||||
}
|
||||
@@ -168,8 +168,9 @@ pub struct Track {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum EventKind {
|
||||
/// A drone shot down: by which system (its index then), with a missile or the guns.
|
||||
Kill { drone: u32, kind: DroneKind, sam: u32, sam_kind: SamKind, sam_index: usize, missile: Option<u32> },
|
||||
/// A drone shot down: by which system (its index then), with a missile or the guns, and how it ended
|
||||
/// (rolled once, live; a replay reads it and never rolls).
|
||||
Kill { drone: u32, kind: DroneKind, sam: u32, sam_kind: SamKind, sam_index: usize, missile: Option<u32>, outcome: Outcome },
|
||||
/// A drone's warhead went off where it aimed: at an object, a system, or the land.
|
||||
Hit { drone: u32, kind: DroneKind, power: u32, object: Option<usize>, sam: Option<(SamKind, usize)> },
|
||||
/// A system destroyed.
|
||||
@@ -331,8 +332,8 @@ pub struct ReplayFire {
|
||||
/// The look of an interception by the drone's warhead: (fireball radius, ticks it burns, loudness).
|
||||
/// A bare decoy pops; a big warhead lights the sky. The same in the live raid and its replay.
|
||||
pub fn kill_look(kind: DroneKind) -> (f32, u32, f32) {
|
||||
let w = kind.spec().warhead.min(8) as f32;
|
||||
(3.5 * (0.85 + 0.12 * w), (8 + (w as u32) / 2) * 9, 1.0 + 0.06 * w)
|
||||
let (size, life, gain, _) = outcome::look(kind, Outcome::DisabledFalling);
|
||||
(size, life, gain)
|
||||
}
|
||||
|
||||
/// A blast's look for an event: (fireball radius, ticks it burns). The live blasts use the same.
|
||||
@@ -340,8 +341,8 @@ pub fn blast_spec(kind: EventKind) -> (f32, u32) {
|
||||
const SIZE: [f32; 5] = [2.5, 4.5, 7.0, 10.0, 13.0];
|
||||
const LIFE: [u32; 5] = [11, 11, 18, 22, 26];
|
||||
match kind {
|
||||
EventKind::Kill { kind, .. } => {
|
||||
let (size, life, _) = kill_look(kind);
|
||||
EventKind::Kill { kind, outcome, .. } => {
|
||||
let (size, life, _, _) = outcome::look(kind, outcome);
|
||||
(size, life)
|
||||
}
|
||||
EventKind::Hit { power, .. } | EventKind::Crash { power, .. } => {
|
||||
@@ -581,6 +582,7 @@ impl Sim {
|
||||
|
||||
/// Draws the recording's drones and interceptors as they were at `t`, as ghosts: ids from `base`.
|
||||
pub fn draw_ghosts(&self, rec: &Recording, t: f64, base: u32, out: &mut Out) {
|
||||
let base_id = base;
|
||||
for (k, tr) in rec.tracks.iter().enumerate() {
|
||||
let Some(pos) = tr.at(rec.origin, t) else { continue };
|
||||
let dir = tr.dir(rec.origin, t);
|
||||
@@ -660,6 +662,31 @@ impl Sim {
|
||||
out.particles("minecraft:large_smoke", f.at + DVec3::Y, 0.8, DVec3::new(0.0, 0.1, 0.0), 0.03, 1 + (smoke * 2.0) as u32);
|
||||
}
|
||||
}
|
||||
// The pieces a breakup or an air detonation threw off, from the recorded outcome (never a new roll): the same
|
||||
// pieces the live raid made, moved by the same flight, a pure function of the time.
|
||||
for (k, e) in rec.events.iter().enumerate() {
|
||||
let EventKind::Kill { drone, outcome, .. } = e.kind else { continue };
|
||||
let age = t - e.at as f64;
|
||||
if outcome == Outcome::DisabledFalling || !(0.0..outcome::PIECE_LIFE as f64).contains(&age) {
|
||||
continue;
|
||||
}
|
||||
let base = rec
|
||||
.track(drone)
|
||||
.and_then(|tr| Some((tr.at(rec.origin, e.at as f64)? - tr.at(rec.origin, e.at as f64 - STEP as f64)?) / STEP as f64))
|
||||
.unwrap_or(DVec3::ZERO);
|
||||
let seed = (k as u64).wrapping_mul(0x2545_f491_4f6c_dd1d) ^ e.at as u64;
|
||||
for (n, p) in outcome::pieces(seed, outcome, base).iter().enumerate() {
|
||||
if age as u32 >= p.life {
|
||||
continue;
|
||||
}
|
||||
let at = outcome::piece_at(e.pos, p, age as u32);
|
||||
let id = base_id + 0x0060_0000 + (k as u32 * 16 + n as u32) * PARTS;
|
||||
out.model(id, "airdef:debris", at, outcome::piece_rot(p, age as u32), p.scale, false);
|
||||
if p.burns && (age as u32) % 3 == 0 {
|
||||
out.particles("minecraft:large_smoke", at, 0.1, DVec3::new(0.0, 0.03, 0.0), 0.01, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Blasts: with the shader effects on, the post pass and the HD lights draw them from
|
||||
// `replay_blasts` (the same as the live ones); the models are the fallback without them.
|
||||
if self.shader {
|
||||
@@ -793,4 +820,46 @@ mod tests {
|
||||
assert_eq!(r.world_tick(50.0), Some(1040 + 10));
|
||||
assert_eq!(r.world_tick(70.0), Some(1100 + 10));
|
||||
}
|
||||
|
||||
// #97: the kill's outcome is a recorded fact: a replay draws the pieces of that outcome and rolls nothing;
|
||||
// an event without one (an old recording) is the plain fall it always was.
|
||||
#[test]
|
||||
fn a_replay_shows_the_recorded_outcome() {
|
||||
let mut sim = Sim::new(5);
|
||||
sim.rec = Some(Recording::new(1, &sim));
|
||||
let sam = sim.id();
|
||||
sim.sams.push(Sam::new(sam, SamKind::Patriot, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(0.0, 120.0, 300.0), DVec3::X, DVec3::new(900.0, 70.0, 0.0));
|
||||
let at = sim.drones[0].pos;
|
||||
let live = sim.shoot_down_by(0, sam, None, Impact::missile(MissileKind::M77n6, at, 6.0), &mut Out::default()).unwrap();
|
||||
let rec = sim.rec.take().unwrap();
|
||||
let recorded = rec.events.iter().find_map(|e| if let EventKind::Kill { outcome, .. } = e.kind { Some(outcome) } else { None });
|
||||
assert_eq!(recorded, Some(live), "the live outcome is what was recorded");
|
||||
let pieces = |rec: &Recording, t: f64| {
|
||||
let mut out = Out::default();
|
||||
sim.draw_ghosts(rec, t, 0x5000_0000, &mut out);
|
||||
out.models.iter().filter(|m| m.name == "airdef:debris").count()
|
||||
};
|
||||
let at_tick = rec.events[0].at as f64;
|
||||
// The same frame twice is the same (a pure function of the time), and the pieces are the outcome's.
|
||||
let mut forced = Recording { events: rec.events.clone(), ..Recording::blank(200) };
|
||||
for (outcome, want) in [(Outcome::AirDetonation, true), (Outcome::Breakup, true), (Outcome::DisabledFalling, false)] {
|
||||
if let EventKind::Kill { outcome: o, .. } = &mut forced.events[0].kind {
|
||||
*o = outcome;
|
||||
}
|
||||
assert_eq!(pieces(&forced, at_tick + 5.0), pieces(&forced, at_tick + 5.0));
|
||||
assert_eq!(pieces(&forced, at_tick + 5.0) > 0, want, "{outcome:?}");
|
||||
assert_eq!(pieces(&forced, at_tick + f64::from(outcome::PIECE_LIFE) + 1.0), 0, "the pieces are gone in time");
|
||||
}
|
||||
// Its flash and sound are the outcome's too.
|
||||
let spec = |o| {
|
||||
let mut e = rec.events[0];
|
||||
if let EventKind::Kill { outcome, .. } = &mut e.kind {
|
||||
*outcome = o;
|
||||
}
|
||||
blast_spec(e.kind)
|
||||
};
|
||||
assert!(spec(Outcome::AirDetonation).0 > spec(Outcome::DisabledFalling).0);
|
||||
assert_eq!(spec(Outcome::default()).0, kill_look(DroneKind::Shahed).0, "an old recording looks as it did");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +473,7 @@ fn pending_exact_answer_does_not_let_the_fuse_kill_through_a_wall() {
|
||||
ground.world.answer(answers, sim.tick);
|
||||
}
|
||||
}
|
||||
(first, sim.kills, sim.drones[0].alive())
|
||||
(first, sim.kills, sim.drones.first().is_some_and(Drone::alive))
|
||||
};
|
||||
for seed in 1..=10 {
|
||||
// Just behind the wall, inside the fuse's reach of a missile held at its face.
|
||||
|
||||
@@ -82,6 +82,10 @@ python3 tools/airdef.py play # или: python3 tools/airdef.py play --world "
|
||||
|
||||
## 3. В игре
|
||||
|
||||
- Обновление из исходников: `git pull`, затем снова `all` (Windows: `py tools\airdef.py all`). Форк и упаковщик мода
|
||||
пересоберутся сами, если патчи изменились.
|
||||
- Windows: нужна видеокарта с Vulkan. Экспорт фильмов (`/airdef replay export`) требует `ffmpeg` в PATH или `HORIZON_FFMPEG`.
|
||||
- Шейдеры уровня шейдерпаков: `/airdef shader hd`. Для слабой видеокарты перед запуском: `$env:HORIZON_HD_SCALE="0.67"` (PowerShell).
|
||||
- Создай мир с читами (или включи их через «Открыть для сети»): мод выдаёт пульты и взрывы командами.
|
||||
- `/airdef give` — пульты, **N** — командный пункт (роли ПВО), **K** — монитор комплекса,
|
||||
`/airdef wave mix 20` — налёт. Подробнее — README.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 3de7a6875140a107e28563cc44489b55f5794517 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 12:37:45 +0300
|
||||
Subject: [PATCH 01/35] Mod API (AirDef fork): world models, client particles,
|
||||
Subject: [PATCH 01/36] Mod API (AirDef fork): world models, client particles,
|
||||
sounds, ground heights
|
||||
|
||||
render.set-models draws block models with an interpolated pose per id;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From a6d64e6415bf618539af464e521091e72b72d72f Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 12:39:45 +0300
|
||||
Subject: [PATCH 02/35] cargo-horizon-mod: report particles and sounds
|
||||
Subject: [PATCH 02/36] cargo-horizon-mod: report particles and sounds
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From ee79b3562feebe51959a01f1585a9e85bd53ccb5 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 13:33:10 +0300
|
||||
Subject: [PATCH 03/35] Mod API (AirDef fork): full-screen post pass for mods
|
||||
Subject: [PATCH 03/36] Mod API (AirDef fork): full-screen post pass for mods
|
||||
|
||||
render.set-post compiles a mod's WGSL after a prelude (camera matrices,
|
||||
time, 256 vec4 of params, the world's colour and depth) and runs it after
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 2b137dbbedd540daeebc7f5e387847aeb56a1355 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 22:09:30 +0300
|
||||
Subject: [PATCH 04/35] Mod models: draw far models as scaled impostors past
|
||||
Subject: [PATCH 04/36] Mod models: draw far models as scaled impostors past
|
||||
the far plane, cull at 4096
|
||||
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From c8ebca6e0af68630e65211844b34d25c5b985c03 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 22:31:00 +0300
|
||||
Subject: [PATCH 05/35] Mod cameras: render.set-views draws the world from
|
||||
Subject: [PATCH 05/36] Mod cameras: render.set-views draws the world from
|
||||
other points into pictures that HUD view shapes show (API level 9)
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 8d2261fc4f8072c32e454139cfea7a8c0cd9d664 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 23:08:21 +0300
|
||||
Subject: [PATCH 06/35] Mods: more fuel per tick and per event (AirDef plans
|
||||
Subject: [PATCH 06/36] Mods: more fuel per tick and per event (AirDef plans
|
||||
raids)
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 6c548de34def8e4a624d734243418090798bd16a Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Wed, 28 Oct 2026 23:25:29 +0300
|
||||
Subject: [PATCH 07/35] Mod cameras up to 1920x1080 (full-screen replays)
|
||||
Subject: [PATCH 07/36] Mod cameras up to 1920x1080 (full-screen replays)
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 9b9e93269d67401cc620567a884d5ce97f68d76e Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 11:15:11 +0300
|
||||
Subject: [PATCH 08/35] Mod cameras: distant terrain tiles, fog measured from
|
||||
Subject: [PATCH 08/36] Mod cameras: distant terrain tiles, fog measured from
|
||||
the camera, no impostors while one is shown
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 065d9fa02966238a5bd9ff460392a1a809db0b11 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 11:25:45 +0300
|
||||
Subject: [PATCH 09/35] Mods: game.world-id, so mods keep state per world (API
|
||||
Subject: [PATCH 09/36] Mods: game.world-id, so mods keep state per world (API
|
||||
level 9)
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 1bf28135fd9a31f837323dc3a8d81ed73343d816 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 12:01:08 +0300
|
||||
Subject: [PATCH 10/35] cargo-horizon-mod: trial runs behind feature full, so a
|
||||
Subject: [PATCH 10/36] cargo-horizon-mod: trial runs behind feature full, so a
|
||||
packing-only tool skips wasmtime
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0a56f5616df4699588cbcc529d4720661baa810f Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 13:18:43 +0300
|
||||
Subject: [PATCH 11/35] HD lighting: G-buffer pass, per-pixel mod point lights
|
||||
Subject: [PATCH 11/36] HD lighting: G-buffer pass, per-pixel mod point lights
|
||||
in HDR, bloom and tone curve; render.set-lights and render.set-lighting (API
|
||||
level 10)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 9ebf0031fe9ba6b7f02afb26e4fd3a1ba4ddb0d0 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 13:59:43 +0300
|
||||
Subject: [PATCH 12/35] HD lighting stage 2: sun and moon shadow cascades, the
|
||||
Subject: [PATCH 12/36] HD lighting stage 2: sun and moon shadow cascades, the
|
||||
world relit (sun by face angle and shadow, sky and block light through the
|
||||
lightmap), light shafts and halos, fog over it again, a light colour grade
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 7a5a38f68923aec62f10bfa0df50b436474ed612 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 16:19:53 +0300
|
||||
Subject: [PATCH 13/35] HD: bind groups cached until a resize or a new source,
|
||||
Subject: [PATCH 13/36] HD: bind groups cached until a resize or a new source,
|
||||
shadow passes draw only the entities that cast shadows
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 8020811e57d4b5a9ea1cd72d30ce859dc5095d35 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 16:25:44 +0300
|
||||
Subject: [PATCH 14/35] HD: lights culled per 16x16 tile (surface and halo
|
||||
Subject: [PATCH 14/36] HD: lights culled per 16x16 tile (surface and halo
|
||||
lists built on the CPU), a naga test for the lighting shaders
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 72d3fddfea329e578162656151350f0aa2efd323 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 16:43:36 +0300
|
||||
Subject: [PATCH 15/35] HD: GPU time per pass in the F3 timing list,
|
||||
Subject: [PATCH 15/36] HD: GPU time per pass in the F3 timing list,
|
||||
half-resolution GTAO with a depth-aware blur
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 1fd83a821bf270879d8ece5aa583f200ed920d89 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 17:02:02 +0300
|
||||
Subject: [PATCH 16/35] HD: shadows draw only sun-facing quads and skip buried
|
||||
Subject: [PATCH 16/36] HD: shadows draw only sun-facing quads and skip buried
|
||||
sections, the far cascade every second frame; TAA (Halton jitter,
|
||||
reprojection by depth, YCoCg variance clipping) before bloom
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 1502d359d599228fe0f44ce6b99a3fded2ac5ea0 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 17:02:02 +0300
|
||||
Subject: [PATCH 17/35] Mods: model handles (render.model-id, model-generation,
|
||||
Subject: [PATCH 17/36] Mods: model handles (render.model-id, model-generation,
|
||||
set-models-by-id; API level 11) so mods send no model names each tick;
|
||||
clear-post and set-lighting documented
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0f9d99b8ad3e4b72e621d84c2396cf1d3d2b7a33 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 17:19:57 +0300
|
||||
Subject: [PATCH 18/35] HD: temporal upscaling (HORIZON_HD_SCALE: world,
|
||||
Subject: [PATCH 18/36] HD: temporal upscaling (HORIZON_HD_SCALE: world,
|
||||
G-buffer and lighting at a lower size, rebuilt to the window in the TAA
|
||||
pass); fix flickering shadows near the player (the near cascade lost its
|
||||
sections on frames the far one was held, the held far matrix ignored the
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 38250c4392e27d5700842ca6ee47291dd1831b72 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 17:47:52 +0300
|
||||
Subject: [PATCH 19/35] HD water: its own pass (colour, normal, depth), the
|
||||
Subject: [PATCH 19/36] HD water: its own pass (colour, normal, depth), the
|
||||
floor under it lit, a composite with world-space waves, refraction with depth
|
||||
absorption in the biome colour, screen-space reflections, Fresnel and a
|
||||
shadowed sun glint (HORIZON_HD_WATER=0 to switch off)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From dbc6f8a6e9c2eeabe1de15f1794013c90be7faa5 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 17:56:04 +0300
|
||||
Subject: [PATCH 20/35] HD water: no vanilla texture on the surface (the biome
|
||||
Subject: [PATCH 20/36] HD water: no vanilla texture on the surface (the biome
|
||||
colour only), a darker, deeper colour
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 13e74537dd6e63482e3613e0e416de1158944dfe Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 18:38:19 +0300
|
||||
Subject: [PATCH 21/35] HD sky and light: a physical atmosphere (Rayleigh, Mie,
|
||||
Subject: [PATCH 21/36] HD sky and light: a physical atmosphere (Rayleigh, Mie,
|
||||
ozone; constants and transmittance after Photon, MIT) for the sky, haze, fog
|
||||
and water reflections; warmer sunlight from the atmosphere's transmittance, a
|
||||
gentle sky-coloured ambient, soft PCSS-lite shadows near the player, a haze
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 6277e051a89c2537570982f6ef275887193c05cf Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 19:02:16 +0300
|
||||
Subject: [PATCH 22/35] HD water: a darker blue, a little clearer, ripples a
|
||||
Subject: [PATCH 22/36] HD water: a darker blue, a little clearer, ripples a
|
||||
little higher
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 982265d21bb9d74ec0040db03feb5a55762286ad Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 21:41:48 +0300
|
||||
Subject: [PATCH 23/35] HD: Photon-style sunsets (Rec. 2020 atmosphere, sun
|
||||
Subject: [PATCH 23/36] HD: Photon-style sunsets (Rec. 2020 atmosphere, sun
|
||||
tint, blue hour; MIT), volumetric clouds with ground shadows instead of
|
||||
vanilla's in HD, volumetric fog with sun shafts and morning mist
|
||||
(HORIZON_HD_CLOUDS=0, HORIZON_HD_VOLFOG=0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 24971b3c67d8c87673eb2e0d204cedf8a2f46d1c Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 21:43:22 +0300
|
||||
Subject: [PATCH 24/35] Mods: world queries for simulations (render.query-rays,
|
||||
Subject: [PATCH 24/36] Mods: world queries for simulations (render.query-rays,
|
||||
query-sections, world-changes; API level 12): block-exact rays and section
|
||||
occupancy by collision, sight or sound, answered next tick within budgets,
|
||||
and a log of changed sections
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From fdec4960983bdff82f3793460f9a5234f0cd3f49 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 22:56:15 +0300
|
||||
Subject: [PATCH 25/35] HD fixes: rain level from the world not from rain
|
||||
Subject: [PATCH 25/36] HD fixes: rain level from the world not from rain
|
||||
geometry (#41), TAA history on the jittered grid (#38), vanilla cloud tint
|
||||
without a depth heuristic (#35), air fog once over water (#37), translucent
|
||||
things in front of HD water (#36), cheaper sunrise fan (#39), halos in thick
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 21391afb26f49505d6cdaf454a6355cd4e747503 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 23:19:53 +0300
|
||||
Subject: [PATCH 26/35] HD split into modules (gfx/hd/: one Rust file and one
|
||||
Subject: [PATCH 26/36] HD split into modules (gfx/hd/: one Rust file and one
|
||||
WGSL file per pass, a shared prelude), contracts for colour, depth, alpha,
|
||||
time and coordinates written down, tests that the frame layout and bindings
|
||||
match between Rust and WGSL (#45)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 8d4cadbf8534309ac847d34e229f6d764770475d Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Thu, 29 Oct 2026 23:22:19 +0300
|
||||
Subject: [PATCH 27/35] HD clouds: noise scales that divide the camera's
|
||||
Subject: [PATCH 27/36] HD clouds: noise scales that divide the camera's
|
||||
65536-block wrap, so the clouds and their shadows no longer jump at x or z =
|
||||
0
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0fb59c782abf269fe555faa3241b31acf41e26d7 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 03:17:11 +0300
|
||||
Subject: [PATCH 28/35] HD: volumetric smoke and missile trails with clear
|
||||
Subject: [PATCH 28/36] HD: volumetric smoke and missile trails with clear
|
||||
tunnels through fog and cloud (render.set-smoke, API level 14; #54); sun
|
||||
speculars by material, wet surfaces and puddles in rain, wind in foliage
|
||||
(HORIZON_HD_SPECULAR=0, HORIZON_HD_WIND=0, HORIZON_HD_SMOKE=0); HD shaders
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From e4bc29da45d0d38244c6eb2ba3ffb9ab853540c0 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 03:26:09 +0300
|
||||
Subject: [PATCH 29/35] HD clouds composited by depth so terrain and vehicles
|
||||
Subject: [PATCH 29/36] HD clouds composited by depth so terrain and vehicles
|
||||
inside or behind the layer are hidden and those in front stay in front (#67);
|
||||
world-anchored noise everywhere (cloud detail by height above the layer, fog,
|
||||
smoke and puddle scales dividing the wrap) (#68); the replay's time is visual
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 20f699796afb12b600236a4e8859cd97430f86f0 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 03:44:45 +0300
|
||||
Subject: [PATCH 30/35] HD smoke: young trails drawn at least as wide as a grid
|
||||
Subject: [PATCH 30/36] HD smoke: young trails drawn at least as wide as a grid
|
||||
cell (density scaled to keep the mass), gentler bulges, so a trail is a
|
||||
smooth ribbon and not a chain of puffs
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 35ffbaa26dd91855c8b93446646ba8c58448d3d0 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 03:59:41 +0300
|
||||
Subject: [PATCH 31/35] Mods: render.set-main-view (API level 15) renders the
|
||||
Subject: [PATCH 31/36] Mods: render.set-main-view (API level 15) renders the
|
||||
screen's world from a mod camera with the full pipeline, so replays get HD
|
||||
and the post effects; small mod views get the post pass with their own camera
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 27e24527550942695164dd3a769a42a659e797ca Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 09:28:05 +0300
|
||||
Subject: [PATCH 32/35] Spot lights for mods (render.set-spot-lights, API level
|
||||
Subject: [PATCH 32/36] Spot lights for mods (render.set-spot-lights, API level
|
||||
16): surfaces lit in the cone, a volumetric beam stopped by depth (#60); film
|
||||
capture (render.capture-*, set-film-quality, API level 17): fixed-step clock,
|
||||
frames piped to ffmpeg or PNGs, offline audio, no chat in the frames (#58);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 615f5c3fa7c19a9895f8972a88333c6f250ad78a Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 14:30:39 +0300
|
||||
Subject: [PATCH 33/35] HD clouds and fog polish: cloud panorama, cirrus,
|
||||
Subject: [PATCH 33/36] HD clouds and fog polish: cloud panorama, cirrus,
|
||||
terrain-aware fog, far smoke cascade; replay world log and film clock;
|
||||
material overlays by sprite name
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0254984fdcce53a4a0f2bff15f9be3b78c93842e Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 15:01:09 +0300
|
||||
Subject: [PATCH 34/35] HD: coloured sun through glass and leaves, rain ripples
|
||||
Subject: [PATCH 34/36] HD: coloured sun through glass and leaves, rain ripples
|
||||
on water, film motion blur and depth of field
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 9645d3f1f47d8bb358d5630288bdd801bd874911 Mon Sep 17 00:00:00 2001
|
||||
From: chexit <chexit@duck.com>
|
||||
Date: Fri, 30 Oct 2026 15:19:32 +0300
|
||||
Subject: [PATCH 35/35] Film export: every frame in flight reaches the writer,
|
||||
Subject: [PATCH 35/36] Film export: every frame in flight reaches the writer,
|
||||
listener follows the main view, cloud wind on film frames, set-smoke reports
|
||||
real activity
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+11
-5
@@ -71,7 +71,8 @@ def fork():
|
||||
stamp = fork_stamp(commit, patches)
|
||||
stamp_file = FORK / ".git" / "airdef-stamp"
|
||||
if not (FORK / ".git").exists():
|
||||
run(["git", "clone", "--filter=blob:none", UPSTREAM, FORK])
|
||||
# Без CRLF на Windows: патчи накладываются на файлы как в апстриме.
|
||||
run(["git", "clone", "-c", "core.autocrlf=false", "--filter=blob:none", UPSTREAM, FORK])
|
||||
branch = subprocess.run(["git", "-C", FORK, "branch", "--show-current"], capture_output=True, text=True).stdout.strip()
|
||||
if branch == "airdef" and stamp_file.exists() and stamp_file.read_text().strip() == stamp:
|
||||
print("horizon/: ветка airdef на нужных коммите и патчах")
|
||||
@@ -110,11 +111,16 @@ def built_game() -> Path:
|
||||
|
||||
def mod():
|
||||
tool = shutil.which("cargo-horizon-mod") or Path.home() / ".cargo" / "bin" / ("cargo-horizon-mod" + EXE)
|
||||
if not Path(tool).exists():
|
||||
if not (FORK / "Cargo.toml").exists():
|
||||
fork()
|
||||
if not (FORK / "Cargo.toml").exists():
|
||||
fork()
|
||||
# Упаковщик должен быть от этого форка: старый не знает новых уровней API.
|
||||
stamp_file = FORK / ".git" / "airdef-packer-stamp"
|
||||
commit = (ROOT / "HORIZON_COMMIT").read_text().strip()
|
||||
stamp = fork_stamp(commit, sorted((ROOT / "horizon-patches").glob("*.patch")))
|
||||
if not Path(tool).exists() or not stamp_file.exists() or stamp_file.read_text().strip() != stamp:
|
||||
# Without trial runs (wasmtime): building a mod needs only packing, a fraction of the compile.
|
||||
run([cargo(), "install", "--locked", "--no-default-features", "--path", FORK / "crates" / "cargo-horizon-mod"])
|
||||
run([cargo(), "install", "--locked", "--force", "--no-default-features", "--path", FORK / "crates" / "cargo-horizon-mod"])
|
||||
stamp_file.write_text(stamp + "\n")
|
||||
run([cargo(), "horizon-mod", "build"], cwd=ROOT / "airdef-mod")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user