summaryrefslogtreecommitdiff
path: root/src/systems/migrate.rs
blob: 80690f3d3bc1766f5e0879de7d76ee8f42f3494b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

use specs::{
	ReadStorage,
	Read,
	Write,
	System,
	Join
};

use crate::components::{Player, Position, Moved, RoomExit};
use crate::resources::{Emigration, Ground};


pub struct Migrate;
impl <'a> System<'a> for Migrate {
	type SystemData = (
		Write<'a, Emigration>,
		Read<'a, Ground>,
		ReadStorage<'a, Player>,
		ReadStorage<'a, Position>,
		ReadStorage<'a, Moved>,
		ReadStorage<'a, RoomExit>,
		
	);
	fn run(&mut self, (mut emigration, ground, players, positions, moved, exits): Self::SystemData) {
	
		for (player, position, _moved) in (&players, &positions, &moved).join() {
			for ent in ground.cells.get(&position.pos).unwrap() {
				if let Some(exit) = exits.get(*ent) {
					emigration.emigrants.push((player.id.clone(), exit.destination.clone(), exit.dest_pos.clone()));
					break;
				}
			}
		}
	}
}