mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'master' of gitlab.com:veloren/dev/veloren into holychowders/agent_awareness2
This commit is contained in:
commit
641a5c4cda
@ -68,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Fixed npcs using `/say` instead of `/tell`
|
||||
- Camera jittering in third person has been significantly reduced
|
||||
- Many water shader issues have been fixed
|
||||
- Flee if attacked even if attacker is not close.
|
||||
|
||||
## [0.13.0] - 2022-07-23
|
||||
|
||||
|
@ -14,7 +14,7 @@ use std::{collections::VecDeque, fmt};
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
use vek::*;
|
||||
|
||||
use super::dialogue::Subject;
|
||||
use super::{dialogue::Subject, Pos};
|
||||
|
||||
pub const DEFAULT_INTERACTION_TIME: f32 = 3.0;
|
||||
pub const TRADE_INTERACTION_TIME: f32 = 300.0;
|
||||
@ -529,6 +529,10 @@ pub struct Agent {
|
||||
pub bearing: Vec2<f32>,
|
||||
pub sounds_heard: Vec<Sound>,
|
||||
pub position_pid_controller: Option<PidController<fn(Vec3<f32>, Vec3<f32>) -> f32, 16>>,
|
||||
/// Position from which to flee. Intended to be the agent's position plus a
|
||||
/// random position offset, to be used when a random flee direction is
|
||||
/// required and reset each time the flee timer is reset.
|
||||
pub flee_from_pos: Option<Pos>,
|
||||
pub awareness: Awareness,
|
||||
}
|
||||
|
||||
@ -627,6 +631,7 @@ impl Agent {
|
||||
bearing: Vec2::zero(),
|
||||
sounds_heard: Vec::new(),
|
||||
position_pid_controller: None,
|
||||
flee_from_pos: None,
|
||||
awareness: Awareness::new(0.0),
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ pub const MAX_PATH_DIST: f32 = 170.0;
|
||||
pub const PARTIAL_PATH_DIST: f32 = 50.0;
|
||||
pub const SEPARATION_DIST: f32 = 10.0;
|
||||
pub const SEPARATION_BIAS: f32 = 0.8;
|
||||
pub const MAX_FLEE_DIST: f32 = 20.0;
|
||||
/// The distance within which agents will flee directly away if attacked from
|
||||
/// distance or if attacker detected.
|
||||
pub const NORMAL_FLEE_DIR_DIST: f32 = 20.0;
|
||||
pub const AVG_FOLLOW_DIST: f32 = 6.0;
|
||||
pub const RETARGETING_THRESHOLD_SECONDS: f64 = 10.0;
|
||||
pub const HEALING_ITEM_THRESHOLD: f32 = 0.5;
|
||||
|
@ -6,17 +6,17 @@ use common::{
|
||||
TRADE_INTERACTION_TIME,
|
||||
},
|
||||
Agent, Alignment, BehaviorCapability, BehaviorState, Body, BuffKind, ControlAction,
|
||||
ControlEvent, Controller, InputKind, InventoryEvent, UtteranceKind,
|
||||
ControlEvent, Controller, InputKind, InventoryEvent, Pos, UtteranceKind,
|
||||
},
|
||||
event::{Emitter, ServerEvent},
|
||||
path::TraversalConfig,
|
||||
};
|
||||
use rand::{prelude::ThreadRng, Rng};
|
||||
use rand::{prelude::ThreadRng, thread_rng, Rng};
|
||||
use specs::{
|
||||
saveload::{Marker, MarkerAllocator},
|
||||
Entity as EcsEntity,
|
||||
};
|
||||
use vek::Vec2;
|
||||
use vek::{Vec2, Vec3};
|
||||
|
||||
use self::interaction::{
|
||||
handle_inbox_cancel_interactions, handle_inbox_finished_trade, handle_inbox_talk,
|
||||
@ -26,8 +26,9 @@ use self::interaction::{
|
||||
|
||||
use super::{
|
||||
consts::{
|
||||
DAMAGE_MEMORY_DURATION, FLEE_DURATION, HEALING_ITEM_THRESHOLD, MAX_FLEE_DIST,
|
||||
MAX_FOLLOW_DIST, NPC_PICKUP_RANGE, RETARGETING_THRESHOLD_SECONDS, STD_AWARENESS_DECREMENT,
|
||||
DAMAGE_MEMORY_DURATION, FLEE_DURATION, HEALING_ITEM_THRESHOLD, MAX_FOLLOW_DIST,
|
||||
NORMAL_FLEE_DIR_DIST, NPC_PICKUP_RANGE, RETARGETING_THRESHOLD_SECONDS,
|
||||
STD_AWARENESS_DECREMENT,
|
||||
},
|
||||
data::{AgentData, ReadData, TargetData},
|
||||
util::{get_entity_by_id, is_dead, is_dead_or_invulnerable, is_invulnerable, stop_pursuing},
|
||||
@ -604,10 +605,10 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
|
||||
let aggro_on = *aggro_on;
|
||||
|
||||
if agent_data.below_flee_health(agent) {
|
||||
let has_opportunity_to_flee = agent.action_state.timers
|
||||
let flee_timer_done = agent.action_state.timers
|
||||
[ActionStateBehaviorTreeTimers::TimerBehaviorTree as usize]
|
||||
< FLEE_DURATION;
|
||||
let within_flee_distance = dist_sqrd < MAX_FLEE_DIST.powi(2);
|
||||
> FLEE_DURATION;
|
||||
let within_normal_flee_dir_dist = dist_sqrd < NORMAL_FLEE_DIR_DIST.powi(2);
|
||||
|
||||
// FIXME: Using action state timer to see if allowed to speak is a hack.
|
||||
if agent.action_state.timers
|
||||
@ -617,8 +618,21 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
|
||||
agent_data.cry_out(agent, event_emitter, read_data);
|
||||
agent.action_state.timers
|
||||
[ActionStateBehaviorTreeTimers::TimerBehaviorTree as usize] = 0.01;
|
||||
} else if within_flee_distance && has_opportunity_to_flee {
|
||||
agent_data.flee(agent, controller, tgt_pos, &read_data.terrain);
|
||||
agent.flee_from_pos = {
|
||||
let random = || thread_rng().gen_range(-1.0..1.0);
|
||||
Some(Pos(
|
||||
agent_data.pos.0 + Vec3::new(random(), random(), random())
|
||||
))
|
||||
};
|
||||
} else if !flee_timer_done {
|
||||
if within_normal_flee_dir_dist {
|
||||
agent_data.flee(agent, controller, tgt_pos, &read_data.terrain);
|
||||
} else if let Some(random_pos) = agent.flee_from_pos {
|
||||
agent_data.flee(agent, controller, &random_pos, &read_data.terrain);
|
||||
} else {
|
||||
agent_data.flee(agent, controller, tgt_pos, &read_data.terrain);
|
||||
}
|
||||
|
||||
agent.action_state.timers
|
||||
[ActionStateBehaviorTreeTimers::TimerBehaviorTree as usize] +=
|
||||
read_data.dt.0;
|
||||
@ -626,6 +640,7 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
|
||||
agent.action_state.timers
|
||||
[ActionStateBehaviorTreeTimers::TimerBehaviorTree as usize] = 0.0;
|
||||
agent.target = None;
|
||||
agent.flee_from_pos = None;
|
||||
agent_data.idle(agent, controller, read_data, rng);
|
||||
}
|
||||
} else if is_dead(target, read_data) {
|
||||
|
@ -412,7 +412,7 @@ impl SettingsChange {
|
||||
}
|
||||
},
|
||||
SettingsChange::Graphics(graphics_change) => {
|
||||
let mut change_all = false;
|
||||
let mut change_preset = false;
|
||||
|
||||
match graphics_change {
|
||||
Graphics::AdjustTerrainViewDistance(terrain_vd) => {
|
||||
@ -490,15 +490,23 @@ impl SettingsChange {
|
||||
},
|
||||
Graphics::ResetGraphicsSettings => {
|
||||
settings.graphics = GraphicsSettings::default();
|
||||
change_all = true;
|
||||
change_preset = true;
|
||||
// Fullscreen mode
|
||||
global_state
|
||||
.window
|
||||
.set_fullscreen_mode(settings.graphics.fullscreen);
|
||||
// Window size
|
||||
global_state
|
||||
.window
|
||||
.set_size(settings.graphics.window_size.into());
|
||||
},
|
||||
Graphics::ChangeGraphicsSettings(f) => {
|
||||
settings.graphics = f(settings.graphics.clone());
|
||||
change_all = true;
|
||||
change_preset = true;
|
||||
},
|
||||
}
|
||||
|
||||
if change_all {
|
||||
if change_preset {
|
||||
let graphics = &settings.graphics;
|
||||
// View distance
|
||||
client_set_view_distance(settings, session_state);
|
||||
@ -521,10 +529,6 @@ impl SettingsChange {
|
||||
.renderer_mut()
|
||||
.set_render_mode(graphics.render_mode.clone())
|
||||
.unwrap();
|
||||
// Fullscreen mode
|
||||
global_state.window.set_fullscreen_mode(graphics.fullscreen);
|
||||
// Window size
|
||||
global_state.window.set_size(graphics.window_size.into());
|
||||
}
|
||||
},
|
||||
SettingsChange::Interface(interface_change) => {
|
||||
|
Loading…
Reference in New Issue
Block a user