Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable hostile ai on protected grids #2398

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Content.Server/NPC/HTN/HTNSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +16,10 @@
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.NPC.Components;
using Content.Shared.NPC.Systems;
using Content.Shared.Tiles; // Frontier
using Robust.Server.GameObjects; // Frontier

namespace Content.Server.NPC.HTN;
Expand All @@ -31,6 +35,7 @@ public sealed class HTNSystem : EntitySystem
[Dependency] private readonly TransformSystem _transform = default!;
private EntityQuery<WorldControllerComponent> _mapQuery;
private EntityQuery<LoadedChunkComponent> _loadedQuery;
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
// Frontier

private readonly JobQueue _planQueue = new(0.004);
Expand Down Expand Up @@ -72,7 +77,7 @@ private void OnLoad()
// Clear all NPCs in case they're hanging onto stale tasks
var query = AllEntityQuery<HTNComponent>();

while (query.MoveNext(out var comp))
while (query.MoveNext(out var comp)) // Frontier
{
comp.PlanningToken?.Cancel();
comp.PlanningToken = null;
Expand Down Expand Up @@ -159,7 +164,7 @@ public void UpdateNPC(ref int count, int maxUpdates, float frameTime)
_planQueue.Process();
var query = EntityQueryEnumerator<ActiveNPCComponent, HTNComponent>();

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)
Expand All @@ -168,6 +173,17 @@ 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<ProtectedGridComponent>(grid, out _))
{
if (EntityManager.TryGetComponent<NpcFactionMemberComponent>(uid, out var npcFactionMemberComponent))
{
if (_npcFaction.IsFactionHostile("NanoTrasen", (uid, npcFactionMemberComponent)))
continue;
}
}
Comment on lines +176 to +185
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going this far, why not just kill them, gib them, and delete their contents? No iteration, fewer entities, nothing to gain by dragging crabs into the zone. They provide no threat, shouldn't reward coming back into a hidey hole.

Might also want to use another flag for this, ProtectedGrid could just mean "I'd like the floors in one piece".

if (grid != null
    && TryComp<ProtectedGridComponent>(grid, out var protectedGrid)
    && protectedGrid.KillHostileMobs
    && TryComp<NpcFactionMemberComponent>(uid, out var npcFactionMember)
    && _npcFaction.IsFactionHostile("NanoTrasen", (uid, npcFactionMember))
{
    // turn it into dust, could play a funny noise
    continue;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea. i will change this soonish


if (comp.PlanningJob != null)
{
if (comp.PlanningJob.Exception != null)
Expand Down
Loading