Add AI factions (#1807)

* Add NPC faction tags

Some stuff isn't easy to represent by the existence of components so tags are intended to provide that functionality for AI usage.

I was 50/50 on having all tags in the 1 component or splitting it into 2. I'm leaning towards 2. This would be for stuff like say "CanMimic" so the mimic knows it's allowed to look like a specific prototype, or something like "smg" on a gun so it can say smg-specific barks for instance (as currently smgs and pistols look the same from a component perspective).

This also means combat behaviors aren't hardcoded per faction, plus it makes it easy to update faction relations during events.

* Factions command

Update faction relationships via commands.

* Remove command TODO

* Woops

Forgot to commit these items

* Serializer writing and parsing

* linq me up fam

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-08-24 20:33:03 +10:00
committed by GitHub
parent df823d2245
commit 969eeb5528
15 changed files with 265 additions and 41 deletions

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.AI
{
[RegisterComponent]
public sealed class AiFactionTagComponent : Component
{
public override string Name => "AiFactionTag";
public Faction Factions { get; private set; } = Faction.None;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataReadWriteFunction(
"factions",
new List<Faction>(),
factions => factions.ForEach(faction => Factions |= faction),
() =>
{
var writeFactions = new List<Faction>();
foreach (Faction fac in Enum.GetValues(typeof(Faction)))
{
if ((Factions & fac) != 0)
{
writeFactions.Add(fac);
}
}
return writeFactions;
});
}
}
[Flags]
public enum Faction
{
None = 0,
NanoTransen = 1 << 0,
SimpleHostile = 1 << 1,
SimpleNeutral = 1 << 2,
Syndicate = 1 << 3,
Xeno = 1 << 4,
}
}