aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/entity/customers.rs17
-rw-r--r--server/src/entity/mod.rs11
2 files changed, 18 insertions, 10 deletions
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<BotDriver<Customer>>,
+ current_spawn_cooldown: f32,
spawn_cooldown: f32,
chair_count: Option<usize>,
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 {