diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 71d4113585..6d9785f924 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -83,7 +83,7 @@ impl Alignment { } } - // Never attacks + // Usually never attacks pub fn passive_towards(self, other: Alignment) -> bool { match (self, other) { (Alignment::Enemy, Alignment::Enemy) => true, @@ -98,6 +98,20 @@ impl Alignment { _ => false, } } + + // Never attacks + pub fn friendly_towards(self, other: Alignment) -> bool { + match (self, other) { + (Alignment::Enemy, Alignment::Enemy) => true, + (Alignment::Owned(a), Alignment::Owned(b)) if a == b => true, + (Alignment::Npc, Alignment::Npc) => true, + (Alignment::Npc, Alignment::Tame) => true, + (Alignment::Tame, Alignment::Npc) => true, + (Alignment::Tame, Alignment::Tame) => true, + (_, Alignment::Passive) => true, + _ => false, + } + } } impl Component for Alignment { diff --git a/server/agent/src/action_nodes.rs b/server/agent/src/action_nodes.rs index 4a5e1ee192..031d6bb369 100644 --- a/server/agent/src/action_nodes.rs +++ b/server/agent/src/action_nodes.rs @@ -1632,6 +1632,7 @@ impl<'a> AgentData<'a> { pub fn is_hunting_animal(&self, entity: EcsEntity, read_data: &ReadData) -> bool { (entity != *self.entity) + && !self.friendly_towards(entity, read_data) && matches!(read_data.bodies.get(entity), Some(Body::QuadrupedSmall(_))) } @@ -1667,6 +1668,16 @@ impl<'a> AgentData<'a> { } } + fn friendly_towards(&self, entity: EcsEntity, read_data: &ReadData) -> bool { + if let (Some(self_alignment), Some(other_alignment)) = + (self.alignment, read_data.alignments.get(entity)) + { + self_alignment.friendly_towards(*other_alignment) + } else { + false + } + } + pub fn can_see_entity( &self, agent: &Agent,