aboutsummaryrefslogtreecommitdiff
path: root/server/src/entity
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-10 18:06:37 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-10 18:06:37 +0200
commit3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996 (patch)
treec3913fce710a879e2375c60a2b78e0cad483de18 /server/src/entity
parentf78856e4cd4928c790748b883b7916585980b3dd (diff)
downloadhurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar
hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar.bz2
hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar.zst
Update to newest rust; replace rand with std random
Diffstat (limited to 'server/src/entity')
-rw-r--r--server/src/entity/bot.rs5
-rw-r--r--server/src/entity/customers.rs13
-rw-r--r--server/src/entity/environment_effect.rs7
-rw-r--r--server/src/entity/mod.rs11
-rw-r--r--server/src/entity/pedestrians.rs19
-rw-r--r--server/src/entity/tram.rs7
6 files changed, 32 insertions, 30 deletions
diff --git a/server/src/entity/bot.rs b/server/src/entity/bot.rs
index 8757cc97..26ae77a6 100644
--- a/server/src/entity/bot.rs
+++ b/server/src/entity/bot.rs
@@ -20,8 +20,7 @@ use anyhow::Result;
use hurrycurry_bot::{BotAlgo, DynBotAlgo};
use hurrycurry_protocol::{Character, Hand, PacketS, PlayerClass, PlayerID};
use log::info;
-use rand::random;
-use std::any::Any;
+use std::{any::Any, random::random};
pub type DynBotDriver = BotDriver<DynBotAlgo>;
@@ -50,7 +49,7 @@ impl<T: BotAlgo + Any> Entity for BotDriver<T> {
}
fn tick(&mut self, c: EntityContext<'_>) -> Result<()> {
if let Some((name, character, class)) = self.join_data.take() {
- self.id = PlayerID(random()); // TODO bad code, can collide
+ self.id = PlayerID(random(..)); // TODO bad code, can collide
info!("spawn {:?} ({name:?})", self.id);
c.packet_in.push_back(PacketS::Join {
name,
diff --git a/server/src/entity/customers.rs b/server/src/entity/customers.rs
index 22522e4e..1e795ac5 100644
--- a/server/src/entity/customers.rs
+++ b/server/src/entity/customers.rs
@@ -1,3 +1,7 @@
+use std::random::random;
+
+use crate::random_float;
+
/*
Hurry Curry! - a game about cooking
Copyright (C) 2025 Hurry Curry! Contributors
@@ -15,11 +19,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use super::{bot::BotDriver, Entity, EntityContext};
+use super::{Entity, EntityContext, bot::BotDriver};
use anyhow::Result;
use hurrycurry_bot::algos::{Customer, CustomerConfig};
use hurrycurry_protocol::{Character, PlayerClass};
-use rand::random;
pub struct Customers {
customers: Vec<BotDriver<Customer>>,
@@ -53,12 +56,12 @@ impl Entity for Customers {
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::<f32>() * 5.;
+ self.spawn_cooldown = 5. + random_float() * 5.;
let bot = BotDriver::new(
"".to_string(),
Character {
- color: random(),
- hairstyle: random(),
+ color: random(..),
+ hairstyle: random(..),
headwear: 0,
},
PlayerClass::Customer,
diff --git a/server/src/entity/environment_effect.rs b/server/src/entity/environment_effect.rs
index ba2c395e..b5344a27 100644
--- a/server/src/entity/environment_effect.rs
+++ b/server/src/entity/environment_effect.rs
@@ -1,3 +1,5 @@
+use crate::random_float;
+
/*
Hurry Curry! - a game about cooking
Copyright (C) 2025 Hurry Curry! Contributors
@@ -18,7 +20,6 @@
use super::{Entity, EntityContext};
use hurrycurry_data::entities::EnvironmentEffect;
use hurrycurry_protocol::PacketC;
-use rand::random;
use std::time::{Duration, Instant};
#[derive(Clone, Debug)]
@@ -42,12 +43,12 @@ impl Entity for EnvironmentEffectController {
if self.next_transition < Instant::now() {
if self.active {
self.next_transition +=
- Duration::from_secs_f32(self.config.on * (0.5 + random::<f32>()));
+ Duration::from_secs_f32(self.config.on * (0.5 + random_float()));
self.active = false;
c.game.environment_effects.remove(&self.config.name);
} else {
self.next_transition +=
- Duration::from_secs_f32(self.config.off * (0.5 + random::<f32>()));
+ Duration::from_secs_f32(self.config.off * (0.5 + random_float()));
self.active = true;
c.game.environment_effects.insert(self.config.name.clone());
}
diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs
index 47d37f3d..ce7cb849 100644
--- a/server/src/entity/mod.rs
+++ b/server/src/entity/mod.rs
@@ -35,9 +35,9 @@ use conveyor::Conveyor;
use customers::Customers;
use environment_effect::{EnvironmentController, EnvironmentEffectController};
use hurrycurry_client_lib::Game;
-use hurrycurry_data::{entities::EntityDecl, Serverdata};
+use hurrycurry_data::{Serverdata, entities::EntityDecl};
use hurrycurry_locale::TrError;
-use hurrycurry_protocol::{glam::IVec2, Character, Gamedata, PacketC, PacketS, PlayerID};
+use hurrycurry_protocol::{Character, Gamedata, PacketC, PacketS, PlayerID, glam::IVec2};
use item_portal::ItemPortal;
use player_portal::PlayerPortal;
use std::{
@@ -133,11 +133,8 @@ pub fn construct_entity(decl: &EntityDecl, data: &Gamedata) -> DynEntity {
} => Box::new(Pedestrians {
players: HashMap::new(),
points,
- spawn_delay_distr: rand_distr::Normal::new(
- spawn_delay,
- spawn_delay_stdev.unwrap_or(0.),
- )
- .unwrap(),
+ spawn_delay,
+ spawn_delay_stdev: spawn_delay_stdev.unwrap_or(0.),
cooldown: 0.,
speed: speed.unwrap_or(0.6),
}),
diff --git a/server/src/entity/pedestrians.rs b/server/src/entity/pedestrians.rs
index fa3276d2..cc5d6d90 100644
--- a/server/src/entity/pedestrians.rs
+++ b/server/src/entity/pedestrians.rs
@@ -1,3 +1,5 @@
+use crate::random_gauss;
+
/*
Hurry Curry! - a game about cooking
Copyright (C) 2025 Hurry Curry! Contributors
@@ -17,15 +19,14 @@
*/
use super::{Entity, EntityContext};
use anyhow::Result;
-use hurrycurry_protocol::{glam::Vec2, Character, PacketS, PlayerClass, PlayerID};
-use rand::{random, rng};
-use rand_distr::Distribution;
-use std::collections::HashMap;
+use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID, glam::Vec2};
+use std::{collections::HashMap, random::random};
pub struct Pedestrians {
pub players: HashMap<PlayerID, usize>,
pub points: Vec<Vec2>,
- pub spawn_delay_distr: rand_distr::Normal<f32>,
+ pub spawn_delay: f32,
+ pub spawn_delay_stdev: f32,
pub cooldown: f32,
pub speed: f32,
}
@@ -37,12 +38,12 @@ impl Entity for Pedestrians {
fn tick(&mut self, c: EntityContext<'_>) -> Result<()> {
self.cooldown -= c.dt;
if self.cooldown <= 0. && self.players.len() < 32 {
- let id = PlayerID(random());
+ let id = PlayerID(random(..));
c.packet_in.push_back(PacketS::Join {
name: "Pedestrian".to_string(),
character: Character {
- color: random(),
- hairstyle: random(),
+ color: random(..),
+ hairstyle: random(..),
headwear: 0,
},
class: PlayerClass::Customer,
@@ -50,7 +51,7 @@ impl Entity for Pedestrians {
position: self.points.first().copied(),
});
self.players.insert(id, 0);
- self.cooldown += self.spawn_delay_distr.sample(&mut rng()).max(0.1);
+ self.cooldown += (self.spawn_delay + self.spawn_delay_stdev * random_gauss()).max(0.1);
}
let mut remove = Vec::new();
diff --git a/server/src/entity/tram.rs b/server/src/entity/tram.rs
index 3186b650..391d16a9 100644
--- a/server/src/entity/tram.rs
+++ b/server/src/entity/tram.rs
@@ -1,3 +1,5 @@
+use std::random::random;
+
/*
Hurry Curry! - a game about cooking
Copyright (C) 2025 Hurry Curry! Contributors
@@ -17,8 +19,7 @@
*/
use super::{Entity, EntityContext};
use anyhow::Result;
-use hurrycurry_protocol::{glam::Vec2, Character, PacketS, PlayerClass, PlayerID};
-use rand::random;
+use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID, glam::Vec2};
pub struct Tram {
pub length: usize,
@@ -37,7 +38,7 @@ impl Entity for Tram {
fn tick(&mut self, c: EntityContext<'_>) -> Result<()> {
if self.ids.is_empty() {
for i in 0..self.length {
- let id = PlayerID(random());
+ let id = PlayerID(random(..));
c.packet_in.push_back(PacketS::Join {
name: format!("Tram {i}"),
character: self.character,