Skip to main content
Verticopolis engine

verticopolis_engine/rules/
halos.rs

1//! The Modern venues' cross-floor halos as one table: which venue reaches
2//! which rooms, over how many floors and how hard. The hourly satisfaction
3//! step applies them (`Simulation::satisfaction_step`, which a rule test
4//! holds to this table), the catalog publishes them for the placement range
5//! rings, and the inspector names the amenity helping a room. Classic has none.
6
7use super::amenities::daycare_family_share;
8use super::{
9    AMENITY_CAP_LIFT_MAX, AQUATIC_HALO_FLOORS, AQUATIC_HALO_MAX, DAYCARE_HALO_FLOORS,
10    DAYCARE_HALO_MAX, FITNESS_HALO_FLOORS, FITNESS_HALO_MAX, NIGHTCLUB_NOISE_FLOORS,
11    NIGHTCLUB_NOISE_MAX, PARTY_HALL_HALO_FLOORS, PARTY_HALL_HALO_MAX, SPA_SERENITY_FLOORS,
12    SPA_SERENITY_MAX,
13};
14use crate::clock::GameMode;
15use crate::facilities::Kind;
16
17/// Whether a halo raises the rooms it reaches or drains them.
18#[derive(Clone, Copy, Debug, PartialEq, Eq)]
19pub enum HaloEffect {
20    /// An amenity: an hourly bonus, and a lift to the ceiling a capped room
21    /// is held to.
22    Lift,
23    /// A nuisance: an hourly drain.
24    Drain,
25}
26
27impl HaloEffect {
28    pub fn as_str(self) -> &'static str {
29        match self {
30            HaloEffect::Lift => "lift",
31            HaloEffect::Drain => "drain",
32        }
33    }
34}
35
36/// One venue's halo.
37#[derive(Clone, Copy, Debug)]
38pub struct Halo {
39    /// The venue that casts it.
40    pub source: Kind,
41    pub effect: HaloEffect,
42    /// How far it reaches: a room `d` floors from the venue's nearest story
43    /// feels `max * (1 - d / floors)`, and none at `floors` or beyond.
44    pub floors: f64,
45    /// The hourly bonus or drain on the venue's own floor.
46    pub max: f64,
47    /// Felt only while the venue is open (the nightclub).
48    pub open_hours_only: bool,
49    /// Scaled by the household's size, largest for the biggest family (the
50    /// daycare).
51    pub family_scaled: bool,
52    felt_by: fn(Kind) -> bool,
53}
54
55impl Halo {
56    /// Whether a room of `kind` feels this halo.
57    pub fn felt_by(&self, kind: Kind) -> bool {
58        (self.felt_by)(kind)
59    }
60
61    /// Whether the halo is felt in `hour`: always, or only while the venue
62    /// is open for one that follows its open hours.
63    pub fn is_felt_at(&self, hour: i64) -> bool {
64        !self.open_hours_only || self.source.is_open_at(hour)
65    }
66
67    /// How many floors a room on `floor` is from a venue whose lowest story
68    /// is `venue_floor`: from its nearer story, so 0 on any story it fills.
69    pub fn distance(&self, venue_floor: i64, floor: i64) -> i64 {
70        let top = venue_floor + self.source.floors() - 1;
71        (venue_floor - floor).max(floor - top).max(0)
72    }
73
74    /// How far a lift raises a capped room's ceiling at full strength, or
75    /// None for a drain.
76    pub fn cap_lift_max(&self) -> Option<f64> {
77        (self.effect == HaloEffect::Lift).then_some(AMENITY_CAP_LIFT_MAX)
78    }
79}
80
81fn is_home(kind: Kind) -> bool {
82    kind == Kind::Condo || kind == Kind::RentalApartment
83}
84
85fn is_home_or_hotel(kind: Kind) -> bool {
86    is_home(kind) || kind.is_hotel()
87}
88
89/// A `static`, so every lookup hands out the same entries. The hourly step
90/// applies the rows in this order, each clamped to 0 and 1 as it lands.
91static MODERN_HALOS: [Halo; 6] = [
92    Halo {
93        source: Kind::FitnessClub,
94        effect: HaloEffect::Lift,
95        floors: FITNESS_HALO_FLOORS,
96        max: FITNESS_HALO_MAX,
97        open_hours_only: false,
98        family_scaled: false,
99        felt_by: is_home,
100    },
101    Halo {
102        source: Kind::Nightclub,
103        effect: HaloEffect::Drain,
104        floors: NIGHTCLUB_NOISE_FLOORS,
105        max: NIGHTCLUB_NOISE_MAX,
106        open_hours_only: true,
107        family_scaled: false,
108        felt_by: is_home_or_hotel,
109    },
110    Halo {
111        source: Kind::Spa,
112        effect: HaloEffect::Lift,
113        floors: SPA_SERENITY_FLOORS,
114        max: SPA_SERENITY_MAX,
115        open_hours_only: false,
116        family_scaled: false,
117        felt_by: Kind::is_hotel,
118    },
119    Halo {
120        source: Kind::Daycare,
121        effect: HaloEffect::Lift,
122        floors: DAYCARE_HALO_FLOORS,
123        max: DAYCARE_HALO_MAX,
124        open_hours_only: false,
125        family_scaled: true,
126        felt_by: is_home,
127    },
128    Halo {
129        source: Kind::AquaticCenter,
130        effect: HaloEffect::Lift,
131        floors: AQUATIC_HALO_FLOORS,
132        max: AQUATIC_HALO_MAX,
133        open_hours_only: false,
134        family_scaled: false,
135        felt_by: is_home_or_hotel,
136    },
137    Halo {
138        source: Kind::PartyHall,
139        effect: HaloEffect::Lift,
140        floors: PARTY_HALL_HALO_FLOORS,
141        max: PARTY_HALL_HALO_MAX,
142        open_hours_only: false,
143        family_scaled: false,
144        felt_by: is_home_or_hotel,
145    },
146];
147
148impl GameMode {
149    /// Every venue halo in this mode: the six Modern ones, none in Classic.
150    pub fn halos(self) -> &'static [Halo] {
151        match self {
152            GameMode::Modern => &MODERN_HALOS,
153            GameMode::Classic => &[],
154        }
155    }
156
157    /// The halo a venue of `kind` casts in this mode, if any.
158    pub fn halo_of(self, kind: Kind) -> Option<&'static Halo> {
159        self.halos().iter().find(|h| h.source == kind)
160    }
161
162    /// The hourly bonus or drain `halo` gives a room `d` floors from its
163    /// venue whose household is `family_size` (read only by a family-scaled
164    /// halo): the same values the hourly step applies, faded over the
165    /// halo's own `floors` from its own `max`.
166    pub fn halo_strength(self, halo: &Halo, d: f64, family_size: f64) -> f64 {
167        let strength = self.halo(d, halo.floors, halo.max);
168        if halo.family_scaled {
169            strength * daycare_family_share(family_size)
170        } else {
171            strength
172        }
173    }
174}