seen entities on ui
This commit is contained in:
parent
a3ffb7d251
commit
2d4758ced1
4 changed files with 97 additions and 11 deletions
81
src/gui.rs
81
src/gui.rs
|
|
@ -1,6 +1,7 @@
|
||||||
use super::{
|
use super::{
|
||||||
camera, gamelog, gamesystem, rex_assets::RexAssets, ArmourClassBonus, Attributes, Equipped, Hidden, HungerClock,
|
camera, gamelog, gamesystem, rex_assets::RexAssets, ArmourClassBonus, Attributes, Consumable, Equippable, Equipped,
|
||||||
HungerState, InBackpack, Map, Name, Player, Point, Pools, Position, RunState, Skill, Skills, State, Viewshed,
|
Hidden, HungerClock, HungerState, InBackpack, Map, Name, Player, Point, Pools, Position, Prop, Renderable,
|
||||||
|
RunState, Skill, Skills, State, Viewshed,
|
||||||
};
|
};
|
||||||
use rltk::{Rltk, VirtualKeyCode, RGB};
|
use rltk::{Rltk, VirtualKeyCode, RGB};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
@ -118,6 +119,82 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
||||||
ctx.print_color_right(70, 53, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "Fainting")
|
ctx.print_color_right(70, 53, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "Fainting")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw equipment
|
||||||
|
let names = ecs.read_storage::<Name>();
|
||||||
|
let backpack = ecs.read_storage::<InBackpack>();
|
||||||
|
let equippables = ecs.read_storage::<Equippable>();
|
||||||
|
let mut equipment: Vec<String> = Vec::new();
|
||||||
|
for (_entity, _pack, name) in
|
||||||
|
(&equippables, &backpack, &names).join().filter(|item| item.1.owner == *player_entity)
|
||||||
|
{
|
||||||
|
equipment.push(format!("- {}", &name.name));
|
||||||
|
}
|
||||||
|
for (_equipped, name) in (&equipped, &names).join().filter(|item| item.0.owner == *player_entity) {
|
||||||
|
equipment.push(format!("- {} (worn)", &name.name));
|
||||||
|
}
|
||||||
|
let mut y = 1;
|
||||||
|
if !equipment.is_empty() {
|
||||||
|
ctx.print_color(72, y, RGB::named(rltk::BLACK), RGB::named(rltk::WHITE), "Equipment");
|
||||||
|
for item in equipment {
|
||||||
|
y += 1;
|
||||||
|
ctx.print_color(72, y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), item);
|
||||||
|
}
|
||||||
|
y += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw consumables
|
||||||
|
ctx.print_color(72, y, RGB::named(rltk::BLACK), RGB::named(rltk::WHITE), "Consumables");
|
||||||
|
let consumables = ecs.read_storage::<Consumable>();
|
||||||
|
for (_entity, _pack, name) in
|
||||||
|
(&consumables, &backpack, &names).join().filter(|item| item.1.owner == *player_entity)
|
||||||
|
{
|
||||||
|
y += 1;
|
||||||
|
ctx.print_color(72, y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), format!("- {}", &name.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw entities seen on screen
|
||||||
|
let viewsheds = ecs.read_storage::<Viewshed>();
|
||||||
|
let renderables = ecs.read_storage::<Renderable>();
|
||||||
|
let hidden = ecs.read_storage::<Hidden>();
|
||||||
|
let props = ecs.read_storage::<Prop>();
|
||||||
|
let map = ecs.fetch::<Map>();
|
||||||
|
let viewshed = viewsheds.get(*player_entity).unwrap();
|
||||||
|
let mut seen_entities: Vec<(String, RGB)> = Vec::new();
|
||||||
|
for tile in viewshed.visible_tiles.iter() {
|
||||||
|
let idx = map.xy_idx(tile.x, tile.y);
|
||||||
|
for entity in map.tile_content[idx].iter() {
|
||||||
|
let mut draw = true;
|
||||||
|
let prop = props.get(*entity);
|
||||||
|
if let Some(_) = prop {
|
||||||
|
draw = false;
|
||||||
|
}
|
||||||
|
let is_hidden = hidden.get(*entity);
|
||||||
|
if let Some(_) = is_hidden {
|
||||||
|
draw = false;
|
||||||
|
}
|
||||||
|
if entity == &*player_entity {
|
||||||
|
draw = false;
|
||||||
|
}
|
||||||
|
let name = &names.get(*entity);
|
||||||
|
if let Some(name) = name {
|
||||||
|
if draw {
|
||||||
|
let fg = renderables.get(*entity).unwrap().fg;
|
||||||
|
seen_entities.push((name.name.to_string(), fg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seen_entities.sort_by(|a, b| b.0.cmp(&a.0));
|
||||||
|
|
||||||
|
if !seen_entities.is_empty() {
|
||||||
|
y += 2;
|
||||||
|
ctx.print_color(72, y, RGB::named(rltk::BLACK), RGB::named(rltk::WHITE), "You see");
|
||||||
|
for entity in seen_entities {
|
||||||
|
y += 1;
|
||||||
|
ctx.print_color(72, y, entity.1, RGB::named(rltk::BLACK), entity.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the message log at [1, 7], ascending, with 7 lines and a max width of 68.
|
// Render the message log at [1, 7], ascending, with 7 lines and a max width of 68.
|
||||||
|
|
|
||||||
|
|
@ -496,7 +496,6 @@ fn main() -> rltk::BError {
|
||||||
let context = RltkBuilder::new()
|
let context = RltkBuilder::new()
|
||||||
.with_title("rust-rl")
|
.with_title("rust-rl")
|
||||||
.with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT)
|
.with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT)
|
||||||
.with_fps_cap(60.0)
|
|
||||||
.with_font("curses14x16.png", 14, 16)
|
.with_font("curses14x16.png", 14, 16)
|
||||||
.with_tile_dimensions(14, 16)
|
.with_tile_dimensions(14, 16)
|
||||||
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "curses14x16.png")
|
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "curses14x16.png")
|
||||||
|
|
|
||||||
|
|
@ -249,9 +249,10 @@ fn random_room_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Buil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut BuilderChain) {
|
fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut BuilderChain) -> bool {
|
||||||
// Pick an initial builder
|
// Pick an initial builder
|
||||||
let builder_roll = rng.roll_dice(1, 16);
|
let builder_roll = rng.roll_dice(1, 16);
|
||||||
|
let mut want_doors = true;
|
||||||
match builder_roll {
|
match builder_roll {
|
||||||
1 => builder.start_with(CellularAutomataBuilder::new()),
|
1 => builder.start_with(CellularAutomataBuilder::new()),
|
||||||
2 => builder.start_with(DrunkardsWalkBuilder::open_area()),
|
2 => builder.start_with(DrunkardsWalkBuilder::open_area()),
|
||||||
|
|
@ -259,7 +260,10 @@ fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Bui
|
||||||
4 => builder.start_with(DrunkardsWalkBuilder::winding_passages()),
|
4 => builder.start_with(DrunkardsWalkBuilder::winding_passages()),
|
||||||
5 => builder.start_with(DrunkardsWalkBuilder::fat_passages()),
|
5 => builder.start_with(DrunkardsWalkBuilder::fat_passages()),
|
||||||
6 => builder.start_with(DrunkardsWalkBuilder::fearful_symmetry()),
|
6 => builder.start_with(DrunkardsWalkBuilder::fearful_symmetry()),
|
||||||
7 => builder.start_with(MazeBuilder::new()),
|
7 => {
|
||||||
|
builder.start_with(MazeBuilder::new());
|
||||||
|
want_doors = false;
|
||||||
|
}
|
||||||
8 => builder.start_with(DLABuilder::walk_inwards()),
|
8 => builder.start_with(DLABuilder::walk_inwards()),
|
||||||
9 => builder.start_with(DLABuilder::walk_outwards()),
|
9 => builder.start_with(DLABuilder::walk_outwards()),
|
||||||
10 => builder.start_with(DLABuilder::central_attractor()),
|
10 => builder.start_with(DLABuilder::central_attractor()),
|
||||||
|
|
@ -280,6 +284,8 @@ fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Bui
|
||||||
// Place the exit and spawn mobs
|
// Place the exit and spawn mobs
|
||||||
builder.with(VoronoiSpawning::new());
|
builder.with(VoronoiSpawning::new());
|
||||||
builder.with(DistantExit::new());
|
builder.with(DistantExit::new());
|
||||||
|
|
||||||
|
return want_doors;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_builder(
|
pub fn random_builder(
|
||||||
|
|
@ -292,9 +298,10 @@ pub fn random_builder(
|
||||||
rltk::console::log(format!("DEBUGINFO: Building random (ID:{}, DIFF:{})", new_id, difficulty));
|
rltk::console::log(format!("DEBUGINFO: Building random (ID:{}, DIFF:{})", new_id, difficulty));
|
||||||
let mut builder = BuilderChain::new(new_id, width, height, difficulty);
|
let mut builder = BuilderChain::new(new_id, width, height, difficulty);
|
||||||
let type_roll = rng.roll_dice(1, 2);
|
let type_roll = rng.roll_dice(1, 2);
|
||||||
|
let mut want_doors = true;
|
||||||
match type_roll {
|
match type_roll {
|
||||||
1 => random_room_builder(rng, &mut builder),
|
1 => random_room_builder(rng, &mut builder),
|
||||||
_ => random_shape_builder(rng, &mut builder),
|
_ => want_doors = random_shape_builder(rng, &mut builder),
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -314,11 +321,14 @@ pub fn random_builder(
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if want_doors {
|
||||||
builder.with(DoorPlacement::new());
|
builder.with(DoorPlacement::new());
|
||||||
|
}
|
||||||
|
|
||||||
if rng.roll_dice(1, 20) == 1 {
|
if rng.roll_dice(1, 20) == 1 {
|
||||||
builder.with(PrefabBuilder::sectional(prefab_builder::prefab_sections::UNDERGROUND_FORT));
|
builder.with(PrefabBuilder::sectional(prefab_builder::prefab_sections::UNDERGROUND_FORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.with(PrefabBuilder::vaults());
|
builder.with(PrefabBuilder::vaults());
|
||||||
// Regardless of anything else, fill the edges back in with walls. We can't walk
|
// Regardless of anything else, fill the edges back in with walls. We can't walk
|
||||||
// there anyway, and we don't want an open line of sight into the unmapped void.
|
// there anyway, and we don't want an open line of sight into the unmapped void.
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ pub fn try_door(i: i32, j: i32, ecs: &mut World) -> RunState {
|
||||||
if let Some(name) = names.get(*potential_target) {
|
if let Some(name) = names.get(*potential_target) {
|
||||||
gamelog::Logger::new().append("The").item_name(&name.name).append("is blocked.").log();
|
gamelog::Logger::new().append("The").item_name(&name.name).append("is blocked.").log();
|
||||||
}
|
}
|
||||||
} else if rng.roll_dice(1, 6) + attributes.strength.bonus < 5 {
|
} else if rng.roll_dice(1, 6) + attributes.strength.bonus < 2 {
|
||||||
if let Some(name) = names.get(*potential_target) {
|
if let Some(name) = names.get(*potential_target) {
|
||||||
gamelog::Logger::new().append("The").item_name(&name.name).append("resists!").log();
|
gamelog::Logger::new().append("The").item_name(&name.name).append("resists!").log();
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +124,7 @@ pub fn open(i: i32, j: i32, ecs: &mut World) -> RunState {
|
||||||
let door = doors.get_mut(*potential_target);
|
let door = doors.get_mut(*potential_target);
|
||||||
if let Some(door) = door {
|
if let Some(door) = door {
|
||||||
if door.open == false {
|
if door.open == false {
|
||||||
if rng.roll_dice(1, 6) + attributes.strength.bonus < 5 {
|
if rng.roll_dice(1, 6) + attributes.strength.bonus < 2 {
|
||||||
if let Some(name) = names.get(*potential_target) {
|
if let Some(name) = names.get(*potential_target) {
|
||||||
gamelog::Logger::new().append("The").item_name(&name.name).append("resists!").log();
|
gamelog::Logger::new().append("The").item_name(&name.name).append("resists!").log();
|
||||||
}
|
}
|
||||||
|
|
@ -213,8 +213,8 @@ pub fn kick(i: i32, j: i32, ecs: &mut World) -> RunState {
|
||||||
if door.open == false {
|
if door.open == false {
|
||||||
let mut particle_builder = ecs.write_resource::<ParticleBuilder>();
|
let mut particle_builder = ecs.write_resource::<ParticleBuilder>();
|
||||||
particle_builder.kick(pos.x + delta_x, pos.y + delta_y);
|
particle_builder.kick(pos.x + delta_x, pos.y + delta_y);
|
||||||
// 33% chance of breaking it down + str
|
// ~33% chance of breaking it down + str
|
||||||
if rng.roll_dice(1, 6) + attributes.strength.bonus > 4 {
|
if rng.roll_dice(1, 10) + attributes.strength.bonus > 6 {
|
||||||
gamelog::Logger::new()
|
gamelog::Logger::new()
|
||||||
.append("As you kick the")
|
.append("As you kick the")
|
||||||
.item_name_n(target_name)
|
.item_name_n(target_name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue