mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move stay position to agent
This commit is contained in:
parent
2cb8e2ca84
commit
4bdbb3ff6b
@ -54,7 +54,6 @@ hud-mine-needs_unhandled_case = Needs ???
|
||||
hud-talk = Talk
|
||||
hud-trade = Trade
|
||||
hud-mount = Mount
|
||||
hud-stay = Stay
|
||||
hud-follow = Follow
|
||||
hud-stay-follow = Stay/Follow
|
||||
hud-sit = Sit
|
||||
hud-steer = Steer
|
||||
|
@ -46,7 +46,6 @@ macro_rules! synced_components {
|
||||
beam_segment: BeamSegment,
|
||||
alignment: Alignment,
|
||||
stance: Stance,
|
||||
pet_state: PetState,
|
||||
// TODO: change this to `SyncFrom::ClientEntity` and sync the bare minimum
|
||||
// from other entities (e.g. just keys needed to show appearance
|
||||
// based on their loadout). Also, it looks like this actually has
|
||||
@ -74,7 +73,6 @@ macro_rules! reexport_comps {
|
||||
($($name:ident: $type:ident,)*) => {
|
||||
mod inner {
|
||||
pub use common::comp::*;
|
||||
pub use common::comp::pet::PetState;
|
||||
use common::link::Is;
|
||||
use common::mounting::{Mount, Rider, VolumeRider};
|
||||
// We alias these because the identifier used for the
|
||||
@ -106,11 +104,6 @@ synced_components!(reexport_comps);
|
||||
|
||||
use crate::sync::{NetSync, SyncFrom};
|
||||
|
||||
// These are synced from any entity within range.
|
||||
impl NetSync for PetState {
|
||||
const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity;
|
||||
}
|
||||
|
||||
impl NetSync for Body {
|
||||
const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity;
|
||||
}
|
||||
|
@ -594,6 +594,7 @@ pub struct Agent {
|
||||
/// required and reset each time the flee timer is reset.
|
||||
pub flee_from_pos: Option<Pos>,
|
||||
pub awareness: Awareness,
|
||||
pub stay_pos: Option<Pos>,
|
||||
/// Inputs sent up to rtsim
|
||||
pub rtsim_outbox: Option<VecDeque<NpcInput>>,
|
||||
}
|
||||
@ -699,6 +700,7 @@ impl Agent {
|
||||
sounds_heard: Vec::new(),
|
||||
position_pid_controller: None,
|
||||
flee_from_pos: None,
|
||||
stay_pos: None,
|
||||
awareness: Awareness::new(0.0),
|
||||
rtsim_outbox: None,
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::comp::{body::Body, phys::Mass, quadruped_medium, quadruped_small, Pos};
|
||||
use crate::comp::{body::Body, phys::Mass, quadruped_medium, quadruped_small};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specs::{Component, DerefFlaggedStorage};
|
||||
use specs::Component;
|
||||
use std::{num::NonZeroU64, sync::Arc};
|
||||
|
||||
pub type PetId = AtomicCell<Option<NonZeroU64>>;
|
||||
@ -108,12 +107,3 @@ impl Component for Pet {
|
||||
// isn't worth using `DenseVecStorage` here.
|
||||
type Storage = specs::VecStorage<Self>;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
|
||||
pub struct PetState {
|
||||
pub stay_pos: Option<Pos>,
|
||||
}
|
||||
|
||||
impl Component for PetState {
|
||||
type Storage = DerefFlaggedStorage<Self>;
|
||||
}
|
||||
|
@ -203,7 +203,6 @@ impl State {
|
||||
ecs.register::<Is<Mount>>();
|
||||
ecs.register::<Is<Rider>>();
|
||||
ecs.register::<Is<VolumeRider>>();
|
||||
ecs.register::<comp::pet::PetState>();
|
||||
ecs.register::<comp::Mass>();
|
||||
ecs.register::<comp::Density>();
|
||||
ecs.register::<comp::Collider>();
|
||||
|
@ -12,7 +12,6 @@ use common::{
|
||||
},
|
||||
slot::EquipSlot,
|
||||
},
|
||||
pet::PetState,
|
||||
ActiveAbilities, Alignment, Body, CharacterState, Combo, Energy, Health, Inventory,
|
||||
LightEmitter, LootOwner, Ori, PhysicsState, Poise, Pos, Presence, Scale, SkillSet, Stance,
|
||||
Stats, Vel,
|
||||
@ -53,7 +52,6 @@ pub struct AgentData<'a> {
|
||||
pub light_emitter: Option<&'a LightEmitter>,
|
||||
pub glider_equipped: bool,
|
||||
pub is_gliding: bool,
|
||||
pub stay_pos: Option<Pos>,
|
||||
pub health: Option<&'a Health>,
|
||||
pub char_state: &'a CharacterState,
|
||||
pub active_abilities: &'a ActiveAbilities,
|
||||
@ -349,7 +347,6 @@ pub struct ReadData<'a> {
|
||||
pub is_mounts: ReadStorage<'a, Is<Mount>>,
|
||||
pub is_riders: ReadStorage<'a, Is<Rider>>,
|
||||
pub is_volume_riders: ReadStorage<'a, Is<VolumeRider>>,
|
||||
pub pet_states: ReadStorage<'a, PetState>,
|
||||
pub time_of_day: Read<'a, TimeOfDay>,
|
||||
pub light_emitter: ReadStorage<'a, LightEmitter>,
|
||||
#[cfg(feature = "worldgen")]
|
||||
|
@ -10,7 +10,7 @@ use common::{
|
||||
inventory::slot::EquipSlot,
|
||||
item::{flatten_counted_items, MaterialStatManifest},
|
||||
loot_owner::LootOwnerKind,
|
||||
pet::{is_mountable, PetState},
|
||||
pet::is_mountable,
|
||||
tool::{AbilityMap, ToolKind},
|
||||
Inventory, LootOwner, Pos, SkillGroupKind,
|
||||
},
|
||||
@ -134,7 +134,7 @@ pub fn handle_mount(server: &mut Server, rider: EcsEntity, mount: EcsEntity) {
|
||||
|
||||
let is_stay = state
|
||||
.ecs()
|
||||
.read_storage::<PetState>()
|
||||
.read_storage::<comp::Agent>()
|
||||
.get(mount)
|
||||
.and_then(|x| x.stay_pos)
|
||||
.is_some();
|
||||
@ -225,7 +225,7 @@ pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: Ec
|
||||
}
|
||||
let prev_pet_pos = state
|
||||
.ecs()
|
||||
.read_storage::<PetState>()
|
||||
.read_storage::<comp::Agent>()
|
||||
.get(pet)
|
||||
.and_then(|s| s.stay_pos);
|
||||
let mut new_pet_pos = None;
|
||||
@ -236,12 +236,11 @@ pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: Ec
|
||||
&& within_mounting_range(positions.get(command_giver), positions.get(pet))
|
||||
&& state.ecs().read_storage::<Is<Mount>>().get(pet).is_none()
|
||||
{
|
||||
let _ = state
|
||||
state
|
||||
.ecs()
|
||||
.write_storage::<PetState>()
|
||||
.insert(pet, PetState {
|
||||
stay_pos: new_pet_pos,
|
||||
});
|
||||
.write_storage::<comp::Agent>()
|
||||
.get_mut(pet)
|
||||
.map(|s| s.stay_pos = new_pet_pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@ impl<'a> System<'a> for Sys {
|
||||
!&read_data.is_mounts,
|
||||
read_data.is_riders.maybe(),
|
||||
read_data.is_volume_riders.maybe(),
|
||||
read_data.pet_states.maybe(),
|
||||
),
|
||||
)
|
||||
.par_join()
|
||||
@ -96,7 +95,7 @@ impl<'a> System<'a> for Sys {
|
||||
light_emitter,
|
||||
group,
|
||||
rtsim_entity,
|
||||
(_, is_rider, is_volume_rider, pet_state),
|
||||
(_, is_rider, is_volume_rider),
|
||||
)| {
|
||||
let mut event_emitter = event_bus.emitter();
|
||||
let mut rng = thread_rng();
|
||||
@ -160,8 +159,6 @@ impl<'a> System<'a> for Sys {
|
||||
matches!(&*item.kind(), comp::item::ItemKind::Glider)
|
||||
});
|
||||
|
||||
let stay_pos = pet_state.and_then(|s| s.stay_pos);
|
||||
|
||||
let is_gliding = matches!(
|
||||
read_data.char_states.get(entity),
|
||||
Some(CharacterState::GlideWield(_) | CharacterState::Glide(_))
|
||||
@ -232,7 +229,6 @@ impl<'a> System<'a> for Sys {
|
||||
light_emitter,
|
||||
glider_equipped,
|
||||
is_gliding,
|
||||
stay_pos,
|
||||
health: read_data.healths.get(entity),
|
||||
char_state,
|
||||
active_abilities,
|
||||
|
@ -406,11 +406,11 @@ fn do_pickup_loot(bdata: &mut BehaviorData) -> bool {
|
||||
fn follow_if_far_away(bdata: &mut BehaviorData) -> bool {
|
||||
if let Some(Target { target, .. }) = bdata.agent.target {
|
||||
if let Some(tgt_pos) = bdata.read_data.positions.get(target) {
|
||||
let stay = bdata.agent_data.stay_pos.is_some();
|
||||
let stay = bdata.agent.stay_pos.is_some();
|
||||
if stay {
|
||||
let stay_pos = bdata.agent_data.stay_pos.map_or(Pos(Vec3::zero()), |v| v);
|
||||
let stay_pos = bdata.agent.stay_pos.map_or(Pos(Vec3::zero()), |v| v);
|
||||
let distance_from_stay = stay_pos.0.distance_squared(bdata.agent_data.pos.0);
|
||||
|
||||
bdata.controller.push_action(ControlAction::Sit);
|
||||
if distance_from_stay > (MAX_STAY_DISTANCE).powi(2) {
|
||||
bdata.agent_data.follow(
|
||||
bdata.agent,
|
||||
@ -421,6 +421,7 @@ fn follow_if_far_away(bdata: &mut BehaviorData) -> bool {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
bdata.controller.push_action(ControlAction::Stand);
|
||||
let dist_sqrd = bdata.agent_data.pos.0.distance_squared(tgt_pos.0);
|
||||
if dist_sqrd > (MAX_PATROL_DIST * bdata.agent.psyche.idle_wander_factor).powi(2) {
|
||||
bdata.agent_data.follow(
|
||||
@ -449,7 +450,7 @@ fn attack_if_owner_hurt(bdata: &mut BehaviorData) -> bool {
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let stay = bdata.agent_data.stay_pos.is_some();
|
||||
let stay = bdata.agent.stay_pos.is_some();
|
||||
if owner_recently_attacked && !stay {
|
||||
bdata.agent_data.attack_target_attacker(
|
||||
bdata.agent,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use common::{
|
||||
comp::{pet::PetState, Alignment, Pet, PhysicsState, Pos},
|
||||
comp::{Agent, Alignment, Pet, PhysicsState, Pos},
|
||||
terrain::TerrainGrid,
|
||||
uid::IdMaps,
|
||||
};
|
||||
@ -16,7 +16,7 @@ impl<'a> System<'a> for Sys {
|
||||
WriteStorage<'a, Pos>,
|
||||
ReadStorage<'a, Alignment>,
|
||||
ReadStorage<'a, Pet>,
|
||||
ReadStorage<'a, PetState>,
|
||||
ReadStorage<'a, Agent>,
|
||||
ReadStorage<'a, PhysicsState>,
|
||||
Read<'a, IdMaps>,
|
||||
);
|
||||
@ -27,7 +27,7 @@ impl<'a> System<'a> for Sys {
|
||||
|
||||
fn run(
|
||||
_job: &mut Job<Self>,
|
||||
(entities, terrain, mut positions, alignments, pets, pet_state, physics, id_maps): Self::SystemData,
|
||||
(entities, terrain, mut positions, alignments, pets, agn, physics, id_maps): Self::SystemData,
|
||||
) {
|
||||
const LOST_PET_DISTANCE_THRESHOLD: f32 = 200.0;
|
||||
|
||||
@ -58,10 +58,7 @@ impl<'a> System<'a> for Sys {
|
||||
.collect();
|
||||
|
||||
for (pet_entity, owner_pos) in lost_pets.iter() {
|
||||
let stay = pet_state
|
||||
.get(*pet_entity)
|
||||
.and_then(|f| f.stay_pos)
|
||||
.is_some();
|
||||
let stay = agn.get(*pet_entity).and_then(|x| x.stay_pos).is_some();
|
||||
if let Some(mut pet_pos) = positions.get_mut(*pet_entity) && !stay{
|
||||
// Move the pets to their owner's position
|
||||
// TODO: Create a teleportation event to handle this instead of
|
||||
|
@ -1504,7 +1504,6 @@ impl Hud {
|
||||
let alignments = ecs.read_storage::<comp::Alignment>();
|
||||
let is_mounts = ecs.read_storage::<Is<Mount>>();
|
||||
let is_riders = ecs.read_storage::<Is<Rider>>();
|
||||
let pet_state = ecs.read_storage::<comp::pet::PetState>();
|
||||
let stances = ecs.read_storage::<comp::Stance>();
|
||||
let time = ecs.read_resource::<Time>();
|
||||
|
||||
@ -2426,24 +2425,16 @@ impl Hud {
|
||||
));
|
||||
if !client.is_riding()
|
||||
&& is_mountable(body, bodies.get(client.entity()))
|
||||
&& pet_state.get(entity).and_then(|st| st.stay_pos).is_none()
|
||||
{
|
||||
options.push((
|
||||
GameInput::Mount,
|
||||
i18n.get_msg("hud-mount").to_string(),
|
||||
));
|
||||
}
|
||||
if pet_state.get(entity).and_then(|st| st.stay_pos).is_some() {
|
||||
options.push((
|
||||
GameInput::StayFollow,
|
||||
i18n.get_msg("hud-follow").to_string(),
|
||||
));
|
||||
} else {
|
||||
options.push((
|
||||
GameInput::StayFollow,
|
||||
i18n.get_msg("hud-stay").to_string(),
|
||||
));
|
||||
}
|
||||
options.push((
|
||||
GameInput::StayFollow,
|
||||
i18n.get_msg("hud-stay-follow").to_string(),
|
||||
));
|
||||
}
|
||||
options
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user