aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/maps/debug.yaml5
-rw-r--r--server/src/entity/environment_effect.rs23
-rw-r--r--server/src/entity/mod.rs9
3 files changed, 28 insertions, 9 deletions
diff --git a/data/maps/debug.yaml b/data/maps/debug.yaml
index 0ea93d77..0ee801ca 100644
--- a/data/maps/debug.yaml
+++ b/data/maps/debug.yaml
@@ -92,8 +92,9 @@ entities:
- !customers
- !player_portal { from: [12.5, 8.5], to: [12.5, 2.5] }
- !item_portal { from: [14, 4], to: [14, 6] }
- - !environment_effect { name: rain, on: 90, off: 60, exclusive: true }
- - !environment_effect { name: wind, on: 90, off: 60, exclusive: true }
+ - !environment_effect { name: rain, on: 60, off: 40 }
+ - !environment_effect { name: wind, on: 60, off: 40 }
+ - !environment [night]
tile_entities:
"}": !conveyor { dir: [1, 0], filter: dough-foodprocessor }
diff --git a/server/src/entity/environment_effect.rs b/server/src/entity/environment_effect.rs
index dcfc08c1..8888f253 100644
--- a/server/src/entity/environment_effect.rs
+++ b/server/src/entity/environment_effect.rs
@@ -32,7 +32,6 @@ pub struct EnvironmentEffect {
on: f32,
#[serde(default = "default_onoff")]
off: f32,
- exclusive: bool,
}
fn default_onoff() -> f32 {
40.
@@ -70,10 +69,8 @@ impl EntityT for EnvironmentEffectController {
} else {
self.next_transition +=
Duration::from_secs_f32(self.config.off * (0.5 + random::<f32>()));
- if game.environment_effects.is_empty() || !self.config.exclusive {
- self.active = true;
- game.environment_effects.insert(self.config.name.clone());
- }
+ self.active = true;
+ game.environment_effects.insert(self.config.name.clone());
}
packet_out.push_back(PacketC::Environment {
effects: game.environment_effects.clone(),
@@ -82,3 +79,19 @@ impl EntityT for EnvironmentEffectController {
Ok(())
}
}
+
+#[derive(Debug, Clone)]
+pub struct EnvironmentController(pub Vec<String>);
+impl EntityT for EnvironmentController {
+ fn tick(
+ &mut self,
+ game: &mut Game,
+ _packet_out: &mut VecDeque<PacketC>,
+ _dt: f32,
+ ) -> anyhow::Result<()> {
+ if game.environment_effects.is_empty() {
+ game.environment_effects.extend(self.0.clone());
+ }
+ Ok(())
+ }
+}
diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs
index 747dd6b7..81061bb5 100644
--- a/server/src/entity/mod.rs
+++ b/server/src/entity/mod.rs
@@ -25,7 +25,7 @@ use crate::{data::ItemTileRegistry, game::Game, interaction::Recipe};
use anyhow::{anyhow, Result};
use conveyor::Conveyor;
use customers::{demands::generate_demands, Customers};
-use environment_effect::{EnvironmentEffect, EnvironmentEffectController};
+use environment_effect::{EnvironmentController, EnvironmentEffect, EnvironmentEffectController};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
ItemIndex, PacketC, TileIndex,
@@ -56,7 +56,8 @@ entities!(
ItemPortal,
PlayerPortal,
Customers,
- EnvironmentEffectController
+ EnvironmentEffectController,
+ EnvironmentController
);
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -80,6 +81,7 @@ pub enum EntityDecl {
},
Customers {},
EnvironmentEffect(EnvironmentEffect),
+ Environment(Vec<String>),
}
pub fn construct_entity(
@@ -137,5 +139,8 @@ pub fn construct_entity(
EntityDecl::EnvironmentEffect(config) => {
Entity::EnvironmentEffectController(EnvironmentEffectController::new(config))
}
+ EntityDecl::Environment(names) => {
+ Entity::EnvironmentController(EnvironmentController(names))
+ }
})
}