summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/componentwrapper.rs1
-rw-r--r--src/room.rs9
-rw-r--r--src/systems/growth.rs21
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));
}
}
}