Complete section 3.7
This commit is contained in:
parent
4011e7d7d3
commit
06e7311523
@ -1,20 +1,28 @@
|
||||
use crate::{Map, Player, Position, Viewshed};
|
||||
use crate::{
|
||||
components::Hidden, components::Name, game_log::GameLog, Map, Player, Position, Viewshed,
|
||||
};
|
||||
use rltk::{field_of_view, Point};
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct VisibilitySystem {}
|
||||
|
||||
impl<'a> System<'a> for VisibilitySystem {
|
||||
#[allow(clippy::type_complexity)]
|
||||
type SystemData = (
|
||||
WriteExpect<'a, Map>,
|
||||
Entities<'a>,
|
||||
WriteStorage<'a, Viewshed>,
|
||||
WriteStorage<'a, Position>,
|
||||
ReadStorage<'a, Position>,
|
||||
ReadStorage<'a, Player>,
|
||||
WriteStorage<'a, Hidden>,
|
||||
WriteExpect<'a, rltk::RandomNumberGenerator>,
|
||||
WriteExpect<'a, GameLog>,
|
||||
ReadStorage<'a, Name>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (mut map, entities, mut viewshed, pos, player) = data;
|
||||
let (mut map, entities, mut viewshed, pos, player, mut hidden, mut rng, mut log, names) =
|
||||
data;
|
||||
|
||||
for (ent, viewshed, pos) in (&entities, &mut viewshed, &pos).join() {
|
||||
if viewshed.dirty {
|
||||
@ -31,10 +39,24 @@ impl<'a> System<'a> for VisibilitySystem {
|
||||
for t in map.visible_tiles.iter_mut() {
|
||||
*t = false
|
||||
}
|
||||
|
||||
for vis in viewshed.visible_tiles.iter() {
|
||||
let idx = map.xy_idx(vis.x, vis.y);
|
||||
map.revealed_tiles[idx] = true;
|
||||
map.visible_tiles[idx] = true;
|
||||
|
||||
// Chance to reveal hidden things
|
||||
for e in map.tile_content[idx].iter() {
|
||||
if let Some(_maybe_hidden) = hidden.get(*e) {
|
||||
if rng.roll_dice(1, 24) == 1 {
|
||||
if let Some(name) = names.get(*e) {
|
||||
log.append(format!("You spotted a {}.", &name.name));
|
||||
}
|
||||
|
||||
hidden.remove(*e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user