Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into Projectile-Guidance
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 12, 2024
2 parents 571b0e6 + 2eba8c4 commit 1cbe4d5
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ public class LiveMethods
[ProtoContract]
public struct Definition_PID
{
[ProtoMember(0)] public float kProportional; // Direct response to error
[ProtoMember(1)] public float kIntegral; // Response to historical error
[ProtoMember(2)] public float kDerivative; // Damping factor
[ProtoMember(1)] public float kProportional; // Direct response to error
[ProtoMember(2)] public float kIntegral; // Response to historical error
[ProtoMember(3)] public float kDerivative; // Damping factor

public PID GetPID()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using Microsoft.Build.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using VRageMath;
using VRageMath;

namespace Heart_Module.Data.Scripts.HeartModule.Utility
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ProtoBuf;
using Sandbox.Game.Entities;
using System;
using System.Security.Cryptography;
using VRage.Game.Entity;
using VRage.Utils;
using VRageMath;
Expand Down Expand Up @@ -71,7 +72,7 @@ public struct PhysicalProjectile
{
[ProtoMember(1)] public float Velocity;
[ProtoMember(2)] public float Acceleration;
[ProtoMember(3)] public float Health; // TODO // <=0 for un-targetable
[ProtoMember(3)] public float Health; // TODO // <= 0 for un-targetable
/// <summary>
/// Max range of projectile, relative to first firing. For hitscans, max hitscan length.
/// </summary>
Expand Down Expand Up @@ -131,7 +132,7 @@ public struct Guidance
[ProtoMember(1)] public float TriggerTime;
[ProtoMember(2)] public float ActiveDuration; // Ignore if -1 or greater than next
[ProtoMember(3)] public bool UseAimPrediction;
[ProtoMember(4)] public float TurnRate;
[ProtoMember(4)] public float MaxTurnRate;
[ProtoMember(6)] public IFF_Enum IFF; // 1 is TargetSelf, 2 is TargetEnemies, 4 is TargetFriendlies
[ProtoMember(7)] public bool DoRaycast;
[ProtoMember(8)] public float CastCone;
Expand All @@ -145,6 +146,7 @@ public struct Guidance
/// Maximum G-force the projectile can sustain.
/// </summary>
[ProtoMember(12)] public float MaxGs;
[ProtoMember(13)] public Definition_PID? PID;
}

public class LiveMethods // TODO: OnGuidanceStage && DistanceToTarget
Expand All @@ -165,4 +167,13 @@ public void RegisterMethods(string definitionName)
public Action<uint> OnEndOfLife;
//public Action<uint, Guidance?> OnGuidanceStage;
}

[ProtoContract]
public struct Definition_PID
{
[ProtoMember(1)] public float kProportional; // Direct response to error
[ProtoMember(2)] public float kIntegral; // Response to historical error
[ProtoMember(3)] public float kDerivative; // Damping factor

}
}
112 changes: 108 additions & 4 deletions OrreryFrameworkDemo/Data/Scripts/OrreryFrameworkDemo/ExampleAmmos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ partial class HeartDefinitions
TriggerTime = 0,
ActiveDuration = -1,
UseAimPrediction = false,
TurnRate = 0f,
MaxTurnRate = 1f,
IFF = IFF_Enum.TargetEnemies,
DoRaycast = false,
CastCone = 0.5f,
Expand All @@ -149,7 +149,7 @@ partial class HeartDefinitions
TriggerTime = 2f,
ActiveDuration = -1f,
UseAimPrediction = true,
TurnRate = 99f,
MaxTurnRate = 99f,
IFF = IFF_Enum.TargetEnemies,
DoRaycast = false,
CastCone = 0.5f,
Expand All @@ -169,6 +169,110 @@ partial class HeartDefinitions
}
};

ProjectileDefinitionBase ExampleAmmoMissilePID => new ProjectileDefinitionBase()
{
Name = "ExampleAmmoMissilePID",
Ungrouped = new Ungrouped()
{
ReloadPowerUsage = 0,
Recoil = 0,
Impulse = 5000,
ShotsPerMagazine = 10,
MagazineItemToConsume = "",
},
Damage = new Damage()
{
SlimBlockDamageMod = 1,
FatBlockDamageMod = 1,
BaseDamage = 1000,
AreaDamage = 0,
AreaRadius = 0,
MaxImpacts = 1,
},
PhysicalProjectile = new PhysicalProjectile()
{
Velocity = 800,
VelocityVariance = 0,
Acceleration = 1,
Health = 1,
MaxTrajectory = 4000,
MaxLifetime = -1,
IsHitscan = false,
ProjectileSize = 1,
},
Visual = new Visual()
{
Model = "Models\\Weapons\\Projectile_Missile.mwm",
//TrailTexture = MyStringId.GetOrCompute("WeaponLaser"),
//TrailFadeTime = 0f,
//TrailLength = 8,
//TrailWidth = 0.5f,
//TrailColor = new VRageMath.Vector4(61, 24, 24, 200),
AttachedParticle = "Smoke_Missile",
ImpactParticle = "MaterialHit_Metal",
VisibleChance = 1f,
},
Audio = new Audio()
{
TravelSound = "",
TravelVolume = 100,
TravelMaxDistance = 1000,
ImpactSound = "WepSmallWarheadExpl",
SoundChance = 0.1f,
},
Guidance = new Guidance[]
{
new Guidance()
{
TriggerTime = 0,
ActiveDuration = -1,
UseAimPrediction = false,
MaxTurnRate = -1f,
IFF = IFF_Enum.TargetEnemies,
DoRaycast = false,
CastCone = 0.5f,
CastDistance = 1000,
Velocity = 50f,

PID = new Definition_PID()
{
kProportional = 0.0001f,
kIntegral = 0.0001f,
kDerivative = 0.0001f,
}
},
new Guidance()
{
TriggerTime = 2f,
ActiveDuration = -1f,
UseAimPrediction = true,
MaxTurnRate = -1f,
IFF = IFF_Enum.TargetEnemies,
DoRaycast = false,
CastCone = 0.5f,
CastDistance = 1000,
Velocity = 50f,
Inaccuracy = 5f,
MaxGs = 99f,

PID = new Definition_PID()
{
kProportional = 0.01f,
kIntegral = 0.01f,
kDerivative = 0.01f,
}
}
},
LiveMethods = new LiveMethods()
{
//OnSpawn = (ProjectileId, Firer) => {
// HeartApi.LogWriteLine("OnSpawn " + ProjectileId + " | " + HeartApi.BlockHasWeapon(Firer));
// },
//OnImpact = (ProjectileId, HitPos, HitNormal, HitEntity) => HeartApi.LogWriteLine("OnImpact " + ProjectileId),
//OnEndOfLife = (ProjectileId) => HeartApi.LogWriteLine("EndOfLife " + ProjectileId),
}
};

ProjectileDefinitionBase ExampleAmmoBeam => new ProjectileDefinitionBase()
{
Name = "ExampleAmmoBeam",
Expand Down Expand Up @@ -226,7 +330,7 @@ partial class HeartDefinitions
// TriggerTime = 0,
// ActiveDuration = -1,
// UseAimPrediction = false,
// TurnRate = -1.5f,
// MaxTurnRate = -1.5f,
// IFF = 2,
// DoRaycast = false,
// CastCone = 0.5f,
Expand All @@ -238,7 +342,7 @@ partial class HeartDefinitions
// TriggerTime = 1f,
// ActiveDuration = -1f,
// UseAimPrediction = false,
// TurnRate = 3.14f,
// MaxTurnRate = 3.14f,
// IFF = 2,
// DoRaycast = false,
// CastCone = 0.5f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ partial class HeartDefinitions
Ammos = new string[]
{
ExampleAmmoMissile.Name,
ExampleAmmoMissilePID.Name,
},

RateOfFire = 20,
Expand All @@ -63,7 +64,7 @@ partial class HeartDefinitions
ProjectilesPerBarrel = 1,
ReloadTime = 6,
DelayUntilFire = 0,
MagazinesToLoad = 2,
MagazinesToLoad = 1,

MaxReloads = -1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ partial class HeartDefinitions
internal HeartDefinitions()
{
LoadWeaponDefinitions(Example2BarrelTurretWeapon, ExampleTurretWeapon, ExampleFixedProjWeapon, ExampleFixedBeamWeapon, ExampleFixedMissileWeapon); //todo tell the user that they forgot to add stuff here when they get an error
LoadAmmoDefinitions(ExampleAmmoProjectile, ExampleAmmoMissile, ExampleAmmoBeam, Hotloaded);
LoadAmmoDefinitions(ExampleAmmoProjectile, ExampleAmmoMissile, ExampleAmmoBeam, Hotloaded, ExampleAmmoMissilePID);
}
}
}

0 comments on commit 1cbe4d5

Please sign in to comment.