From dd98a22feb98f90ac619fa112df564a62446fe50 Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+ari-steas@users.noreply.github.com> Date: Sat, 1 Mar 2025 16:25:48 -0600 Subject: [PATCH 1/2] Emergency bounce zone fix --- .../Data/Scripts/SUGMA/GameState/BounceZone.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Gamemode Mods/StarCore SUGMA Gamemodes/Data/Scripts/SUGMA/GameState/BounceZone.cs b/Gamemode Mods/StarCore SUGMA Gamemodes/Data/Scripts/SUGMA/GameState/BounceZone.cs index 5b787af9f..ab354299d 100644 --- a/Gamemode Mods/StarCore SUGMA Gamemodes/Data/Scripts/SUGMA/GameState/BounceZone.cs +++ b/Gamemode Mods/StarCore SUGMA Gamemodes/Data/Scripts/SUGMA/GameState/BounceZone.cs @@ -20,7 +20,6 @@ internal class BounceZone : ComponentBase private int _ticks; private int _fastStart; - private readonly HashSet _skipEntityTypes = new HashSet { /* Add pre-ignored Types Here */ }; private readonly List _managedEntities = new List(1000); private readonly BoxDrawing _sphereDraw; @@ -81,17 +80,13 @@ private bool ShouldProcessEntity(MyEntity ent) Type entType = ent.GetType(); // Fast check against cache - if (_skipEntityTypes.Contains(entType) || ent.MarkedForClose || ent.IsPreview || ent.Physics == null || ent.Physics.IsPhantom || !ent.InScene) - { + if (ent.MarkedForClose || ent.IsPreview || ent.Physics == null || ent.Physics.IsPhantom || !ent.InScene) return false; - } var grid = ent as MyCubeGrid; var player = ent as IMyCharacter; if (grid == null && player == null) { - // Cache this type for future fast checks - _skipEntityTypes.Add(entType); return false; } From 6c56824eff11519a01c5e6758767495fcdca55c1 Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+ari-steas@users.noreply.github.com> Date: Thu, 6 Mar 2025 00:31:09 -0600 Subject: [PATCH 2/2] aa --- .../Data/Scripts/ShipPoints/API/StealthAPI.cs | 119 ++++++++++++++++++ .../Data/Scripts/ShipPoints/MasterSession.cs | 4 + .../ShipPoints/ShipTracking/ShipTracker.cs | 8 ++ 3 files changed, 131 insertions(+) create mode 100644 Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/StealthAPI.cs diff --git a/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/StealthAPI.cs b/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/StealthAPI.cs new file mode 100644 index 000000000..8f62cc6da --- /dev/null +++ b/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/StealthAPI.cs @@ -0,0 +1,119 @@ +using Sandbox.ModAPI; +using System; +using System.Collections.Generic; +using VRage.Game.ModAPI; + +namespace StealthSystem +{ + internal class StealthAPI + { + /// Returns true if drive status was toggled successfully. + /// Ignore power requirements and overheat. + public bool ToggleStealth(IMyTerminalBlock drive, bool force) => _toggleStealth?.Invoke(drive, force) ?? false; + + /// Returns status of drive. 0 = Ready, 1 = Active, 2 = Cooldown, 3 = Not enough power, 4 = Offline + public int GetStatus(IMyTerminalBlock drive) => _getStatus?.Invoke(drive) ?? 4; + + /// Returns remaining duration of stealth/cooldown. + public int GetDuration(IMyTerminalBlock drive) => _getDuration?.Invoke(drive) ?? 0; + + /// Retuns active stealth drive on grid if one exists, otherwise returns null. + public IMyTerminalBlock GetMainDrive(IMyCubeGrid grid) => _getMainDrive?.Invoke(grid); + + /// Collection to populate with heat sinks on grid. + public void GetHeatSinks(IMyCubeGrid grid, ICollection sinks) => _getHeatSinks?.Invoke(grid, sinks); + + + + private const long CHANNEL = 2172757427; + private bool _isRegistered; + private bool _apiInit; + private Action _readyCallback; + + private Func _toggleStealth; + private Func _getStatus; + private Func _getDuration; + private Func _getMainDrive; + private Action> _getHeatSinks; + + public bool IsReady { get; private set; } + + + /// + /// Ask CoreSystems to send the API methods. + /// Throws an exception if it gets called more than once per session without . + /// + /// Method to be called when CoreSystems replies. + public void Load(Action readyCallback = null) + { + if (_isRegistered) + throw new Exception($"{GetType().Name}.Load() should not be called multiple times!"); + + _readyCallback = readyCallback; + _isRegistered = true; + MyAPIGateway.Utilities.RegisterMessageHandler(CHANNEL, HandleMessage); + MyAPIGateway.Utilities.SendModMessage(CHANNEL, "ApiEndpointRequest"); + } + + public void Unload() + { + MyAPIGateway.Utilities.UnregisterMessageHandler(CHANNEL, HandleMessage); + + ApiAssign(null); + + _isRegistered = false; + _apiInit = false; + IsReady = false; + } + + private void HandleMessage(object obj) + { + if (_apiInit || obj is string + ) // the sent "ApiEndpointRequest" will also be received here, explicitly ignoring that + return; + + var dict = obj as IReadOnlyDictionary; + + if (dict == null) + return; + + ApiAssign(dict); + + IsReady = true; + _readyCallback?.Invoke(); + } + + public void ApiAssign(IReadOnlyDictionary delegates) + { + _apiInit = (delegates != null); + /// base methods + AssignMethod(delegates, "ToggleStealth", ref _toggleStealth); + AssignMethod(delegates, "GetStatus", ref _getStatus); + AssignMethod(delegates, "GetDuration", ref _getDuration); + AssignMethod(delegates, "GetMainDrive", ref _getMainDrive); + AssignMethod(delegates, "GetHeatSinks", ref _getHeatSinks); + } + + private void AssignMethod(IReadOnlyDictionary delegates, string name, ref T field) + where T : class + { + if (delegates == null) + { + field = null; + return; + } + + Delegate del; + if (!delegates.TryGetValue(name, out del)) + throw new Exception($"{GetType().Name} :: Couldn't find {name} delegate of type {typeof(T)}"); + + field = del as T; + + if (field == null) + throw new Exception( + $"{GetType().Name} :: Delegate {name} is not type {typeof(T)}, instead it's: {del.GetType()}"); + } + + } + +} \ No newline at end of file diff --git a/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/MasterSession.cs b/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/MasterSession.cs index 9d1c78f61..19d6edb72 100644 --- a/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/MasterSession.cs +++ b/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/MasterSession.cs @@ -4,6 +4,7 @@ using StarCore.ShareTrack.HeartNetworking; using StarCore.ShareTrack.ShipTracking; using StarCore.ShareTrack.TrackerApi; +using StealthSystem; using VRage.Game.Components; using VRageMath; @@ -20,6 +21,7 @@ internal class MasterSession : MySessionComponentBase public static MasterSession I; public static SharetrackConfig Config; + public StealthAPI StealthApi = new StealthAPI(); public HudAPIv2 TextHudApi; public Action HudRegistered = () => { }; @@ -46,6 +48,8 @@ public override void LoadData() _buildingBlockPoints = new BuildingBlockPoints(); TrackingManager.Init(); // Initialize TrackingManager, but don't start tracking yet + StealthApi.Load(); + if (!MyAPIGateway.Utilities.IsDedicated) // Initialize the sphere entities // Initialize the text_api with the HUDRegistered callback diff --git a/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs b/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs index 1c9c81463..9990a8477 100644 --- a/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs +++ b/Gamemode Mods/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs @@ -351,6 +351,14 @@ public void UpdateHud() camera.WorldMatrix.Forward); var stealthed = ((uint)Grid.Flags & 0x1000000) > 0; + + if (MasterSession.I.StealthApi?.IsReady ?? false) + { + var mainStealthDrive = MasterSession.I.StealthApi.GetMainDrive(Grid); + if (mainStealthDrive != null) + stealthed |= MasterSession.I.StealthApi.GetStatus(mainStealthDrive) == 1; + } + var visible = !(newOrigin.X > 1 || newOrigin.X < -1 || newOrigin.Y > 1 || newOrigin.Y < -1) && angle <= fov && !stealthed;