Hit Detection

This commit is contained in:
Reinier Vens 2021-01-08 12:44:10 +00:00
commit 871c978301
225 changed files with 210834 additions and 237 deletions

View file

@ -18,9 +18,6 @@ public class ConstantWeaponData : WeaponData
public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
{
private ConstantWeaponData _data;
public int _burstCount;
public float _burstTimer;
private Entity Entity { get; }
private EquippedItem Item { get; }

View file

@ -9,31 +9,31 @@ using Unity.Mathematics;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LauncherData : InstantWeaponData
{
[InspectableAnimationCurve, JsonProperty("guidance"), Key(7)]
[InspectableAnimationCurve, JsonProperty("guidance"), Key(9)]
public float4[] GuidanceCurve;
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(8)]
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(10)]
public float4[] ThrustCurve;
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(9)]
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(11)]
public float4[] LiftCurve;
[InspectableField, JsonProperty("thrust"), Key(10)]
[InspectableField, JsonProperty("thrust"), Key(12)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("lockAngle"), Key(11)]
[InspectableField, JsonProperty("lockAngle"), Key(13)]
public float LockAngle;
[InspectableField, JsonProperty("frequency"), Key(12)]
[InspectableField, JsonProperty("frequency"), Key(14)]
public float DodgeFrequency;
[InspectableField, JsonProperty("launchSpeed"), Key(13)]
[InspectableField, JsonProperty("launchSpeed"), Key(15)]
public PerformanceStat LaunchSpeed = new PerformanceStat();
[InspectableField, JsonProperty("missileSpeed"), Key(14)]
[InspectableField, JsonProperty("missileSpeed"), Key(16)]
public PerformanceStat MissileSpeed = new PerformanceStat();
[InspectableField, JsonProperty("lockOnTime"), Key(15)]
[InspectableField, JsonProperty("lockOnTime"), Key(17)]
public PerformanceStat LockOnTime = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)

View file

@ -9,13 +9,13 @@ using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ProjectileWeaponData : InstantWeaponData
{
[InspectableField, JsonProperty("spread"), Key(7)]
[InspectableField, JsonProperty("spread"), Key(9)]
public PerformanceStat Spread = new PerformanceStat();
[InspectableField, JsonProperty("bulletInherit"), Key(8)]
[InspectableField, JsonProperty("bulletInherit"), Key(10)]
public float Inherit;
[InspectableField, JsonProperty("bulletVelocity"), Key(9)]
[InspectableField, JsonProperty("bulletVelocity"), Key(11)]
public PerformanceStat Velocity = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)

View file

@ -17,20 +17,26 @@ public abstract class WeaponData : BehaviorData
[InspectableField, JsonProperty("damage"), Key(2)]
public PerformanceStat Damage = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(3)]
[RangedFloatInspectable(0,1), JsonProperty("penetration"), Key(3)]
public PerformanceStat Penetration = new PerformanceStat();
[RangedFloatInspectable(0,1), JsonProperty("damageSpread"), Key(4)]
public PerformanceStat DamageSpread = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(5)]
public PerformanceStat Range = new PerformanceStat();
[InspectablePrefab, JsonProperty("effect"), Key(4)]
[InspectablePrefab, JsonProperty("effect"), Key(6)]
public string EffectPrefab;
}
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public abstract class InstantWeaponData : WeaponData
{
[InspectableField, JsonProperty("burstCount"), Key(5)]
[InspectableField, JsonProperty("burstCount"), Key(7)]
public int BurstCount;
[InspectableField, JsonProperty("burstTime"), Key(6)]
[InspectableField, JsonProperty("burstTime"), Key(8)]
public PerformanceStat BurstTime = new PerformanceStat();
}

View file

@ -49,7 +49,9 @@ public abstract class Entity
public readonly Dictionary<string, float> Messages = new Dictionary<string, float>();
public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
public readonly Dictionary<HardpointData, (float3 position, float3 direction)> HardpointTransforms = new Dictionary<HardpointData, (float3 position, float3 direction)>();
public readonly Dictionary<HardpointData, (float3 position, float3 direction)> HardpointTransforms =
new Dictionary<HardpointData, (float3 position, float3 direction)>();
public Dictionary<HardpointData, float> HardpointArmor;
public readonly List<EquippedItem>[] TriggerGroups;
@ -58,6 +60,7 @@ public abstract class Entity
public EquippedItem[,] GearOccupancy;
public EquippedItem[,] ThermalOccupancy;
public HardpointData[,] Hardpoints;
public float[,] Armor;
private EquippedItem[] _orderedEquipment;
protected bool _active;
@ -67,6 +70,11 @@ public abstract class Entity
public float Mass { get; private set; }
public float Visibility => VisibilitySources.Values.Sum();
public Subject<(HardpointData hardpoint, float damage)> HardpointDamage = new Subject<(HardpointData, float)>();
public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>();
public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>();
public Subject<float> HullDamage = new Subject<float>();
public bool Active
{
get => _active;
@ -94,23 +102,27 @@ public abstract class Entity
Zone = zone;
Hull = hull;
Name = hull.Name;
MapShip();
MapEntity();
TriggerGroups = new List<EquippedItem>[itemManager.GameplaySettings.TriggerGroupCount];
for(int i=0; i<itemManager.GameplaySettings.TriggerGroupCount; i++)
TriggerGroups[i] = new List<EquippedItem>();
}
private void MapShip()
private void MapEntity()
{
var hullData = ItemManager.GetData(Hull) as HullData;
HardpointArmor = hullData.Hardpoints.ToDictionary(hp => hp, hp => hp.Armor);
Equipment.Add(new EquippedItem(ItemManager, Hull, int2.zero, this));
Mass = hullData.Mass;
Temperature = new float[hullData.Shape.Width, hullData.Shape.Height];
Conductivity = new float4[hullData.Shape.Width, hullData.Shape.Height];
ThermalMass = new float[hullData.Shape.Width, hullData.Shape.Height];
Armor = new float[hullData.Shape.Width, hullData.Shape.Height];
var cellCount = hullData.Shape.Coordinates.Length;
foreach (var v in hullData.Shape.Coordinates)
{
if (!hullData.InteriorCells[v])
Armor[v.x, v.y] = hullData.Armor;
Temperature[v.x, v.y] = 280;
Conductivity[v.x, v.y] = hullData.Conductivity;
ThermalMass[v.x, v.y] = hullData.Mass * hullData.SpecificHeat / cellCount;
@ -261,6 +273,11 @@ public abstract class Entity
var itemShapeInset = hullData.Shape.Inset(itemData.Shape, hullCoord, item.Rotation);
var hardpointShapeInset = hullData.Shape.Inset(hardpoint.Shape, hardpoint.Position);
// Check every cell of the hardpoint shape
foreach(var v in hardpointShapeInset.Coordinates)
if (GearOccupancy[v.x, v.y] != null)
return false;
// Check every cell of the item's shape
foreach (var i in itemShapeInset.Coordinates)
{

View file

@ -12,6 +12,14 @@ public enum ItemRotation
Clockwise = 3
}
public enum HitType
{
Armor,
Hardpoint,
Gear,
Thermal
}
public enum LauncherCaliber
{
Micro,

View file

@ -333,6 +333,9 @@ public class HullData : EquippableItemData
[InspectableField, JsonProperty("gridOffset"), Key(17)]
public float GridOffset;
[InspectableField, JsonProperty("armor"), Key(18)]
public float Armor;
[IgnoreMember]
public Shape InteriorCells
{
@ -360,6 +363,7 @@ public class HardpointData : ITintInspector
[InspectableField, JsonProperty("shape"), Key(2)] public Shape Shape = new Shape();
[InspectableField, JsonProperty("transform"), Key(3)] public string Transform;
[InspectableField, JsonProperty("rotation"), Key(4)] public ItemRotation Rotation;
[InspectableField, JsonProperty("armor"), Key(5)] public float Armor;
public override string ToString()
{