aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-12 15:40:14 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-12 15:40:14 +0100
commit5321f2f18cb1a968778f7bc8ceaa13255bde586e (patch)
tree9a6594a214e290f3ca5daa20bf39f931b06d95dd
parent6c9e1480978e839692fa73f7e28639c3f95a36ee (diff)
downloadhurrycurry-5321f2f18cb1a968778f7bc8ceaa13255bde586e.tar
hurrycurry-5321f2f18cb1a968778f7bc8ceaa13255bde586e.tar.bz2
hurrycurry-5321f2f18cb1a968778f7bc8ceaa13255bde586e.tar.zst
environment_effect delay changes + doc entities
-rw-r--r--data/README.md26
-rw-r--r--server/data/src/entities.rs4
-rw-r--r--server/src/entity/environment_effect.rs18
3 files changed, 33 insertions, 15 deletions
diff --git a/data/README.md b/data/README.md
index 9f7bbca1..5a3f56b8 100644
--- a/data/README.md
+++ b/data/README.md
@@ -36,8 +36,24 @@ maps. For example crates should always be exclusive.
An incomplete list of entities.
-- `!customers`
- - `spawn_cooldown`: Minimum delay between spawning new customers in seconds.
- The actual time is randomized in range min..min*2.
- - `scaling_factor`: Maximum number of customers to be spawned per chair. If
- the limit is not reached, new ones are spawned regularly.
+- `!customers` Customers that walk to chairs, order items and reward points.
+ - `spawn_cooldown`(number): Minimum delay between spawning new customers in
+ seconds. The actual time is randomized in range min..min*2.
+ - `scaling_factor`(number): Maximum number of customers to be spawned per
+ chair. If the limit is not reached, new ones are spawned regularly.
+- `!environment` A static list of environment modifiers (strings) for this map.
+- `!environment_effect` Environment modifier that is toggles on and off in
+ intervals
+ - `name`(string)
+ - `on`(number, default=40): Delay from enable to disable
+ - `off`(number, default=40): Delay from disable to enable
+ - `on_stdev`(opt. number): If set, randomizes delay with gaussian distribition
+ and given standard deviation.
+ - `off_stdev`(opt. number)
+- `!player_portal` Teleports players that get fairly close to `from` to `to`.
+ - `from`(2d vector)
+ - `to`(2d vector)
+- `!item_portal` Teleports items.
+ - `from`(2d vector)
+ - `to`(2d vector)
+- `!tag_minigame`
diff --git a/server/data/src/entities.rs b/server/data/src/entities.rs
index 586674cf..c8c94759 100644
--- a/server/data/src/entities.rs
+++ b/server/data/src/entities.rs
@@ -92,8 +92,12 @@ pub struct EnvironmentEffect {
pub name: String,
#[serde(default = "default_onoff")]
pub on: f32,
+ #[serde(default)]
+ pub on_stdev: f32,
#[serde(default = "default_onoff")]
pub off: f32,
+ #[serde(default)]
+ pub off_stdev: f32,
}
fn default_onoff() -> f32 {
40.
diff --git a/server/src/entity/environment_effect.rs b/server/src/entity/environment_effect.rs
index e50a65ff..fab6f47b 100644
--- a/server/src/entity/environment_effect.rs
+++ b/server/src/entity/environment_effect.rs
@@ -1,5 +1,3 @@
-use crate::random_float;
-
/*
Hurry Curry! - a game about cooking
Copyright (C) 2025 Hurry Curry! Contributors
@@ -17,23 +15,24 @@ use crate::random_float;
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+
use super::{Entity, EntityContext};
+use crate::random_gauss;
use hurrycurry_data::entities::EnvironmentEffect;
use hurrycurry_locale::TrError;
use hurrycurry_protocol::PacketC;
-use std::time::{Duration, Instant};
#[derive(Clone, Debug)]
pub struct EnvironmentEffectController {
config: EnvironmentEffect,
- next_transition: Instant,
+ next_transition: f32,
active: bool,
}
impl EnvironmentEffectController {
pub fn new(config: EnvironmentEffect) -> Self {
Self {
- next_transition: Instant::now() + Duration::from_secs_f32(config.on),
+ next_transition: config.on,
active: false,
config,
}
@@ -41,15 +40,14 @@ impl EnvironmentEffectController {
}
impl Entity for EnvironmentEffectController {
fn tick(&mut self, c: EntityContext) -> Result<(), TrError> {
- if self.next_transition < Instant::now() {
+ self.next_transition -= c.dt;
+ if self.next_transition < 0. {
if self.active {
- self.next_transition +=
- Duration::from_secs_f32(self.config.on * (0.5 + random_float()));
+ self.next_transition += self.config.off + random_gauss() * self.config.off_stdev;
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_float()));
+ self.next_transition += self.config.on + random_gauss() * self.config.on_stdev;
self.active = true;
c.game.environment_effects.insert(self.config.name.clone());
}