58 lines
1.0 KiB
Rust
58 lines
1.0 KiB
Rust
use std::fmt;
|
|
|
|
use crate::{entity::{Entity, Location}, generators::TownNameGenerator};
|
|
|
|
#[derive(Clone)]
|
|
pub struct Town {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Tavern {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub enum Structure {
|
|
Town(Town),
|
|
Tavern(Tavern),
|
|
}
|
|
|
|
pub struct Site {
|
|
pub entity: Entity,
|
|
pub loc: Location,
|
|
pub structure: Structure,
|
|
pub coins: u32,
|
|
}
|
|
|
|
|
|
impl Town {
|
|
pub fn new() -> Town {
|
|
Town {
|
|
name: TownNameGenerator::name(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Tavern {
|
|
pub fn new() -> Tavern {
|
|
Tavern {
|
|
name: TownNameGenerator::name(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Structure {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Structure::Town(t) => write!(f, "Town: {}", t.name),
|
|
Structure::Tavern(t) => write!(f, "Tavern: {}", t.name),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Site {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, "{}", self.structure)
|
|
}
|
|
} |