diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-26 18:27:18 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-26 18:27:22 +0200 |
commit | 9c7673253f7dcc50d761345c3fdcd0d6d3654f3e (patch) | |
tree | 4a2c8c036f16e97c22767303a20d5be34635ef70 /server/src/game.rs | |
parent | eb6527dec240c94d8cd27573c96c83cea2618cb3 (diff) | |
download | hurrycurry-9c7673253f7dcc50d761345c3fdcd0d6d3654f3e.tar hurrycurry-9c7673253f7dcc50d761345c3fdcd0d6d3654f3e.tar.bz2 hurrycurry-9c7673253f7dcc50d761345c3fdcd0d6d3654f3e.tar.zst |
add draft weather/environment system
Diffstat (limited to 'server/src/game.rs')
-rw-r--r-- | server/src/game.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/server/src/game.rs b/server/src/game.rs index d649d87e..69272159 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -25,8 +25,8 @@ use anyhow::{anyhow, bail, Result}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, movement::MovementBase, - ClientGamedata, ItemIndex, ItemLocation, Menu, Message, PacketC, PacketS, PlayerID, - RecipeIndex, Score, TileIndex, + ClientGamedata, Environment, ItemIndex, ItemLocation, Menu, Message, PacketC, PacketS, + PlayerID, RecipeIndex, Score, TileIndex, }; use log::{info, warn}; use std::{ @@ -76,6 +76,8 @@ pub struct Game { end: Option<Instant>, pub lobby: bool, + pub environment_next_update: Instant, + pub environment: Environment, pub score_changed: bool, pub score: Score, } @@ -93,11 +95,13 @@ impl Game { data: Gamedata::default().into(), players: HashMap::new(), tiles: HashMap::new(), + environment_next_update: Instant::now(), walkable: HashSet::new(), end: None, entities: Arc::new(RwLock::new(vec![])), players_spatial_index: SpatialIndex::default(), score: Score::default(), + environment: Environment::default(), score_changed: false, } } @@ -117,6 +121,9 @@ impl Game { neighbors: [None, None, None, None], }) } + self.score = Score::default(); + self.end = None; + self.environment = Environment::default(); self.walkable.clear(); } pub fn load( @@ -215,6 +222,7 @@ impl Game { .collect(), }, }); + out.push(PacketC::UpdateEnvironment(self.environment.clone())); for (&id, player) in &self.players { out.push(PacketC::AddPlayer { id, @@ -589,9 +597,16 @@ impl Game { } } + let now = Instant::now(); + + if self.environment_next_update < now { + packet_out.push_back(PacketC::UpdateEnvironment(self.environment.clone())); + self.environment_next_update += Duration::from_secs(5); + } + if let Some(end) = self.end { - self.score.time_remaining = (end - Instant::now()).as_secs_f64(); - if end < Instant::now() { + self.score.time_remaining = (end - now).as_secs_f64(); + if end < now { let relative_score = (self.score.points * 100) / self.data.score_baseline.max(1); self.score.stars = match relative_score { 100.. => 3, |