From 74048009990e814315f1c8fffde18cc718ce37d4 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 26 Jan 2020 01:11:32 +0000 Subject: [PATCH] Added neutral NPC spawning --- common/src/comp/agent.rs | 2 +- server/src/sys/terrain.rs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 41d6050381..2585c379eb 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -13,7 +13,7 @@ pub enum Alignment { impl Alignment { pub fn hostile_towards(self, other: Alignment) -> bool { match (self, other) { - (Alignment::Wild, Alignment::Npc) => true, + (Alignment::Wild, Alignment::Npc) => false, _ => self != other, } } diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 06fe790a2a..f20c21dc32 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -100,12 +100,18 @@ impl<'a> System<'a> for Sys { if let EntityKind::Waypoint = entity.kind { server_emitter.emit(ServerEvent::CreateWaypoint(entity.pos)); } else { - const SPAWN_NPCS: &'static [fn() -> (String, comp::Body, Option)] = &[ + const SPAWN_NPCS: &'static [fn() -> ( + String, + comp::Body, + Option, + comp::Alignment, + )] = &[ (|| { ( "Traveler".into(), comp::Body::Humanoid(comp::humanoid::Body::random()), Some(assets::load_expect_cloned("common.items.weapons.staff_1")), + comp::Alignment::Enemy, ) }) as _, (|| { @@ -113,6 +119,7 @@ impl<'a> System<'a> for Sys { "Wolf".into(), comp::Body::QuadrupedMedium(comp::quadruped_medium::Body::random()), None, + comp::Alignment::Enemy, ) }) as _, (|| { @@ -120,6 +127,7 @@ impl<'a> System<'a> for Sys { "Duck".into(), comp::Body::BirdMedium(comp::bird_medium::Body::random()), None, + comp::Alignment::Wild, ) }) as _, (|| { @@ -127,6 +135,7 @@ impl<'a> System<'a> for Sys { "Rat".into(), comp::Body::Critter(comp::critter::Body::random()), None, + comp::Alignment::Wild, ) }) as _, (|| { @@ -134,10 +143,11 @@ impl<'a> System<'a> for Sys { "Pig".into(), comp::Body::QuadrupedSmall(comp::quadruped_small::Body::random()), None, + comp::Alignment::Wild, ) }), ]; - let (name, mut body, main) = SPAWN_NPCS + let (name, mut body, main, alignment) = SPAWN_NPCS .choose(&mut rand::thread_rng()) .expect("SPAWN_NPCS is nonempty")( ); @@ -177,7 +187,7 @@ impl<'a> System<'a> for Sys { pos: Pos(entity.pos), stats, body, - alignment: comp::Alignment::Enemy, + alignment, agent: comp::Agent::default().with_patrol_origin(entity.pos), scale: comp::Scale(scale), })