Skip to content

Commit

Permalink
Merge pull request #1 from whatston3/power-switchable-machines-sugges…
Browse files Browse the repository at this point in the history
…tions

Power switchable machines suggestions
  • Loading branch information
spacedwarf14 authored Sep 23, 2024
2 parents 20635a6 + d5aa598 commit 00f7836
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions Content.Server/Shuttles/Systems/ThrusterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,33 @@ public override void Initialize()
SubscribeLocalEvent<ThrusterComponent, UpgradeExamineEvent>(OnUpgradeExamine);
SubscribeLocalEvent<ThrusterComponent, SignalReceivedEvent>(OnSignalReceived); // Frontier
}
private void OnSignalReceived(EntityUid uid, ThrusterComponent component, ref SignalReceivedEvent args) // Frontier

// Frontier: signal handler
private void OnSignalReceived(EntityUid uid, ThrusterComponent component, ref SignalReceivedEvent args)
{
if (args.Port == component.OffPort) // Frontier
DisableThruster(uid, component); // Frontier
else if (args.Port == component.OnPort) // Frontier
EnableThruster(uid, component); // Frontier
else if (args.Port == component.TogglePort) // Frontier
OnActivateThruster(uid, component); // Frontier
if (args.Port == component.OffPort)
component.Enabled = false;
else if (args.Port == component.OnPort)
component.Enabled = true;
else if (args.Port == component.TogglePort)
component.Enabled ^= true;
else
return; // Invalid port, don't change the thruster.

if (!component.Enabled)
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != 0 && apcPower.Load != 1)
apcPower.Load = 1;
DisableThruster(uid, component);
}
else if (CanEnable(uid, component))
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != apcPower.Load)
apcPower.Load = component.OriginalLoad;
EnableThruster(uid, component);
}
}
// End Frontier: signal handler

private void OnThrusterExamine(EntityUid uid, ThrusterComponent component, ExaminedEvent args)
{
Expand Down Expand Up @@ -143,33 +161,26 @@ private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref
}
}

private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent? args = null) // Frontier
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
{
if (args != null) // Frontier
{
if (args.Handled || !args.Complex)
return;
}
if (args.Handled || !args.Complex)
return;

component.Enabled ^= true;

if (!component.Enabled)
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != 0) // Frontier
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != 0 && apcPower.Load != 1) // Frontier
apcPower.Load = 1; // Frontier

DisableThruster(uid, component);
if (args != null) // Frontier
args.Handled = true;
args.Handled = true;
}
else if (CanEnable(uid, component))
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != apcPower.Load) // Frontier
apcPower.Load = component.OriginalLoad; // Frontier

EnableThruster(uid, component);
if (args != null) // Frontier
args.Handled = true;
args.Handled = true;
}
}

Expand Down

0 comments on commit 00f7836

Please sign in to comment.