aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/entity/customers.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/server/src/entity/customers.rs b/server/src/entity/customers.rs
index 8c515e92..aaf6995f 100644
--- a/server/src/entity/customers.rs
+++ b/server/src/entity/customers.rs
@@ -23,6 +23,7 @@ use rand::random;
pub struct Customers {
customers: Vec<BotDriver<Customer>>,
spawn_cooldown: f32,
+ chair_count: Option<usize>,
}
impl Customers {
@@ -30,15 +31,25 @@ impl Customers {
Ok(Self {
customers: Default::default(),
spawn_cooldown: 0.,
+ chair_count: None,
})
}
}
impl Entity for Customers {
fn tick(&mut self, c: EntityContext) -> Result<()> {
+ let chairs = *self.chair_count.get_or_insert_with(|| {
+ c.game
+ .tiles
+ .values()
+ .filter(|t| c.game.data.tile_name(t.kind) == "table")
+ .count()
+ });
+ let max_count = 5.min(chairs);
+
self.spawn_cooldown -= c.dt;
self.spawn_cooldown = self.spawn_cooldown.max(0.);
- if self.customers.len() < 5 && self.spawn_cooldown <= 0. {
+ if self.customers.len() < max_count && self.spawn_cooldown <= 0. {
self.spawn_cooldown = 10. + random::<f32>() * 10.;
let bot = BotDriver::new(
"".to_string(),