aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/demands.yaml12
-rw-r--r--server/src/customer/mod.rs52
-rw-r--r--server/src/data.rs3
3 files changed, 52 insertions, 15 deletions
diff --git a/data/demands.yaml b/data/demands.yaml
index 1400e9d9..375eeb8b 100644
--- a/data/demands.yaml
+++ b/data/demands.yaml
@@ -1,6 +1,6 @@
-- { from: burger-meal, to: dirty-plate }
-- { from: tomatoburger-meal, to: dirty-plate }
-- { from: tomatosteak-meal, to: dirty-plate }
-- { from: steak-meal, to: dirty-plate }
-- { from: bread-meal, to: dirty-plate }
-- { from: sliced-tomato-meal, to: dirty-plate }
+- { from: burger-meal, to: dirty-plate, duration: 15 }
+- { from: tomatoburger-meal, to: dirty-plate, duration: 20 }
+- { from: tomatosteak-meal, to: dirty-plate, duration: 20 }
+- { from: steak-meal, to: dirty-plate, duration: 15 }
+- { from: bread-meal, to: dirty-plate, duration: 15 }
+- { from: sliced-tomato-meal, to: dirty-plate, duration: 10 }
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));
diff --git a/server/src/data.rs b/server/src/data.rs
index 51347c7c..e59b8b35 100644
--- a/server/src/data.rs
+++ b/server/src/data.rs
@@ -38,12 +38,14 @@ pub struct InitialMap {
pub struct DemandDecl {
from: String,
to: String,
+ duration: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Demand {
pub from: ItemIndex,
pub to: ItemIndex,
+ pub duration: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
@@ -109,6 +111,7 @@ pub fn build_gamedata(
demands.push(Demand {
from: ItemIndex(register(&item_names, d.from)),
to: ItemIndex(register(&item_names, d.to)),
+ duration: d.duration,
})
}