From a3fb84e727f2690e1420245074a84a3e74799862 Mon Sep 17 00:00:00 2001 From: BDCarrillo <90526940+BDCarrillo@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:16:15 -0600 Subject: [PATCH 1/2] Functional Warheads --- Data/Scripts/CoreSystems/Ai/AiFields.cs | 1 + Data/Scripts/CoreSystems/Ai/AiSupport.cs | 8 + .../Controls/CreateCustomActions.cs | 15 +- .../EntityComp/Controls/TerminalHelpers.cs | 24 +- .../Controls/Weapon/WeaponActions.cs | 13 +- .../EntityComp/Controls/Weapon/WeaponUi.cs | 6 +- .../EntityComp/Parts/Weapon/WeaponComp.cs | 4 +- .../EntityComp/Parts/Weapon/WeaponState.cs | 2 +- .../CoreSystems/Projectiles/ProjectileHits.cs | 2 +- .../CoreSystems/Session/SessionControls.cs | 1 + .../CoreSystems/Session/SessionUpdate.cs | 208 ++++++++++-------- .../CoreSystems/Support/StaticUtils.cs | 19 ++ 12 files changed, 199 insertions(+), 104 deletions(-) diff --git a/Data/Scripts/CoreSystems/Ai/AiFields.cs b/Data/Scripts/CoreSystems/Ai/AiFields.cs index 8bf8b552..17d203da 100644 --- a/Data/Scripts/CoreSystems/Ai/AiFields.cs +++ b/Data/Scripts/CoreSystems/Ai/AiFields.cs @@ -64,6 +64,7 @@ public partial class Ai internal readonly List QueuedSounds = new List(); internal readonly List TrackingComps = new List(); internal readonly List WeaponComps = new List(32); + internal readonly List CriticalComps = new List(); internal readonly List UpgradeComps = new List(32); internal readonly List SupportComps = new List(32); internal readonly List ControlComps = new List(32); diff --git a/Data/Scripts/CoreSystems/Ai/AiSupport.cs b/Data/Scripts/CoreSystems/Ai/AiSupport.cs index 811c18e4..246c1a7b 100644 --- a/Data/Scripts/CoreSystems/Ai/AiSupport.cs +++ b/Data/Scripts/CoreSystems/Ai/AiSupport.cs @@ -33,6 +33,9 @@ internal void CompChange(bool add, CoreComponent comp) WeaponIdx.Add(wComp, WeaponComps.Count); WeaponComps.Add(wComp); + if (wComp.HasArming || wComp.IsBomb) + CriticalComps.Add(wComp); + if (wComp.Data.Repo.Values.Set.Overrides.WeaponGroupId > 0) CompWeaponGroups[wComp] = wComp.Data.Repo.Values.Set.Overrides.WeaponGroupId; @@ -56,6 +59,10 @@ internal void CompChange(bool add, CoreComponent comp) var wCompMaxWepRange = wComp.MaxDetectDistance; WeaponComps.RemoveAtFast(weaponIdx); + + if (wComp.HasArming || wComp.IsBomb) + CriticalComps.Remove(wComp); + if (weaponIdx < WeaponComps.Count) WeaponIdx[WeaponComps[weaponIdx]] = weaponIdx; WeaponIdx.Remove(wComp); @@ -505,6 +512,7 @@ internal void CleanUp() TrackingComps.Clear(); PlayerControl.Clear(); WeaponComps.Clear(); + CriticalComps.Clear(); UpgradeComps.Clear(); SupportComps.Clear(); ControlComps.Clear(); diff --git a/Data/Scripts/CoreSystems/EntityComp/Controls/CreateCustomActions.cs b/Data/Scripts/CoreSystems/EntityComp/Controls/CreateCustomActions.cs index 7260c2c6..8192288e 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Controls/CreateCustomActions.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Controls/CreateCustomActions.cs @@ -13,7 +13,7 @@ public static void CreateArmReaction(Session session) { var action = MyAPIGateway.TerminalControls.CreateAction("Arm"); action.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds"; - action.Name = new StringBuilder("Arm Critical Reaction"); + action.Name = new StringBuilder("Arm Warhead"); action.Action = CustomActions.RequestSetArmed; action.Writer = CustomActions.ArmWriter; action.Enabled = TerminalHelpers.CanBeArmed; @@ -22,6 +22,19 @@ public static void CreateArmReaction(Session session) MyAPIGateway.TerminalControls.AddAction(action); session.CustomActions.Add(action); } + public static void CreateTriggerNow(Session session) + { + var action = MyAPIGateway.TerminalControls.CreateAction("Detonate"); + action.Icon = @"Textures\GUI\Icons\Actions\SwitchOn.dds"; + action.Name = new StringBuilder("Detonate Now"); + action.Action = CustomActions.TriggerCriticalReaction; + action.Writer = TerminalHelpers.EmptyStringBuilder; + action.Enabled = TerminalHelpers.CanBeArmed; + action.ValidForGroups = true; + + MyAPIGateway.TerminalControls.AddAction(action); + session.CustomActions.Add(action); + } internal static void CreateShootMode(Session session) { diff --git a/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs b/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs index bf047550..e479e625 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs @@ -29,7 +29,7 @@ internal static void AddUiControls(Session session) where T : IMyTerminalBloc AddWeaponCrticalTimeSliderRange(session, "Detonation", Localization.GetText("TerminalDetonationTitle"), Localization.GetText("TerminalDetonationTooltip"), BlockUi.GetArmedTimer, BlockUi.RequestSetArmedTimer, NotCounting, CanBeArmed, BlockUi.GetMinCriticalTime, BlockUi.GetMaxCriticalTime, true); AddButtonNoAction(session, "StartCount", Localization.GetText("TerminalStartCountTitle"), Localization.GetText("TerminalStartCountTooltip"), BlockUi.StartCountDown, NotCounting, CanBeArmed); AddButtonNoAction(session, "StopCount", Localization.GetText("TerminalStopCountTitle"), Localization.GetText("TerminalStopCountTooltip"), BlockUi.StopCountDown, IsCounting, CanBeArmed); - AddCheckboxNoAction(session, "Arm", Localization.GetText("TerminalArmTitle"), Localization.GetText("TerminalArmTooltip"), BlockUi.GetArmed, BlockUi.RequestSetArmed, true, CanBeArmed); + AddCheckboxWarhead(session, "Arm", Localization.GetText("TerminalArmTitle"), Localization.GetText("TerminalArmTooltip"), BlockUi.GetArmed, BlockUi.RequestSetArmed, true, CanBeArmed); AddButtonNoAction(session, "Trigger", Localization.GetText("TerminalTriggerTitle"), Localization.GetText("TerminalTriggerTooltip"), BlockUi.TriggerCriticalReaction, IsArmed, CanBeArmed); } @@ -239,7 +239,7 @@ internal static bool KeyShootWeapon(IMyTerminalBlock block) { var comp = block.Components.Get(); - return comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon; + return comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon && !comp.HasArming; } internal static bool UiRofSlider(IMyTerminalBlock block) @@ -394,7 +394,7 @@ internal static bool IsFalse(IMyTerminalBlock block) internal static bool WeaponIsReadyAndSorter(IMyTerminalBlock block) { var comp = block?.Components?.Get() as Weapon.WeaponComponent; - var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon && comp.TypeSpecific == CoreComponent.CompTypeSpecific.SorterWeapon && comp.Data?.Repo != null; + var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon && comp.TypeSpecific == CoreComponent.CompTypeSpecific.SorterWeapon && comp.Data?.Repo != null && !comp.HasArming; if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip()) return false; @@ -405,7 +405,7 @@ internal static bool WeaponIsReadyAndSorter(IMyTerminalBlock block) internal static bool IsReady(IMyTerminalBlock block) { var comp = block?.Components?.Get() as Weapon.WeaponComponent; - var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null; + var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null && !comp.HasArming; if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip()) return false; @@ -984,6 +984,22 @@ internal static IMyTerminalControlCheckbox AddCheckboxNoAction(Session sessio return c; } + internal static IMyTerminalControlCheckbox AddCheckboxWarhead(Session session, string name, string title, string tooltip, Func getter, Action setter, bool allowGroup, Func visibleGetter = null, bool forceEnable = false) where T : IMyTerminalBlock + { + var c = MyAPIGateway.TerminalControls.CreateControl("WC_" + name); + + c.Title = MyStringId.GetOrCompute(title); + c.Tooltip = MyStringId.GetOrCompute(tooltip); + c.Getter = getter; + c.Setter = setter; + c.Visible = visibleGetter; + c.Enabled = CanBeArmed; + + MyAPIGateway.TerminalControls.AddControl(c); + session.CustomControls.Add(c); + + return c; + } internal static IMyTerminalControlOnOffSwitch AddOnOffSwitchNoAction(Session session, string name, string title, string tooltip, Func getter, Action setter, bool allowGroup, Func visibleGetter = null) where T : IMyTerminalBlock { diff --git a/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponActions.cs b/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponActions.cs index 32d20ba3..9d35f701 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponActions.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponActions.cs @@ -24,6 +24,15 @@ internal static void RequestSetArmed(IMyTerminalBlock blk) Weapon.WeaponComponent.RequestSetValue(comp, "Armed", newValue, Session.I.PlayerId); } + internal static void TriggerCriticalReaction(IMyTerminalBlock blk) + { + var comp = blk?.Components?.Get() as Weapon.WeaponComponent; + if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) + return; + + Weapon.WeaponComponent.RequestCriticalReaction(comp); + } + internal static void TerminalActionToggleShoot(IMyTerminalBlock blk) { var comp = blk?.Components?.Get() as Weapon.WeaponComponent; @@ -485,9 +494,9 @@ internal static void ArmWriter(IMyTerminalBlock blk, StringBuilder sb) var comp = blk.Components.Get() as Weapon.WeaponComponent; if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return; if (comp.Data.Repo.Values.Set.Overrides.Armed) - sb.Append(Localization.GetText("ActionStateOn")); + sb.Append("Armed"); else - sb.Append(Localization.GetText("ActionStateOff")); + sb.Append("Disarmed"); } internal static void ShootStateWriter(IMyTerminalBlock blk, StringBuilder sb) diff --git a/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponUi.cs b/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponUi.cs index e4bb5eaf..3c372165 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponUi.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponUi.cs @@ -936,7 +936,7 @@ internal static void RequestSetArmed(IMyTerminalBlock block, bool newValue) var value = newValue ? 1 : 0; Weapon.WeaponComponent.RequestSetValue(comp, "Armed", value, Session.I.PlayerId); - if (Session.I.IsServer) comp.Cube.UpdateTerminal(); + comp.Cube.UpdateTerminalWarhead(); } internal static void TriggerCriticalReaction(IMyTerminalBlock block) @@ -951,7 +951,7 @@ internal static void StartCountDown(IMyTerminalBlock block) var comp = block?.Components?.Get() as Weapon.WeaponComponent; if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return; Weapon.WeaponComponent.RequestCountDown(comp, true); - if (Session.I.IsServer) comp.Cube.UpdateTerminal(); + comp.Cube.UpdateTerminalWarhead(); } internal static void StopCountDown(IMyTerminalBlock block) @@ -959,7 +959,7 @@ internal static void StopCountDown(IMyTerminalBlock block) var comp = block?.Components?.Get() as Weapon.WeaponComponent; if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return; Weapon.WeaponComponent.RequestCountDown(comp, false); - if (Session.I.IsServer) comp.Cube.UpdateTerminal(); + comp.Cube.UpdateTerminalWarhead(); } internal static bool ShowCamera(IMyTerminalBlock block) diff --git a/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponComp.cs b/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponComp.cs index 0f0ec695..0a7574c2 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponComp.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponComp.cs @@ -99,7 +99,7 @@ internal WeaponComponent(MyEntity coreEntity, MyDefinitionId id) internal void WeaponInit() { var wValues = Data.Repo.Values; - var triggered = wValues.State.Trigger == Trigger.On; + var triggered = wValues.State.Trigger == Trigger.On || wValues.State.Trigger == Trigger.Once; for (int i = 0; i < Collection.Count; i++) { var w = Collection[i]; @@ -129,6 +129,8 @@ internal void WeaponInit() } else if (TypeSpecific == CompTypeSpecific.Phantom) { + if(triggered) + w.ProtoWeaponAmmo.CurrentAmmo = 1; Ai.OnlyWeaponComp = w.Comp; var maxRange = w.Comp.PrimaryWeapon.GetMaxWeaponRange(); if (maxRange > w.Comp.Ai.MaxTargetingRange) diff --git a/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponState.cs b/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponState.cs index 3f665531..96f9a61c 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponState.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponState.cs @@ -224,7 +224,7 @@ public void CriticalMonitor() { if (--cSet.Overrides.ArmedTimer == 0) { - CriticalOnDestruction(); + CriticalOnDestruction(true); } } } diff --git a/Data/Scripts/CoreSystems/Projectiles/ProjectileHits.cs b/Data/Scripts/CoreSystems/Projectiles/ProjectileHits.cs index 761849d3..89f06d5e 100644 --- a/Data/Scripts/CoreSystems/Projectiles/ProjectileHits.cs +++ b/Data/Scripts/CoreSystems/Projectiles/ProjectileHits.cs @@ -852,7 +852,7 @@ internal int GetEntityCompareDist(HitEntity x, HitEntity y, ProInfo info) { var posI = hitEnt.Vector3ICache[j]; var firstBlock = grid.GetCubeBlock(posI) as IMySlimBlock; - if (firstBlock != null && firstBlock != lastBlockHit && !firstBlock.IsDestroyed && (hitEnt.Info.Ai.AiType != Ai.AiTypes.Grid || firstBlock != hitEnt.Info.Weapon.Comp.Cube.SlimBlock || ewarWeaponDamage && firstBlock == hitEnt.Info.Weapon.Comp.Cube.SlimBlock)) + if (firstBlock != null && firstBlock != lastBlockHit && !firstBlock.IsDestroyed && (hitEnt.Info.Ai.AiType != Ai.AiTypes.Grid || firstBlock != hitEnt.Info.Weapon.Comp.Cube?.SlimBlock || ewarWeaponDamage && firstBlock == hitEnt.Info.Weapon.Comp.Cube?.SlimBlock)) { lastBlockHit = firstBlock; hitEnt.Blocks.Add(new HitEntity.RootBlocks {Block = firstBlock, QueryPos = posI}); diff --git a/Data/Scripts/CoreSystems/Session/SessionControls.cs b/Data/Scripts/CoreSystems/Session/SessionControls.cs index 55ccd72f..f13be283 100644 --- a/Data/Scripts/CoreSystems/Session/SessionControls.cs +++ b/Data/Scripts/CoreSystems/Session/SessionControls.cs @@ -207,6 +207,7 @@ internal static void CreateCustomCameraActions(Session session) where T : IMy internal static void CreateCustomActionSet(Session session) where T : IMyTerminalBlock { CreateCustomActions.CreateArmReaction(session); + CreateCustomActions.CreateTriggerNow(session); CreateCustomActions.CreateShootToggle(session); CreateCustomActions.CreateShootOn(session); CreateCustomActions.CreateShootOff(session); diff --git a/Data/Scripts/CoreSystems/Session/SessionUpdate.cs b/Data/Scripts/CoreSystems/Session/SessionUpdate.cs index 245a1418..e35f20ef 100644 --- a/Data/Scripts/CoreSystems/Session/SessionUpdate.cs +++ b/Data/Scripts/CoreSystems/Session/SessionUpdate.cs @@ -14,6 +14,7 @@ using Sandbox.ModAPI.Weapons; using SpaceEngineers.Game.ModAPI; using VRage.Game.Entity; +using VRage.Game; namespace CoreSystems { @@ -63,6 +64,122 @@ private void AiLoop() if (ai.QueuedSounds.Count > 0) ai.ProcessQueuedSounds(); + /// + /// Critical/warhead update section + /// + for (int i = 0; i < ai.CriticalComps.Count; i++) + { + var wComp = ai.CriticalComps[i]; + if (wComp.CloseCondition) + { + if (wComp.Slim != null && !wComp.Slim.IsDestroyed) + wComp.Slim.DoDamage(float.MaxValue, MyDamageType.Explosion, false); + } + var wValues = wComp.Data.Repo.Values; + var overrides = wValues.Set.Overrides; + for (int j = 0; j < wComp.Platform.Weapons.Count; j++) + { + var w = wComp.Platform.Weapons[j]; + if (w.CriticalReaction && !wComp.CloseCondition && (overrides.Armed || wValues.State.CountingDown || wValues.State.CriticalReaction)) + w.CriticalMonitor(); + } + } + + /// + /// Phantom update section + /// + for (int i = 0; i < ai.PhantomComps.Count; i++) + { + var pComp = ai.PhantomComps[i]; + + if (pComp.CloseCondition || pComp.HasCloseConsition && pComp.AllWeaponsOutOfAmmo()) + { + if (!pComp.CloseCondition) + pComp.ForceClose(pComp.SubtypeName); + continue; + } + if (pComp.Status != Started) + pComp.HealthCheck(); + if (pComp.Platform.State != CorePlatform.PlatformState.Ready || pComp.IsDisabled || pComp.IsAsleep || pComp.CoreEntity.MarkedForClose || pComp.LazyUpdate && !ai.DbUpdated && Tick > pComp.NextLazyUpdateStart) + continue; + + if (ai.DbUpdated || !pComp.UpdatedState) + { + pComp.DetectStateChanges(false); + } + + switch (pComp.Data.Repo.Values.State.Trigger) + { + case Once: + pComp.ShootManager.RequestShootSync(PlayerId, Weapon.ShootManager.RequestType.Once, Weapon.ShootManager.Signals.Once); + break; + case On: + pComp.ShootManager.RequestShootSync(PlayerId, Weapon.ShootManager.RequestType.On, Weapon.ShootManager.Signals.On); + break; + } + + var pValues = pComp.Data.Repo.Values; + var overrides = pValues.Set.Overrides; + var cMode = overrides.Control; + var sMode = overrides.ShootMode; + + var onConfrimed = pValues.State.Trigger == On && !pComp.ShootManager.FreezeClientShoot && !pComp.ShootManager.WaitingShootResponse && (sMode != Weapon.ShootManager.ShootModes.AiShoot || pComp.ShootManager.Signal == Weapon.ShootManager.Signals.Manual); + var noShootDelay = pComp.ShootManager.ShootDelay == 0 || pComp.ShootManager.ShootDelay != 0 && pComp.ShootManager.ShootDelay-- == 0; + + /// + /// Phantom update section + /// + for (int j = 0; j < pComp.Platform.Phantoms.Count; j++) + { + var p = pComp.Platform.Phantoms[j]; + if (p.ActiveAmmoDef.AmmoDef.Const.Reloadable && !p.Loading) + { + + if (IsServer && (p.ProtoWeaponAmmo.CurrentAmmo == 0 || p.CheckInventorySystem)) + p.ComputeServerStorage(); + else if (IsClient) + { + + if (p.ClientReloading && p.Reload.EndId > p.ClientEndId && p.Reload.StartId == p.ClientStartId) + p.Reloaded(); + else + p.ClientReload(); + } + } + else if (p.Loading && Tick >= p.ReloadEndTick) + p.Reloaded(1); + + var reloading = p.ActiveAmmoDef.AmmoDef.Const.Reloadable && p.ClientMakeUpShots == 0 && (p.Loading || p.ProtoWeaponAmmo.CurrentAmmo == 0); + var overHeat = p.PartState.Overheated && p.OverHeatCountDown == 0; + var canShoot = !overHeat && !reloading; + + var autoShot = pComp.Data.Repo.Values.State.Trigger == On || p.AiShooting && pComp.Data.Repo.Values.State.Trigger == Off; + var anyShot = !pComp.ShootManager.FreezeClientShoot && (p.ShootCount > 0 || onConfrimed) && noShootDelay || autoShot && sMode == Weapon.ShootManager.ShootModes.AiShoot; + + var delayedFire = p.System.DelayCeaseFire && !p.Target.IsAligned && Tick - p.CeaseFireDelayTick <= p.System.CeaseFireDelay; + var shoot = (anyShot || p.FinishShots || delayedFire); + var shotReady = canShoot && shoot; + + if (shotReady) + { + p.Shoot(); + } + else + { + + if (p.IsShooting) + p.StopShooting(); + + if (p.BarrelSpinning) + { + + var spinDown = !(shotReady && ai.CanShoot && p.System.Values.HardPoint.Loading.SpinFree); + p.SpinBarrel(spinDown); + } + } + } + } + if (ai.AiType == Ai.AiTypes.Grid && !ai.HasPower || enforcement.ServerSleepSupport && IsServer && ai.AwakeComps == 0 && ai.WeaponsTracking == 0 && ai.SleepingComps > 0 && !ai.CheckProjectiles && ai.AiSleep && !ai.DbUpdated) continue; @@ -160,94 +277,6 @@ private void AiLoop() } } - /// - /// Phantom update section - /// - for (int i = 0; i < ai.PhantomComps.Count; i++) - { - var pComp = ai.PhantomComps[i]; - - if (pComp.CloseCondition || pComp.HasCloseConsition && pComp.AllWeaponsOutOfAmmo()) { - if (!pComp.CloseCondition) - pComp.ForceClose(pComp.SubtypeName); - continue; - } - if (pComp.Status != Started) - pComp.HealthCheck(); - if (pComp.Platform.State != CorePlatform.PlatformState.Ready || pComp.IsDisabled || pComp.IsAsleep || pComp.CoreEntity.MarkedForClose || pComp.LazyUpdate && !ai.DbUpdated && Tick > pComp.NextLazyUpdateStart) - continue; - - if (ai.DbUpdated || !pComp.UpdatedState) { - pComp.DetectStateChanges(false); - } - - switch (pComp.Data.Repo.Values.State.Trigger) - { - case Once: - pComp.ShootManager.RequestShootSync(PlayerId, Weapon.ShootManager.RequestType.Once, Weapon.ShootManager.Signals.Once); - break; - case On: - pComp.ShootManager.RequestShootSync(PlayerId, Weapon.ShootManager.RequestType.On, Weapon.ShootManager.Signals.On); - break; - } - - var pValues = pComp.Data.Repo.Values; - var overrides = pValues.Set.Overrides; - var cMode = overrides.Control; - var sMode = overrides.ShootMode; - - var onConfrimed = pValues.State.Trigger == On && !pComp.ShootManager.FreezeClientShoot && !pComp.ShootManager.WaitingShootResponse && (sMode != Weapon.ShootManager.ShootModes.AiShoot || pComp.ShootManager.Signal == Weapon.ShootManager.Signals.Manual); - var noShootDelay = pComp.ShootManager.ShootDelay == 0 || pComp.ShootManager.ShootDelay != 0 && pComp.ShootManager.ShootDelay-- == 0; - - /// - /// Phantom update section - /// - for (int j = 0; j < pComp.Platform.Phantoms.Count; j++) - { - var p = pComp.Platform.Phantoms[j]; - if (p.ActiveAmmoDef.AmmoDef.Const.Reloadable && !p.Loading) { - - if (IsServer && (p.ProtoWeaponAmmo.CurrentAmmo == 0 || p.CheckInventorySystem)) - p.ComputeServerStorage(); - else if (IsClient) { - - if (p.ClientReloading && p.Reload.EndId > p.ClientEndId && p.Reload.StartId == p.ClientStartId) - p.Reloaded(); - else - p.ClientReload(); - } - } - else if (p.Loading && Tick >= p.ReloadEndTick) - p.Reloaded(1); - - var reloading = p.ActiveAmmoDef.AmmoDef.Const.Reloadable && p.ClientMakeUpShots == 0 && (p.Loading || p.ProtoWeaponAmmo.CurrentAmmo == 0); - var overHeat = p.PartState.Overheated && p.OverHeatCountDown == 0; - var canShoot = !overHeat && !reloading; - - var autoShot = pComp.Data.Repo.Values.State.Trigger == On || p.AiShooting && pComp.Data.Repo.Values.State.Trigger == Off; - var anyShot = !pComp.ShootManager.FreezeClientShoot && (p.ShootCount > 0 || onConfrimed) && noShootDelay || autoShot && sMode == Weapon.ShootManager.ShootModes.AiShoot; - - var delayedFire = p.System.DelayCeaseFire && !p.Target.IsAligned && Tick - p.CeaseFireDelayTick <= p.System.CeaseFireDelay; - var shoot = (anyShot || p.FinishShots || delayedFire); - var shotReady = canShoot && shoot; - - if (shotReady) { - p.Shoot(); - } - else { - - if (p.IsShooting) - p.StopShooting(); - - if (p.BarrelSpinning) { - - var spinDown = !(shotReady && ai.CanShoot && p.System.Values.HardPoint.Loading.SpinFree); - p.SpinBarrel(spinDown); - } - } - } - } - /// /// Control update section /// @@ -586,9 +615,6 @@ private void AiLoop() HudUi.WeaponsToDisplay.Add(w); } - if (w.CriticalReaction && !wComp.CloseCondition && (overrides.Armed || wValues.State.CountingDown || wValues.State.CriticalReaction)) - w.CriticalMonitor(); - if (w.Target.ClientDirty) w.Target.ClientUpdate(w, w.TargetData); diff --git a/Data/Scripts/CoreSystems/Support/StaticUtils.cs b/Data/Scripts/CoreSystems/Support/StaticUtils.cs index c87c8cc7..65199957 100644 --- a/Data/Scripts/CoreSystems/Support/StaticUtils.cs +++ b/Data/Scripts/CoreSystems/Support/StaticUtils.cs @@ -162,6 +162,25 @@ public static void UpdateTerminal(this MyCubeBlock block) */ } + public static void UpdateTerminalWarhead(this MyCubeBlock block) + { + ((IMyTerminalBlock)block).SetDetailedInfoDirty(); + try + { + if (block == RefreshToggleCube && RefreshToggle != null) + { + RefreshTerminalControls((IMyTerminalBlock)block); + return; + } + + if (!GetRefreshToggle()) + return; + + RefreshToggleCube = block; + RefreshTerminalControls((IMyTerminalBlock)block); + } + catch (Exception ex) { Log.Line($"Exception in UpdateTerminal: {ex}"); } + } public static bool GetRefreshToggle() { From b2b62e5c8b814fa78a3aca46bca51455cabc4942 Mon Sep 17 00:00:00 2001 From: BDCarrillo <90526940+BDCarrillo@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:58:12 -0600 Subject: [PATCH 2/2] Timer updates --- Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs b/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs index e479e625..3cae5e54 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs @@ -353,6 +353,7 @@ internal static bool NotCounting(IMyTerminalBlock block) var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null; if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip()) return false; + comp.Cube.UpdateTerminalWarhead(); return !comp.Data.Repo.Values.State.CountingDown; }