From 2aa6ced3572060ca0369575fc1cef977bb2748c5 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 5 Jan 2023 17:22:36 +0000 Subject: [PATCH] Removed patrol origin from humanoid NPCs --- rtsim/src/rule/npc_ai.rs | 4 +++- server/src/rtsim2/tick.rs | 13 ------------- server/src/sys/terrain.rs | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/rtsim/src/rule/npc_ai.rs b/rtsim/src/rule/npc_ai.rs index aee8047f85..f9c609391f 100644 --- a/rtsim/src/rule/npc_ai.rs +++ b/rtsim/src/rule/npc_ai.rs @@ -467,7 +467,9 @@ fn villager(visiting_site: SiteId) -> impl Action { format!("travel to visiting site") } })) - } else if DayPeriod::from(ctx.time_of_day.0).is_dark() { + } else if DayPeriod::from(ctx.time_of_day.0).is_dark() + && !matches!(ctx.npc.profession, Some(Profession::Guard)) + { important( now(move |ctx| { if let Some(house_wpos) = ctx diff --git a/server/src/rtsim2/tick.rs b/server/src/rtsim2/tick.rs index 03e4327ab9..421a6b24b3 100644 --- a/server/src/rtsim2/tick.rs +++ b/server/src/rtsim2/tick.rs @@ -260,19 +260,6 @@ impl<'a> System<'a> for Sys { if let Some(agent) = agent { agent.rtsim_controller.travel_to = npc.goto.map(|(wpos, _)| wpos); agent.rtsim_controller.speed_factor = npc.goto.map_or(1.0, |(_, sf)| sf); - // TODO: - // agent.rtsim_controller.heading_to = - // npc.pathing.intersite_path.as_ref(). - // and_then(|(path, _)| { - // Some( - // index - // .sites - // - // .get(data.sites.get(path.end)?.world_site?) - // .name() - // .to_string(), - // ) - // }); } }); } diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index ce5765c839..ea6fd4952e 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -513,15 +513,19 @@ impl NpcData { }; let agent = has_agency.then(|| { - comp::Agent::from_body(&body) - .with_behavior( - Behavior::default() - .maybe_with_capabilities(can_speak.then_some(BehaviorCapability::SPEAK)) - .maybe_with_capabilities(trade_for_site.map(|_| BehaviorCapability::TRADE)) - .with_trade_site(trade_for_site), - ) - .with_patrol_origin(pos) - .with_no_flee_if(matches!(agent_mark, Some(agent::Mark::Guard)) || no_flee) + let mut agent = comp::Agent::from_body(&body).with_behavior( + Behavior::default() + .maybe_with_capabilities(can_speak.then_some(BehaviorCapability::SPEAK)) + .maybe_with_capabilities(trade_for_site.map(|_| BehaviorCapability::TRADE)) + .with_trade_site(trade_for_site), + ); + + // Non-humanoids get a patrol origin to stop them moving too far + if !matches!(body, comp::Body::Humanoid(_)) { + agent = agent.with_patrol_origin(pos); + } + + agent.with_no_flee_if(matches!(agent_mark, Some(agent::Mark::Guard)) || no_flee) }); let agent = if matches!(alignment, comp::Alignment::Enemy)