veloren_rtsim/data/
faction.rs1use crate::data::Sentiments;
2use common::rtsim::Actor;
3pub use common::rtsim::FactionId;
4use serde::{Deserialize, Serialize};
5use slotmap::HopSlotMap;
6use std::ops::{Deref, DerefMut};
7use vek::*;
8
9#[derive(Clone, Serialize, Deserialize)]
10pub struct Faction {
11 pub seed: u32,
12 pub leader: Option<Actor>,
13 pub good_or_evil: bool, #[serde(default)]
16 pub sentiments: Sentiments,
17}
18
19impl Faction {
20 pub fn cleanup(&mut self) {
21 self.sentiments
22 .cleanup(crate::data::sentiment::FACTION_MAX_SENTIMENTS);
23 }
24}
25
26#[derive(Clone, Default, Serialize, Deserialize)]
27pub struct Factions {
28 pub factions: HopSlotMap<FactionId, Faction>,
29}
30
31impl Factions {
32 pub fn create(&mut self, faction: Faction) -> FactionId { self.factions.insert(faction) }
33}
34
35impl Deref for Factions {
36 type Target = HopSlotMap<FactionId, Faction>;
37
38 fn deref(&self) -> &Self::Target { &self.factions }
39}
40
41impl DerefMut for Factions {
42 fn deref_mut(&mut self) -> &mut Self::Target { &mut self.factions }
43}