Skip to main content
Verticopolis engine

verticopolis_engine/facilities/
predicates.rs

1// What each kind does in the simulation: transport capacity, staff
2// access, opening hours, demand and households. Internal to the engine; a
3// host reads these facts from the catalog.
4
5use super::*;
6
7/// Whether shop and restaurant customers come in person from outside the
8/// tower (`crowd::walk_ins`). Off for now (owner, 2026-11-14): at full
9/// demand they jammed the elevators of towers built before 3.12.0 and
10/// tenants moved out over congestion. While it is off, those venues count
11/// their customers from demand as 3.11 did, with nobody shown arriving.
12pub const WALK_INS_ON: bool = false;
13
14/// A per-thread stand-in for [`WALK_INS_ON`] in tests.
15#[cfg(test)]
16fn walk_ins_switch() -> &'static std::thread::LocalKey<std::cell::Cell<bool>> {
17    thread_local! {
18        static ON: std::cell::Cell<bool> = const { std::cell::Cell::new(WALK_INS_ON) };
19    }
20    &ON
21}
22
23/// Turns walk-ins on or off for the calling test's thread, so their own
24/// tests keep running while [`WALK_INS_ON`] is off.
25#[cfg(test)]
26pub fn set_walk_ins_for_test(on: bool) {
27    walk_ins_switch().with(|w| w.set(on));
28}
29
30#[cfg(test)]
31fn walk_ins_on() -> bool {
32    walk_ins_switch().with(std::cell::Cell::get)
33}
34
35#[cfg(not(test))]
36fn walk_ins_on() -> bool {
37    WALK_INS_ON
38}
39
40/// How many hours before a venue opens its crew is called in
41/// (`Kind::staffed_at`).
42const CREW_CALL_AHEAD: i64 = 4;
43
44#[doc(hidden)]
45impl Kind {
46    #[doc(hidden)]
47    /// `transportCarCapacity`.
48    pub fn car_capacity(self) -> f64 {
49        match self {
50            Kind::ElevatorStandard => 21.0,
51            Kind::ElevatorService => 17.0,
52            Kind::ElevatorExpress => 42.0,
53            Kind::Escalator => 30.0,
54            Kind::Stairs => 8.0,
55            _ => 0.0,
56        }
57    }
58
59    #[doc(hidden)]
60    /// The capacity byte the `.TDT` exporter writes in an elevator header. The
61    /// byte is unreliable (a real save's service shaft carried 21), so the
62    /// service value the exporter always wrote stays: the referee pins it.
63    pub fn tdt_header_capacity(self) -> i64 {
64        match self {
65            Kind::ElevatorService => 10,
66            other => other.car_capacity() as i64,
67        }
68    }
69
70    #[doc(hidden)]
71    /// `isStaffOnlyTransport`.
72    pub fn is_staff_only_transport(self) -> bool {
73        self.facility().staff_only
74    }
75
76    #[doc(hidden)]
77    /// `isStaffTransportKind`: staff-only elevators plus stairs.
78    pub fn is_staff_transport(self) -> bool {
79        self.is_staff_only_transport() || self == Kind::Stairs
80    }
81
82    #[doc(hidden)]
83    pub fn is_walkway(self) -> bool {
84        matches!(self, Kind::Stairs | Kind::Escalator)
85    }
86
87    #[doc(hidden)]
88    /// `WALKWAY_WILLINGNESS`.
89    pub fn walkway_willingness(self) -> Option<i64> {
90        match self {
91            Kind::Stairs => Some(4),
92            Kind::Escalator => Some(7),
93            _ => None,
94        }
95    }
96
97    #[doc(hidden)]
98    /// `attendanceCap`.
99    pub fn attendance_cap(self) -> Option<i64> {
100        self.facility().attendance
101    }
102
103    #[doc(hidden)]
104    /// A kind a meal trip can be sent to (every `MealWindow::venues` list),
105    /// so the customers inside it are people who walked or rode in.
106    pub fn is_meal_venue(self) -> bool {
107        matches!(
108            self,
109            Kind::FastFood | Kind::Restaurant | Kind::FoodHall | Kind::Cinema
110        )
111    }
112
113    #[doc(hidden)]
114    /// A shop or restaurant whose customers come in from outside the tower
115    /// at the rate its demand sets (`crowd::walk_ins`): every kind with a
116    /// spend per customer but the daycare, whose children are not shoppers.
117    /// Each walk-in comes through the lobby or the Metro and rides the cars
118    /// like anyone else, and the day's patronage counts the ones who got
119    /// there. None does while [`WALK_INS_ON`] is off.
120    pub fn takes_walk_ins(self) -> bool {
121        walk_ins_on()
122            && matches!(
123                self,
124                Kind::FastFood
125                    | Kind::Restaurant
126                    | Kind::FoodHall
127                    | Kind::Amusements
128                    | Kind::BoutiqueBay
129                    | Kind::Nightclub
130                    | Kind::Spa
131                    | Kind::SkyBar
132                    | Kind::Shop
133            )
134    }
135
136    #[doc(hidden)]
137    /// A kind whose head count mirrors the visitors inside it (an
138    /// attendance venue, a [`Kind::is_meal_venue`] or a kind that
139    /// [`Kind::takes_walk_ins`]). The count lives
140    /// in the unsaved `customers_in`, which a load counts again from the
141    /// visitors the save's crowd carries (`crowd::save`) and an undo starts
142    /// at 0, and the dispatch estimate skips it, since those visitors ride
143    /// as real people.
144    pub fn counts_visitors(self) -> bool {
145        self.attendance_cap().is_some() || self.is_meal_venue() || self.takes_walk_ins()
146    }
147
148    #[doc(hidden)]
149    /// The staff a room of this kind keeps at work while it is open, who
150    /// come in and go home as people in a Modern tower (`crowd::commuters`);
151    /// 0 for a kind with no staff of its own. The original draws no venue
152    /// staff, so these are our own.
153    pub fn staff_size(self) -> i64 {
154        match self {
155            Kind::Shop | Kind::BoutiqueBay => 2,
156            Kind::FastFood | Kind::Amusements | Kind::Spa | Kind::SkyBar => 3,
157            Kind::Restaurant | Kind::Nightclub | Kind::Daycare => 4,
158            Kind::Cinema | Kind::PartyHall => 4,
159            Kind::FoodHall | Kind::AquaticCenter => 6,
160            _ => 0,
161        }
162    }
163
164    #[doc(hidden)]
165    /// Whether this kind keeps staff of its own ([`Kind::staff_size`]).
166    pub fn has_staff(self) -> bool {
167        self.staff_size() > 0
168    }
169
170    #[doc(hidden)]
171    /// Whether a venue's staff should be at work at `hour`: while it is
172    /// open, and from four hours before it opens (`CREW_CALL_AHEAD`), so a
173    /// shop that opens at 10 has its crew ride in at 6, before the office
174    /// rush. A break of four hours or less, such as a restaurant's between
175    /// lunch and dinner, keeps them in.
176    pub fn staffed_at(self, hour: i64) -> bool {
177        self.has_staff()
178            && (0..=CREW_CALL_AHEAD).any(|d| self.is_open_at((hour + d).rem_euclid(24)))
179    }
180
181    #[doc(hidden)]
182    /// Whether a room of this kind in a `mode` tower opens only once its
183    /// staff have come in (`crowd::commuters`): a venue with staff, in a
184    /// tower whose staff commute in person.
185    pub fn waits_for_staff(self, mode: crate::clock::GameMode) -> bool {
186        self.has_staff() && mode.venue_staff_commute_in_person()
187    }
188
189    #[doc(hidden)]
190    /// A kind whose workers come in and go home as people in a `mode` tower
191    /// (`crowd::commuters`): its head count is the workers who got there,
192    /// and the dispatch estimate skips it, since they ride the cars
193    /// themselves. Offices in Modern today.
194    pub fn commutes_in_person(self, mode: crate::clock::GameMode) -> bool {
195        self == Kind::Office && mode.office_workers_commute_in_person()
196    }
197
198    #[doc(hidden)]
199    /// A home whose residents leave for the day and come home as people in a
200    /// `mode` tower (`crowd::commuters`): a condo, apartment or studio. Its
201    /// head count is the residents at home, and the dispatch estimate skips
202    /// it, since they ride the cars themselves. Modern homes today.
203    pub fn lives_in_person(self, mode: crate::clock::GameMode) -> bool {
204        (self == Kind::Condo || self.is_rental()) && mode.residents_commute_in_person()
205    }
206
207    #[doc(hidden)]
208    /// A kind whose head count is the people who really got there in a
209    /// `mode` tower: an office whose workers commute
210    /// ([`Kind::commutes_in_person`]) or a home whose residents do
211    /// ([`Kind::lives_in_person`]). The hourly head count and the dispatch
212    /// estimate leave it alone.
213    pub fn arrives_in_person(self, mode: crate::clock::GameMode) -> bool {
214        self.commutes_in_person(mode) || self.lives_in_person(mode)
215    }
216
217    #[doc(hidden)]
218    /// How many residents of a home of this kind stay in on a weekday while
219    /// the rest are out (the hourly head count's daytime figure): one in a
220    /// condo or apartment, nobody in a studio.
221    pub fn residents_home_by_day(self) -> i64 {
222        i64::from(self.has_household())
223    }
224
225    #[doc(hidden)]
226    /// `isCommercialKind`.
227    pub fn is_commercial(self) -> bool {
228        matches!(
229            self,
230            Kind::FastFood
231                | Kind::Restaurant
232                | Kind::FoodHall
233                | Kind::Amusements
234                | Kind::BoutiqueBay
235                | Kind::Nightclub
236                | Kind::Spa
237                | Kind::SkyBar
238                | Kind::Daycare
239                | Kind::Shop
240                | Kind::Cinema
241        )
242    }
243
244    #[doc(hidden)]
245    /// A venue that makes no noise for the rooms beside it on its floor,
246    /// though it is commercial in every other sense: the spa is calm by
247    /// design, and the daycare keeps the hours its neighbors are at work.
248    pub fn is_quiet_venue(self) -> bool {
249        matches!(self, Kind::Spa | Kind::Daycare)
250    }
251
252    #[doc(hidden)]
253    /// A commercial venue that makes noise for the rooms beside it on its
254    /// floor: every commercial kind except the quiet ones. (An office is a
255    /// noise source too, for homes and hotel rooms; the noise check adds it.)
256    pub fn is_noisy_venue(self) -> bool {
257        self.is_commercial() && !self.is_quiet_venue()
258    }
259
260    #[doc(hidden)]
261    /// `hasBusinessHours`.
262    pub fn has_business_hours(self) -> bool {
263        self.is_commercial() || matches!(self, Kind::PartyHall | Kind::AquaticCenter)
264    }
265
266    #[doc(hidden)]
267    /// `isOpenAt`.
268    pub fn is_open_at(self, hour: i64) -> bool {
269        match self {
270            Kind::FastFood => (7..22).contains(&hour),
271            Kind::Restaurant => (11..14).contains(&hour) || (17..23).contains(&hour),
272            Kind::FoodHall => (10..22).contains(&hour),
273            Kind::Shop => (10..21).contains(&hour),
274            Kind::Amusements => (10..24).contains(&hour),
275            Kind::Nightclub => !(2..20).contains(&hour),
276            Kind::BoutiqueBay => (10..21).contains(&hour),
277            Kind::Spa => (9..21).contains(&hour),
278            Kind::SkyBar => (16..24).contains(&hour),
279            Kind::Daycare => (7..19).contains(&hour),
280            Kind::Cinema => (12..24).contains(&hour),
281            Kind::PartyHall => (17..24).contains(&hour),
282            Kind::AquaticCenter => (8..22).contains(&hour),
283            _ => true,
284        }
285    }
286
287    #[doc(hidden)]
288    /// `openHoursPerDay`.
289    pub fn open_hours_per_day(self) -> i64 {
290        let h = (0..24).filter(|&hr| self.is_open_at(hr)).count() as i64;
291        if h == 0 {
292            1
293        } else {
294            h
295        }
296    }
297
298    #[doc(hidden)]
299    /// `isUnmetDemandKind`.
300    pub fn is_unmet_demand_kind(self) -> bool {
301        matches!(self, Kind::Office | Kind::Condo | Kind::RentalApartment) || self.is_hotel()
302    }
303
304    #[doc(hidden)]
305    /// `isLeaseAmenityKind`.
306    pub fn is_lease_amenity(self) -> bool {
307        matches!(self, Kind::FitnessClub | Kind::Clinic)
308    }
309
310    #[doc(hidden)]
311    /// `hasHousehold`.
312    pub fn has_household(self) -> bool {
313        matches!(self, Kind::Condo | Kind::RentalApartment)
314    }
315
316    #[doc(hidden)]
317    pub fn is_staff_kind(self) -> bool {
318        matches!(
319            self,
320            Kind::Security | Kind::Medical | Kind::Housekeeping | Kind::Recycling
321        )
322    }
323
324    #[doc(hidden)]
325    /// The one-way ambient venue pool in `spawnFloors`.
326    pub fn is_ambient_venue(self) -> bool {
327        matches!(
328            self,
329            Kind::Shop
330                | Kind::Restaurant
331                | Kind::FastFood
332                | Kind::Amusements
333                | Kind::BoutiqueBay
334                | Kind::Nightclub
335                | Kind::Spa
336                | Kind::SkyBar
337                | Kind::Daycare
338        )
339    }
340}