1use crate::lot::Lot;
9
10pub const LOT_WIDTH: i64 = 375;
12pub const MAX_FLOOR: i64 = 100;
15pub const MIN_FLOOR: i64 = -9;
18pub const LOBBY_INTERVAL: i64 = 15;
20pub const MAX_LOBBY_HEIGHT: i64 = 3;
24#[doc(hidden)]
25pub const WEDDING_HALL_TOP_FLOOR: i64 = MAX_FLOOR + 4;
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
31pub enum Kind {
37 Lobby,
39 Floor,
41 Office,
43 Condo,
45 HotelSingle,
47 HotelDouble,
49 HotelSuite,
51 FastFood,
53 Restaurant,
55 FoodHall,
57 Shop,
59 Cinema,
61 PartyHall,
63 Amusements,
65 BoutiqueBay,
67 FitnessClub,
69 Clinic,
71 Nightclub,
73 Spa,
75 SkyBar,
77 AquaticCenter,
79 Daycare,
81 Stairs,
83 Escalator,
85 ElevatorStandard,
87 ElevatorService,
89 ElevatorExpress,
91 ParkingRamp,
93 Parking,
95 Security,
97 Medical,
99 Housekeeping,
101 Recycling,
103 Metro,
105 WeddingHall,
107 RentalStudio,
109 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 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 pub fn facility(self) -> &'static Facility {
171 &FACILITIES[self as usize]
172 }
173
174 pub fn as_str(self) -> &'static str {
176 self.facility().key
177 }
178
179 pub fn parse(s: &str) -> Option<Kind> {
188 FACILITIES.iter().find(|f| f.key == s).map(|f| f.kind)
189 }
190
191 pub fn is_structural(self) -> bool {
193 matches!(self, Kind::Floor | Kind::Lobby)
194 }
195
196 pub fn is_transport(self) -> bool {
198 self.facility().transport
199 }
200
201 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 pub fn is_room(self) -> bool {
224 !self.is_structural() && !self.is_transport()
225 }
226
227 #[doc(hidden)]
228 pub fn floors(self) -> i64 {
230 self.facility().floors.unwrap_or(1)
231 }
232
233 #[doc(hidden)]
234 pub fn highest_story(self) -> i64 {
238 Lot::STANDARD.highest_story(self)
239 }
240
241 #[doc(hidden)]
242 pub fn highest_base_floor(self) -> i64 {
245 Lot::STANDARD.highest_base_floor(self)
246 }
247
248 #[doc(hidden)]
249 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 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 pub fn resale_refund(self) -> f64 {
279 (self.facility().cost * 0.5).floor()
280 }
281
282 #[doc(hidden)]
283 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 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)]
364pub 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
379pub const MODERN_METRO_STATION_CAP: i64 = 3;
383
384#[doc(hidden)]
385pub 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#[doc(hidden)]
407pub fn is_basement(floor: i64) -> bool {
408 floor < 1
409}
410
411pub(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)]
432pub 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;