Skip to content

Commit

Permalink
add turret AI
Browse files Browse the repository at this point in the history
  • Loading branch information
CrimeMoot authored Jan 2, 2025
1 parent ec207b6 commit 8a51d81
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Content.Shared/Verbs/VerbCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ public VerbCategory(string text, string? icon, bool iconsOnly = false)
public static readonly VerbCategory SelectType = new("verb-categories-select-type", null);

public static readonly VerbCategory PowerLevel = new("verb-categories-power-level", null);

public static readonly VerbCategory TurretControlMode = new("verb-categories-turret-control-mode", null); // Cats-edit-TurretControl
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Shared._Cats.TurretControl.Components;

[RegisterComponent]
public sealed partial class TurretControllableComponent : Component;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Shared._Cats.TurretControl.Components;

[RegisterComponent]
public sealed partial class TurretControllerComponent : Component;
60 changes: 60 additions & 0 deletions Content.Shared/_Cats/TurretControl/TurretControlSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Content.Shared._Cats.TurretControl.Components;
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Prototypes;
using Content.Shared.NPC.Systems;
using Content.Shared.Verbs;

namespace Content.Shared._Cats.TurretControl;

public sealed class TurretControlSystem : EntitySystem
{
[Dependency] private readonly NpcFactionSystem _faction = default!;

[ValidatePrototypeId<NpcFactionPrototype>]
private const string Passive = "TurretPassive";

[ValidatePrototypeId<NpcFactionPrototype>]
private const string Peace = "TurretPeace";

[ValidatePrototypeId<NpcFactionPrototype>]
private const string Hostile = "TurretHostile";

public override void Initialize()
{
SubscribeLocalEvent<TurretControllableComponent, GetVerbsEvent<Verb>>(OnGetVerbs);
}

private void OnGetVerbs(Entity<TurretControllableComponent> entity, ref GetVerbsEvent<Verb> e)
{
if (!HasComp<TurretControllerComponent>(e.User))
return;

if (!TryComp<NpcFactionMemberComponent>(entity, out var factionMember))
return;

e.Verbs.Add(CreateVerb((entity, factionMember), "turret-control-mode-nobody", Passive, 3));
e.Verbs.Add(CreateVerb((entity, factionMember), "turret-control-mode-hostile", Peace, 2));
e.Verbs.Add(CreateVerb((entity, factionMember), "turret-control-mode-everybody", Hostile, 1));
}

private Verb CreateVerb(Entity<NpcFactionMemberComponent?> entity, string text, string faction, int priority)
{
return new()
{
Text = Loc.GetString(text),
Disabled = _faction.IsMember(entity, faction),
Category = VerbCategory.TurretControlMode,
Priority = priority,
Act = () => SetFaction(entity, faction)
};
}

private void SetFaction(Entity<NpcFactionMemberComponent?> entity, string faction)
{
_faction.RemoveFaction(entity, Passive);
_faction.RemoveFaction(entity, Peace);
_faction.RemoveFaction(entity, Hostile);

_faction.AddFaction(entity, faction);
}
}
9 changes: 9 additions & 0 deletions Resources/Locale/ru-RU/_Cats/turret-control.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
turret-control-mode-nobody = Никто
turret-control-mode-hostile = Враждебные
turret-control-mode-everybody = Все
verb-categories-turret-control-mode = Задать цель
ent-WeaponTurretControl = { ent-BaseWeaponTurret }
.desc = { ent-BaseWeaponTurret.desc }
.suffix = Управляемая
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
- type: MovementSpeedModifier
baseWalkSpeed: 30
# Corvax-End
- type: TurretController # Cats-TurretControl

- type: entity
id: ActionAGhostShowSolar
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/silicon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@
- type: Speech
speechVerb: Robotic
speechSounds: Borg
- type: TurretController # Cats-TurretControl
- type: Tag
tags:
- HideContextMenu
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- type: entity
parent: BaseWeaponTurret
id: WeaponTurretControl
suffix: Control
components:
- type: NpcFactionMember
factions:
- TurretPeace
- type: TurretControllable
37 changes: 37 additions & 0 deletions Resources/Prototypes/_SpaceCats/ai_factions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- type: npcFaction
id: TurretPassive

- type: npcFaction
id: TurretPeace
hostile:
- Dragon
- SimpleHostile
- Xeno
- Blob
- Flesh
- Xeno
- Zombie

- type: npcFaction
id: TurretHostile
hostile:
- Dragon
- NanoTrasen
- Mouse
- Passive
- PetsNT
- SimpleHostile
- SimpleNeutral
- Syndicate
- Xeno
- Zombie
- Revolutionary
- Blob
- SuperZloy
- Spanish
- Britan
- SpecialForce
- CombineForce
- CentralCommand
- FleshHuman
- Flesh

0 comments on commit 8a51d81

Please sign in to comment.