diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-23 00:13:40 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:31:11 +0200 |
commit | 4d274b80d36d9a3136b4070d03459b8e3450b162 (patch) | |
tree | 59a8efd918cc96b01182525ddaeaf1688f85a2c5 /server | |
parent | 2eaa2593a74e2d82da3a814d6f2544802fdb0d6b (diff) | |
download | hurrycurry-4d274b80d36d9a3136b4070d03459b8e3450b162.tar hurrycurry-4d274b80d36d9a3136b4070d03459b8e3450b162.tar.bz2 hurrycurry-4d274b80d36d9a3136b4070d03459b8e3450b162.tar.zst |
customer timeout
Diffstat (limited to 'server')
-rw-r--r-- | server/src/customer/mod.rs | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index 4b715c78..c7a1c5b9 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -42,6 +42,7 @@ enum CustomerState { Waiting { demand: DemandIndex, chair: IVec2, + timeout: f32, }, Eating { demand: DemandIndex, @@ -184,33 +185,50 @@ impl CustomerManager { )); p.state = CustomerState::Waiting { chair: *chair, + timeout: 60., demand, }; } } - CustomerState::Waiting { chair, demand } => { + CustomerState::Waiting { + chair, + demand, + timeout, + } => { debug!("{id:?} waiting"); - let demand_data = &self.demand.data.demand(*demand); - let demand_pos = [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] - .into_iter() - .find_map(|off| { - let pos = *chair + off; - if self.items.get(&pos) == Some(&demand_data.from) { - Some(pos) - } else { - None + *timeout -= dt; + if *timeout <= 0. { + let path = find_path( + &self.walkable, + p.movement.position.as_ivec2(), + self.demand.data.customer_spawn.as_ivec2(), + ) + .expect("no path to exit"); + *self.chairs.get_mut(&chair).unwrap() = true; + p.state = CustomerState::Exiting { path } + } else { + let demand_data = &self.demand.data.demand(*demand); + let demand_pos = [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] + .into_iter() + .find_map(|off| { + let pos = *chair + off; + if self.items.get(&pos) == Some(&demand_data.from) { + Some(pos) + } else { + None + } + }); + if let Some(pos) = demand_pos { + packets_out.push((id, PacketS::Communicate { message: None })); + for edge in [true, false] { + packets_out.push((id, PacketS::Interact { pos, edge })) + } + p.state = CustomerState::Eating { + demand: *demand, + target: pos, + progress: 0., + chair: *chair, } - }); - if let Some(pos) = demand_pos { - packets_out.push((id, PacketS::Communicate { message: None })); - for edge in [true, false] { - packets_out.push((id, PacketS::Interact { pos, edge })) - } - p.state = CustomerState::Eating { - demand: *demand, - target: pos, - progress: 0., - chair: *chair, } } } |