Skip to content

Commit

Permalink
Ports Salv Cannon requiring power from Frontier (DeltaV-Station#2227)
Browse files Browse the repository at this point in the history
* meow

* meow
  • Loading branch information
Lyndomen authored Nov 18, 2024
1 parent a430ec6 commit b1941ef
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.AutoFire.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using Content.Shared.Weapons.Ranged.Components;
using Content.Server.Power.Components; // Frontier
using Content.Server.Power.EntitySystems; // Frontier
using Content.Shared.Interaction; // Frontier
using Content.Shared.Examine; // Frontier
using Content.Shared.Power; // Frontier

namespace Content.Server.Weapons.Ranged.Systems;

Expand Down Expand Up @@ -26,4 +31,111 @@ public override void Update(float frameTime)
AttemptShoot(uid, gun);
}
}

// New Frontiers - Shuttle Gun Power Draw - makes shuttle guns require power if they
// have an ApcPowerReceiverComponent
// This code is licensed under AGPLv3. See AGPLv3.txt
private void OnGunExamine(EntityUid uid, AutoShootGunComponent component, ExaminedEvent args)
{
if (!HasComp<ApcPowerReceiverComponent>(uid))
return;

// Powered is already handled by other power components
var enabled = Loc.GetString(component.On ? "gun-comp-enabled" : "gun-comp-disabled");

args.PushMarkup(enabled);
}

private void OnActivateGun(EntityUid uid, AutoShootGunComponent component, ActivateInWorldEvent args)
{
if (args.Handled || !args.Complex)
return;

component.On ^= true;

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

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

EnableGun(uid, component);
args.Handled = true;
}
}

/// <summary>
/// Tries to disable the AutoShootGun.
/// </summary>
public void DisableGun(EntityUid uid, AutoShootGunComponent component)
{
if (component.CanFire)
component.CanFire = false;
}

public bool CanEnable(EntityUid uid, AutoShootGunComponent component)
{
var xform = Transform(uid);

// Must be anchored to fire.
if (!xform.Anchored)
return false;

// No power needed? Always works.
if (!HasComp<ApcPowerReceiverComponent>(uid))
return true;

// Not switched on? Won't work.
if (!component.On)
return false;

return this.IsPowered(uid, EntityManager);
}

public void EnableGun(EntityUid uid, AutoShootGunComponent component, TransformComponent? xform = null)
{
if (!component.CanFire)
component.CanFire = true;
}

private void OnAnchorChange(EntityUid uid, AutoShootGunComponent component, ref AnchorStateChangedEvent args)
{
if (args.Anchored && CanEnable(uid, component))
EnableGun(uid, component);
else
DisableGun(uid, component);
}

private void OnGunInit(EntityUid uid, AutoShootGunComponent component, ComponentInit args)
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad == 0)
component.OriginalLoad = apcPower.Load;

if (!component.On)
return;

if (CanEnable(uid, component))
EnableGun(uid, component);
}

private void OnGunShutdown(EntityUid uid, AutoShootGunComponent component, ComponentShutdown args)
{
DisableGun(uid, component);
}

private void OnPowerChange(EntityUid uid, AutoShootGunComponent component, ref PowerChangedEvent args)
{
if (args.Powered && CanEnable(uid, component))
EnableGun(uid, component);
else
DisableGun(uid, component);
}
// End of Frontier modified code
}
9 changes: 9 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Robust.Shared.Containers;
using Content.Shared.Interaction; // Frontier
using Content.Shared.Examine; // Frontier
using Content.Shared.Power; // Frontier

namespace Content.Server.Weapons.Ranged.Systems;

Expand All @@ -48,6 +51,12 @@ public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BallisticAmmoProviderComponent, PriceCalculationEvent>(OnBallisticPrice);
SubscribeLocalEvent<AutoShootGunComponent, ActivateInWorldEvent>(OnActivateGun); // Frontier
SubscribeLocalEvent<AutoShootGunComponent, ComponentInit>(OnGunInit); // Frontier
SubscribeLocalEvent<AutoShootGunComponent, ComponentShutdown>(OnGunShutdown); // Frontier
SubscribeLocalEvent<AutoShootGunComponent, ExaminedEvent>(OnGunExamine); // Frontier
SubscribeLocalEvent<AutoShootGunComponent, PowerChangedEvent>(OnPowerChange); // Frontier
SubscribeLocalEvent<AutoShootGunComponent, AnchorStateChangedEvent>(OnAnchorChange); // Frontier
}

private void OnBallisticPrice(EntityUid uid, BallisticAmmoProviderComponent component, ref PriceCalculationEvent args)
Expand Down
17 changes: 17 additions & 0 deletions Content.Shared/Weapons/Ranged/Components/AutoShootGunComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,21 @@ public sealed partial class AutoShootGunComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool Enabled;

/// <summary>
/// Frontier - Whether the gun is switched on (e.g. through user interaction)
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool On { get; set; } = true;

/// <summary>
/// Frontier - Whether or not the gun can actually fire (i.e. switched on and receiving power if needed)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool CanFire;

/// <summary>
/// Frontier - Amount of power this gun needs from an APC in Watts to function.
/// </summary>
public float OriginalLoad { get; set; } = 0;
}
3 changes: 3 additions & 0 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ public void AttemptShoot(EntityUid gunUid, GunComponent gun)

private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
{
if (TryComp<AutoShootGunComponent>(gunUid, out var auto) && !auto.CanFire) // Frontier
return; // Frontier

if (gun.FireRateModified <= 0f ||
!_actionBlockerSystem.CanAttack(user))
return;
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/_NF/weapons/gun.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gun-comp-enabled = The gun is turned [color=green]on[/color].
gun-comp-disabled = The gun is turned [color=red]off[/color].
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,6 @@
count: 5
- type: Machine
board: ShuttleGunKineticCircuitboard
- type: ExtensionCableReceiver # Frontier
- type: ApcPowerReceiver # Frontier
powerLoad: 1500 # Frontier

0 comments on commit b1941ef

Please sign in to comment.