diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-06-26 20:41:09 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-06-26 20:41:09 +0200 | 
| commit | 9265813857500642b0e71ecc86e452ac3975d6ed (patch) | |
| tree | 208f109123d84f252cdcfa19a0ed043e03a8abdb /server/src/customer/mod.rs | |
| parent | cac2287a1292ee3d9392a670a8e1a0352165b936 (diff) | |
| download | hurrycurry-9265813857500642b0e71ecc86e452ac3975d6ed.tar hurrycurry-9265813857500642b0e71ecc86e452ac3975d6ed.tar.bz2 hurrycurry-9265813857500642b0e71ecc86e452ac3975d6ed.tar.zst | |
send score
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 | 
