//! **The scenario engine** (`docs/mockups/scenarios/`, `docs/notes/scenarios.md`). //! //! A scenario is a lens with a clock. It plays a timeline of **primitives** — //! a point, rings, a plume, a [`track`], a [`region`] state, an arc, a field, a //! counter — placed on a [`board`] (official areas, H3 cells, a network), each //! with a source and how sure it is. A nuclear exchange, a night of drones, a //! municipality's figures and a solar storm are scenario files; nothing here //! knows about any of them. //! //! So far: tracks, and region states on official areas — listed, derived from //! tracks, or read off a figure the areas carry — on the [`ladder`] of rungs //! from the stars to the street, and [`Play::at`]: the state of every //! primitive at a time. No `bevy`: atlas, the simulator and the client share it. pub mod board; pub mod ladder; pub mod region; pub mod time; pub mod track; use board::{AreaSet, Board, LonLat}; use ladder::Rung; use region::{RegionStateSpec, RegionStates, Visits}; use serde::Deserialize; use time::{Clock, Stamp, Time}; use track::{Track, TrackSpec}; /// How sure a primitive is; drawn, never hidden (v1-engine: "uncertainty is /// drawn"). #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Confidence { /// From a record of what happened. Documented, /// A model's output. #[default] Modelled, /// Made up for an exercise; marked so on every screen. Invented, } /// How real what a scenario shows is. Each wears its own frame on every screen /// and every rung (v4-whole). #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Mode { /// Official feeds only; the only mode that may look like a warning. Live, /// A published study or a past event, as written. Replay, /// What if, here, today? Striped, never sent to anyone as an alert. Exercise, /// Fiction, kept off Earth. Sandbox, } #[derive(Deserialize)] #[serde(deny_unknown_fields)] struct ClockSpec { start: Stamp, end: Stamp, /// Where the clock stands when the scenario opens; its start when absent. #[serde(default)] opens: Option, /// From here on the figures are a model's, not a measurement's: a /// forecast's first year. Drawn hatched on the clock. #[serde(default)] forecast: Option, } #[derive(Deserialize)] #[serde(deny_unknown_fields)] struct MetaSpec { name: String, mode: Mode, #[serde(default)] summary: String, /// The question a person brings to it ("Who lives here?"), which is what /// the shelf of lenses lists it under. #[serde(default)] question: Option, sources: Vec, #[serde(default)] confidence: Confidence, clock: ClockSpec, } #[derive(Deserialize)] #[serde(deny_unknown_fields)] struct FileSpec { scenario: MetaSpec, #[serde(default)] track: Vec, #[serde(default)] region_state: Vec, } /// What a scenario says about itself. #[derive(Clone, Debug)] pub struct Meta { pub name: String, pub mode: Mode, pub summary: String, pub question: Option, pub sources: Vec, pub confidence: Confidence, } /// Why a scenario could not be read or played. #[derive(Debug, thiserror::Error)] pub enum ScenarioError { #[error("scenario file: {0}")] Parse(#[from] toml::de::Error), #[error("scenario: {0}")] Invalid(String), #[error("scenario needs board {0}, which is not loaded")] MissingBoard(Board), } /// A scenario, read and on its clock. #[derive(Clone, Debug)] pub struct Scenario { pub meta: Meta, pub clock: Clock, /// Where the clock stands when it opens. pub opens: Time, /// Where a model takes over from measurement, when it does. pub forecast: Option