From 215441cabe00a018cd91f10ebfafe01fc7b94ee2 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 16 Jul 2024 19:52:38 -0500 Subject: [PATCH 1/4] Update ShieldCharge.cs --- .../DefenseShields/ShieldLogic/ShieldCharge.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs index 6293d8b..af4549e 100644 --- a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs +++ b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs @@ -217,12 +217,22 @@ private float PowerNeeded(float hpsEfficiency) ShieldChargeRate = 0; } } - - _powerNeeded = _shieldMaintaintPower + _shieldConsumptionRate + _otherPower; + float shuntingEnergyMultiplier = CalculateShuntedEnergyMultiplier(); + // Adjust total power needed to include shunting cost + _powerNeeded = (_shieldMaintaintPower + _shieldConsumptionRate + _otherPower) * shuntingEnergyMultiplier; return powerForShield; } + private float CalculateShuntedEnergyMultiplier() + { + // Count the number of shunted sides + int shuntedSides = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); + + // Calculate the multiplier (5% increase per shunted side) + return 1f + (shuntedSides * 0.05f); + } + private bool PowerLoss(bool powerLost, bool serverNoPower) { if (powerLost) { From bdb7a557f9def29667bd883157c549c11daea2bc Mon Sep 17 00:00:00 2001 From: MuzzMuzz <48306411+MuzzMuzz@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:08:14 -0600 Subject: [PATCH 2/4] Calc changes shuntedCount multiplier now also affects _shieldMaintaintPower. Should mean its progressively less efficient the more shunts you use. --- .../DefenseShields/ShieldLogic/ShieldCharge.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs index af4549e..1d855fc 100644 --- a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs +++ b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs @@ -193,6 +193,13 @@ private float PowerNeeded(float hpsEfficiency) var cleanPower = ShieldAvailablePower + ShieldCurrentPower; _otherPower = ShieldMaxPower - cleanPower; + + // Get multiplier from shunt count + float shuntingEnergyMultiplier = CalculateShuntedEnergyMultiplier(); + + // Apply shunting multiplier to shield maintenance power + _shieldMaintaintPower *= shuntingEnergyMultiplier; + var powerForShield = (cleanPower * 0.9f) - _shieldMaintaintPower; var rawMaxChargeRate = powerForShield > 0 ? powerForShield : 0f; rawMaxChargeRate = MathHelper.Clamp(rawMaxChargeRate, minRecharge, maxRecharge); @@ -217,7 +224,8 @@ private float PowerNeeded(float hpsEfficiency) ShieldChargeRate = 0; } } - float shuntingEnergyMultiplier = CalculateShuntedEnergyMultiplier(); + + // Adjust total power needed to include shunting cost _powerNeeded = (_shieldMaintaintPower + _shieldConsumptionRate + _otherPower) * shuntingEnergyMultiplier; @@ -226,11 +234,11 @@ private float PowerNeeded(float hpsEfficiency) private float CalculateShuntedEnergyMultiplier() { - // Count the number of shunted sides - int shuntedSides = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); + // Calculation taken from TapiBackend.cs line 969, counts shunts. + int shuntedCount = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); - // Calculate the multiplier (5% increase per shunted side) - return 1f + (shuntedSides * 0.05f); + // Calculate the multiplier (5% increase per shunted side). + return 1f + (shuntedCount * 0.05f); } private bool PowerLoss(bool powerLost, bool serverNoPower) From e87e421b7dc692342e44a715de228071f3ec54ca Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Fri, 19 Jul 2024 13:45:09 -0500 Subject: [PATCH 3/4] heat equation recalcs and a dedicated server check removed so that the shield shunt toggle updates things --- Data/Scripts/DefenseShields/Control/DsUi.cs | 2 +- .../DefenseShields/ShieldLogic/ShieldCharge.cs | 12 +++++++----- .../DefenseShields/ShieldLogic/ShieldHeat.cs | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Data/Scripts/DefenseShields/Control/DsUi.cs b/Data/Scripts/DefenseShields/Control/DsUi.cs index 23c3e0b..9a9a3e2 100644 --- a/Data/Scripts/DefenseShields/Control/DsUi.cs +++ b/Data/Scripts/DefenseShields/Control/DsUi.cs @@ -724,7 +724,7 @@ internal static bool GetSideShunting(IMyTerminalBlock block) internal static void SetSideShunting(IMyTerminalBlock block, bool newValue) { var comp = block?.GameLogic?.GetAs(); - if (comp == null || Session.Instance.DedicatedServer) return; + if (comp == null /*|| Session.Instance.DedicatedServer*/) return; if (comp.DsSet.Settings.SideShunting != newValue) { comp.StartRedirectTimer(); diff --git a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs index 1d855fc..d80d5df 100644 --- a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs +++ b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs @@ -195,7 +195,7 @@ private float PowerNeeded(float hpsEfficiency) _otherPower = ShieldMaxPower - cleanPower; // Get multiplier from shunt count - float shuntingEnergyMultiplier = CalculateShuntedEnergyMultiplier(); + float shuntingEnergyMultiplier = CalculateShuntedEnergyFactor(); // Apply shunting multiplier to shield maintenance power _shieldMaintaintPower *= shuntingEnergyMultiplier; @@ -231,14 +231,16 @@ private float PowerNeeded(float hpsEfficiency) return powerForShield; } - - private float CalculateShuntedEnergyMultiplier() + + private float CalculateShuntedEnergyFactor() { // Calculation taken from TapiBackend.cs line 969, counts shunts. int shuntedCount = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); - // Calculate the multiplier (5% increase per shunted side). - return 1f + (shuntedCount * 0.05f); + // This is based off of the surface area of one segment + // One segment = ( (4πr^2 / 6) / 4πr^2) * 100% = 16.666666... repeating... + // Simplifying: (1 / 6) * 100% ≈ 16.67% = close enough + return 1f + (shuntedCount * 0.1667f); } private bool PowerLoss(bool powerLost, bool serverNoPower) diff --git a/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs b/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs index 0beb2ea..b7f60b7 100644 --- a/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs +++ b/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs @@ -82,6 +82,11 @@ private void Heating() var nextCycle = _heatCycle == (_currentHeatStep * scaledHeatingSteps) + scaledOverHeat; var fastCoolDown = (heatSinkActive || DsState.State.Overload) && (_heatCycle % 200 == 0); + + float shuntingHeatFactor = CalculateShuntedHeatFactor(); + + ChargeMgr.AbsorbHeat *= shuntingHeatFactor; + var pastThreshold = ChargeMgr.AbsorbHeat > nextThreshold; var venting = lastStep && pastThreshold; var leftCritical = lastStep && _tick >= _heatVentingTick; @@ -129,6 +134,17 @@ private void Heating() } } + private float CalculateShuntedHeatFactor() + { + // Calculation taken from TapiBackend.cs line 969, counts shunts. + int shuntedCount = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); + + // This is based off of the surface area of one segment + // One segment = ( (4πr^2 / 6) / 4πr^2) * 100% = 16.666666... repeating... + // Simplifying: (1 / 6) * 100% ≈ 16.67% = close enough + return 1f + (shuntedCount * 0.1667f); + } + private void HeatTick() { var ewarProt = DsState.State.Enhancer && ShieldComp?.Modulator?.ModSet != null && ShieldComp.Modulator.ModSet.Settings.EmpEnabled && ShieldMode != ShieldType.Station; From ba60473ae5f564ee040fc6832d14dd9dc8ff13a0 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Fri, 19 Jul 2024 16:46:49 -0500 Subject: [PATCH 4/4] debug shownotifications, ensuring the calcs turn off in shunting is disabled --- .../ShieldLogic/ShieldCharge.cs | 26 ++++++-- .../DefenseShields/ShieldLogic/ShieldHeat.cs | 22 +++++-- Data/Scripts/concatrecursivelyandminify.bat | 60 +++++++++++++++++++ 3 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 Data/Scripts/concatrecursivelyandminify.bat diff --git a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs index d80d5df..c1381f1 100644 --- a/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs +++ b/Data/Scripts/DefenseShields/ShieldLogic/ShieldCharge.cs @@ -231,16 +231,30 @@ private float PowerNeeded(float hpsEfficiency) return powerForShield; } - + + // Calculation taken from TapiBackend.cs line 969, counts shunts. + + + // This is based off of the surface area of one segment + // One segment = ( (4πr^2 / 6) / 4πr^2) * 100% = 16.666666... repeating... + // Simplifying: (1 / 6) * 100% ≈ 16.67% = close enough + private float CalculateShuntedEnergyFactor() { - // Calculation taken from TapiBackend.cs line 969, counts shunts. + if (!DsSet.Settings.SideShunting) + { + // Add debug notification when shunting is disabled + //MyAPIGateway.Utilities.ShowNotification("Shunting Energy Factor: 1.00 (Disabled)", 100, "White"); + return 1f; + } + int shuntedCount = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); + float factor = 1f + (shuntedCount * 0.1667f); + + // Add debug notification + //MyAPIGateway.Utilities.ShowNotification($"Shunting Energy Factor: {factor:F2}", 100, "White"); - // This is based off of the surface area of one segment - // One segment = ( (4πr^2 / 6) / 4πr^2) * 100% = 16.666666... repeating... - // Simplifying: (1 / 6) * 100% ≈ 16.67% = close enough - return 1f + (shuntedCount * 0.1667f); + return factor; } private bool PowerLoss(bool powerLost, bool serverNoPower) diff --git a/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs b/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs index b7f60b7..ac185d2 100644 --- a/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs +++ b/Data/Scripts/DefenseShields/ShieldLogic/ShieldHeat.cs @@ -134,15 +134,27 @@ private void Heating() } } + // Calculation taken from TapiBackend.cs line 969, counts shunts. + // This is based off of the surface area of one segment + // One segment = ( (4πr^2 / 6) / 4πr^2) * 100% = 16.666666... repeating... + // Simplifying: (1 / 6) * 100% ≈ 16.67% = close enough + private float CalculateShuntedHeatFactor() { - // Calculation taken from TapiBackend.cs line 969, counts shunts. + if (!DsSet.Settings.SideShunting) + { + // Add debug notification when shunting is disabled + //MyAPIGateway.Utilities.ShowNotification("Shunting Heat Factor: 1.00 (Disabled)", 100, "White"); + return 1f; + } + int shuntedCount = Math.Abs(ShieldRedirectState.X) + Math.Abs(ShieldRedirectState.Y) + Math.Abs(ShieldRedirectState.Z); + float factor = 1f + (shuntedCount * 0.1667f); + + // Add debug notification + //MyAPIGateway.Utilities.ShowNotification($"Shunting Heat Factor: {factor:F2}", 100, "White"); - // This is based off of the surface area of one segment - // One segment = ( (4πr^2 / 6) / 4πr^2) * 100% = 16.666666... repeating... - // Simplifying: (1 / 6) * 100% ≈ 16.67% = close enough - return 1f + (shuntedCount * 0.1667f); + return factor; } private void HeatTick() diff --git a/Data/Scripts/concatrecursivelyandminify.bat b/Data/Scripts/concatrecursivelyandminify.bat new file mode 100644 index 0000000..9bbffa3 --- /dev/null +++ b/Data/Scripts/concatrecursivelyandminify.bat @@ -0,0 +1,60 @@ +@echo off +setlocal enabledelayedexpansion +chcp 65001 +REM ^^ this is to change the encoding to UTF-8, apparently + +echo Starting operation... + +set TEMP_OUTPUT=temp_concatenated.txt +set FINAL_OUTPUT=minified_output.txt +set /a COUNT=0 +set /a ERRORS=0 + +if exist "%TEMP_OUTPUT%" ( + echo Existing temporary file found. Deleting... + del "%TEMP_OUTPUT%" +) + +if exist "%FINAL_OUTPUT%" ( + echo Existing output file found. Deleting... + del "%FINAL_OUTPUT%" +) + +for /r %%i in (*.cs) do ( + echo Processing: "%%i" + type "%%i" >> "%TEMP_OUTPUT%" + if errorlevel 1 ( + echo Error processing "%%i". + set /a ERRORS+=1 + ) else ( + set /a COUNT+=1 + ) +) + +echo Concatenation completed. +echo Total files processed: %COUNT% +if %ERRORS% gtr 0 ( + echo There were %ERRORS% errors during the concatenation. +) else ( + echo No errors encountered during concatenation. +) + +echo Minifying concatenated file... +csmin < "%TEMP_OUTPUT%" > "%FINAL_OUTPUT%" +if errorlevel 1 ( + echo Error occurred during minification. + set /a ERRORS+=1 +) else ( + echo Minification completed successfully. +) + +echo Cleaning up temporary file... +del "%TEMP_OUTPUT%" + +echo Operation completed. +if %ERRORS% gtr 0 ( + echo There were %ERRORS% errors during the entire operation. +) else ( + echo No errors encountered during the entire operation. +) +pause \ No newline at end of file