From 6c9e1480978e839692fa73f7e28639c3f95a36ee Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 12 Dec 2025 15:23:02 +0100 Subject: Customizable customer spawn delay (close #522) --- server/src/entity/customers.rs | 17 ++++++++++------- server/src/entity/mod.rs | 11 ++++++++--- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'server/src/entity') diff --git a/server/src/entity/customers.rs b/server/src/entity/customers.rs index 148faf81..c1bfb525 100644 --- a/server/src/entity/customers.rs +++ b/server/src/entity/customers.rs @@ -25,16 +25,18 @@ use std::random::random; pub struct Customers { customers: Vec>, + current_spawn_cooldown: f32, spawn_cooldown: f32, chair_count: Option, scaling_factor: f32, } impl Customers { - pub fn new(scaling_factor: f32) -> Self { + pub fn new(scaling_factor: f32, spawn_cooldown: f32) -> Self { Self { - customers: Default::default(), - spawn_cooldown: 0., + customers: Vec::new(), + current_spawn_cooldown: 0., + spawn_cooldown, chair_count: None, scaling_factor, } @@ -52,10 +54,11 @@ impl Entity for Customers { }); let max_count = (self.scaling_factor * chairs as f32).max(1.) as usize; - self.spawn_cooldown -= c.dt; - self.spawn_cooldown = self.spawn_cooldown.max(0.); - if self.customers.len() < max_count && self.spawn_cooldown <= 0. { - self.spawn_cooldown = 5. + random_float() * 5.; + self.current_spawn_cooldown -= c.dt; + self.current_spawn_cooldown = self.current_spawn_cooldown.max(0.); + if self.customers.len() < max_count && self.current_spawn_cooldown <= 0. { + self.current_spawn_cooldown = + self.spawn_cooldown + random_float() * self.spawn_cooldown; let bot = BotDriver::new( "".to_string(), Character { diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index 2c46a017..279826a9 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -126,9 +126,14 @@ pub fn construct_entity(decl: &EntityDecl) -> DynEntity { blocker_tile, active: true, }), - EntityDecl::Customers { scaling_factor, .. } => { - Box::new(Customers::new(scaling_factor.unwrap_or(0.5))) - } + EntityDecl::Customers { + scaling_factor, + spawn_cooldown, + .. + } => Box::new(Customers::new( + scaling_factor.unwrap_or(0.5), + spawn_cooldown.unwrap_or(5.), + )), EntityDecl::EnvironmentEffect(config) => Box::new(EnvironmentEffectController::new(config)), EntityDecl::Environment(names) => Box::new(EnvironmentController(names)), EntityDecl::Tram { -- cgit v1.3