summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/attacking.rs2
-rw-r--r--src/systems/controlinput.rs10
-rw-r--r--src/systems/create.rs11
-rw-r--r--src/systems/mod.rs4
-rw-r--r--src/systems/moving.rs22
-rw-r--r--src/systems/trapping.rs46
6 files changed, 62 insertions, 33 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs
index 0fb5cf7..6535a75 100644
--- a/src/systems/attacking.rs
+++ b/src/systems/attacking.rs
@@ -18,13 +18,13 @@ impl <'a> System<'a> for Attacking {
WriteStorage<'a, Health>
);
fn run(&mut self, (mut victims, mut healths): Self::SystemData) {
-
for (health, attacked) in (&mut healths, &mut victims).join() {
for attack in attacked.attacks.drain(..) {
health.health -= attack.damage;
}
health.health = util::clamp(health.health, 0, health.maxhealth);
}
+ victims.clear();
}
}
diff --git a/src/systems/controlinput.rs b/src/systems/controlinput.rs
index bd8b23c..71373f5 100644
--- a/src/systems/controlinput.rs
+++ b/src/systems/controlinput.rs
@@ -21,15 +21,7 @@ impl <'a> System<'a> for ControlInput {
ReadStorage<'a, Player>
);
fn run(&mut self, (entities, mut input, mut controllers, players): Self::SystemData) {
- {
- let mut ents = Vec::new();
- for (ent, _controller) in (&*entities, &controllers).join() {
- ents.push(ent);
- }
- for ent in ents {
- controllers.remove(ent);
- }
- }
+ controllers.clear();
for (player, entity) in (&players, &entities).join() {
if let Some(control) = input.actions.get(&player.id){
diff --git a/src/systems/create.rs b/src/systems/create.rs
index 8463f9e..c995bcb 100644
--- a/src/systems/create.rs
+++ b/src/systems/create.rs
@@ -4,7 +4,6 @@ use specs::{
Write,
WriteStorage,
System,
- Join,
Entities,
LazyUpdate,
Builder
@@ -25,15 +24,7 @@ impl <'a> System<'a> for Create {
);
fn run(&mut self, (entities, mut new_entities, updater, mut new): Self::SystemData) {
- {
- let mut ents = Vec::new();
- for (ent, _new) in (&entities, &new).join() {
- ents.push(ent);
- }
- for ent in ents {
- new.remove(ent);
- }
- }
+ new.clear();
for (pos, preentity) in &new_entities.to_build {
let mut builder = updater.create_entity(&entities);
for comp in preentity {
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index f93088d..7864b1c 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -9,6 +9,7 @@ mod take;
mod migrate;
mod useitem;
mod attacking;
+mod trapping;
pub use self::{
controlinput::ControlInput,
@@ -20,5 +21,6 @@ pub use self::{
take::Take,
migrate::Migrate,
useitem::Use,
- attacking::Attacking
+ attacking::Attacking,
+ trapping::Trapping
};
diff --git a/src/systems/moving.rs b/src/systems/moving.rs
index ccd9455..daa1eb4 100644
--- a/src/systems/moving.rs
+++ b/src/systems/moving.rs
@@ -18,7 +18,8 @@ use crate::{
Blocking,
Position,
Floor,
- Moved
+ Moved,
+ Entered
},
controls::{
Control
@@ -40,19 +41,13 @@ impl <'a> System<'a> for Move {
ReadStorage<'a, Blocking>,
Write<'a, Ground>,
ReadStorage<'a, Floor>,
- WriteStorage<'a, Moved>
+ WriteStorage<'a, Moved>,
+ WriteStorage<'a, Entered>
);
- fn run(&mut self, (entities, controllers, mut positions, size, blocking, mut ground, floor, mut moved): Self::SystemData) {
- {
- let mut ents = Vec::new();
- for (ent, _moved) in (&*entities, &moved).join() {
- ents.push(ent);
- }
- for ent in ents {
- moved.remove(ent);
- }
- }
+ fn run(&mut self, (entities, controllers, mut positions, size, blocking, mut ground, floor, mut moved, mut entered): Self::SystemData) {
+ moved.clear();
+ entered.clear();
for (ent, controller, mut pos) in (&entities, &controllers, &mut positions.restrict_mut()).join(){
match &controller.0 {
Control::Move(direction) => {
@@ -74,6 +69,9 @@ impl <'a> System<'a> for Move {
ground.cells.get_mut(&pos_mut.pos).unwrap().remove(&ent);
pos_mut.pos = newpos;
ground.cells.entry(newpos).or_insert_with(HashSet::new).insert(ent);
+ for ent in ground.cells.get(&newpos).unwrap() {
+ let _ = entered.insert(*ent, Entered);
+ }
}
}
_ => {}
diff --git a/src/systems/trapping.rs b/src/systems/trapping.rs
new file mode 100644
index 0000000..144cd94
--- /dev/null
+++ b/src/systems/trapping.rs
@@ -0,0 +1,46 @@
+
+use specs::{
+ WriteStorage,
+ ReadStorage,
+ Entities,
+ Read,
+ System,
+ Join
+};
+
+use crate::{
+ components::{Health, Attacked, Moved, Entered, Trap, Position},
+ resources::Ground
+};
+
+
+pub struct Trapping;
+impl <'a> System<'a> for Trapping {
+ type SystemData = (
+ Entities<'a>,
+ WriteStorage<'a, Attacked>,
+ ReadStorage<'a, Health>,
+ ReadStorage<'a, Moved>,
+ ReadStorage<'a, Entered>,
+ ReadStorage<'a, Trap>,
+ ReadStorage<'a, Position>,
+ Read<'a, Ground>
+ );
+ fn run(&mut self, (entities, mut victims, healths, moves, entereds, traps, positions, ground): Self::SystemData) {
+
+ for (entity, _entered, trap, position) in (&entities, &entereds, &traps, &positions).join() {
+ for ent in ground.cells.get(&position.pos).unwrap(){
+ if ent != &entity && moves.contains(*ent) && healths.contains(*ent) {
+ victims
+ .entry(*ent)
+ .unwrap()
+ .or_insert_with(Attacked::default)
+ .attacks
+ .push(trap.attack.clone());
+
+ }
+ }
+ }
+ }
+}
+