diff options
| author | troido <troido@protonmail.com> | 2020-04-01 14:31:28 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-01 14:31:28 +0200 |
| commit | a911b7fabbaac429efd1747c3b1e925f679752f9 (patch) | |
| tree | 3a6a3f0482e485a546cbf6ac87b1d131dc9cd718 | |
| parent | 1ceb4c6f23287bca98f0c3946d5678dce5d0457c (diff) | |
growing should theoretically work after room unloading
| -rw-r--r-- | src/componentwrapper.rs | 1 | ||||
| -rw-r--r-- | src/room.rs | 9 | ||||
| -rw-r--r-- | src/systems/growth.rs | 21 |
3 files changed, 23 insertions, 8 deletions
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 345c986..40faa2d 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -183,6 +183,7 @@ components!( Loot (loot: LootList); Grow (into: Template, delay: Int, target_time: SomeTime); Equipment () {panic!("equipment from parameters not implemented")}; + CreationTime (time: Int) {CreationTime{time: Timestamp(time)}}; ); diff --git a/src/room.rs b/src/room.rs index 983ba11..9df131a 100644 --- a/src/room.rs +++ b/src/room.rs @@ -122,7 +122,7 @@ impl <'a, 'b>Room<'a, 'b> { world.insert(NewEntities::new(encyclopedia)); register_insert!( world, - (Position, Visible, Controller, Movable, Blocking, Floor, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, Dead, Trap, Fighter, Healing, Volatile, ControlCooldown, Autofight, MonsterAI, Home, Mortal, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment), + (Position, Visible, Controller, Movable, Blocking, Floor, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, Dead, Trap, Fighter, Healing, Volatile, ControlCooldown, Autofight, MonsterAI, Home, Mortal, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment, CreationTime), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time) ); @@ -273,4 +273,11 @@ impl <'a, 'b>Room<'a, 'b> { } +#[cfg(test)] +mod tests { + + + +} + diff --git a/src/systems/growth.rs b/src/systems/growth.rs index 7472115..97ae5f3 100644 --- a/src/systems/growth.rs +++ b/src/systems/growth.rs @@ -15,9 +15,11 @@ use crate::{ components::{ Position, Grow, - Removed + Removed, + CreationTime }, - resources::{NewEntities, Time} + resources::{NewEntities, Time}, + componentwrapper::ComponentWrapper }; @@ -29,19 +31,24 @@ impl <'a> System<'a> for Growth{ Write<'a, NewEntities>, WriteStorage<'a, Grow>, WriteStorage<'a, Removed>, - Read<'a, Time> + Read<'a, Time>, + ReadStorage<'a, CreationTime> ); - fn run(&mut self, (entities, positions, mut new, mut grows, mut removeds, time): Self::SystemData) { + fn run(&mut self, (entities, positions, mut new, mut grows, mut removeds, time, creation_times): Self::SystemData) { for (entity, position, grow) in (&entities, &positions, &mut grows).join(){ + let creation_time = creation_times.get(entity).map(|ct| ct.time).unwrap_or(time.time); if grow.target_time == None { let duration = grow.delay as f64 * (1.0 + rand::random::<f64>()) / (if rand::random() {1.0} else {2.0}); - grow.target_time = Some(time.time + duration as i64); + grow.target_time = Some(creation_time + duration as i64); } - if grow.target_time.unwrap() <= time.time { + let target_time = grow.target_time.unwrap(); + if target_time <= time.time { removeds.insert(entity, Removed).unwrap(); // todo: error handling - new.create(position.pos, grow.into.clone()).unwrap(); + let mut preent = new.encyclopedia.construct(&grow.into).unwrap(); + preent.push(ComponentWrapper::CreationTime(CreationTime{time: target_time + 1})); + new.to_build.push((position.pos, preent)); } } } |
