diff options
| author | troido <troido@protonmail.com> | 2020-03-03 13:36:44 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-03 13:36:44 +0100 |
| commit | b2157791dfcaab18ec7f8ebb958341fe325cf419 (patch) | |
| tree | f94e638573878599b0ee108a0b06fbe1c8f69ef9 /src/componentwrapper.rs | |
| parent | a8d0e075613cc973b66c37510103108362fe7d3d (diff) | |
added spawners an not-saved assemblages/templates
Diffstat (limited to 'src/componentwrapper.rs')
| -rw-r--r-- | src/componentwrapper.rs | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index c553f61..a03ab17 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use specs::Builder; +use rand::Rng; use crate::{ PlayerId, @@ -8,37 +9,22 @@ use crate::{ Sprite, playerstate::RoomPos, components::{ - Visible, - Movable, - Blocking, - Player, - Floor, - Item, - Inventory, - Health, - Serialise, - RoomExit, - Trap, - Fighter, - Healing, - Volatile, AttackMessage, - Autofight, - MonsterAI, - Mortal + Clan }, - parameter::{Parameter, ParameterType} + parameter::{Parameter, ParameterType}, + Timestamp }; macro_rules! components { - ($($comp: ident ($($paramname: ident : $paramtype: ident),*) {$creation: expr});*;) => { + ($($comp: ident ($($paramname: ident : $paramtype: ident),*) $creation: expr);*;) => { #[derive(Clone)] pub enum ComponentWrapper{ $( - $comp($comp), + $comp(crate::components::$comp), )* } @@ -58,6 +44,7 @@ macro_rules! components { $( ComponentType::$comp => Some(Self::$comp({ + use crate::components::$comp; $( let $paramname = match parameters.remove(stringify!($paramname))? { Parameter::$paramtype(p) => p, @@ -140,6 +127,22 @@ components!( Autofight () {Autofight::default()}; MonsterAI (move_chance: Float, homesickness: Float, view_distance: Int) {MonsterAI{move_chance, homesickness, view_distance}}; Mortal () {Mortal}; + Spawner (amount: Int, delay: Int, clan: String, template: Template) { + Spawner{ + amount: amount as usize, + delay, + clan: Clan{name: + if clan == "" { + format!("$random({})", rand::thread_rng().gen::<u32>()) + } else { + clan + } + }, + template, + last_spawn: Timestamp(0) + } + }; + Clan (name: String) Clan{name}; ); |
