Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.github/workflows/ @StarCoreSE/workflow-access
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public EliminationGamemode()

public override void Close()
{
StopRound();
if (IsStarted)
StopRound();
}

public override void UpdateActive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Sandbox.Game;
using VRageMath;
using VRage.ModAPI;
using static SC.SUGMA.GameModes.Domination.DominationGamemode;

namespace SC.SUGMA.GameModes.RocketCore
{
Expand Down Expand Up @@ -51,7 +52,8 @@ public RocketCoreGamemode()

public override void Close()
{
StopRound();
if (IsStarted)
StopRound();
}

public override void UpdateActive()
Expand All @@ -72,7 +74,6 @@ public override void UpdateActive()
continue;
// Goal was made
PointTracker.AddFactionPoints(zoneSet.Key, -1);
SUGMA_SessionComponent.I.GetComponent<RocketCoreHud>("rocHud")?.GoalScored(zoneSet.Key);

if (_winningFaction != null)
break;
Expand Down Expand Up @@ -159,6 +160,10 @@ public override void StartRound(string[] arguments = null)
if (!MyAPIGateway.Utilities.IsDedicated)
SUGMA_SessionComponent.I.RegisterComponent("rocHud", new RocketCoreHud(this));

PointTracker.OnPointsUpdated += (faction, points) =>
{
SUGMA_SessionComponent.I.GetComponent<RocketCoreHud>("rocHud")?.GoalScored(faction);
};
SpawnBall();

Log.Info("Started a ROC match." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public TeamDeathmatchGamemode()

public override void Close()
{
StopRound();
if (IsStarted)
StopRound();
}

public override void UpdateActive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class SUGMA_SessionComponent : MySessionComponentBase
public GamemodeBase CurrentGamemode;

public bool HasInited;
public bool IsClosing { get; private set; } = false;

public ShareTrackApi ShareTrackApi = new ShareTrackApi();
public ShieldApi ShieldApi = new ShieldApi();
Expand Down Expand Up @@ -209,6 +210,7 @@ public override void UpdateAfterSimulation()

protected override void UnloadData()
{
IsClosing = true;
try
{
foreach (var component in _components.Values.ToArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void SetDamageEnabled(bool value)

public static void SetWorldPermissionsForMatch(bool matchActive)
{
if (MyAPIGateway.Session == null)
if (SUGMA_SessionComponent.I.IsClosing)
return;

MyAPIGateway.Utilities.ShowMessage("SUGMA",
Expand Down
31 changes: 15 additions & 16 deletions Utility Mods/MoA Fusion Systems/Data/BlockCategories.sbc
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
<DisplayName>Fusion Systems</DisplayName>
<Name>Fusion Systems</Name>
<ItemIds>
<string>Caster_Accelerator_0</string>
<string>Caster_Accelerator_90</string>
<string>Caster_Feeder</string>
<string>Caster_CentralPipe_0</string>
<string>Caster_CentralPipe_90</string>
<string>Caster_CentralPipe_T</string>
<string>Caster_FocusLens</string>
<string>Caster_Reactor</string>
<string>Heat_Heatsink</string>
<string>Heat_FlatRadiator</string>
<string>Caster_ConveyorCap</string>
<string>RadiatorPanel</string>
<string>ExtendableRadiatorBase</string>
<string>Heat_FlatRadiator</string>
<string>ActiveRadiator</string>
<string>ActiveRadiatorFake</string>
<string>CubeBlock/Caster_Accelerator_0</string>
<string>CubeBlock/Caster_Accelerator_90</string>
<string>CubeBlock/Caster_Feeder</string>
<string>CubeBlock/Caster_CentralPipe_0</string>
<string>CubeBlock/Caster_CentralPipe_90</string>
<string>CubeBlock/Caster_CentralPipe_T</string>
<string>Thrust/Caster_FocusLens</string>
<string>Reactor/Caster_Reactor</string>
<string>CubeBlock/Heat_Heatsink</string>
<string>CubeBlock/Heat_FlatRadiator</string>
<string>OxygenTank/Caster_ConveyorCap</string>
<string>CubeBlock/RadiatorPanel</string>
<string>TerminalBlock/ExtendableRadiatorBase</string>
<string>TerminalBlock/ActiveRadiator</string>
<string>TerminalBlock/ActiveRadiatorFake</string>
</ItemIds>
</Category>
</CategoryClasses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,24 @@ public abstract class FusionPart<T> : MyGameLogicComponent, IMyEventProxy
public float PowerConsumption;

public MySync<float, SyncDirection.BothWays> PowerUsageSync;
internal FusionPartSettings Settings;
internal static ModularDefinitionApi ModularApi => Epstein_Fusion_DS.ModularDefinition.ModularApi;
private FusionPartSettings Settings;
protected static ModularDefinitionApi ModularApi => Epstein_Fusion_DS.ModularDefinition.ModularApi;

/// <summary>
/// Block subtypes allowed.
/// </summary>
internal abstract string[] BlockSubtypes { get; }
protected abstract string[] BlockSubtypes { get; }

/// <summary>
/// Human-readable name for this part type.
/// </summary>
internal abstract string ReadableName { get; }
protected abstract string ReadableName { get; }

internal virtual Func<IMyTerminalBlock, float> MinOverrideLimit { get; } = b => 0.01f;
internal virtual Func<IMyTerminalBlock, float> MaxOverrideLimit { get; } = b => 4;
protected virtual Func<IMyTerminalBlock, float> MinOverrideLimit { get; } = b => 0.01f;
protected virtual Func<IMyTerminalBlock, float> MaxOverrideLimit { get; } = b => 4;
protected abstract float ProductionPerFusionPower { get; }

protected int bufferBlockCount = 1;

#region Controls

Expand Down Expand Up @@ -182,7 +185,7 @@ private void AppendingCustomInfo(IMyTerminalBlock block, StringBuilder stringBui
stringBuilder.Insert(0, InfoText.ToString());
}

public abstract void UpdatePower(float powerGeneration, float outputPerFusionPower, int numberParts);
public abstract void UpdatePower(float powerGeneration, int numberParts);

#endregion

Expand All @@ -191,7 +194,8 @@ private void AppendingCustomInfo(IMyTerminalBlock block, StringBuilder stringBui
public override void Init(MyObjectBuilder_EntityBase objectBuilder)
{
base.Init(objectBuilder);
NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
Block = (T)Entity;
NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
}

public override void UpdateOnceBeforeFrame()
Expand All @@ -204,13 +208,29 @@ public override void UpdateOnceBeforeFrame()

LoadSettings();
PowerUsageSync.Value = Settings.PowerUsage;
OverridePowerUsageSync.Value = Settings.OverridePowerUsage;
SaveSettings();

// Trigger power update is only needed when OverrideEnabled is false
PowerUsageSync.ValueChanged += value =>
{
Settings.PowerUsage = value.Value;
if (!OverrideEnabled.Value)
UpdatePower(BufferPowerGeneration, bufferBlockCount);
SaveSettings();
};

OverridePowerUsageSync.Value = Settings.OverridePowerUsage;
// Trigger power update is only needed when OverrideEnabled is true
OverridePowerUsageSync.ValueChanged += value =>
{
Settings.OverridePowerUsage = value.Value;
SaveSettings();
if (OverrideEnabled.Value)
UpdatePower(BufferPowerGeneration, bufferBlockCount);
SaveSettings();
};

// Trigger power update if boostEnabled is changed
OverrideEnabled.ValueChanged += value => UpdatePower(BufferPowerGeneration, bufferBlockCount);

if (!HaveControlsInited.Contains(ReadableName))
CreateControls();
Expand Down Expand Up @@ -243,14 +263,26 @@ public override void UpdateAfterSimulation()
}
}

protected void SetPowerBoost(bool value)
{
if (OverrideEnabled.Value == value)
return;

OverrideEnabled.Value = value;
UpdatePower(BufferPowerGeneration, bufferBlockCount);
}

#endregion

#region Settings

internal void SaveSettings()
{
if (Block == null || Settings == null)
{
ModularApi.Log($"save block null or settings null for {typeof(T).Name}");
return; // called too soon or after it was already closed, ignore
}

if (MyAPIGateway.Utilities == null)
throw new NullReferenceException(
Expand All @@ -270,9 +302,6 @@ internal virtual void LoadDefaultSettings()

Settings.PowerUsage = 1.0f;
Settings.OverridePowerUsage = 1.5f;

PowerUsageSync.Value = Settings.PowerUsage;
OverridePowerUsageSync.Value = Settings.OverridePowerUsage;
}

internal virtual bool LoadSettings()
Expand Down Expand Up @@ -303,39 +332,19 @@ internal virtual bool LoadSettings()
Settings.PowerUsage = loadedSettings.PowerUsage;
Settings.OverridePowerUsage = loadedSettings.OverridePowerUsage;

PowerUsageSync.Value = loadedSettings.PowerUsage;
OverridePowerUsageSync.Value = loadedSettings.OverridePowerUsage;

return true;
}
}
catch (Exception e)
{
MyLog.Default.WriteLineAndConsole("Exception in loading FusionPart settings: " + e);
MyAPIGateway.Utilities.ShowMessage("Fusion Systems", "Exception in loading FusionPart settings: " + e);
ModularApi.Log("Exception in loading FusionPart settings: " + e);
}

return false;
}

public override bool IsSerialized()
{
if (Block.CubeGrid?.Physics == null)
return base.IsSerialized();

try
{
SaveSettings();
}
catch (Exception e)
{
MyLog.Default.WriteLineAndConsole("Exception in loading FusionPart settings: " + e);
MyAPIGateway.Utilities.ShowMessage("Fusion Systems", "Exception in loading FusionPart settings: " + e);
}

return base.IsSerialized();
}

#endregion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace Epstein_Fusion_DS.FusionParts.FusionReactor
[MyEntityComponentDescriptor(typeof(MyObjectBuilder_Reactor), false, "Caster_Reactor")]
public class FusionReactorLogic : FusionPart<IMyReactor>
{
private int _bufferBlockCount = 1;
private float _bufferReactorOutput;


internal override string[] BlockSubtypes => new[] { "Caster_Reactor" };
internal override string ReadableName => "Reactor";
protected override string[] BlockSubtypes => new[] { "Caster_Reactor" };
protected override string ReadableName => "Reactor";
protected override float ProductionPerFusionPower => SFusionSystem.MegawattsPerFusionPower;


public override void UpdatePower(float powerGeneration, float megawattsPerFusionPower, int numberReactors)
public override void UpdatePower(float powerGeneration, int numberReactors)
{
BufferPowerGeneration = powerGeneration;
_bufferBlockCount = numberReactors;
bufferBlockCount = numberReactors;

var reactorConsumptionMultiplier =
OverrideEnabled.Value
Expand All @@ -35,57 +35,23 @@ public override void UpdatePower(float powerGeneration, float megawattsPerFusion
var reactorEfficiencyMultiplier = 1 / (0.489f + reactorConsumptionMultiplier);

// Power generated (per second)
var reactorOutput = reactorEfficiencyMultiplier * powerConsumption * megawattsPerFusionPower;
var reactorOutput = reactorEfficiencyMultiplier * powerConsumption * ProductionPerFusionPower;

_bufferReactorOutput = reactorOutput;
MaxPowerConsumption = powerConsumption / 60;

InfoText.Clear();
InfoText.AppendLine(
$"\nOutput: {Math.Round(reactorOutput, 1)}/{Math.Round(powerGeneration * 60 * megawattsPerFusionPower, 1)}");
$"\nOutput: {Math.Round(reactorOutput, 1)}/{Math.Round(powerGeneration * 60 * ProductionPerFusionPower, 1)}");
InfoText.AppendLine($"Input: {Math.Round(powerConsumption, 1)}/{Math.Round(powerGeneration * 60, 1)}");
InfoText.AppendLine($"Efficiency: {Math.Round(reactorEfficiencyMultiplier * 100)}%");

// Convert back into power per tick
SyncMultipliers.ReactorOutput(Block, _bufferReactorOutput);
}

public void SetPowerBoost(bool value)
{
if (OverrideEnabled.Value == value)
return;

OverrideEnabled.Value = value;
UpdatePower(BufferPowerGeneration, SFusionSystem.MegawattsPerFusionPower, _bufferBlockCount);
}

#region Base Methods

public override void Init(MyObjectBuilder_EntityBase definition)
{
base.Init(definition);
Block = (IMyReactor)Entity;
NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

// Trigger power update is only needed when OverrideEnabled is false
PowerUsageSync.ValueChanged += value =>
{
if (!OverrideEnabled.Value)
UpdatePower(BufferPowerGeneration, SFusionSystem.MegawattsPerFusionPower, _bufferBlockCount);
};

// Trigger power update is only needed when OverrideEnabled is true
OverridePowerUsageSync.ValueChanged += value =>
{
if (OverrideEnabled.Value)
UpdatePower(BufferPowerGeneration, SFusionSystem.MegawattsPerFusionPower, _bufferBlockCount);
};

// Trigger power update if boostEnabled is changed
OverrideEnabled.ValueChanged += value =>
UpdatePower(BufferPowerGeneration, SFusionSystem.MegawattsPerFusionPower, _bufferBlockCount);
}

public override void UpdateAfterSimulation()
{
base.UpdateAfterSimulation();
Expand Down
Loading