From 2db4fbd13deea8853bc2323e4dc791b591fd1e00 Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+Jnick-24@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:18:12 -0600 Subject: [PATCH] MISSILE GUIDANCE IN MULTIPLAYER!!! --- .../GuidanceHelpers/ProjectileGuidance.cs | 2 +- .../n_SerializableProjectileInfos.cs | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/GuidanceHelpers/ProjectileGuidance.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/GuidanceHelpers/ProjectileGuidance.cs index 1cf700e3..c8c6be89 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/GuidanceHelpers/ProjectileGuidance.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/GuidanceHelpers/ProjectileGuidance.cs @@ -196,7 +196,7 @@ internal void PreformRaycast(Guidance currentstage) internal bool IsTargetAllowed(IMyEntity target, Guidance? currentStage) { - if (currentStage == null) + if (currentStage == null || target == null) return false; if (projectile.Firer == 0) return true; diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileNetworking/n_SerializableProjectileInfos.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileNetworking/n_SerializableProjectileInfos.cs index 8a1225e9..92f78f71 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileNetworking/n_SerializableProjectileInfos.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileNetworking/n_SerializableProjectileInfos.cs @@ -218,6 +218,9 @@ public n_SerializableFireEvents(List projectiles) directionX = new float[projectiles.Count]; directionY = new float[projectiles.Count]; directionZ = new float[projectiles.Count]; + targetEntities = new long[projectiles.Count]; + + bool needsTargetEntities = false; for (int i = 0; i < projectiles.Count; i++) { @@ -226,8 +229,17 @@ public n_SerializableFireEvents(List projectiles) directionX[i] = (float)projectiles[i].Direction.X; directionY[i] = (float)projectiles[i].Direction.Y; directionZ[i] = (float)projectiles[i].Direction.Z; + + if (projectiles[i].Guidance != null && projectiles[i].Guidance.GetTarget() != null) + { + needsTargetEntities = true; + targetEntities[i] = projectiles[i].Guidance.GetTarget().EntityId; + } } + if (!needsTargetEntities) + targetEntities = null; + MillisecondsFromMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds; } @@ -253,6 +265,7 @@ public n_SerializableFireEvents(long[] firerWeaponId, uint[] uniqueProjectileId, [ProtoMember(23)] private float[] directionX; [ProtoMember(24)] private float[] directionY; [ProtoMember(25)] private float[] directionZ; + [ProtoMember(26)] private long[] targetEntities; //[ProtoMember(26)] private byte[] muzzleIdx; // TODO: Sync muzzle index for fireevents. public Vector3[] Direction() // just using a Vector3 adds 2 extra bytes (!!!) @@ -270,7 +283,7 @@ public Vector3 Direction(int index) return new Vector3(directionX[index], directionY[index], directionZ[index]); } - [ProtoMember(26)] public int MillisecondsFromMidnight; + [ProtoMember(27)] public int MillisecondsFromMidnight; public Projectile ToProjectile(int index) { @@ -293,12 +306,9 @@ public Projectile ToProjectile(int index) LastUpdate = DateTime.UtcNow.Date.AddMilliseconds(MillisecondsFromMidnight - HeartData.I.Net.ServerTimeOffset).Ticks }; - if (p.Guidance != null) // Assign target for self-guided projectiles + if (targetEntities != null && p.Guidance != null) // Assign target for self-guided projectiles { - if (weapon is SorterTurretLogic) - p.Guidance.SetTarget(((SorterTurretLogic)weapon).TargetEntity); - else - p.Guidance.SetTarget(WeaponManagerAi.I.GetTargeting(weapon.SorterWep.CubeGrid)?.PrimaryGridTarget); + p.Guidance.SetTarget(MyAPIGateway.Entities.GetEntityById(targetEntities[index])); } // TODO: Look into engine tick based syncing? Server time can vary DRASTICALLY.