veloren/common/src/comp/agent.rs

88 lines
1.8 KiB
Rust
Raw Normal View History

use crate::path::Chaser;
use specs::{Component, Entity as EcsEntity};
use specs_idvs::IDVStorage;
2019-07-29 19:54:58 +00:00
use vek::*;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Alignment {
Wild,
Enemy,
Npc,
Owned(EcsEntity),
}
impl Alignment {
// Always attacks
pub fn hostile_towards(self, other: Alignment) -> bool {
match (self, other) {
(Alignment::Enemy, Alignment::Enemy) => false,
(Alignment::Enemy, _) => true,
(_, Alignment::Enemy) => true,
_ => false,
}
}
// Never attacks
pub fn passive_towards(self, other: Alignment) -> bool {
match (self, other) {
(Alignment::Owned(a), Alignment::Owned(b)) if a == b => true,
_ => false,
}
}
}
impl Component for Alignment {
type Storage = IDVStorage<Self>;
}
#[derive(Clone, Debug, Default)]
pub struct Agent {
pub patrol_origin: Option<Vec3<f32>>,
2020-01-25 18:49:47 +00:00
pub activity: Activity,
}
impl Agent {
pub fn with_patrol_origin(mut self, origin: Vec3<f32>) -> Self {
self.patrol_origin = Some(origin);
self
}
}
impl Component for Agent {
type Storage = IDVStorage<Self>;
}
2020-01-25 18:49:47 +00:00
#[derive(Clone, Debug)]
pub enum Activity {
Idle(Vec2<f32>),
2020-01-25 18:49:47 +00:00
Follow(EcsEntity, Chaser),
Attack {
target: EcsEntity,
chaser: Chaser,
time: f64,
been_close: bool,
},
2020-01-25 18:49:47 +00:00
}
impl Activity {
pub fn is_follow(&self) -> bool {
match self {
Activity::Follow(_, _) => true,
_ => false,
}
}
pub fn is_attack(&self) -> bool {
match self {
Activity::Attack { .. } => true,
2020-01-25 18:49:47 +00:00
_ => false,
}
}
}
impl Default for Activity {
fn default() -> Self {
Activity::Idle(Vec2::zero())
2020-01-25 18:49:47 +00:00
}
}