diff options
| author | troido <troido@protonmail.com> | 2020-04-13 13:13:04 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-13 13:13:04 +0200 |
| commit | db7b138cb66a2b48492e457fdf0ae8cd65cc73db (patch) | |
| tree | 048e7931d0c7055ebdc7ce5b8f5083cc62154336 /src | |
| parent | 56f44d5898696d1af50f38009629384f8d38cb46 (diff) | |
volate replaced by grow
Diffstat (limited to 'src')
| -rw-r--r-- | src/assemblage.rs | 4 | ||||
| -rw-r--r-- | src/components/mod.rs | 9 | ||||
| -rw-r--r-- | src/componentwrapper.rs | 3 | ||||
| -rw-r--r-- | src/purgatory.rs | 2 | ||||
| -rw-r--r-- | src/room.rs | 6 | ||||
| -rw-r--r-- | src/systems/growth.rs | 8 | ||||
| -rw-r--r-- | src/systems/mod.rs | 2 | ||||
| -rw-r--r-- | src/systems/volate.rs | 34 |
8 files changed, 13 insertions, 55 deletions
diff --git a/src/assemblage.rs b/src/assemblage.rs index 348f5c2..e3238c9 100644 --- a/src/assemblage.rs +++ b/src/assemblage.rs @@ -142,10 +142,10 @@ impl Assemblage { pub fn validate(&self) -> Result<()> { for (comptype, parameters) in &self.components { for (paramname, paramtype) in comptype.parameters() { - let param = parameters.get(paramname).ok_or(aerr!("missing parameter {} for component {:?} in {:?}", paramname, comptype, self))?; + let param = parameters.get(paramname).ok_or(aerr!("missing parameter {} for component {:?}", paramname, comptype))?; let actualtype = param.get_type(&self.arguments)?; if actualtype != paramtype { - return Err(aerr!("parameter type incorrect")); + return Err(aerr!("parameter type incorrect for {} for component {:?}. Expected {:?}, got {:?}", paramname, comptype, paramtype, actualtype)); } } } diff --git a/src/components/mod.rs b/src/components/mod.rs index 49aacfc..269b0b2 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -149,14 +149,6 @@ pub struct Healing { pub next_heal: Option<Timestamp> } - -#[derive(Component, Debug, Clone)] -#[storage(HashMapStorage)] -pub struct Volatile { - pub delay: i64, - pub end_time: Option<Timestamp> -} - #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] pub struct ControlCooldown { @@ -212,6 +204,7 @@ pub struct Loot { #[storage(HashMapStorage)] pub struct Grow { pub delay: i64, + pub spread: f64, pub target_time: Option<Timestamp>, pub trigger: Trigger } diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index beee01f..f9cb31f 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -162,7 +162,6 @@ components!( Trap (damage: Int) {Trap{attack: AttackType::Attack(damage)}}; Fighter (damage: Int, cooldown: Int) {Fighter{attack: AttackType::Attack(damage), cooldown, range: 1}}; Healing (delay: Int, health: Int) {Healing{delay, health, next_heal: None}}; - Volatile (delay: Int) {Volatile{delay, end_time: None}}; Autofight () {Autofight::default()}; MonsterAI (move_chance: Float, homesickness: Float, view_distance: Int); Spawner (amount: Int, delay: Int, clan: String, template: Template, initial_spawn: Bool) { @@ -206,6 +205,7 @@ components!( Grow ( trigger: String (panic!("can't turn trigger to string")), delay: Int (Grow.delay), + spread: Float (Grow.spread), target_time: Int ({ if let Some(time) = Grow.target_time { time.0 @@ -217,6 +217,7 @@ components!( Grow { trigger: Trigger::from_str(&trigger).ok_or(aerr!("invalid trigger name {}", trigger))?, delay, + spread, target_time: if target_time == -1 { None } else { Some(Timestamp(target_time)) } // please forgive me for using -1 as null }; diff --git a/src/purgatory.rs b/src/purgatory.rs index f5f8c06..27db35a 100644 --- a/src/purgatory.rs +++ b/src/purgatory.rs @@ -13,7 +13,6 @@ use crate::{ systems::{ Move, ControlInput, - Volate, UpdateCooldowns, ControlAI, } @@ -25,7 +24,6 @@ pub fn purgatory_id() -> RoomId { pub fn create_purgatory<'a, 'b>(encyclopedia: &Encyclopedia) -> Room<'a, 'b> { let dispatcher = DispatcherBuilder::new() - .with(Volate, "volate", &[]) .with(UpdateCooldowns, "cool_down", &[]) .with(ControlInput, "controlinput", &["cool_down"]) .with(ControlAI, "controlai", &["cool_down"]) diff --git a/src/room.rs b/src/room.rs index afe617b..c0e2cd7 100644 --- a/src/room.rs +++ b/src/room.rs @@ -58,7 +58,6 @@ use crate::{ Trapping, Fight, Heal, - Volate, UpdateCooldowns, ControlAI, Die, @@ -73,7 +72,6 @@ use crate::{ pub fn default_dispatcher<'a, 'b>() -> Dispatcher<'a, 'b> { DispatcherBuilder::new() - .with(Volate, "volate", &[]) .with(Growth, "growth", &[]) .with(UpdateCooldowns, "cool_down", &[]) .with(Spawn, "spawn", &[]) @@ -90,7 +88,7 @@ pub fn default_dispatcher<'a, 'b>() -> Dispatcher<'a, 'b> { .with(Die, "die", &["attacking"]) .with(DropLoot, "droploot", &["attacking"]) .with(Building, "building", &["attacking"]) - .with(Migrate, "migrate", &["move", "attacking", "volate", "die"]) + .with(Migrate, "migrate", &["move", "attacking", "die"]) .build() } @@ -120,7 +118,7 @@ impl <'a, 'b>Room<'a, 'b> { world.insert(NewEntities::new(encyclopedia)); register_insert!( world, - (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, Volatile, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment, TimeOffset, Flags, Ear, Build), + (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment, TimeOffset, Flags, Ear, Build), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time) ); diff --git a/src/systems/growth.rs b/src/systems/growth.rs index 3baa3e8..7daa3d7 100644 --- a/src/systems/growth.rs +++ b/src/systems/growth.rs @@ -33,8 +33,12 @@ impl <'a> System<'a> for Growth{ for (entity, grow) in (&entities, &mut grows).join(){ if grow.target_time == None { let creation_time = time.time + time_offsets.get(entity).map(|ct| ct.dtime).unwrap_or(0); - let duration = grow.delay as f64 * (1.0 + rand::random::<f64>()) / (if rand::random() {1.0} else {2.0}); - grow.target_time = Some(creation_time + duration as i64); + let mut r = 1.0 - rand::random::<f64>() * grow.spread; + if rand::random() { + r = 1.0 / r; + } + let duration = (grow.delay as f64 * r + 0.4) as i64; + grow.target_time = Some(creation_time + duration); } let target_time = grow.target_time.unwrap(); if target_time <= time.time { diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 72a6845..fbd5c64 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -12,7 +12,6 @@ mod attacking; mod trapping; mod fight; mod heal; -mod volate; mod updatecooldowns; mod controlai; mod die; @@ -37,7 +36,6 @@ pub use self::{ trapping::Trapping, fight::Fight, heal::Heal, - volate::Volate, updatecooldowns::UpdateCooldowns, controlai::ControlAI, die::Die, diff --git a/src/systems/volate.rs b/src/systems/volate.rs deleted file mode 100644 index cd50995..0000000 --- a/src/systems/volate.rs +++ /dev/null @@ -1,34 +0,0 @@ - -use specs::{ - Read, - WriteStorage, - Entities, - System, - Join -}; - -use crate::{ - components::{Volatile, Removed}, - resources::Time -}; - -pub struct Volate; -impl <'a> System<'a> for Volate { - type SystemData = ( - Entities<'a>, - WriteStorage<'a, Volatile>, - WriteStorage<'a, Removed>, - Read<'a, Time> - ); - fn run(&mut self, (entities, mut volatiles, mut removals, timestamp): Self::SystemData) { - for (ent, volatile) in (&entities, &mut volatiles).join() { - if let Some(time) = volatile.end_time { - if time <= timestamp.time { - removals.insert(ent, Removed).unwrap(); - } - } else { - volatile.end_time = Some(timestamp.time + volatile.delay); - } - } - } -} |
