Skip to content

Commit

Permalink
Change laser turrets AI (#1721)
Browse files Browse the repository at this point in the history
* Change laser turrets AI

* delete needless usings
  • Loading branch information
Kirus59 committed Sep 1, 2024
1 parent 37ae9eb commit ddabe22
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Content.Server/NPC/Components/NPCRangedCombatComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.NPC.Systems;
using Content.Shared.Physics;
using Robust.Shared.Audio;

namespace Content.Server.NPC.Components;
Expand Down Expand Up @@ -54,4 +55,9 @@ public sealed partial class NPCRangedCombatComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? SoundTargetInLOS;

//SS220 Change laser turrets AI begin
[ViewVariables(VVAccess.ReadWrite)]
public CollisionGroup? CollisionGroup;
//SS220 Change laser turrets AI end
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Content.Shared.CombatMode;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Physics;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Audio;

namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Combat.Ranged;
Expand Down Expand Up @@ -68,6 +70,14 @@ public override void Startup(NPCBlackboard blackboard)
{
ranged.SoundTargetInLOS = losSound;
}

//SS220 Change laser turrets AI begin
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
if (_entManager.HasComponent<HitscanBatteryAmmoProviderComponent>(owner))
{
ranged.CollisionGroup = CollisionGroup.Opaque;
}
//SS220 Change laser turrets AI end
}

public void ConditionalShutdown(NPCBlackboard blackboard)
Expand Down
9 changes: 8 additions & 1 deletion Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ private void UpdateRanged(float frameTime)
{
comp.LOSAccumulator += UnoccludedCooldown;
// For consistency with NPC steering.
comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f);

//SS220 Change laser turrets AI begin
//comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f);
if (comp.CollisionGroup is { } collisionMask)
comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f, collisionMask);
else
comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f);
//SS220 Change laser turrets AI end
}

if (!comp.TargetInLOS)
Expand Down
37 changes: 37 additions & 0 deletions Content.Server/SS220/NPC/TargetInLOSIgnoreWindowsPrecondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Server.Interaction;
using Content.Server.NPC;
using Content.Server.NPC.HTN.Preconditions;
using Content.Shared.Physics;

namespace Content.Server.SS220.NPC;

public sealed partial class TargetInLOSOpaqueCollisionPrecondition : HTNPrecondition
{
[Dependency] private readonly IEntityManager _entManager = default!;
private InteractionSystem _interaction = default!;

[DataField("targetKey")]
public string TargetKey = "Target";

[DataField("rangeKey")]
public string RangeKey = "RangeKey";

public override void Initialize(IEntitySystemManager sysManager)
{
base.Initialize(sysManager);
_interaction = sysManager.GetEntitySystem<InteractionSystem>();
}

public override bool IsMet(NPCBlackboard blackboard)
{
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);

if (!blackboard.TryGetValue<EntityUid>(TargetKey, out var target, _entManager))
return false;

var range = blackboard.GetValueOrDefault<float>(RangeKey, _entManager);

return _interaction.InRangeUnobstructed(owner, target, range, CollisionGroup.Opaque);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
startingCharge: 500
- type: HTN
rootTask:
task: TurretCompound
task: LaserTurretCompound
blackboard:
RotateSpeed: !type:Single
5
Expand Down
31 changes: 31 additions & 0 deletions Resources/Prototypes/SS220/NPCs/turrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- type: htnCompound
id: LaserTurretCompound
branches:
- tasks:
- !type:HTNPrimitiveTask
operator: !type:UtilityOperator
proto: NearbyGunTargets

- !type:HTNPrimitiveTask
preconditions:
- !type:KeyExistsPrecondition
key: Target
- !type:TargetInRangePrecondition
targetKey: Target
# TODO: Non-scuffed
rangeKey: RangedRange
- !type:TargetInLOSOpaqueCollisionPrecondition
targetKey: Target
rangeKey: RangedRange
operator: !type:GunOperator
targetKey: Target
requireLOS: true
services:
- !type:UtilityService
id: RangedService
proto: NearbyGunTargets
key: Target

- tasks:
- !type:HTNCompoundTask
task: IdleSpinCompound

0 comments on commit ddabe22

Please sign in to comment.