diff options
Diffstat (limited to 'server/src/customer/mod.rs')
-rw-r--r-- | server/src/customer/mod.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index ba65a5e2..9e474b8f 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -41,6 +41,10 @@ pub struct DemandState { chairs: HashMap<IVec2, bool>, customer_id_counter: PlayerID, customers: HashMap<PlayerID, Customer>, + + pub completed: usize, + pub failed: usize, + pub score_changed: bool, } enum CustomerState { @@ -73,6 +77,9 @@ impl DemandState { pub fn new(data: Arc<Gamedata>, map: &HashMap<IVec2, Tile>) -> Self { let chair = data.get_tile_by_name("chair"); Self { + score_changed: true, + completed: 0, + failed: 0, walkable: map .iter() .filter(|(_, v)| !data.is_tile_colliding(v.kind)) @@ -157,6 +164,8 @@ impl DemandState { ) .expect("no path to exit"); *self.chairs.get_mut(&chair).unwrap() = true; + self.failed += 1; + self.score_changed = true; p.state = CustomerState::Exiting { path } } else { let demand_data = &data.demand(*demand); @@ -219,6 +228,8 @@ impl DemandState { ) .ok_or(anyhow!("no path to exit"))?; *self.chairs.get_mut(&chair).unwrap() = true; + self.completed += 1; + self.score_changed = true; p.state = CustomerState::Exiting { path } } } @@ -238,7 +249,7 @@ impl DemandState { Ok(()) } - pub fn select_chair(&mut self) -> Option<IVec2> { + fn select_chair(&mut self) -> Option<IVec2> { use rand::seq::IteratorRandom; let (chosen, free) = self .chairs |