initiative_core/world/place/building/
mod.rs

1mod business;
2mod education;
3mod government;
4mod military;
5mod religious;
6mod travel;
7
8use crate::world::place::{PlaceData, PlaceType};
9use crate::world::Demographics;
10use initiative_macros::WordList;
11use rand::prelude::*;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, WordList)]
15#[serde(into = "&'static str", try_from = "&str")]
16pub enum BuildingType {
17    #[term = "building"]
18    Any,
19
20    Business(business::BusinessType),
21    Education(education::EducationType),
22    Government(government::GovernmentType),
23    Military(military::MilitaryType),
24    Religious(religious::ReligiousType),
25    #[alias = "house"]
26    #[alias = "manor"]
27    #[alias = "mansion"]
28    Residence,
29    Travel(travel::TravelType),
30}
31
32impl BuildingType {
33    pub const fn get_emoji(&self) -> Option<&'static str> {
34        match self {
35            Self::Any => None,
36            Self::Business(subtype) => subtype.get_emoji(),
37            Self::Education(subtype) => subtype.get_emoji(),
38            Self::Government(subtype) => subtype.get_emoji(),
39            Self::Military(subtype) => subtype.get_emoji(),
40            Self::Religious(subtype) => subtype.get_emoji(),
41            Self::Residence => Some("🏠"),
42            Self::Travel(subtype) => subtype.get_emoji(),
43        }
44    }
45}
46
47pub fn generate(place: &mut PlaceData, rng: &mut impl Rng, demographics: &Demographics) {
48    if let Some(PlaceType::Building(subtype)) = place.subtype.value() {
49        match subtype {
50            BuildingType::Business(_) => business::generate(place, rng, demographics),
51            BuildingType::Religious(_) => religious::generate(place, rng, demographics),
52            _ => {}
53        }
54    }
55}