1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
mod business;
mod education;
mod government;
mod military;
mod religious;
mod travel;

use crate::world::place::{PlaceData, PlaceType};
use crate::world::Demographics;
use initiative_macros::WordList;
use rand::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, WordList)]
#[serde(into = "&'static str", try_from = "&str")]
pub enum BuildingType {
    #[term = "building"]
    Any,

    Business(business::BusinessType),
    Education(education::EducationType),
    Government(government::GovernmentType),
    Military(military::MilitaryType),
    Religious(religious::ReligiousType),
    #[alias = "house"]
    #[alias = "manor"]
    #[alias = "mansion"]
    Residence,
    Travel(travel::TravelType),
}

impl BuildingType {
    pub const fn get_emoji(&self) -> Option<&'static str> {
        match self {
            Self::Any => None,
            Self::Business(subtype) => subtype.get_emoji(),
            Self::Education(subtype) => subtype.get_emoji(),
            Self::Government(subtype) => subtype.get_emoji(),
            Self::Military(subtype) => subtype.get_emoji(),
            Self::Religious(subtype) => subtype.get_emoji(),
            Self::Residence => Some("🏠"),
            Self::Travel(subtype) => subtype.get_emoji(),
        }
    }
}

pub fn generate(place: &mut PlaceData, rng: &mut impl Rng, demographics: &Demographics) {
    if let Some(PlaceType::Building(subtype)) = place.subtype.value() {
        match subtype {
            BuildingType::Business(_) => business::generate(place, rng, demographics),
            BuildingType::Religious(_) => religious::generate(place, rng, demographics),
            _ => {}
        }
    }
}