diff options
Diffstat (limited to 'server/src/customer/mod.rs')
-rw-r--r-- | server/src/customer/mod.rs | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index 4c557d41..23770ef2 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -35,9 +35,23 @@ struct DemandState { } enum CustomerState { - WalkingToChair { path: Path, chair: IVec2 }, - Waiting { chair: IVec2, demand: DemandIndex }, - Exiting { path: Path }, + Entering { + path: Path, + chair: IVec2, + }, + Waiting { + demand: DemandIndex, + chair: IVec2, + }, + Eating { + demand: DemandIndex, + target: IVec2, + progress: f32, + chair: IVec2, + }, + Exiting { + path: Path, + }, } struct Customer { @@ -150,14 +164,15 @@ impl CustomerManager { facing: Vec2::X, vel: Vec2::ZERO, }, - state: CustomerState::WalkingToChair { path, chair }, + state: CustomerState::Entering { path, chair }, }, ); } let mut customers_to_remove = Vec::new(); for (&id, p) in &mut self.customers { match &mut p.state { - CustomerState::WalkingToChair { path, chair } => { + CustomerState::Entering { path, chair } => { + debug!("{id:?} entering"); packets_out.push((id, path.execute_tick(&mut p.movement, &self.walkable, dt))); if path.is_done() { let demand = self.demand.generate_demand(); @@ -174,12 +189,13 @@ impl CustomerManager { } } CustomerState::Waiting { chair, demand } => { - let demand = &self.demand.data.demand(*demand); + 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.from) { + if self.items.get(&pos) == Some(&demand_data.from) { Some(pos) } else { None @@ -190,6 +206,24 @@ impl CustomerManager { 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, + } + } + } + CustomerState::Eating { + demand, + target, + progress, + chair, + } => { + debug!("{id:?} eating"); + let demand = self.demand.data.demand(*demand); + *progress += dt / demand.duration; + if *progress >= 1. { packets_out.push(( id, PacketS::ReplaceHand { @@ -197,7 +231,7 @@ impl CustomerManager { }, )); for edge in [true, false] { - packets_out.push((id, PacketS::Interact { pos, edge })) + packets_out.push((id, PacketS::Interact { pos: *target, edge })) } let path = find_path( &self.walkable, @@ -208,9 +242,9 @@ impl CustomerManager { *self.chairs.get_mut(&chair).unwrap() = true; p.state = CustomerState::Exiting { path } } - debug!("waiting") } CustomerState::Exiting { path } => { + debug!("{id:?} exiting"); packets_out.push((id, path.execute_tick(&mut p.movement, &self.walkable, dt))); if path.is_done() { packets_out.push((id, PacketS::Leave)); |