From b2157791dfcaab18ec7f8ebb958341fe325cf419 Mon Sep 17 00:00:00 2001 From: troido Date: Tue, 3 Mar 2020 13:36:44 +0100 Subject: added spawners an not-saved assemblages/templates --- src/componentwrapper.rs | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/componentwrapper.rs') 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::()) + } else { + clan + } + }, + template, + last_spawn: Timestamp(0) + } + }; + Clan (name: String) Clan{name}; ); -- cgit