delvewright_dsl/stealth.rs
1//! Stealth zones: the shadow regions a stealth section is judged by.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::AnchorId;
7
8/// A stealth "shadow" region (DSL v0.6, spec-0014): an axis-aligned box centred
9/// on `anchor`, extending `extent` blocks along each axis (so the box spans
10/// `anchor ± extent`). Presented in-world via dark cells but judged purely by
11/// region membership, so the check is deterministic and provable.
12#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
13#[serde(deny_unknown_fields)]
14pub struct StealthZone {
15 /// The prefab anchor at the centre of the zone box.
16 pub anchor: AnchorId,
17 /// Half-extents `[x, y, z]` in blocks from the anchor (each component ≥ 0);
18 /// the zone AABB is `[anchor - extent, anchor + extent]`.
19 pub extent: [u32; 3],
20}
21
22/// **Where something reaches, as one of two spellings** (spec-0102 §3.4): an
23/// anchor-centred box, or a whole place.
24///
25/// The pair `set-atmosphere` repaints and a pulse is heard in. Declared once
26/// and flattened into each carrier, so the JSON keeps the two flat keys every
27/// carrier writes in the same words, and a carrier that names neither or both
28/// is refused by the one rule that reads it (`DW0929`).
29#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
30pub struct PlaceRef {
31 /// The volume, as an anchor-centred box (`anchor ± extent`) — resolved
32 /// through the one `Plan::zone_box` every box verb takes.
33 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub region: Option<StealthZone>,
35 /// A whole place: an `area/…` id, or a site-plan box's `node/…`, whose
36 /// bounds the compiler reads from the placement.
37 #[serde(default, skip_serializing_if = "Option::is_none")]
38 pub place: Option<String>,
39}
40
41impl PlaceRef {
42 /// `Some(words)` when the reference names neither or both spellings — the
43 /// shape `DW0929` refuses wherever a `PlaceRef` is read.
44 pub fn ambiguity(&self) -> Option<&'static str> {
45 match (&self.region, &self.place) {
46 (Some(_), Some(_)) => Some("names both a `region` and a `place`"),
47 (None, None) => Some("names neither a `region` nor a `place`"),
48 _ => None,
49 }
50 }
51}