mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix awareness changes.
This commit is contained in:
parent
571b07d54a
commit
95fd092e26
@ -582,8 +582,7 @@ impl Awareness {
|
|||||||
pub fn reached(&self) -> bool { self.reached }
|
pub fn reached(&self) -> bool { self.reached }
|
||||||
|
|
||||||
pub fn change_by(&mut self, amount: f32) {
|
pub fn change_by(&mut self, amount: f32) {
|
||||||
let change = amount;
|
self.level = (self.level + amount).clamp(Self::UNAWARE, Self::ALERT);
|
||||||
self.level = (self.level + change).clamp(Self::UNAWARE, Self::ALERT);
|
|
||||||
|
|
||||||
if self.state() == AwarenessState::Alert {
|
if self.state() == AwarenessState::Alert {
|
||||||
self.reached = true;
|
self.reached = true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
consts::{
|
consts::{
|
||||||
AVG_FOLLOW_DIST, DEFAULT_ATTACK_RANGE, IDLE_HEALING_ITEM_THRESHOLD, PARTIAL_PATH_DIST,
|
AVG_FOLLOW_DIST, DEFAULT_ATTACK_RANGE, IDLE_HEALING_ITEM_THRESHOLD, PARTIAL_PATH_DIST,
|
||||||
SEPARATION_BIAS, SEPARATION_DIST, STD_AWARENESS_DECREMENT,
|
SEPARATION_BIAS, SEPARATION_DIST, STD_AWARENESS_DECAY_RATE,
|
||||||
},
|
},
|
||||||
data::{AgentData, AttackData, Path, ReadData, Tactic, TargetData},
|
data::{AgentData, AttackData, Path, ReadData, Tactic, TargetData},
|
||||||
util::{
|
util::{
|
||||||
@ -167,7 +167,9 @@ impl<'a> AgentData<'a> {
|
|||||||
TimerIdle = 0,
|
TimerIdle = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
agent.awareness.change_by(STD_AWARENESS_DECREMENT);
|
agent
|
||||||
|
.awareness
|
||||||
|
.change_by(STD_AWARENESS_DECAY_RATE * read_data.dt.0);
|
||||||
|
|
||||||
// Light lanterns at night
|
// Light lanterns at night
|
||||||
// TODO Add a method to turn on NPC lanterns underground
|
// TODO Add a method to turn on NPC lanterns underground
|
||||||
@ -700,9 +702,7 @@ impl<'a> AgentData<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let is_detected = |entity: EcsEntity, e_pos: &Pos| {
|
let is_detected = |entity: EcsEntity, e_pos: &Pos| {
|
||||||
let chance = thread_rng().gen_bool(0.3);
|
self.can_sense_directly_near(e_pos)
|
||||||
|
|
||||||
(self.can_sense_directly_near(e_pos) && chance)
|
|
||||||
|| self.can_see_entity(agent, controller, entity, e_pos, read_data)
|
|| self.can_see_entity(agent, controller, entity, e_pos, read_data)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1548,7 +1548,8 @@ impl<'a> AgentData<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn can_sense_directly_near(&self, e_pos: &Pos) -> bool {
|
pub fn can_sense_directly_near(&self, e_pos: &Pos) -> bool {
|
||||||
e_pos.0.distance_squared(self.pos.0) < 5_f32.powi(2)
|
let chance = thread_rng().gen_bool(0.3);
|
||||||
|
e_pos.0.distance_squared(self.pos.0) < 5_f32.powi(2) && chance
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn menacing(
|
pub fn menacing(
|
||||||
|
@ -14,4 +14,4 @@ pub const RETARGETING_THRESHOLD_SECONDS: f64 = 10.0;
|
|||||||
pub const HEALING_ITEM_THRESHOLD: f32 = 0.5;
|
pub const HEALING_ITEM_THRESHOLD: f32 = 0.5;
|
||||||
pub const IDLE_HEALING_ITEM_THRESHOLD: f32 = 0.999;
|
pub const IDLE_HEALING_ITEM_THRESHOLD: f32 = 0.999;
|
||||||
pub const DEFAULT_ATTACK_RANGE: f32 = 2.0;
|
pub const DEFAULT_ATTACK_RANGE: f32 = 2.0;
|
||||||
pub const STD_AWARENESS_DECREMENT: f32 = -0.001;
|
pub const STD_AWARENESS_DECAY_RATE: f32 = -0.05;
|
||||||
|
@ -28,7 +28,7 @@ use super::{
|
|||||||
consts::{
|
consts::{
|
||||||
DAMAGE_MEMORY_DURATION, FLEE_DURATION, HEALING_ITEM_THRESHOLD, MAX_FOLLOW_DIST,
|
DAMAGE_MEMORY_DURATION, FLEE_DURATION, HEALING_ITEM_THRESHOLD, MAX_FOLLOW_DIST,
|
||||||
NORMAL_FLEE_DIR_DIST, NPC_PICKUP_RANGE, RETARGETING_THRESHOLD_SECONDS,
|
NORMAL_FLEE_DIR_DIST, NPC_PICKUP_RANGE, RETARGETING_THRESHOLD_SECONDS,
|
||||||
STD_AWARENESS_DECREMENT,
|
STD_AWARENESS_DECAY_RATE,
|
||||||
},
|
},
|
||||||
data::{AgentData, ReadData, TargetData},
|
data::{AgentData, ReadData, TargetData},
|
||||||
util::{get_entity_by_id, is_dead, is_dead_or_invulnerable, is_invulnerable, stop_pursuing},
|
util::{get_entity_by_id, is_dead, is_dead_or_invulnerable, is_invulnerable, stop_pursuing},
|
||||||
@ -534,17 +534,19 @@ fn update_target_awareness(bdata: &mut BehaviorData) -> bool {
|
|||||||
let tgt_pos = target.and_then(|t| read_data.positions.get(t));
|
let tgt_pos = target.and_then(|t| read_data.positions.get(t));
|
||||||
|
|
||||||
if let (Some(target), Some(tgt_pos)) = (target, tgt_pos) {
|
if let (Some(target), Some(tgt_pos)) = (target, tgt_pos) {
|
||||||
let perceives_target = agent_data
|
if agent_data.can_see_entity(agent, controller, target, tgt_pos, read_data) {
|
||||||
.can_see_entity(agent, controller, target, tgt_pos, read_data)
|
agent.awareness.change_by(1.75 * read_data.dt.0);
|
||||||
|| agent_data.can_sense_directly_near(tgt_pos);
|
} else if agent_data.can_sense_directly_near(tgt_pos) {
|
||||||
|
agent.awareness.change_by(0.25);
|
||||||
if perceives_target {
|
|
||||||
agent.awareness.change_by(0.04);
|
|
||||||
} else {
|
} else {
|
||||||
agent.awareness.change_by(STD_AWARENESS_DECREMENT);
|
agent
|
||||||
|
.awareness
|
||||||
|
.change_by(STD_AWARENESS_DECAY_RATE * read_data.dt.0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
agent.awareness.change_by(STD_AWARENESS_DECREMENT);
|
agent
|
||||||
|
.awareness
|
||||||
|
.change_by(STD_AWARENESS_DECAY_RATE * read_data.dt.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if bdata.agent.awareness.state() == AwarenessState::Unaware {
|
if bdata.agent.awareness.state() == AwarenessState::Unaware {
|
||||||
|
Loading…
Reference in New Issue
Block a user