diff options
| author | troido <troido@protonmail.com> | 2020-03-04 19:47:00 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-04 19:47:00 +0100 |
| commit | 022e439a6677b9865b7a3287dbd197d86266f8ef (patch) | |
| tree | 00c8cd7c08fe29cf9f6652b0082f2b13617e426c /src/systems | |
| parent | f8364fb636a8e9276939ae8523966b038388e4ff (diff) | |
implemented growth
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/droploot.rs | 3 | ||||
| -rw-r--r-- | src/systems/growth.rs | 48 | ||||
| -rw-r--r-- | src/systems/heal.rs | 10 | ||||
| -rw-r--r-- | src/systems/mod.rs | 4 | ||||
| -rw-r--r-- | src/systems/spawn.rs | 4 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 4 | ||||
| -rw-r--r-- | src/systems/volate.rs | 4 |
7 files changed, 63 insertions, 14 deletions
diff --git a/src/systems/droploot.rs b/src/systems/droploot.rs index 616d38d..1b8f824 100644 --- a/src/systems/droploot.rs +++ b/src/systems/droploot.rs @@ -3,7 +3,6 @@ use rand::Rng; use specs::{ ReadStorage, - WriteStorage, System, Join, Write @@ -22,7 +21,7 @@ use crate::{ pub struct DropLoot; impl <'a> System<'a> for DropLoot{ type SystemData = ( - WriteStorage<'a, Position>, + ReadStorage<'a, Position>, Write<'a, NewEntities>, ReadStorage<'a, Dead>, ReadStorage<'a, Loot> diff --git a/src/systems/growth.rs b/src/systems/growth.rs new file mode 100644 index 0000000..7472115 --- /dev/null +++ b/src/systems/growth.rs @@ -0,0 +1,48 @@ + +use rand; + +use specs::{ + ReadStorage, + WriteStorage, + Entities, + System, + Join, + Write, + Read +}; + +use crate::{ + components::{ + Position, + Grow, + Removed + }, + resources::{NewEntities, Time} +}; + + +pub struct Growth; +impl <'a> System<'a> for Growth{ + type SystemData = ( + Entities<'a>, + ReadStorage<'a, Position>, + Write<'a, NewEntities>, + WriteStorage<'a, Grow>, + WriteStorage<'a, Removed>, + Read<'a, Time> + ); + + fn run(&mut self, (entities, positions, mut new, mut grows, mut removeds, time): Self::SystemData) { + for (entity, position, grow) in (&entities, &positions, &mut grows).join(){ + 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); + } + if grow.target_time.unwrap() <= time.time { + removeds.insert(entity, Removed).unwrap(); + // todo: error handling + new.create(position.pos, grow.into.clone()).unwrap(); + } + } + } +} diff --git a/src/systems/heal.rs b/src/systems/heal.rs index 458bc17..34e67f4 100644 --- a/src/systems/heal.rs +++ b/src/systems/heal.rs @@ -8,7 +8,7 @@ use specs::{ use crate::{ components::{Health, Healing}, - resources::TimeStamp + resources::Time }; @@ -17,19 +17,19 @@ impl <'a> System<'a> for Heal { type SystemData = ( WriteStorage<'a, Health>, WriteStorage<'a, Healing>, - Read<'a, TimeStamp> + Read<'a, Time> ); - fn run(&mut self, (mut healths, mut healing, timestamp): Self::SystemData) { + fn run(&mut self, (mut healths, mut healing, time): Self::SystemData) { for (health, mut heal) in (&mut healths, &mut healing).join() { if let Some(next_heal) = heal.next_heal { - if next_heal <= timestamp.time { + if next_heal <= time.time { health.heal(heal.health); heal.next_heal = None } } if health.health < health.maxhealth && heal.next_heal == None { - heal.next_heal = Some(timestamp.time + heal.delay) + heal.next_heal = Some(time.time + heal.delay) } } } diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 1735df9..318d5ee 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -19,6 +19,7 @@ mod die; mod spawn; mod interact; mod droploot; +mod growth; pub use self::{ controlinput::ControlInput, @@ -40,5 +41,6 @@ pub use self::{ die::Die, spawn::Spawn, interact::Interact, - droploot::DropLoot + droploot::DropLoot, + growth::Growth }; diff --git a/src/systems/spawn.rs b/src/systems/spawn.rs index 27dcb1f..33dbc95 100644 --- a/src/systems/spawn.rs +++ b/src/systems/spawn.rs @@ -17,7 +17,7 @@ use crate::{ Clan, Home }, - resources::{NewEntities, TimeStamp}, + resources::{NewEntities, Time}, componentwrapper::ComponentWrapper }; @@ -30,7 +30,7 @@ impl <'a> System<'a> for Spawn { Write<'a, NewEntities>, WriteStorage<'a, Spawner>, ReadStorage<'a, Clan>, - Read<'a, TimeStamp> + Read<'a, Time> ); fn run(&mut self, (positions, mut new, mut spawners, clans, time): Self::SystemData) { diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index ab147b7..89a301c 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -29,7 +29,7 @@ impl <'a> System<'a> for Use { type SystemData = ( Entities<'a>, ReadStorage<'a, Controller>, - WriteStorage<'a, Position>, + ReadStorage<'a, Position>, WriteStorage<'a, Inventory>, Write<'a, NewEntities>, WriteStorage<'a, AttackInbox> @@ -42,7 +42,7 @@ impl <'a> System<'a> for Use { if let Some(item) = inventory.items.get(*rank) { match &item.action { Build(template) => { - let _ = new.create(position.pos, template.clone()); + new.create(position.pos, template.clone()).unwrap(); inventory.items.remove(*rank); } Eat(health_diff) => { diff --git a/src/systems/volate.rs b/src/systems/volate.rs index 8cfa826..cd50995 100644 --- a/src/systems/volate.rs +++ b/src/systems/volate.rs @@ -9,7 +9,7 @@ use specs::{ use crate::{ components::{Volatile, Removed}, - resources::TimeStamp + resources::Time }; pub struct Volate; @@ -18,7 +18,7 @@ impl <'a> System<'a> for Volate { Entities<'a>, WriteStorage<'a, Volatile>, WriteStorage<'a, Removed>, - Read<'a, TimeStamp> + Read<'a, Time> ); fn run(&mut self, (entities, mut volatiles, mut removals, timestamp): Self::SystemData) { for (ent, volatile) in (&entities, &mut volatiles).join() { |
