From 7e14b30f9e850f713c16cf5afeeaf1099bc14fe4 Mon Sep 17 00:00:00 2001 From: CommodoreChet <50426713+CommodoreChet@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:30:13 -0600 Subject: [PATCH 1/4] Impliment ShareTrack Siege Indicator --- .../Data/Scripts/ShipPoints/API/SCDAPI.cs | 232 ++++++++++++++++++ .../Data/Scripts/ShipPoints/AllGridsList.cs | 17 +- .../ShipPoints/ShipTracking/ShipTracker.cs | 28 +++ 3 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/SCDAPI.cs diff --git a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/SCDAPI.cs b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/SCDAPI.cs new file mode 100644 index 000000000..81f5c047c --- /dev/null +++ b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/API/SCDAPI.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Sandbox.ModAPI; +using VRage.Game.Entity; + +namespace StarCore.ShareTrack.API +{ + public class FieldGeneratorAPI + { + private bool _initialized; + + private Func _getFirstFieldGeneratorOnGrid; + + private Func _isSiegeActive; + private Action _setSiegeActive; + + private Func _isSiegeCooldownActive; + private Action _setSiegeCooldownActive; + + private Func _getSiegeCooldown; + private Action _setSiegeCooldown; + + private Func _getFieldPower; + private Action _setFieldPower; + + private Func _getMaximumFieldPower; + private Func_getMinimumFieldPower; + + private Func _getPowerDraw; + + private Func _getStability; + private Action _setStability; + + /// + /// Returns first valid field generator for the specified grid EntityID. + /// + /// EntityID of the cubegrid to check against. + /// IMyFunctionalBlock of the first field generator if one exists; otherwise, null. + public IMyFunctionalBlock GetFirstFieldGeneratorOnGrid(long entityID) => _getFirstFieldGeneratorOnGrid?.Invoke(entityID) ?? null; + + /// + /// Returns whether or not the specified block is in siege mode. + /// + /// Block to check. + /// true if siege mode is active; otherwise, false. + public bool IsSiegeActive(IMyFunctionalBlock block) => _isSiegeActive?.Invoke(block) ?? false; + + /// + /// Sets the siege mode state on the given block. + /// + /// Block whose siege state will be modified. + /// Whether siege mode should be active (true) or inactive (false). + public void SetSiegeActive(IMyFunctionalBlock block, bool Active) => _setSiegeActive?.Invoke(block, Active); + + /// + /// Returns whether or not the specified blocks siege mode is on cooldown. + /// + /// Block to check. + /// true if the cooldown is active; otherwise, false. + public bool IsSiegeCooldownActive(IMyFunctionalBlock block) => _isSiegeCooldownActive?.Invoke(block) ?? false; + + /// + /// Sets the siege mode cooldown state on the given block. + /// + /// Block whose cooldown state will be modified. + /// Whether the cooldown should be active (true) or inactive (false). + public void SetSiegeCooldownActive(IMyFunctionalBlock block, bool Active) => _setSiegeCooldownActive?.Invoke(block, Active); + + /// + /// Returns the specified blocks current cooldown time. + /// + /// Block to check. + /// The siege cooldown time, or 0 if no cooldown is active. + public int GetSiegeCooldown(IMyFunctionalBlock block) => _getSiegeCooldown?.Invoke(block) ?? 0; + + /// + /// Sets the cooldown time on the given block. + /// + /// Block whose cooldown will be modified. + /// Time to set the cooldown to, in seconds. + public void SetSiegeCooldown(IMyFunctionalBlock block, int Time) => _setSiegeCooldown?.Invoke(block, Time); + + /// + /// Returns the specified block current field power. + /// + /// Block to check. + /// The current field power. + public float GetFieldPower(IMyFunctionalBlock block) => _getFieldPower?.Invoke(block) ?? 0; + + /// + /// Sets the field power on the given block. + /// + /// Block whose field power will be modified. + /// + /// The field power to set as a float, expressed as a percentage and capped by minimum/maximum field power. + /// + public void SetFieldPower(IMyFunctionalBlock block, float Power) => _setFieldPower?.Invoke(block, Power); + + /// + /// Returns the specified blocks maximum field power. + /// + /// Block to check. + /// The maximum field power. + public float GetMaximumFieldPower(IMyFunctionalBlock block) => _getMaximumFieldPower?.Invoke(block) ?? 0; + + /// + /// Returns the specified block minimum field power. + /// + /// Block to check. + /// The minimum field power. + public float GetMinimumFieldPower(IMyFunctionalBlock block) => _getMinimumFieldPower?.Invoke(block) ?? 0; + + /// + /// Returns the specified blocks current power draw. + /// + /// Block to check. + /// The current power draw. + public float GetPowerDraw(IMyFunctionalBlock block) => _getPowerDraw?.Invoke(block) ?? 0; + + /// + /// Returns the specified blocks current stability. + /// + /// Block to check. + /// The current stability. + public float GetStability(IMyFunctionalBlock block) => _getStability?.Invoke(block) ?? 0; + + /// + /// Sets the stability on the given block. + /// + /// Block whose stability will be modified. + /// + /// The stability to set as a float, expressed as a percentage with a maximum of 100. + /// + public void SetStability(IMyFunctionalBlock block, float Stability) => _setStability?.Invoke(block, Stability); + + + private const long HandlerID = 917632; + private bool _APIRegistered; + private Action _ReadyCallback; + + public bool IsReady { get; private set; } + + + public void LoadAPI(Action ReadyCallback = null) + { + if (_APIRegistered) + throw new Exception($"{GetType().Name}.LoadAPI() should not be called multiple times!"); + + _ReadyCallback = ReadyCallback; + _APIRegistered = true; + MyAPIGateway.Utilities.RegisterMessageHandler(HandlerID, HandleMessage); + MyAPIGateway.Utilities.SendModMessage(HandlerID, "APIRequest"); + } + + public void UnloadAPI() + { + MyAPIGateway.Utilities.UnregisterMessageHandler(HandlerID, HandleMessage); + + ApiAssign(null); + + _APIRegistered = false; + _initialized = false; + IsReady = false; + } + + private void HandleMessage(object obj) + { + if (_initialized || obj is string) + return; + + var dict = obj as IReadOnlyDictionary; + + if (dict == null) + return; + + ApiAssign(dict); + + IsReady = true; + _ReadyCallback?.Invoke(); + } + + public void ApiAssign(IReadOnlyDictionary delegates) + { + _initialized = delegates != null; + + AssignMethod(delegates, "GetFirstFieldGeneratorOnGrid", ref _getFirstFieldGeneratorOnGrid); + + AssignMethod(delegates, "IsSiegeActive", ref _isSiegeActive); + AssignMethod(delegates, "SetSiegeActive", ref _setSiegeActive); + + AssignMethod(delegates, "IsSiegeCooldownActive", ref _isSiegeCooldownActive); + AssignMethod(delegates, "SetSiegeCooldownActive", ref _setSiegeCooldownActive); + + AssignMethod(delegates, "GetSiegeCooldown", ref _getSiegeCooldown); + AssignMethod(delegates, "SetSiegeCooldown", ref _setSiegeCooldown); + + AssignMethod(delegates, "GetFieldPower", ref _getFieldPower); + AssignMethod(delegates, "SetFieldPower", ref _setFieldPower); + + AssignMethod(delegates, "GetMaximumFieldPower", ref _getMaximumFieldPower); + AssignMethod(delegates, "GetMinimumFieldPower", ref _getMinimumFieldPower); + + AssignMethod(delegates, "GetPowerDraw", ref _getPowerDraw); + + AssignMethod(delegates, "GetStability", ref _getStability); + AssignMethod(delegates, "SetStability", ref _setStability); + } + + 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()}"); + } + } +} diff --git a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/AllGridsList.cs b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/AllGridsList.cs index cb8dc4e54..e631096e1 100644 --- a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/AllGridsList.cs +++ b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/AllGridsList.cs @@ -264,8 +264,18 @@ private string CreateDisplayString(string ownerName, ShipTracker tracker, int we var functionalColor = tracker.IsFunctional ? "white" : "red"; var integrityColor = integrityPercent >= 75 ? "White" : integrityPercent >= 50 ? "LightCoral" : integrityPercent >= 25 ? "IndianRed" : "FireBrick"; + var siegeColor = "white"; + string siegeDisplay = ""; + if (tracker.FieldGenerator != null) + { + siegeDisplay = tracker.IsSiegeActive ? "[SIEGED] " : ""; + siegeColor = tracker.IsSiegeActive ? tracker.GeneratorDisplayBlink == 1 ? "red" : "yellow" : "white"; + + tracker.GeneratorDisplayBlink = 1 - tracker.GeneratorDisplayBlink; + } + return - $"{ownerDisplay,-8}{integrityPercent,3}% P:{power,3} T:{thrust,3} W:{wep} S:{shieldPercent,3}%"; + $"{siegeDisplay}{ownerDisplay,-8}{integrityPercent,3}% P:{power,3} T:{thrust,3} W:{wep} S:{shieldPercent,3}%"; } @@ -322,6 +332,7 @@ public static IMyCubeGrid RaycastGridFromCamera() public WcApi WcApi { get; private set; } public ShieldApi ShieldApi { get; private set; } public RtsApi RtsApi { get; private set; } + public FieldGeneratorAPI FieldGeneratorAPI { get; private set; } private HudPointsList _hudPointsList; @@ -372,6 +383,9 @@ public void InitApi() // Initialize the RTS_api and load it if it's not null RtsApi = new RtsApi(); RtsApi?.Load(); + + FieldGeneratorAPI = new FieldGeneratorAPI(); + FieldGeneratorAPI?.LoadAPI(); } public void Close() @@ -381,6 +395,7 @@ public void Close() WcApi?.Unload(); ShieldApi?.Unload(); RtsApi?.Unload(); + FieldGeneratorAPI?.UnloadAPI(); if (PointValues != null) { PointValues.Clear(); diff --git a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs index 57511dc9d..8966c6fd8 100644 --- a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs +++ b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs @@ -124,6 +124,7 @@ private void TransferToGrid(IMyCubeGrid newGrid, bool showOnHud = true) } private ShieldApi ShieldApi => AllGridsList.I.ShieldApi; + private FieldGeneratorAPI FieldGeneratorAPI => AllGridsList.I.FieldGeneratorAPI; public IMyCubeGrid Grid { get; private set; } @@ -655,6 +656,33 @@ public Dictionary WeaponCounts #endregion + #region Field Generator Stats + public IMyFunctionalBlock FieldGenerator => FieldGeneratorAPI.GetFirstFieldGeneratorOnGrid(Grid.EntityId); + + public bool IsSiegeActive + { + get + { + var fieldGenerator = FieldGeneratorAPI.GetFirstFieldGeneratorOnGrid(Grid.EntityId); + if (fieldGenerator == null) + return false; + return FieldGeneratorAPI.IsSiegeActive(fieldGenerator); + } + } + + public float CurrentFieldPower + { + get + { + var fieldGenerator = FieldGeneratorAPI.GetFirstFieldGeneratorOnGrid(Grid.EntityId); + if (fieldGenerator == null) + return 0; + return FieldGeneratorAPI.GetFieldPower(fieldGenerator); + } + } + + public int GeneratorDisplayBlink; + #endregion #endregion } } \ No newline at end of file From 96fd91fa8d20f7c49c2c0ecb1d7f206f847cb1c5 Mon Sep 17 00:00:00 2001 From: CommodoreChet <50426713+CommodoreChet@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:54:15 -0600 Subject: [PATCH 2/4] Additional --- .../ShipPoints/ShipTracking/ShipTracker.cs | 2 + .../FieldGenerator/FieldGenerator_Config.cs | 214 ++++++++++++++++++ .../FieldGenerator/FieldGenerator_Core.cs | 26 +-- 3 files changed, 218 insertions(+), 24 deletions(-) create mode 100644 Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs diff --git a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs index 8966c6fd8..3f8cc4b92 100644 --- a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs +++ b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs @@ -371,6 +371,8 @@ public void UpdateHud() nameTagText += "\n" + GridName; if (!IsFunctional) nameTagText += ":[Dead]"; + if (FieldGenerator != null) + nameTagText += IsSiegeActive ? " [SIEGED]" : ""; _nametag.Message.Append(nameTagText.TrimStart('\n')); _nametag.Offset = -_nametag.GetTextLength() / 2; diff --git a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs new file mode 100644 index 000000000..7b821d10f --- /dev/null +++ b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs @@ -0,0 +1,214 @@ +using System; +using System.IO; +using Sandbox.ModAPI; +using VRage.Game.Components; +using VRage.Game.ModAPI.Ingame.Utilities; // this ingame namespace is safe to use in mods as it has nothing to collide with +using VRage.Utils; + +namespace Starcore.FieldGenerator +{ + [MySessionComponentDescriptor(MyUpdateOrder.NoUpdate)] + public class FieldGenerator_Config : MySessionComponentBase + { + public static Generator_Settings Config { get; private set; } = new Generator_Settings(); + + public override void LoadData() + { + Config.Load(); + } + } + + public class Generator_Settings + { + const string VariableId = nameof(FieldGenerator_Config); // IMPORTANT: must be unique as it gets written in a shared space (sandbox.sbc) + const string FileName = "FieldGenerator_Config.ini"; // the file that gets saved to world storage under your mod's folder + const string IniSection = "FieldGenerator_Config"; + + // settings you'd be reading, and their defaults. + public bool SimplifiedMode = true; + + public int MaxModuleCount = 4; + public float PerModuleAmount = 10f; + + public float MaxPowerDraw = 500.00f; + public float MinPowerDraw = 50.00f; + + public int MaxSiegeTime = 60; + public int SiegePowerDraw = 900; + public float SiegeModeResistence = 0.9f; + + // Stability Related Settings - Locked Behind Simplified + public int DamageEventThreshold = 6; + public int ResetInterval = 3; + + public int MinBlockCount = 2500; + public int MaxBlockCount = 35000; + + public float SizeModifierMin = 1.2f; + public float SizeModifierMax = 0.8f; + + void LoadConfig(MyIni iniParser) + { + MaxModuleCount = iniParser.Get(IniSection, nameof(MaxModuleCount)).ToInt32(MaxModuleCount); + PerModuleAmount = iniParser.Get(IniSection, nameof(PerModuleAmount)).ToSingle(PerModuleAmount); + + MaxPowerDraw = iniParser.Get(IniSection, nameof(MaxPowerDraw)).ToSingle(MaxPowerDraw); + MinPowerDraw = iniParser.Get(IniSection, nameof(MinPowerDraw)).ToSingle(MinPowerDraw); + + MaxSiegeTime = iniParser.Get(IniSection, nameof(MaxSiegeTime)).ToInt32(MaxSiegeTime); + SiegePowerDraw = iniParser.Get(IniSection, nameof(SiegePowerDraw)).ToInt32(SiegePowerDraw); + SiegeModeResistence = iniParser.Get(IniSection, nameof(SiegeModeResistence)).ToSingle(SiegeModeResistence); + + SimplifiedMode = iniParser.Get(IniSection, nameof(SimplifiedMode)).ToBoolean(SimplifiedMode); + + DamageEventThreshold = iniParser.Get(IniSection, nameof(DamageEventThreshold)).ToInt32(DamageEventThreshold); + ResetInterval = iniParser.Get(IniSection, nameof(ResetInterval)).ToInt32(ResetInterval); + + MinBlockCount = iniParser.Get(IniSection, nameof(MinBlockCount)).ToInt32(MinBlockCount); + MaxBlockCount = iniParser.Get(IniSection, nameof(MaxBlockCount)).ToInt32(MaxBlockCount); + + SizeModifierMin = iniParser.Get(IniSection, nameof(SizeModifierMin)).ToSingle(SizeModifierMin); + SizeModifierMax = iniParser.Get(IniSection, nameof(SizeModifierMax)).ToSingle(SizeModifierMax); + } + + void SaveConfig(MyIni iniParser) + { + iniParser.Set(IniSection, nameof(MaxModuleCount), MaxModuleCount); + iniParser.SetComment(IniSection, nameof(MaxModuleCount), + " \n[Maximum number of upgrade modules that can be attached to the Field Generator core.]\n" + + "[Each core has 4 mounting points by default.]\n" + + "[Default: 4]"); + + iniParser.Set(IniSection, nameof(PerModuleAmount), PerModuleAmount); + iniParser.SetComment(IniSection, nameof(PerModuleAmount), + " \n[Amount of resistance each attached upgrade module provides.]\n" + + "[Default: 10.0]"); + + iniParser.Set(IniSection, nameof(MaxPowerDraw), MaxPowerDraw); + iniParser.SetComment(IniSection, nameof(MaxPowerDraw), + " \n[The maximum power draw (in MW) when the Field Generator is at full power.]\n" + + "[Default: 500 MW]"); + + iniParser.Set(IniSection, nameof(MinPowerDraw), MinPowerDraw); + iniParser.SetComment(IniSection, nameof(MinPowerDraw), + " \n[Baseline power draw (in MW) at minimum field power.]\n" + + "[Default: 50 MW]"); + + iniParser.Set(IniSection, nameof(MaxSiegeTime), MaxSiegeTime); + iniParser.SetComment(IniSection, nameof(MaxSiegeTime), + " \n[Maximum duration (in seconds) the Field Generator can remain in Siege mode.]\n" + + "[Default: 60s]\n"); + + iniParser.Set(IniSection, nameof(SiegePowerDraw), SiegePowerDraw); + iniParser.SetComment(IniSection, nameof(SiegePowerDraw), + " \n[Power draw (in MW) while Siege mode is active.]\n" + + "[Overrides normal scaled power draw.]\n" + + "[Default: 900 MW]"); + + iniParser.Set(IniSection, nameof(SiegeModeResistence), SiegeModeResistence); + iniParser.SetComment(IniSection, nameof(SiegeModeResistence), + " \n[Amount of damage resistance provided by Siege mode (0.0 to 1.0).]\n" + + "[Example: 0.9 means 90% damage reduction from normal.]\n" + + "[Default: 0.9]"); + + iniParser.Set(IniSection, nameof(SimplifiedMode), SimplifiedMode); + iniParser.SetComment(IniSection, nameof(SimplifiedMode), + " \n[Whether to disable (true) or enable (false) the advanced stability system.]\n" + + "[Default: true]"); + + iniParser.Set(IniSection, nameof(DamageEventThreshold), DamageEventThreshold); + iniParser.SetComment(IniSection, nameof(DamageEventThreshold), + " \n[Number of damage events (within ResetInterval) needed to trigger stability reduction.]\n" + + "[Default: 6]"); + + iniParser.Set(IniSection, nameof(ResetInterval), ResetInterval); + iniParser.SetComment(IniSection, nameof(ResetInterval), + " \n[Time interval (in seconds) between damage counter resets.]\n" + + "[Default: 3]"); + + iniParser.Set(IniSection, nameof(MinBlockCount), MinBlockCount); + iniParser.SetComment(IniSection, nameof(MinBlockCount), + " \n[Minimum grid block count used in the size-based stability calculation.]\n" + + "[Default: 2500]"); + + iniParser.Set(IniSection, nameof(MaxBlockCount), MaxBlockCount); + iniParser.SetComment(IniSection, nameof(MaxBlockCount), + " \n[Maximum grid block count used in the size-based stability calculation.]\n" + + "[Default: 35000]"); + + iniParser.Set(IniSection, nameof(SizeModifierMin), SizeModifierMin); + iniParser.SetComment(IniSection, nameof(SizeModifierMin), + " \n[The lower bound of the size modifier.]\n" + + "[Size Modifier can reduce or increase stability change based on the grid size. This Min is the Increase at Min Grid Size]\n" + + "[Default: 1.2]"); + + iniParser.Set(IniSection, nameof(SizeModifierMax), SizeModifierMax); + iniParser.SetComment(IniSection, nameof(SizeModifierMax), + " \n[The upper bound of the size modifier.]\n" + + "[Size Modifier can reduce or increase stability change based on the grid size. This Max is the Reduction at Max Grid Size]\n" + + "[Default: 0.8]"); + } + + // nothing to edit below this point + + public Generator_Settings() + { + } + + public void Load() + { + if(MyAPIGateway.Session.IsServer) + LoadOnHost(); + else + LoadOnClient(); + } + + void LoadOnHost() + { + MyIni iniParser = new MyIni(); + + // load file if exists then save it regardless so that it can be sanitized and updated + + if(MyAPIGateway.Utilities.FileExistsInWorldStorage(FileName, typeof(Generator_Settings))) + { + using(TextReader file = MyAPIGateway.Utilities.ReadFileInWorldStorage(FileName, typeof(Generator_Settings))) + { + string text = file.ReadToEnd(); + + MyIniParseResult result; + if(!iniParser.TryParse(text, out result)) + throw new Exception($"Config error: {result.ToString()}"); + + LoadConfig(iniParser); + } + } + + iniParser.Clear(); // remove any existing settings that might no longer exist + + SaveConfig(iniParser); + + string saveText = iniParser.ToString(); + + MyAPIGateway.Utilities.SetVariable(VariableId, saveText); + + using(TextWriter file = MyAPIGateway.Utilities.WriteFileInWorldStorage(FileName, typeof(Generator_Settings))) + { + file.Write(saveText); + } + } + + void LoadOnClient() + { + string text; + if(!MyAPIGateway.Utilities.GetVariable(VariableId, out text)) + throw new Exception("No config found in sandbox.sbc!"); + + MyIni iniParser = new MyIni(); + MyIniParseResult result; + if(!iniParser.TryParse(text, out result)) + throw new Exception($"Config error: {result.ToString()}"); + + LoadConfig(iniParser); + } + } +} \ No newline at end of file diff --git a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs index 5275154c1..ab5b00db3 100644 --- a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs +++ b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs @@ -24,30 +24,6 @@ namespace Starcore.FieldGenerator { - public class Config - { - public const bool SimplifiedMode = true; - - public const float PerModuleAmount = 10f; - public const int MaxModuleCount = 4; - - public const int MaxSiegeTime = 60; - public const int SiegePowerDraw = 900; - public const float SiegeModeResistence = 0.9f; - - public const int DamageEventThreshold = 6; - public const int ResetInterval = 3; - - public const float SizeModifierMax = 0.8f; - public const int MaxBlockCount = 35000; - - public const float SizeModifierMin = 1.2f; - public const int MinBlockCount = 2500; - - public const float MaxPowerDraw = 500.00f; - public const float MinPowerDraw = 50.00f; - } - [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Collector), false, "FieldGen_Core")] public class FieldGenerator : MyGameLogicComponent, IMyEventProxy { @@ -55,6 +31,8 @@ public class FieldGenerator : MyGameLogicComponent, IMyEventProxy private readonly bool IsServer = MyAPIGateway.Session.IsServer; public readonly Guid SettingsID = new Guid("7A7AC398-FAE3-44E5-ABD5-8AE49434DDF6"); + private Generator_Settings Config = FieldGenerator_Config.Config; + private int _damageEventCounter = 0; private float _stabilityChange = 0; private int _resetCounter = 0; From 25ccfff08469a195fb3aa2c185c8855ee0d82fad Mon Sep 17 00:00:00 2001 From: CommodoreChet <50426713+CommodoreChet@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:54:36 -0600 Subject: [PATCH 3/4] Revert "Additional" This reverts commit 96fd91fa8d20f7c49c2c0ecb1d7f206f847cb1c5. --- .../ShipPoints/ShipTracking/ShipTracker.cs | 2 - .../FieldGenerator/FieldGenerator_Config.cs | 214 ------------------ .../FieldGenerator/FieldGenerator_Core.cs | 26 ++- 3 files changed, 24 insertions(+), 218 deletions(-) delete mode 100644 Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs diff --git a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs index 3f8cc4b92..8966c6fd8 100644 --- a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs +++ b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs @@ -371,8 +371,6 @@ public void UpdateHud() nameTagText += "\n" + GridName; if (!IsFunctional) nameTagText += ":[Dead]"; - if (FieldGenerator != null) - nameTagText += IsSiegeActive ? " [SIEGED]" : ""; _nametag.Message.Append(nameTagText.TrimStart('\n')); _nametag.Offset = -_nametag.GetTextLength() / 2; diff --git a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs deleted file mode 100644 index 7b821d10f..000000000 --- a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Config.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.IO; -using Sandbox.ModAPI; -using VRage.Game.Components; -using VRage.Game.ModAPI.Ingame.Utilities; // this ingame namespace is safe to use in mods as it has nothing to collide with -using VRage.Utils; - -namespace Starcore.FieldGenerator -{ - [MySessionComponentDescriptor(MyUpdateOrder.NoUpdate)] - public class FieldGenerator_Config : MySessionComponentBase - { - public static Generator_Settings Config { get; private set; } = new Generator_Settings(); - - public override void LoadData() - { - Config.Load(); - } - } - - public class Generator_Settings - { - const string VariableId = nameof(FieldGenerator_Config); // IMPORTANT: must be unique as it gets written in a shared space (sandbox.sbc) - const string FileName = "FieldGenerator_Config.ini"; // the file that gets saved to world storage under your mod's folder - const string IniSection = "FieldGenerator_Config"; - - // settings you'd be reading, and their defaults. - public bool SimplifiedMode = true; - - public int MaxModuleCount = 4; - public float PerModuleAmount = 10f; - - public float MaxPowerDraw = 500.00f; - public float MinPowerDraw = 50.00f; - - public int MaxSiegeTime = 60; - public int SiegePowerDraw = 900; - public float SiegeModeResistence = 0.9f; - - // Stability Related Settings - Locked Behind Simplified - public int DamageEventThreshold = 6; - public int ResetInterval = 3; - - public int MinBlockCount = 2500; - public int MaxBlockCount = 35000; - - public float SizeModifierMin = 1.2f; - public float SizeModifierMax = 0.8f; - - void LoadConfig(MyIni iniParser) - { - MaxModuleCount = iniParser.Get(IniSection, nameof(MaxModuleCount)).ToInt32(MaxModuleCount); - PerModuleAmount = iniParser.Get(IniSection, nameof(PerModuleAmount)).ToSingle(PerModuleAmount); - - MaxPowerDraw = iniParser.Get(IniSection, nameof(MaxPowerDraw)).ToSingle(MaxPowerDraw); - MinPowerDraw = iniParser.Get(IniSection, nameof(MinPowerDraw)).ToSingle(MinPowerDraw); - - MaxSiegeTime = iniParser.Get(IniSection, nameof(MaxSiegeTime)).ToInt32(MaxSiegeTime); - SiegePowerDraw = iniParser.Get(IniSection, nameof(SiegePowerDraw)).ToInt32(SiegePowerDraw); - SiegeModeResistence = iniParser.Get(IniSection, nameof(SiegeModeResistence)).ToSingle(SiegeModeResistence); - - SimplifiedMode = iniParser.Get(IniSection, nameof(SimplifiedMode)).ToBoolean(SimplifiedMode); - - DamageEventThreshold = iniParser.Get(IniSection, nameof(DamageEventThreshold)).ToInt32(DamageEventThreshold); - ResetInterval = iniParser.Get(IniSection, nameof(ResetInterval)).ToInt32(ResetInterval); - - MinBlockCount = iniParser.Get(IniSection, nameof(MinBlockCount)).ToInt32(MinBlockCount); - MaxBlockCount = iniParser.Get(IniSection, nameof(MaxBlockCount)).ToInt32(MaxBlockCount); - - SizeModifierMin = iniParser.Get(IniSection, nameof(SizeModifierMin)).ToSingle(SizeModifierMin); - SizeModifierMax = iniParser.Get(IniSection, nameof(SizeModifierMax)).ToSingle(SizeModifierMax); - } - - void SaveConfig(MyIni iniParser) - { - iniParser.Set(IniSection, nameof(MaxModuleCount), MaxModuleCount); - iniParser.SetComment(IniSection, nameof(MaxModuleCount), - " \n[Maximum number of upgrade modules that can be attached to the Field Generator core.]\n" + - "[Each core has 4 mounting points by default.]\n" + - "[Default: 4]"); - - iniParser.Set(IniSection, nameof(PerModuleAmount), PerModuleAmount); - iniParser.SetComment(IniSection, nameof(PerModuleAmount), - " \n[Amount of resistance each attached upgrade module provides.]\n" + - "[Default: 10.0]"); - - iniParser.Set(IniSection, nameof(MaxPowerDraw), MaxPowerDraw); - iniParser.SetComment(IniSection, nameof(MaxPowerDraw), - " \n[The maximum power draw (in MW) when the Field Generator is at full power.]\n" + - "[Default: 500 MW]"); - - iniParser.Set(IniSection, nameof(MinPowerDraw), MinPowerDraw); - iniParser.SetComment(IniSection, nameof(MinPowerDraw), - " \n[Baseline power draw (in MW) at minimum field power.]\n" + - "[Default: 50 MW]"); - - iniParser.Set(IniSection, nameof(MaxSiegeTime), MaxSiegeTime); - iniParser.SetComment(IniSection, nameof(MaxSiegeTime), - " \n[Maximum duration (in seconds) the Field Generator can remain in Siege mode.]\n" + - "[Default: 60s]\n"); - - iniParser.Set(IniSection, nameof(SiegePowerDraw), SiegePowerDraw); - iniParser.SetComment(IniSection, nameof(SiegePowerDraw), - " \n[Power draw (in MW) while Siege mode is active.]\n" + - "[Overrides normal scaled power draw.]\n" + - "[Default: 900 MW]"); - - iniParser.Set(IniSection, nameof(SiegeModeResistence), SiegeModeResistence); - iniParser.SetComment(IniSection, nameof(SiegeModeResistence), - " \n[Amount of damage resistance provided by Siege mode (0.0 to 1.0).]\n" + - "[Example: 0.9 means 90% damage reduction from normal.]\n" + - "[Default: 0.9]"); - - iniParser.Set(IniSection, nameof(SimplifiedMode), SimplifiedMode); - iniParser.SetComment(IniSection, nameof(SimplifiedMode), - " \n[Whether to disable (true) or enable (false) the advanced stability system.]\n" + - "[Default: true]"); - - iniParser.Set(IniSection, nameof(DamageEventThreshold), DamageEventThreshold); - iniParser.SetComment(IniSection, nameof(DamageEventThreshold), - " \n[Number of damage events (within ResetInterval) needed to trigger stability reduction.]\n" + - "[Default: 6]"); - - iniParser.Set(IniSection, nameof(ResetInterval), ResetInterval); - iniParser.SetComment(IniSection, nameof(ResetInterval), - " \n[Time interval (in seconds) between damage counter resets.]\n" + - "[Default: 3]"); - - iniParser.Set(IniSection, nameof(MinBlockCount), MinBlockCount); - iniParser.SetComment(IniSection, nameof(MinBlockCount), - " \n[Minimum grid block count used in the size-based stability calculation.]\n" + - "[Default: 2500]"); - - iniParser.Set(IniSection, nameof(MaxBlockCount), MaxBlockCount); - iniParser.SetComment(IniSection, nameof(MaxBlockCount), - " \n[Maximum grid block count used in the size-based stability calculation.]\n" + - "[Default: 35000]"); - - iniParser.Set(IniSection, nameof(SizeModifierMin), SizeModifierMin); - iniParser.SetComment(IniSection, nameof(SizeModifierMin), - " \n[The lower bound of the size modifier.]\n" + - "[Size Modifier can reduce or increase stability change based on the grid size. This Min is the Increase at Min Grid Size]\n" + - "[Default: 1.2]"); - - iniParser.Set(IniSection, nameof(SizeModifierMax), SizeModifierMax); - iniParser.SetComment(IniSection, nameof(SizeModifierMax), - " \n[The upper bound of the size modifier.]\n" + - "[Size Modifier can reduce or increase stability change based on the grid size. This Max is the Reduction at Max Grid Size]\n" + - "[Default: 0.8]"); - } - - // nothing to edit below this point - - public Generator_Settings() - { - } - - public void Load() - { - if(MyAPIGateway.Session.IsServer) - LoadOnHost(); - else - LoadOnClient(); - } - - void LoadOnHost() - { - MyIni iniParser = new MyIni(); - - // load file if exists then save it regardless so that it can be sanitized and updated - - if(MyAPIGateway.Utilities.FileExistsInWorldStorage(FileName, typeof(Generator_Settings))) - { - using(TextReader file = MyAPIGateway.Utilities.ReadFileInWorldStorage(FileName, typeof(Generator_Settings))) - { - string text = file.ReadToEnd(); - - MyIniParseResult result; - if(!iniParser.TryParse(text, out result)) - throw new Exception($"Config error: {result.ToString()}"); - - LoadConfig(iniParser); - } - } - - iniParser.Clear(); // remove any existing settings that might no longer exist - - SaveConfig(iniParser); - - string saveText = iniParser.ToString(); - - MyAPIGateway.Utilities.SetVariable(VariableId, saveText); - - using(TextWriter file = MyAPIGateway.Utilities.WriteFileInWorldStorage(FileName, typeof(Generator_Settings))) - { - file.Write(saveText); - } - } - - void LoadOnClient() - { - string text; - if(!MyAPIGateway.Utilities.GetVariable(VariableId, out text)) - throw new Exception("No config found in sandbox.sbc!"); - - MyIni iniParser = new MyIni(); - MyIniParseResult result; - if(!iniParser.TryParse(text, out result)) - throw new Exception($"Config error: {result.ToString()}"); - - LoadConfig(iniParser); - } - } -} \ No newline at end of file diff --git a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs index ab5b00db3..5275154c1 100644 --- a/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs +++ b/Utility Mods/Stable/SCDefenseBlocks/Data/Scripts/OneFuckingFolderDeeper/FieldGenerator/FieldGenerator_Core.cs @@ -24,6 +24,30 @@ namespace Starcore.FieldGenerator { + public class Config + { + public const bool SimplifiedMode = true; + + public const float PerModuleAmount = 10f; + public const int MaxModuleCount = 4; + + public const int MaxSiegeTime = 60; + public const int SiegePowerDraw = 900; + public const float SiegeModeResistence = 0.9f; + + public const int DamageEventThreshold = 6; + public const int ResetInterval = 3; + + public const float SizeModifierMax = 0.8f; + public const int MaxBlockCount = 35000; + + public const float SizeModifierMin = 1.2f; + public const int MinBlockCount = 2500; + + public const float MaxPowerDraw = 500.00f; + public const float MinPowerDraw = 50.00f; + } + [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Collector), false, "FieldGen_Core")] public class FieldGenerator : MyGameLogicComponent, IMyEventProxy { @@ -31,8 +55,6 @@ public class FieldGenerator : MyGameLogicComponent, IMyEventProxy private readonly bool IsServer = MyAPIGateway.Session.IsServer; public readonly Guid SettingsID = new Guid("7A7AC398-FAE3-44E5-ABD5-8AE49434DDF6"); - private Generator_Settings Config = FieldGenerator_Config.Config; - private int _damageEventCounter = 0; private float _stabilityChange = 0; private int _resetCounter = 0; From defb0edf6e40a8963f246cce03c712339b96c428 Mon Sep 17 00:00:00 2001 From: CommodoreChet <50426713+CommodoreChet@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:55:32 -0600 Subject: [PATCH 4/4] Additional --- .../Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs index 8966c6fd8..137085f65 100644 --- a/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs +++ b/Gamemode Mods/Stable/Starcore_Sharetrack/Data/Scripts/ShipPoints/ShipTracking/ShipTracker.cs @@ -371,6 +371,8 @@ public void UpdateHud() nameTagText += "\n" + GridName; if (!IsFunctional) nameTagText += ":[Dead]"; + if (FieldGenerator != null) + nameTagText += IsSiegeActive ? " [SIEGED]" : ""; _nametag.Message.Append(nameTagText.TrimStart('\n')); _nametag.Offset = -_nametag.GetTextLength() / 2;