diff options
| -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,                          }                      }                  } | 
