Skip to main content
Verticopolis engine

verticopolis_engine/catalog/
noise.rs

1//! The catalog's view of the same-floor noise rule
2//! ([`crate::rules::NOISE_RULES`]), which the placement overlay draws in
3//! Modern: how far a room's noise carries along its floor, and how far it
4//! hears its noisy neighbors.
5
6use serde::Serialize;
7
8use crate::clock::GameMode;
9use crate::facilities::{Kind, FACILITIES};
10use crate::rules::NOISE_RULES;
11
12/// One reach of a room's same-floor noise.
13#[derive(Clone, Debug, PartialEq, Serialize)]
14#[serde(rename_all = "camelCase")]
15pub struct NoiseEntry {
16    /// `carries` (the room makes noise these kinds hear) or `hears` (the
17    /// room hears noise these kinds make).
18    pub role: &'static str,
19    /// How many tiles past each of the room's edges the noise counts, the
20    /// tile beside the room being tile 0. A lobby tile or a gap in the floor
21    /// stops it.
22    pub tiles: i64,
23    /// The other side's kinds, in catalog order.
24    pub kinds: Vec<&'static str>,
25}
26
27fn keys(matches: impl Fn(Kind) -> bool) -> Vec<&'static str> {
28    FACILITIES
29        .iter()
30        .filter(|f| matches(f.kind))
31        .map(|f| f.key)
32        .collect()
33}
34
35/// The reaches a room of `kind` shows while it is placed: the rule it hears
36/// first, then each rule it is a source for. Empty in a mode that keeps the
37/// rule unshown.
38pub(super) fn noise_entries(mode: GameMode, kind: Kind) -> Vec<NoiseEntry> {
39    if !mode.shows_noise_reach() {
40        return Vec::new();
41    }
42    let hears = NOISE_RULES
43        .iter()
44        .filter(|r| r.heard_by(kind))
45        .map(|r| NoiseEntry {
46            role: "hears",
47            tiles: r.tiles,
48            kinds: keys(|k| r.made_by(k)),
49        });
50    let carries = NOISE_RULES
51        .iter()
52        .filter(|r| r.made_by(kind))
53        .map(|r| NoiseEntry {
54            role: "carries",
55            tiles: r.tiles,
56            kinds: keys(|k| r.heard_by(k)),
57        });
58    hears.chain(carries).collect()
59}