Sensor Ping
Added ping feature to sensors, pulsing a wave of revealing light into the level Added IEventBehavior interface, used by sensors and weapons, for behaviors containing event subscriptions which need to be reset when EntityInstance is disposed Implemented sensor impact for locked weapons (lock speed varies with sensor acquisition) Added ping cooldown bar to HUD Added spline curve implementations to AetheriaMath, applied better mapping to wormhole transition animation Tweaked loadout generator to prefer larger items to a controllable degree (e.g. very important for cargo bays, less for shop inventory), shop inventory bans non-ship hulls and manages internal space more effectively
This commit is contained in:
parent
fd81bf267e
commit
645fcf4b09
62 changed files with 115821 additions and 79 deletions
|
|
@ -35,6 +35,11 @@ public interface IDisposableBehavior
|
|||
void Dispose();
|
||||
}
|
||||
|
||||
public interface IEventBehavior
|
||||
{
|
||||
void ResetEvents();
|
||||
}
|
||||
|
||||
public interface IInitializableBehavior
|
||||
{
|
||||
void Initialize();
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class ChargedWeaponData : InstantWeaponData
|
|||
}
|
||||
}
|
||||
|
||||
public class ChargedWeapon : InstantWeapon
|
||||
public class ChargedWeapon : InstantWeapon, IEventBehavior
|
||||
{
|
||||
private ChargedWeaponData _data;
|
||||
private bool _charging;
|
||||
|
|
@ -79,6 +79,7 @@ public class ChargedWeapon : InstantWeapon
|
|||
|
||||
public override void ResetEvents()
|
||||
{
|
||||
base.ResetEvents();
|
||||
OnStartCharging = null;
|
||||
OnStopCharging = null;
|
||||
OnCharged = null;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class ConstantWeaponData : WeaponData
|
|||
}
|
||||
}
|
||||
|
||||
public class ConstantWeapon : Weapon, IProgressBehavior
|
||||
public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
||||
{
|
||||
private ConstantWeaponData _data;
|
||||
private int _ammo = 1;
|
||||
|
|
@ -49,7 +49,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior
|
|||
public event Action OnStartFiring;
|
||||
public event Action OnStopFiring;
|
||||
|
||||
public override void ResetEvents()
|
||||
public void ResetEvents()
|
||||
{
|
||||
OnReloadBegin = null;
|
||||
OnReloadComplete = null;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class InstantWeaponData : WeaponData
|
|||
}
|
||||
}
|
||||
|
||||
public class InstantWeapon : Weapon, IProgressBehavior
|
||||
public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
||||
{
|
||||
private InstantWeaponData _data;
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ public class InstantWeapon : Weapon, IProgressBehavior
|
|||
public event Action OnCooldownComplete;
|
||||
public event Action OnFire;
|
||||
|
||||
public override void ResetEvents()
|
||||
public virtual void ResetEvents()
|
||||
{
|
||||
OnReloadBegin = null;
|
||||
OnReloadComplete = null;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class LockWeapon : InstantWeapon
|
|||
if (degrees < LockAngle)
|
||||
{
|
||||
var lerp = 1 - unlerp(0, 90, degrees);
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * delta * LockSpeed);
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * delta * LockSpeed * pow(Entity.EntityInfoGathered[Entity.Target.Value], SensorImpact));
|
||||
}
|
||||
else _lock = saturate(_lock - delta * Decay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
|
|
@ -10,11 +12,32 @@ using static Unity.Mathematics.math;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class SensorData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("sensitivity"), Key(3), RuntimeInspectable]
|
||||
[InspectableField, JsonProperty("sensitivity"), Key(3), RuntimeInspectable]
|
||||
public PerformanceStat Sensitivity = new PerformanceStat();
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("sensitivityCurve"), Key(4), RuntimeInspectable]
|
||||
[InspectableAnimationCurve, JsonProperty("sensitivityCurve"), Key(4), RuntimeInspectable]
|
||||
public float4[] SensitivityCurve;
|
||||
|
||||
[InspectableField, JsonProperty("pingBoost"), Key(5), RuntimeInspectable]
|
||||
public PerformanceStat PingBoost;
|
||||
|
||||
[InspectableField, JsonProperty("pingEnergy"), Key(6), RuntimeInspectable]
|
||||
public PerformanceStat PingEnergy;
|
||||
|
||||
[InspectableField, JsonProperty("pingVisibility"), Key(7), RuntimeInspectable]
|
||||
public PerformanceStat PingVisibility;
|
||||
|
||||
[InspectableField, JsonProperty("pingRange"), Key(8), RuntimeInspectable]
|
||||
public PerformanceStat PingRange;
|
||||
|
||||
[InspectableField, JsonProperty("pingCooldown"), Key(9), RuntimeInspectable]
|
||||
public PerformanceStat PingCooldown;
|
||||
|
||||
[InspectableField, JsonProperty("pingDuration"), Key(10)]
|
||||
public float PingDuration = 2;
|
||||
|
||||
[InspectableField, JsonProperty("pingRadiusExponent"), Key(11)]
|
||||
public float PingRadiusExponent = .5f;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
|
|
@ -22,15 +45,55 @@ public class SensorData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
public class Sensor : IBehavior
|
||||
public class Sensor : IBehavior, IEventBehavior
|
||||
{
|
||||
private SensorData _data;
|
||||
private float _pingCooldown;
|
||||
private float _pingLerp;
|
||||
private bool _pinging;
|
||||
private float _pingRadius;
|
||||
private HashSet<Entity> _pingedEntities = new HashSet<Entity>();
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public float Cooldown
|
||||
{
|
||||
get => saturate(_pingCooldown);
|
||||
}
|
||||
|
||||
public float PingRadius
|
||||
{
|
||||
get => _pingRadius;
|
||||
}
|
||||
|
||||
public float PingBrightness => pow(1 - _pingLerp, _data.PingRadiusExponent);
|
||||
|
||||
public event Action OnPingStart;
|
||||
public event Action OnPingEnd;
|
||||
|
||||
public void ResetEvents()
|
||||
{
|
||||
OnPingStart = null;
|
||||
OnPingEnd = null;
|
||||
}
|
||||
|
||||
public void Ping()
|
||||
{
|
||||
if(_pingCooldown < 0 && Item.Entity.TryConsumeEnergy(Item.Evaluate(_data.PingEnergy)))
|
||||
{
|
||||
Item.Entity.VisibilitySources[this] = Item.Evaluate(_data.PingVisibility);
|
||||
_pinging = true;
|
||||
_pingCooldown = 1;
|
||||
_pingLerp = 0;
|
||||
_pingRadius = 0;
|
||||
_pingedEntities.Clear();
|
||||
OnPingStart?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public Sensor(ItemManager context, SensorData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
|
|
@ -42,6 +105,19 @@ public class Sensor : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (_pinging)
|
||||
{
|
||||
_pingLerp += delta / _data.PingDuration;
|
||||
_pingRadius = lerp(0, Item.Evaluate(_data.PingRange), pow(_pingLerp, _data.PingRadiusExponent));
|
||||
if (_pingLerp > 1)
|
||||
{
|
||||
_pinging = false;
|
||||
OnPingEnd?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
_pingCooldown -= delta / Item.Evaluate(_data.PingCooldown);
|
||||
|
||||
// TODO: Handle Active Detection / Visibility From Reflected Radiance
|
||||
var hardpoint = Entity.Hardpoints[Item.Position.x, Item.Position.y];
|
||||
var forward = hardpoint != null && Entity.HardpointTransforms.ContainsKey(hardpoint) ?
|
||||
|
|
@ -54,35 +130,32 @@ public class Sensor : IBehavior
|
|||
var diff = entity.Position.xz - Entity.Position.xz;
|
||||
var angle = acos(dot(forward, normalize(diff)));
|
||||
var dist = length(diff);
|
||||
float previous;
|
||||
float previous, next;
|
||||
Entity.EntityInfoGathered.TryGetValue(entity, out previous);
|
||||
var next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
_data.SensitivityCurve.Evaluate(angle / PI) *
|
||||
delta / dist);
|
||||
if (!_pingedEntities.Contains(entity) && dist < _pingRadius)
|
||||
{
|
||||
_pingedEntities.Add(entity);
|
||||
next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
Item.Evaluate(_data.PingBoost) *
|
||||
dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
_data.SensitivityCurve.Evaluate(angle / PI) *
|
||||
delta / dist);
|
||||
}
|
||||
next *= 1 - Context.GameplaySettings.TargetInfoDecay * delta;
|
||||
//Context.Log($"{entity.Name} visibility {(int)(previous * 100)}% -> {(int)(next * 100)}%");
|
||||
Entity.EntityInfoGathered[entity] = next;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
// var ship = Hardpoint.Ship.Ship.transform;
|
||||
// var contacts =
|
||||
// Physics.OverlapSphere(ship.position, _data.Range.Evaluate(Hardpoint)).Where(c=>c.attachedRigidbody?.GetComponent<Targetable>()!=null).Select(c=>c.attachedRigidbody.GetComponent<Targetable>());
|
||||
// foreach (var contact in contacts)
|
||||
// {
|
||||
// var diff = (contact.transform.position - ship.position).Flatland();
|
||||
// var angle = acos(dot(ship.forward.Flatland().normalized,
|
||||
// diff.normalized)) / (float)PI;
|
||||
// var sens = _data.Sensitivity.Evaluate(Hardpoint) *
|
||||
// Hardpoint.Ship.HullData.VisibilityCurve.Evaluate(saturate(angle));
|
||||
// var vis = contact.Visibility / diff.sqrMagnitude;
|
||||
// if(vis > 1/sens)
|
||||
// Hardpoint.Ship.Contacts[contact] = Time.time;
|
||||
// }
|
||||
//
|
||||
// Hardpoint.Ship.VisibilitySources[this] = _data.Radiance.Evaluate(Hardpoint) / _data.RadianceMasking.Evaluate(Hardpoint);
|
||||
}
|
||||
}
|
||||
|
|
@ -109,8 +109,6 @@ public abstract class Weapon : IActivatedBehavior
|
|||
_itemData = context.GetData(item.EquippableItem);
|
||||
}
|
||||
|
||||
public virtual void ResetEvents(){}
|
||||
|
||||
protected virtual void UpdateStats()
|
||||
{
|
||||
Damage = Item.Evaluate(_data.Damage);
|
||||
|
|
|
|||
Loading…
Reference in a new issue