From f1fd4d68a944fa490517b6114cf052380aa70121 Mon Sep 17 00:00:00 2001 From: GreaseMonk <1354802+GreaseMonk@users.noreply.github.com> Date: Sun, 10 Nov 2024 11:39:57 +0100 Subject: [PATCH 1/2] Disable AI on protected grids WIP --- Content.Server/NPC/HTN/HTNSystem.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Content.Server/NPC/HTN/HTNSystem.cs b/Content.Server/NPC/HTN/HTNSystem.cs index 69a47a4bb13..08d20ab08d5 100644 --- a/Content.Server/NPC/HTN/HTNSystem.cs +++ b/Content.Server/NPC/HTN/HTNSystem.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Text; using System.Threading; +using Content.Server._NF.PacifiedZone; using Content.Server.Administration.Managers; using Robust.Shared.CPUJob.JobQueues; using Robust.Shared.CPUJob.JobQueues.Queues; @@ -15,7 +16,8 @@ using Robust.Shared.Utility; using Content.Server.Worldgen; // Frontier using Content.Server.Worldgen.Components; // Frontier -using Content.Server.Worldgen.Systems; // Frontier +using Content.Server.Worldgen.Systems; +using Content.Shared.Tiles; // Frontier using Robust.Server.GameObjects; // Frontier namespace Content.Server.NPC.HTN; @@ -72,7 +74,7 @@ private void OnLoad() // Clear all NPCs in case they're hanging onto stale tasks var query = AllEntityQuery(); - while (query.MoveNext(out var comp)) + while (query.MoveNext(out var comp)) // Frontier { comp.PlanningToken?.Cancel(); comp.PlanningToken = null; @@ -168,6 +170,11 @@ public void UpdateNPC(ref int count, int maxUpdates, float frameTime) if (!IsNPCActive(uid)) // Frontier continue; + // Frontier: Disable hostile AI in pacified zones + var grid = Transform(uid).GridUid; + if (grid != null && EntityManager.TryGetComponent(grid, out _)) + continue; + if (comp.PlanningJob != null) { if (comp.PlanningJob.Exception != null) From 03042633046948da341c7b3ff977559ef3cb3fed Mon Sep 17 00:00:00 2001 From: GreaseMonk <1354802+GreaseMonk@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:42:31 +0100 Subject: [PATCH 2/2] Check if faction is hostile --- Content.Server/NPC/HTN/HTNSystem.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Content.Server/NPC/HTN/HTNSystem.cs b/Content.Server/NPC/HTN/HTNSystem.cs index 08d20ab08d5..849d8b2fe88 100644 --- a/Content.Server/NPC/HTN/HTNSystem.cs +++ b/Content.Server/NPC/HTN/HTNSystem.cs @@ -17,6 +17,8 @@ using Content.Server.Worldgen; // Frontier using Content.Server.Worldgen.Components; // Frontier using Content.Server.Worldgen.Systems; +using Content.Shared.NPC.Components; +using Content.Shared.NPC.Systems; using Content.Shared.Tiles; // Frontier using Robust.Server.GameObjects; // Frontier @@ -33,6 +35,7 @@ public sealed class HTNSystem : EntitySystem [Dependency] private readonly TransformSystem _transform = default!; private EntityQuery _mapQuery; private EntityQuery _loadedQuery; + [Dependency] private readonly NpcFactionSystem _npcFaction = default!; // Frontier private readonly JobQueue _planQueue = new(0.004); @@ -161,7 +164,7 @@ public void UpdateNPC(ref int count, int maxUpdates, float frameTime) _planQueue.Process(); var query = EntityQueryEnumerator(); - while(query.MoveNext(out var uid, out _, out var comp)) + while(query.MoveNext(out var uid, out var activeNpcComponent, out var comp)) { // If we're over our max count or it's not MapInit then ignore the NPC. if (count >= maxUpdates) @@ -173,7 +176,13 @@ public void UpdateNPC(ref int count, int maxUpdates, float frameTime) // Frontier: Disable hostile AI in pacified zones var grid = Transform(uid).GridUid; if (grid != null && EntityManager.TryGetComponent(grid, out _)) - continue; + { + if (EntityManager.TryGetComponent(uid, out var npcFactionMemberComponent)) + { + if (_npcFaction.IsFactionHostile("NanoTrasen", (uid, npcFactionMemberComponent))) + continue; + } + } if (comp.PlanningJob != null) {