diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/customer/mod.rs | 9 | ||||
-rw-r--r-- | server/src/game.rs | 2 | ||||
-rw-r--r-- | server/src/state.rs | 14 |
3 files changed, 21 insertions, 4 deletions
diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index f90b2eb2..8e6f1db6 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -41,6 +41,7 @@ pub struct DemandState { chairs: HashMap<IVec2, bool>, customer_id_counter: PlayerID, customers: HashMap<PlayerID, Customer>, + spawn_cooldown: f32, pub completed: usize, pub failed: usize, @@ -93,6 +94,7 @@ impl DemandState { customer_id_counter: PlayerID(0), customers: Default::default(), data, + spawn_cooldown: 0., } } } @@ -106,7 +108,10 @@ impl DemandState { dt: f32, points: &mut i64, ) -> Result<()> { - if self.customers.len() < 5 { + self.spawn_cooldown -= dt; + self.spawn_cooldown = self.spawn_cooldown.max(0.); + if self.customers.len() < 5 && self.spawn_cooldown <= 0. { + self.spawn_cooldown = 5. + random::<f32>() * 10.; self.customer_id_counter.0 -= 1; let id = self.customer_id_counter; packets_out.push(( @@ -145,7 +150,7 @@ impl DemandState { )); p.state = CustomerState::Waiting { chair: *chair, - timeout: 60., + timeout: 60. + random::<f32>() * 30., demand, }; } diff --git a/server/src/game.rs b/server/src/game.rs index 599aadbd..54266351 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -62,7 +62,7 @@ pub struct Player { pub struct Game { data: Arc<Gamedata>, tiles: HashMap<IVec2, Tile>, - players: HashMap<PlayerID, Player>, + pub players: HashMap<PlayerID, Player>, packet_out: VecDeque<PacketC>, demand: Option<DemandState>, pub points: i64, diff --git a/server/src/state.rs b/server/src/state.rs index ffcc8fa2..4716d271 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -22,7 +22,7 @@ enum Command { Start { #[arg(default_value = "small-default-default")] spec: String, - #[arg(default_value = "300")] + #[arg(default_value = "420")] timer: u64, }, Effect { @@ -99,6 +99,18 @@ impl State { self.game.load(data, Some(Duration::from_secs(timer))); } Command::End => { + self.tx + .send(PacketC::ServerMessage { + text: format!( + "Game was aborted by {}.", + self.game + .players + .get(&player) + .ok_or(anyhow!("player missing"))? + .name + ), + }) + .ok(); self.game .load(self.index.generate("lobby-none-none".to_string())?, None); } |