blindness - misc
This commit is contained in:
parent
1714b94397
commit
cfe5884a0b
13 changed files with 47 additions and 23 deletions
|
|
@ -64,28 +64,40 @@ impl<'a> System<'a> for VisibleAI {
|
||||||
// If we didn't already evaluate this idx (if it's not contained in the HashSet),
|
// If we didn't already evaluate this idx (if it's not contained in the HashSet),
|
||||||
// and it's not the idx we're standing on, then evaluate here w/ minds taken into
|
// and it's not the idx we're standing on, then evaluate here w/ minds taken into
|
||||||
// account.
|
// account.
|
||||||
if this_idx != idx && idxs.contains(&idx) {
|
if this_idx != idx && !idxs.contains(&idx) {
|
||||||
evaluate(entity, idx, &ancestries, &factions, &mut reactions, Some(&minds));
|
evaluate(entity, idx, &ancestries, &factions, &mut reactions, Some(&minds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut done = false;
|
reactions.sort_by(|(a, _, _), (b, _, _)| {
|
||||||
|
let (a_x, a_y) = (a % map.width as usize, a / map.width as usize);
|
||||||
|
let dist_a = DistanceAlg::PythagorasSquared.distance2d(Point::new(a_x, a_y), Point::new(pos.x, pos.y));
|
||||||
|
let dist_a_estimate = dist_a as i32;
|
||||||
|
let (b_x, b_y) = (b % map.width as usize, b / map.width as usize);
|
||||||
|
let dist_b = DistanceAlg::PythagorasSquared.distance2d(Point::new(b_x, b_y), Point::new(pos.x, pos.y));
|
||||||
|
let dist_b_estimate = dist_b as i32;
|
||||||
|
return dist_b_estimate.cmp(&dist_a_estimate);
|
||||||
|
});
|
||||||
|
let mut found_flee = false;
|
||||||
for reaction in reactions.iter() {
|
for reaction in reactions.iter() {
|
||||||
match reaction.1 {
|
match reaction.1 {
|
||||||
Reaction::Attack => {
|
Reaction::Attack => {
|
||||||
wants_to_approach
|
if !found_flee {
|
||||||
.insert(entity, WantsToApproach { idx: reaction.0 as i32 })
|
wants_to_approach
|
||||||
.expect("Error inserting WantsToApproach");
|
.insert(entity, WantsToApproach { idx: reaction.0 as i32 })
|
||||||
chasing.insert(entity, Chasing { target: reaction.2 }).expect("Unable to insert Chasing");
|
.expect("Error inserting WantsToApproach");
|
||||||
done = true;
|
chasing.insert(entity, Chasing { target: reaction.2 }).expect("Unable to insert Chasing");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reaction::Flee => {
|
Reaction::Flee => {
|
||||||
flee.push(reaction.0);
|
flee.push(reaction.0);
|
||||||
|
found_flee = true;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !done && !flee.is_empty() {
|
if !flee.is_empty() {
|
||||||
wants_to_flee.insert(entity, WantsToFlee { indices: flee }).expect("Unable to insert");
|
wants_to_flee.insert(entity, WantsToFlee { indices: flee }).expect("Unable to insert");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +115,9 @@ fn evaluate(
|
||||||
crate::spatial::for_each_tile_content(idx, |other_entity| {
|
crate::spatial::for_each_tile_content(idx, |other_entity| {
|
||||||
let mut check = true;
|
let mut check = true;
|
||||||
if minds.is_some() {
|
if minds.is_some() {
|
||||||
|
console::log("Minds got passed! Evaluating!");
|
||||||
if minds.unwrap().get(other_entity).is_none() {
|
if minds.unwrap().get(other_entity).is_none() {
|
||||||
|
console::log("No brain here. Skipping!");
|
||||||
check = false;
|
check = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{add_effect, get_noncursed, targeting, EffectSpawner, EffectType, Entity, Targets, World};
|
use super::{add_effect, targeting, EffectSpawner, EffectType, Entity, Targets, World};
|
||||||
use crate::{
|
use crate::{
|
||||||
gamelog,
|
gamelog,
|
||||||
gamesystem::{hp_per_level, mana_per_level},
|
gamesystem::{hp_per_level, mana_per_level},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{EffectSpawner, EffectType};
|
use super::{EffectSpawner, EffectType};
|
||||||
use crate::{HungerClock, BUC};
|
use crate::HungerClock;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
||||||
pub fn modify_nutrition(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
|
pub fn modify_nutrition(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ pub enum EffectType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub enum Targets {
|
pub enum Targets {
|
||||||
Entity { target: Entity },
|
Entity { target: Entity },
|
||||||
EntityList { targets: Vec<Entity> },
|
EntityList { targets: Vec<Entity> },
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ impl Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends text in YELLOW to the current message logger.
|
/// Appends text in YELLOW to the current message logger.
|
||||||
|
#[allow(unused)]
|
||||||
pub fn npc_name<T: ToString>(mut self, text: T) -> Self {
|
pub fn npc_name<T: ToString>(mut self, text: T) -> Self {
|
||||||
let mut text_with_space = text.to_string();
|
let mut text_with_space = text.to_string();
|
||||||
text_with_space.push_str(" ");
|
text_with_space.push_str(" ");
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use super::{
|
use super::{
|
||||||
ai::CARRY_CAPACITY_PER_STRENGTH, camera, gamelog, gamesystem, hunger_system::get_hunger_colour,
|
ai::CARRY_CAPACITY_PER_STRENGTH, camera, gamelog, gamesystem, hunger_system::get_hunger_colour,
|
||||||
rex_assets::RexAssets, ArmourClassBonus, Attributes, Beatitude, Burden, Charges, Equipped, Hidden, HungerClock,
|
rex_assets::RexAssets, ArmourClassBonus, Attributes, Beatitude, Burden, Charges, Equipped, Hidden, HungerClock,
|
||||||
HungerState, InBackpack, MagicItem, MagicItemClass, Map, MasterDungeonMap, Name, ObfuscatedName, Player, Point,
|
HungerState, InBackpack, MagicItem, Map, MasterDungeonMap, Name, ObfuscatedName, Player, Point, Pools, Position,
|
||||||
Pools, Position, Prop, Renderable, RunState, Skill, Skills, State, Viewshed, BUC,
|
Prop, Renderable, RunState, Skill, Skills, State, Viewshed, BUC,
|
||||||
};
|
};
|
||||||
use rltk::prelude::*;
|
use rltk::prelude::*;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
@ -527,7 +527,7 @@ pub fn item_colour_ecs(ecs: &World, item: Entity) -> (u8, u8, u8) {
|
||||||
return WHITE;
|
return WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn item_colour(item: Entity, beatitudes: &ReadStorage<Beatitude>, dm: &MasterDungeonMap) -> (u8, u8, u8) {
|
pub fn item_colour(item: Entity, beatitudes: &ReadStorage<Beatitude>) -> (u8, u8, u8) {
|
||||||
if let Some(beatitude) = beatitudes.get(item) {
|
if let Some(beatitude) = beatitudes.get(item) {
|
||||||
if beatitude.known {
|
if beatitude.known {
|
||||||
match beatitude.buc {
|
match beatitude.buc {
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ impl<'a> System<'a> for ItemEquipSystem {
|
||||||
can_equip = false;
|
can_equip = false;
|
||||||
logger = logger
|
logger = logger
|
||||||
.append("You can't remove the")
|
.append("You can't remove the")
|
||||||
.colour(item_colour(item_entity, &beatitudes, &dm))
|
.colour(item_colour(item_entity, &beatitudes))
|
||||||
.append_n(
|
.append_n(
|
||||||
obfuscate_name(
|
obfuscate_name(
|
||||||
item_entity,
|
item_entity,
|
||||||
|
|
@ -94,7 +94,7 @@ impl<'a> System<'a> for ItemEquipSystem {
|
||||||
if target == *player_entity {
|
if target == *player_entity {
|
||||||
logger = logger
|
logger = logger
|
||||||
.append("You remove your")
|
.append("You remove your")
|
||||||
.colour(item_colour(*item, &beatitudes, &dm))
|
.colour(item_colour(*item, &beatitudes))
|
||||||
.append_n(
|
.append_n(
|
||||||
obfuscate_name(*item, &names, &magic_items, &obfuscated_names, &beatitudes, &dm, None)
|
obfuscate_name(*item, &names, &magic_items, &obfuscated_names, &beatitudes, &dm, None)
|
||||||
.0,
|
.0,
|
||||||
|
|
@ -112,7 +112,7 @@ impl<'a> System<'a> for ItemEquipSystem {
|
||||||
if target == *player_entity {
|
if target == *player_entity {
|
||||||
logger = logger
|
logger = logger
|
||||||
.append("You equip the")
|
.append("You equip the")
|
||||||
.colour(item_colour(wants_to_use_item.item, &beatitudes, &dm))
|
.colour(item_colour(wants_to_use_item.item, &beatitudes))
|
||||||
.append_n(
|
.append_n(
|
||||||
obfuscate_name(
|
obfuscate_name(
|
||||||
wants_to_use_item.item,
|
wants_to_use_item.item,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl<'a> System<'a> for ItemRemoveSystem {
|
||||||
can_remove = false;
|
can_remove = false;
|
||||||
gamelog::Logger::new()
|
gamelog::Logger::new()
|
||||||
.append("You can't remove the")
|
.append("You can't remove the")
|
||||||
.colour(item_colour(to_remove.item, &beatitudes, &dm))
|
.colour(item_colour(to_remove.item, &beatitudes))
|
||||||
.append_n(
|
.append_n(
|
||||||
obfuscate_name(
|
obfuscate_name(
|
||||||
to_remove.item,
|
to_remove.item,
|
||||||
|
|
@ -72,7 +72,7 @@ impl<'a> System<'a> for ItemRemoveSystem {
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
gamelog::Logger::new()
|
gamelog::Logger::new()
|
||||||
.append("You unequip the")
|
.append("You unequip the")
|
||||||
.colour(item_colour(to_remove.item, &beatitudes, &dm))
|
.colour(item_colour(to_remove.item, &beatitudes))
|
||||||
.append_n(
|
.append_n(
|
||||||
obfuscate_name(
|
obfuscate_name(
|
||||||
to_remove.item,
|
to_remove.item,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ pub struct Mob {
|
||||||
pub attributes: Option<MobAttributes>,
|
pub attributes: Option<MobAttributes>,
|
||||||
pub skills: Option<HashMap<String, i32>>,
|
pub skills: Option<HashMap<String, i32>>,
|
||||||
pub vision_range: i32,
|
pub vision_range: i32,
|
||||||
|
pub telepathy_range: Option<i32>,
|
||||||
pub equipped: Option<Vec<String>>,
|
pub equipped: Option<Vec<String>>,
|
||||||
pub loot: Option<LootTableInfo>,
|
pub loot: Option<LootTableInfo>,
|
||||||
pub quips: Option<Vec<String>>,
|
pub quips: Option<Vec<String>>,
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ macro_rules! apply_flags {
|
||||||
"SMALL_GROUP" => {} // These flags are for region spawning,
|
"SMALL_GROUP" => {} // These flags are for region spawning,
|
||||||
"LARGE_GROUP" => {} // and don't need to apply a component.
|
"LARGE_GROUP" => {} // and don't need to apply a component.
|
||||||
"MULTIATTACK" => $eb = $eb.with(MultiAttack {}),
|
"MULTIATTACK" => $eb = $eb.with(MultiAttack {}),
|
||||||
|
"BLIND" => $eb = $eb.with(Blind {}),
|
||||||
_ => rltk::console::log(format!("Unrecognised flag: {}", flag.as_str())),
|
_ => rltk::console::log(format!("Unrecognised flag: {}", flag.as_str())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -379,6 +380,9 @@ pub fn spawn_named_mob(
|
||||||
eb = spawn_position(pos, eb, key, raws);
|
eb = spawn_position(pos, eb, key, raws);
|
||||||
eb = eb.with(Name { name: mob_template.name.clone(), plural: mob_template.name.clone() });
|
eb = eb.with(Name { name: mob_template.name.clone(), plural: mob_template.name.clone() });
|
||||||
eb = eb.with(Viewshed { visible_tiles: Vec::new(), range: mob_template.vision_range, dirty: true });
|
eb = eb.with(Viewshed { visible_tiles: Vec::new(), range: mob_template.vision_range, dirty: true });
|
||||||
|
if let Some(telepath) = &mob_template.telepathy_range {
|
||||||
|
eb = eb.with(Telepath { telepath_tiles: Vec::new(), range: *telepath, dirty: true });
|
||||||
|
}
|
||||||
if let Some(renderable) = &mob_template.renderable {
|
if let Some(renderable) = &mob_template.renderable {
|
||||||
eb = eb.with(get_renderable_component(renderable));
|
eb = eb.with(get_renderable_component(renderable));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,10 @@ pub fn save_game(ecs: &mut World) {
|
||||||
AOE,
|
AOE,
|
||||||
ArmourClassBonus,
|
ArmourClassBonus,
|
||||||
Attributes,
|
Attributes,
|
||||||
|
Beatitude,
|
||||||
|
Blind,
|
||||||
BlocksTile,
|
BlocksTile,
|
||||||
BlocksVisibility,
|
BlocksVisibility,
|
||||||
Beatitude,
|
|
||||||
Burden,
|
Burden,
|
||||||
Chasing,
|
Chasing,
|
||||||
Clock,
|
Clock,
|
||||||
|
|
@ -178,9 +179,10 @@ pub fn load_game(ecs: &mut World) {
|
||||||
AOE,
|
AOE,
|
||||||
ArmourClassBonus,
|
ArmourClassBonus,
|
||||||
Attributes,
|
Attributes,
|
||||||
|
Beatitude,
|
||||||
|
Blind,
|
||||||
BlocksTile,
|
BlocksTile,
|
||||||
BlocksVisibility,
|
BlocksVisibility,
|
||||||
Beatitude,
|
|
||||||
Burden,
|
Burden,
|
||||||
Chasing,
|
Chasing,
|
||||||
Clock,
|
Clock,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{
|
use super::{
|
||||||
ai::NORMAL_SPEED, random_table::RandomTable, raws, Clock, Energy, EquipmentChanged, Faction, HungerClock,
|
ai::NORMAL_SPEED, random_table::RandomTable, raws, Clock, Energy, EquipmentChanged, Faction, HungerClock,
|
||||||
HungerState, Map, Name, Player, Position, Rect, Renderable, SerializeMe, Skill, Skills, TileType, Viewshed,
|
HungerState, Map, Mind, Name, Player, Position, Rect, Renderable, SerializeMe, Skill, Skills, TileType, Viewshed,
|
||||||
};
|
};
|
||||||
use rltk::{RandomNumberGenerator, RGB};
|
use rltk::{RandomNumberGenerator, RGB};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
@ -26,6 +26,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||||
render_order: 0,
|
render_order: 0,
|
||||||
})
|
})
|
||||||
.with(Player {})
|
.with(Player {})
|
||||||
|
.with(Mind {})
|
||||||
.with(Faction { name: "player".to_string() })
|
.with(Faction { name: "player".to_string() })
|
||||||
.with(Viewshed { visible_tiles: Vec::new(), range: 12, dirty: true })
|
.with(Viewshed { visible_tiles: Vec::new(), range: 12, dirty: true })
|
||||||
.with(Name { name: "you".to_string(), plural: "you".to_string() })
|
.with(Name { name: "you".to_string(), plural: "you".to_string() })
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl<'a> System<'a> for VisibilitySystem {
|
||||||
for (ent, viewshed, pos) in (&entities, &mut viewshed, &pos).join() {
|
for (ent, viewshed, pos) in (&entities, &mut viewshed, &pos).join() {
|
||||||
if viewshed.dirty {
|
if viewshed.dirty {
|
||||||
viewshed.dirty = false;
|
viewshed.dirty = false;
|
||||||
let mut range = if let Some(is_blind) = blind_entities.get(ent) { 1 } else { viewshed.range };
|
let range = if let Some(_is_blind) = blind_entities.get(ent) { 1 } else { viewshed.range };
|
||||||
let origin = Point::new(pos.x, pos.y);
|
let origin = Point::new(pos.x, pos.y);
|
||||||
viewshed.visible_tiles = SymmetricShadowcasting.field_of_view(origin, range, &*map);
|
viewshed.visible_tiles = SymmetricShadowcasting.field_of_view(origin, range, &*map);
|
||||||
viewshed.visible_tiles.retain(|p| {
|
viewshed.visible_tiles.retain(|p| {
|
||||||
|
|
@ -94,7 +94,7 @@ impl<'a> System<'a> for VisibilitySystem {
|
||||||
if telepath.dirty {
|
if telepath.dirty {
|
||||||
telepath.dirty = false;
|
telepath.dirty = false;
|
||||||
let mut range = telepath.range;
|
let mut range = telepath.range;
|
||||||
if let Some(is_blind) = blind_entities.get(ent) {
|
if let Some(_is_blind) = blind_entities.get(ent) {
|
||||||
range *= BLIND_TELEPATHY_RANGE_MULTIPLIER;
|
range *= BLIND_TELEPATHY_RANGE_MULTIPLIER;
|
||||||
}
|
}
|
||||||
telepath.telepath_tiles = fast_fov(pos.x, pos.y, range);
|
telepath.telepath_tiles = fast_fov(pos.x, pos.y, range);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue