Skip to main content
Verticopolis engine

verticopolis_engine/
facilities.rs

1//! What can be built: [`Kind`] names every floor tile, room and transport,
2//! and the constants here give the lot's size.
3//!
4//! Prices, sizes, star requirements and build limits for a mode come from
5//! [`crate::catalog::catalog`], which a frontend reads instead of keeping
6//! tables of its own.
7
8use crate::lot::Lot;
9
10/// The lot's width in tiles. A tile column `x` runs from 0 to `LOT_WIDTH - 1`.
11pub const LOT_WIDTH: i64 = 375;
12/// The top floor of the standard lot ([`crate::lot`]), and the highest top
13/// floor any lot has: grids sized for every tower read it.
14pub const MAX_FLOOR: i64 = 100;
15/// The lowest basement floor. Floor 1 is the ground floor and floor 0 the
16/// first basement.
17pub const MIN_FLOOR: i64 = -9;
18/// Sky lobbies go every this many floors above the ground floor.
19pub const LOBBY_INTERVAL: i64 = 15;
20/// The most stories a lobby rises (#308). The original builds a lobby two
21/// stories high when Ctrl is held at its first placement, and three with
22/// Ctrl+Shift.
23pub const MAX_LOBBY_HEIGHT: i64 = 3;
24#[doc(hidden)]
25/// The wedding hall stands on floor `MAX_FLOOR` and rises four stories above it,
26/// the only facility that does. Grids that hold every story of every unit size
27/// to this.
28pub const WEDDING_HALL_TOP_FLOOR: i64 = MAX_FLOOR + 4;
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
31/// Everything a player can build.
32///
33/// [`Kind::as_str`] and [`Kind::parse`] convert to and from the names the
34/// save, the catalog and the JavaScript binding use (`lobby`, `hotelSingle`,
35/// `elevatorExpress`, ...).
36pub enum Kind {
37    /// Lobby. Floor 1 is all lobby; a lobby every fifteenth floor above it is a sky lobby.
38    Lobby,
39    /// Floor. An empty floor tile, which rooms stand on.
40    Floor,
41    /// Office.
42    Office,
43    /// Condominium.
44    Condo,
45    /// Single Room.
46    HotelSingle,
47    /// Double Room.
48    HotelDouble,
49    /// Suite.
50    HotelSuite,
51    /// Fast Food.
52    FastFood,
53    /// Restaurant.
54    Restaurant,
55    /// Food Hall. Modern only.
56    FoodHall,
57    /// Retail Shop.
58    Shop,
59    /// Cinema.
60    Cinema,
61    /// Party Hall.
62    PartyHall,
63    /// Amusements. Modern only.
64    Amusements,
65    /// Boutique Bay. Modern only.
66    BoutiqueBay,
67    /// Fitness Club. Modern only.
68    FitnessClub,
69    /// Clinic. Modern only.
70    Clinic,
71    /// Nightclub. Modern only.
72    Nightclub,
73    /// Spa. Modern only.
74    Spa,
75    /// Sky Bar. Modern only.
76    SkyBar,
77    /// Aquatic Center. Modern only.
78    AquaticCenter,
79    /// Daycare. Modern only.
80    Daycare,
81    /// Stairway. Spans two floors.
82    Stairs,
83    /// Escalator. Spans two floors.
84    Escalator,
85    /// Standard Elevator.
86    ElevatorStandard,
87    /// Service Elevator. Staff only.
88    ElevatorService,
89    /// Express Elevator. Stops at the lobbies and every basement floor it passes (a basement stop can be turned off), and spans the whole tower.
90    ElevatorExpress,
91    /// Parking Ramp.
92    ParkingRamp,
93    /// Parking Space.
94    Parking,
95    /// Security.
96    Security,
97    /// Medical Center.
98    Medical,
99    /// Housekeeping.
100    Housekeeping,
101    /// Recycling Center.
102    Recycling,
103    /// Metro Station.
104    Metro,
105    /// Wedding Hall. Stands on the top floor.
106    WeddingHall,
107    /// Studio. A rental home. Modern only.
108    RentalStudio,
109    /// Apartment. A rental home. Modern only.
110    RentalApartment,
111}
112
113#[doc(hidden)]
114#[derive(Clone, Copy, Debug, PartialEq, Eq)]
115pub enum Category {
116    Structure,
117    Transport,
118    Office,
119    Residential,
120    Hotel,
121    Food,
122    Retail,
123    Entertainment,
124    Service,
125    Special,
126}
127
128#[doc(hidden)]
129#[derive(Clone, Copy, Debug)]
130pub struct Facility {
131    pub kind: Kind,
132    pub key: &'static str,
133    pub category: Category,
134    pub name: &'static str,
135    pub width: i64,
136    pub floors: Option<i64>,
137    pub cost: f64,
138    pub min_star: i64,
139    pub population: i64,
140    pub attendance: Option<i64>,
141    pub modern_only: bool,
142    pub transport: bool,
143    pub staff_only: bool,
144    pub basement: bool,
145}
146
147impl Facility {
148    #[doc(hidden)]
149    /// Whether a tower of `mode` builds this kind at all, the star gate
150    /// aside: a Modern-only kind is built only where the mode's rule
151    /// (`GameMode::builds_modern_only_kinds`) allows it. The build gate
152    /// (`is_unlocked`) and the catalog's `available` both read it.
153    pub fn available_in(&self, mode: crate::clock::GameMode) -> bool {
154        !self.modern_only || mode.builds_modern_only_kinds()
155    }
156}
157
158mod predicates;
159#[cfg(test)]
160pub use predicates::set_walk_ins_for_test;
161pub use predicates::WALK_INS_ON;
162mod table;
163#[doc(hidden)]
164pub use table::FACILITIES;
165
166impl Kind {
167    #[doc(hidden)]
168    /// The catalog row. `FACILITIES` is laid out in `Kind` order, which the
169    /// `catalog_order` test pins, so the lookup is an index.
170    pub fn facility(self) -> &'static Facility {
171        &FACILITIES[self as usize]
172    }
173
174    /// The kind's name in saves and the catalog, such as `fastFood`.
175    pub fn as_str(self) -> &'static str {
176        self.facility().key
177    }
178
179    /// The kind with this name, as [`as_str`](Kind::as_str) writes it.
180    ///
181    /// ```
182    /// use verticopolis_engine::facilities::Kind;
183    ///
184    /// assert_eq!(Kind::parse("hotelSuite"), Some(Kind::HotelSuite));
185    /// assert_eq!(Kind::HotelSuite.as_str(), "hotelSuite");
186    /// ```
187    pub fn parse(s: &str) -> Option<Kind> {
188        FACILITIES.iter().find(|f| f.key == s).map(|f| f.kind)
189    }
190
191    /// A floor or lobby tile.
192    pub fn is_structural(self) -> bool {
193        matches!(self, Kind::Floor | Kind::Lobby)
194    }
195
196    /// An elevator, stairs or an escalator.
197    pub fn is_transport(self) -> bool {
198        self.facility().transport
199    }
200
201    /// One of the three elevator kinds.
202    pub fn is_elevator(self) -> bool {
203        matches!(
204            self,
205            Kind::ElevatorStandard | Kind::ElevatorService | Kind::ElevatorExpress
206        )
207    }
208
209    #[doc(hidden)]
210    pub fn is_hotel(self) -> bool {
211        matches!(
212            self,
213            Kind::HotelSingle | Kind::HotelDouble | Kind::HotelSuite
214        )
215    }
216
217    #[doc(hidden)]
218    pub fn is_rental(self) -> bool {
219        matches!(self, Kind::RentalStudio | Kind::RentalApartment)
220    }
221
222    /// Anything that is neither a floor tile nor a transport.
223    pub fn is_room(self) -> bool {
224        !self.is_structural() && !self.is_transport()
225    }
226
227    #[doc(hidden)]
228    /// `facilityFloors`.
229    pub fn floors(self) -> i64 {
230        self.facility().floors.unwrap_or(1)
231    }
232
233    #[doc(hidden)]
234    /// The highest story a unit of this kind may occupy on the standard lot:
235    /// `MAX_FLOOR`, except the wedding hall, which stands on floor
236    /// `MAX_FLOOR` and rises above it. A tower asks its own lot.
237    pub fn highest_story(self) -> i64 {
238        Lot::STANDARD.highest_story(self)
239    }
240
241    #[doc(hidden)]
242    /// The highest floor a unit of this kind may stand on (its bottom story),
243    /// on the standard lot.
244    pub fn highest_base_floor(self) -> i64 {
245        Lot::STANDARD.highest_base_floor(self)
246    }
247
248    #[doc(hidden)]
249    /// `maxSpanFor`, on the standard lot.
250    pub fn max_span(self) -> i64 {
251        Lot::STANDARD.max_span(self)
252    }
253
254    #[doc(hidden)]
255    pub fn is_fixed_span(self) -> bool {
256        self.is_transport() && self.max_span() == 1
257    }
258
259    #[doc(hidden)]
260    pub fn max_cars(self) -> i64 {
261        8
262    }
263
264    #[doc(hidden)]
265    /// `buildMinutes`.
266    pub fn build_minutes(self) -> f64 {
267        if self.is_structural() {
268            return 0.0;
269        }
270        let f = self.facility();
271        (8.0_f64 * 60.0).min(crate::jsmath::round(
272            60.0 + f.width as f64 * 8.0 + f.cost / 5000.0,
273        ))
274    }
275
276    #[doc(hidden)]
277    /// `resaleRefund`.
278    pub fn resale_refund(self) -> f64 {
279        (self.facility().cost * 0.5).floor()
280    }
281
282    #[doc(hidden)]
283    /// `subtypeListFor`.
284    pub fn subtype_list(self) -> Option<&'static [&'static str]> {
285        Some(match self {
286            Kind::Restaurant => &[
287                "English Pub",
288                "French",
289                "Chinese",
290                "Sushi Bar",
291                "Steak House",
292            ],
293            Kind::FastFood => &[
294                "Japanese Soba",
295                "Chinese Cafe",
296                "Hamburger Stand",
297                "Ice Cream",
298                "Coffee Shop",
299            ],
300            Kind::Shop => &[
301                "Men's Clothing",
302                "Pet Store",
303                "Flower Shop",
304                "Book Store",
305                "Drug Store",
306                "Boutique",
307                "Electronics",
308                "Bank",
309                "Hair Salon",
310                "Post Office",
311                "Sports Gear",
312            ],
313            Kind::FoodHall => &[
314                "Ramen Bar",
315                "Taco Stand",
316                "Bubble Tea",
317                "Poke Bowl",
318                "Deli Counter",
319                "Coffee Cart",
320            ],
321            Kind::Amusements => &["Classic Arcade", "VR Lounge", "Claw Parlor", "Mini Golf"],
322            Kind::BoutiqueBay => &[
323                "Florist",
324                "Barber",
325                "Phone Repair",
326                "Vintage",
327                "Tattoo",
328                "Record Store",
329                "Gallery",
330            ],
331            Kind::FitnessClub => &[
332                "Weight Floor",
333                "Yoga Studio",
334                "Spin Studio",
335                "Boxing Gym",
336                "Climbing Wall",
337            ],
338            Kind::Clinic => &["Dental", "Urgent Care", "Optometry", "Pharmacy", "Physio"],
339            _ => return None,
340        })
341    }
342}
343
344impl Category {
345    #[doc(hidden)]
346    /// The category as the TypeScript engine spells it.
347    pub fn as_str(self) -> &'static str {
348        match self {
349            Category::Structure => "structure",
350            Category::Transport => "transport",
351            Category::Office => "office",
352            Category::Residential => "residential",
353            Category::Hotel => "hotel",
354            Category::Food => "food",
355            Category::Retail => "retail",
356            Category::Entertainment => "entertainment",
357            Category::Service => "service",
358            Category::Special => "special",
359        }
360    }
361}
362
363#[doc(hidden)]
364/// `BUILD_CAPS`: SimTower's caps, which Classic keeps. Read a tower's caps
365/// through `build_cap_in`, which adds the mode's exceptions.
366pub fn build_cap(kind: Kind) -> Option<i64> {
367    match kind {
368        Kind::Metro => Some(1),
369        Kind::WeddingHall => Some(1),
370        Kind::Security => Some(10),
371        Kind::Medical => Some(10),
372        Kind::Cinema => Some(16),
373        Kind::PartyHall => Some(16),
374        Kind::AquaticCenter => Some(8),
375        _ => None,
376    }
377}
378
379/// The most metro stations a Modern tower may hold. SimTower allowed one, as
380/// Classic does; Modern lets a long platform have a station at each end and
381/// one between, all on the first station's row (`Tower::metro_reason`).
382pub const MODERN_METRO_STATION_CAP: i64 = 3;
383
384#[doc(hidden)]
385/// The most a tower in `mode` may hold of `kind` alone: `build_cap`, except
386/// where the mode allows more (several metro stations in Modern).
387pub fn build_cap_in(mode: crate::clock::GameMode, kind: Kind) -> Option<i64> {
388    match kind {
389        Kind::Metro if mode.builds_several_metro_stations() => Some(MODERN_METRO_STATION_CAP),
390        _ => build_cap(kind),
391    }
392}
393
394mod pools;
395pub use pools::{
396    pools_for, transport_cap, transport_pools, Pool, CLASSIC_VENUE_POOL, MODERN_ELEVATOR_SHAFT_CAP,
397    MODERN_POOLED_CAPS, POOLED_CAPS,
398};
399
400#[doc(hidden)]
401pub fn is_lobby_floor(floor: i64) -> bool {
402    floor == 1 || (floor > 1 && floor % LOBBY_INTERVAL == 0)
403}
404
405/// Whether `floor` is below the ground floor (B1 is floor 0).
406#[doc(hidden)]
407pub fn is_basement(floor: i64) -> bool {
408    floor < 1
409}
410
411/// Whether a stop-list entry names a basement floor. A fraction matches no
412/// floor and is left as the save wrote it.
413pub(crate) fn is_basement_stop(f: f64) -> bool {
414    f.fract() == 0.0 && is_basement(f as i64)
415}
416
417#[doc(hidden)]
418pub fn is_sky_lobby_floor(floor: i64) -> bool {
419    floor >= 2 && floor % LOBBY_INTERVAL == 0
420}
421
422#[doc(hidden)]
423pub fn ground_floor_structure_kind(kind: Kind, floor: i64) -> Kind {
424    if kind == Kind::Floor && floor == 1 {
425        Kind::Lobby
426    } else {
427        kind
428    }
429}
430
431#[doc(hidden)]
432/// Whether `kind` is kept above ground (`NO_BASEMENT_KINDS`). SimTower builds
433/// offices, condos and hotel rooms above ground only, and housekeeping with
434/// the hotel. Every home follows the condo, so Modern's studios and
435/// apartments stay above ground too: no home of any kind goes underground.
436pub fn no_basement(kind: Kind) -> bool {
437    let home = kind == Kind::Condo || kind.is_rental();
438    let hotel = kind.is_hotel() || kind == Kind::Housekeeping;
439    home || hotel || kind == Kind::Office
440}
441
442#[doc(hidden)]
443pub fn covers_ground_floor(floor: i64, hgt: i64) -> bool {
444    floor <= 1 && floor + hgt > 1
445}
446
447#[doc(hidden)]
448pub const NEEDS_FLOORS: &str = "Transport must run through built floors. Lay floors first.";
449#[doc(hidden)]
450pub const SHAFT_OVERLAP: &str = "Transport shafts cannot overlap.";
451
452#[cfg(test)]
453mod tests;