mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Don't hunt friendly animals
This commit is contained in:
parent
c8d0443111
commit
082bcdb755
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user