AI State Machine First Pass

Implemented first pass on code-driven state machine logic for flexible AI agents
This commit is contained in:
Reinier Vens 2021-02-11 03:14:20 +00:00
commit 8d4bd04891
26 changed files with 489 additions and 137 deletions

View file

@ -9,40 +9,40 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class ChargedWeaponData : InstantWeaponData
{
[InspectableField, JsonProperty("chargeTime"), Key(19), RuntimeInspectable]
[InspectableField, JsonProperty("chargeTime"), Key(21), RuntimeInspectable]
public PerformanceStat ChargeTime = new PerformanceStat();
[InspectableField, JsonProperty("chargeEnergy"), Key(20), RuntimeInspectable]
[InspectableField, JsonProperty("chargeEnergy"), Key(22), RuntimeInspectable]
public PerformanceStat ChargeEnergy = new PerformanceStat();
[InspectableField, JsonProperty("chargeHeat"), Key(21), RuntimeInspectable]
[InspectableField, JsonProperty("chargeHeat"), Key(23), RuntimeInspectable]
public PerformanceStat ChargeHeat = new PerformanceStat();
[InspectableField, JsonProperty("canFireEarly"), Key(22)]
[InspectableField, JsonProperty("canFireEarly"), Key(24)]
public bool CanFireEarly;
[InspectableField, JsonProperty("failureCharge"), Key(23)]
[InspectableField, JsonProperty("failureCharge"), Key(25)]
public float FailureCharge;
[InspectableField, JsonProperty("failureDamage"), Key(24)]
[InspectableField, JsonProperty("failureDamage"), Key(26)]
public float FailureDamage = 1;
[InspectableField, JsonProperty("chargeDamage"), Key(25)]
[InspectableField, JsonProperty("chargeDamage"), Key(27)]
public float ChargeFiringDamageMultiplier = 1;
[InspectableField, JsonProperty("chargeSpread"), Key(26)]
[InspectableField, JsonProperty("chargeSpread"), Key(28)]
public float ChargeFiringSpreadMultiplier = 1;
[InspectableField, JsonProperty("chargeBurstCount"), Key(27)]
[InspectableField, JsonProperty("chargeBurstCount"), Key(29)]
public float ChargeFiringBurstCountMultiplier = 1;
[InspectableField, JsonProperty("chargeVisibility"), Key(28)]
[InspectableField, JsonProperty("chargeVisibility"), Key(30)]
public float ChargeFiringVisibilityMultiplier = 1;
[InspectableField, JsonProperty("chargeVelocity"), Key(29)]
[InspectableField, JsonProperty("chargeVelocity"), Key(31)]
public float ChargeFiringVelocityMultiplier = 1;
[InspectableField, JsonProperty("chargeHeatMul"), Key(30)]
[InspectableField, JsonProperty("chargeHeatMul"), Key(32)]
public float ChargeFiringHeatMultiplier = 1;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
@ -131,7 +131,7 @@ public class ChargedWeapon : InstantWeapon
public override void Activate()
{
if(!_coolingDown)
if(!_charging && !_coolingDown)
{
OnStartCharging?.Invoke();
_charging = true;

View file

@ -11,7 +11,7 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ConstantWeaponData : WeaponData
{
[InspectablePrefab, JsonProperty("ammoInterval"), Key(15)]
[InspectablePrefab, JsonProperty("ammoInterval"), Key(17)]
public float AmmoInterval = 1;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
@ -112,7 +112,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior
public override void Activate()
{
if(!_reloading)
if(!_firing && !_reloading)
{
_firing = true;
OnStartFiring?.Invoke();

View file

@ -9,16 +9,16 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class InstantWeaponData : WeaponData
{
[InspectableField, JsonProperty("count"), Key(15)]
[InspectableField, JsonProperty("count"), Key(17)]
public PerformanceStat Count = new PerformanceStat();
[InspectableField, JsonProperty("burstTime"), Key(16)]
[InspectableField, JsonProperty("burstTime"), Key(18)]
public PerformanceStat BurstTime = new PerformanceStat();
[InspectableField, JsonProperty("cooldown"), Key(17), RuntimeInspectable]
[InspectableField, JsonProperty("cooldown"), Key(19), RuntimeInspectable]
public PerformanceStat Cooldown = new PerformanceStat();
[InspectablePrefab, JsonProperty("ammoInterval"), Key(18)]
[InspectablePrefab, JsonProperty("ammoInterval"), Key(20)]
public bool SingleAmmoBurst;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)

View file

@ -9,22 +9,22 @@ using Unity.Mathematics;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LauncherData : LockWeaponData
{
[InspectableAnimationCurve, JsonProperty("guidance"), Key(24)]
[InspectableAnimationCurve, JsonProperty("guidance"), Key(26)]
public float4[] GuidanceCurve;
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(25)]
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(27)]
public float4[] ThrustCurve;
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(26)]
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(28)]
public float4[] LiftCurve;
[InspectableField, JsonProperty("thrust"), Key(27)]
[InspectableField, JsonProperty("thrust"), Key(29)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("frequency"), Key(28)]
[InspectableField, JsonProperty("frequency"), Key(30)]
public float DodgeFrequency;
[InspectableField, JsonProperty("missileSpeed"), Key(29), RuntimeInspectable]
[InspectableField, JsonProperty("missileSpeed"), Key(31), RuntimeInspectable]
public PerformanceStat MissileVelocity = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
@ -36,22 +36,22 @@ public class LauncherData : LockWeaponData
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GuidedWeaponData : InstantWeaponData
{
[InspectableAnimationCurve, JsonProperty("guidance"), Key(24)]
[InspectableAnimationCurve, JsonProperty("guidance"), Key(21)]
public float4[] GuidanceCurve;
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(25)]
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(22)]
public float4[] ThrustCurve;
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(26)]
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(23)]
public float4[] LiftCurve;
[InspectableField, JsonProperty("thrust"), Key(27)]
[InspectableField, JsonProperty("thrust"), Key(24)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("frequency"), Key(28)]
[InspectableField, JsonProperty("frequency"), Key(25)]
public float DodgeFrequency;
[InspectableField, JsonProperty("missileSpeed"), Key(29), RuntimeInspectable]
[InspectableField, JsonProperty("missileSpeed"), Key(26), RuntimeInspectable]
public PerformanceStat MissileVelocity = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)

View file

@ -9,19 +9,19 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class LockWeaponData : InstantWeaponData
{
[InspectableField, JsonProperty("speed"), Key(19), RuntimeInspectable]
[InspectableField, JsonProperty("speed"), Key(21), RuntimeInspectable]
public PerformanceStat LockSpeed = new PerformanceStat();
[InspectableField, JsonProperty("sensorImpact"), Key(20)]
[InspectableField, JsonProperty("sensorImpact"), Key(22)]
public PerformanceStat SensorImpact = new PerformanceStat();
[InspectableField, JsonProperty("threshold"), Key(21), RuntimeInspectable]
[InspectableField, JsonProperty("threshold"), Key(23), RuntimeInspectable]
public PerformanceStat LockAngle = new PerformanceStat();
[InspectableField, JsonProperty("directionImpact"), Key(22)]
[InspectableField, JsonProperty("directionImpact"), Key(24)]
public PerformanceStat DirectionImpact = new PerformanceStat();
[InspectableField, JsonProperty("decay"), Key(23)]
[InspectableField, JsonProperty("decay"), Key(25)]
public PerformanceStat Decay = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)

View file

@ -4,12 +4,17 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class SensorData : BehaviorData
{
[InspectableField, JsonProperty("sensitivity"), Key(3), RuntimeInspectable]
public PerformanceStat Sensitivity = new PerformanceStat();
[InspectableField, JsonProperty("sensitivityCurve"), Key(4), RuntimeInspectable]
public float4[] SensitivityCurve;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
@ -38,6 +43,21 @@ public class Sensor : IBehavior
public bool Execute(float delta)
{
// TODO: Handle Active Detection / Visibility From Reflected Radiance
var hardpoint = Entity.Hardpoints[Item.Position.x, Item.Position.y];
var forward = Entity.HardpointTransforms.ContainsKey(hardpoint) ?
normalize(Entity.HardpointTransforms[hardpoint].direction.xz) :
Entity.Direction;
foreach (var entity in Entity.Zone.Entities)
{
var diff = entity.Position.xz - Entity.Position.xz;
var angle = acos(dot(forward, normalize(diff)));
var dist = length(diff);
Entity.EntityInfoGathered[entity] +=
entity.Visibility *
Context.Evaluate(_data.Sensitivity, Item.EquippableItem, Entity) *
_data.SensitivityCurve.Evaluate(angle / PI) *
delta / dist;
}
return true;
// var ship = Hardpoint.Ship.Ship.transform;
// var contacts =

View file

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
[Union(0, typeof(InstantWeaponData)),
Union(1, typeof(LauncherData)),
@ -27,34 +28,40 @@ public abstract class WeaponData : BehaviorData
[RangedFloatInspectable(0,1), JsonProperty("damageSpread"), Key(4)]
public PerformanceStat DamageSpread = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(5), RuntimeInspectable]
[InspectableField, JsonProperty("minRange"), Key(5), RuntimeInspectable]
public PerformanceStat MinRange = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(6), RuntimeInspectable]
public PerformanceStat Range = new PerformanceStat();
[InspectableAnimationCurve, JsonProperty("damageRange"), Key(7), RuntimeInspectable]
public float4[] DamageCurve;
[InspectablePrefab, JsonProperty("effect"), Key(6)]
[InspectablePrefab, JsonProperty("effect"), Key(8)]
public string EffectPrefab;
[InspectablePrefab, JsonProperty("energy"), Key(7), RuntimeInspectable]
[InspectablePrefab, JsonProperty("energy"), Key(9), RuntimeInspectable]
public PerformanceStat Energy = new PerformanceStat();
[InspectablePrefab, JsonProperty("heat"), Key(8), RuntimeInspectable]
[InspectablePrefab, JsonProperty("heat"), Key(10), RuntimeInspectable]
public PerformanceStat Heat = new PerformanceStat();
[InspectablePrefab, JsonProperty("visibility"), Key(9), RuntimeInspectable]
[InspectablePrefab, JsonProperty("visibility"), Key(11), RuntimeInspectable]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("ammo"), Key(10), RuntimeInspectable]
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("ammo"), Key(12), RuntimeInspectable]
public Guid AmmoType;
[InspectablePrefab, JsonProperty("magSize"), Key(11)]
[InspectablePrefab, JsonProperty("magSize"), Key(13)]
public int MagazineSize;
[InspectablePrefab, JsonProperty("reloadTime"), Key(12)]
[InspectablePrefab, JsonProperty("reloadTime"), Key(14)]
public float ReloadTime = 1;
[InspectablePrefab, JsonProperty("spread"), Key(13)]
[InspectablePrefab, JsonProperty("spread"), Key(15)]
public PerformanceStat Spread = new PerformanceStat();
[InspectableField, JsonProperty("velocity"), Key(14)]
[InspectableField, JsonProperty("velocity"), Key(16)]
public PerformanceStat Velocity = new PerformanceStat();
}
@ -73,6 +80,7 @@ public abstract class Weapon : IActivatedBehavior
public float Damage { get; protected set; }
public float Penetration { get; protected set; }
public float DamageSpread { get; protected set; }
public float MinRange { get; protected set; }
public float Range { get; protected set; }
public float Energy { get; protected set; }
public float Heat { get; protected set; }
@ -103,6 +111,7 @@ public abstract class Weapon : IActivatedBehavior
Damage = Context.Evaluate(_data.Damage, Item.EquippableItem, Entity);
Penetration = Context.Evaluate(_data.Penetration, Item.EquippableItem, Entity);
DamageSpread = Context.Evaluate(_data.DamageSpread, Item.EquippableItem, Entity);
MinRange = Context.Evaluate(_data.MinRange, Item.EquippableItem, Entity);
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
Energy = Context.Evaluate(_data.Energy, Item.EquippableItem, Entity);
Heat = Context.Evaluate(_data.Heat, Item.EquippableItem, Entity);