Skip to content

Commit

Permalink
Cherrypick "Shoot Over Bodies" And Related PRs (Simple-Station#479)
Browse files Browse the repository at this point in the history
# Description
This is a manual cherry-pick of the following PRs:
space-wizards/space-station-14#27905
space-wizards/space-station-14#28072
space-wizards/space-station-14#28571

I REQUIRE these for my work in PR Simple-Station#11 , and cannot complete said PR
without these cherry-picks. This set of PRs from Wizden adds a feature
where entities can selectively opt-out of being shot at unless a player
intentionally targets them, which I can use as a simple and elegant
solution to one of the largest glaring issues for Segmented Entities. I
could simply give Lamia segments the new
RequireProjectileTargetComponent, which adds them to the system. Future
segmented entities such as the hypothetical "Heretic Worm" may or may
not use this feature, depending on their intended implementation.

---------

Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
  • Loading branch information
VMSolidus and DangerRevolution authored Jun 23, 2024
1 parent 287f33c commit 40d411b
Show file tree
Hide file tree
Showing 34 changed files with 167 additions and 22 deletions.
8 changes: 8 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Client.Gameplay;
using Content.Client.Items;
using Content.Client.Weapons.Ranged.Components;
using Content.Shared.Camera;
Expand All @@ -12,6 +13,7 @@
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.State;
using Robust.Shared.Animations;
using Robust.Shared.Input;
using Robust.Shared.Map;
Expand All @@ -27,6 +29,7 @@ public sealed partial class GunSystem : SharedGunSystem
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IStateManager _state = default!;
[Dependency] private readonly AnimationPlayerSystem _animPlayer = default!;
[Dependency] private readonly InputSystem _inputSystem = default!;
[Dependency] private readonly SharedCameraRecoilSystem _recoil = default!;
Expand Down Expand Up @@ -171,10 +174,15 @@ public override void Update(float frameTime)
// Define target coordinates relative to gun entity, so that network latency on moving grids doesn't fuck up the target location.
var coordinates = EntityCoordinates.FromMap(entity, mousePos, TransformSystem, EntityManager);

NetEntity? target = null;
if (_state.CurrentState is GameplayStateBase screen)
target = GetNetEntity(screen.GetClickedEntity(mousePos));

Log.Debug($"Sending shoot request tick {Timing.CurTick} / {Timing.CurTime}");

EntityManager.RaisePredictiveEvent(new RequestShootEvent
{
Target = target,
Coordinates = GetNetCoordinates(coordinates),
Gun = GetNetEntity(gunUid),
});
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid?

private void ShootOrThrow(EntityUid uid, Vector2 mapDirection, Vector2 gunVelocity, GunComponent gun, EntityUid gunUid, EntityUid? user)
{
if (gun.Target is { } target && !TerminatingOrDeleted(target))
{
var targeted = EnsureComp<TargetedProjectileComponent>(uid);
targeted.Target = target;
Dirty(uid, targeted);
}

// Do a throw
if (!HasComp<ProjectileComponent>(uid))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Damage.Components;

/// <summary>
/// Prevent the object from getting hit by projetiles unless you target the object.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(RequireProjectileTargetSystem))]
public sealed partial class RequireProjectileTargetComponent : Component
{
[DataField, AutoNetworkedField]
public bool Active = true;
}
51 changes: 51 additions & 0 deletions Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Standing;
using Robust.Shared.Physics.Events;

namespace Content.Shared.Damage.Components;

public sealed class RequireProjectileTargetSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<RequireProjectileTargetComponent, PreventCollideEvent>(PreventCollide);
SubscribeLocalEvent<RequireProjectileTargetComponent, StoodEvent>(StandingBulletHit);
SubscribeLocalEvent<RequireProjectileTargetComponent, DownedEvent>(LayingBulletPass);
}

private void PreventCollide(Entity<RequireProjectileTargetComponent> ent, ref PreventCollideEvent args)
{
if (args.Cancelled)
return;

if (!ent.Comp.Active)
return;

var other = args.OtherEntity;
if (HasComp<ProjectileComponent>(other) &&
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
{
args.Cancelled = true;
}
}

private void SetActive(Entity<RequireProjectileTargetComponent> ent, bool value)
{
if (ent.Comp.Active == value)
return;

ent.Comp.Active = value;
Dirty(ent);
}

private void StandingBulletHit(Entity<RequireProjectileTargetComponent> ent, ref StoodEvent args)
{
SetActive(ent, false);
}

private void LayingBulletPass(Entity<RequireProjectileTargetComponent> ent, ref DownedEvent args)
{
SetActive(ent, true);
}
}
3 changes: 3 additions & 0 deletions Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Pointing;
using Content.Shared.Projectiles;
using Content.Shared.Pulling.Events;
using Content.Shared.Speech;
using Content.Shared.Standing;
using Content.Shared.Strip.Components;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;

namespace Content.Shared.Mobs.Systems;

Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Weapons/Ranged/Components/GunComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public sealed partial class GunComponent : Component
[ViewVariables]
public EntityCoordinates? ShootCoordinates = null;

/// <summary>
/// Who the gun is being requested to shoot at directly.
/// </summary>
[ViewVariables]
public EntityUid? Target = null;

/// <summary>
/// The base value for how many shots to fire per burst.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.GameStates;

namespace Content.Shared.Weapons.Ranged.Components;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedGunSystem))]
public sealed partial class TargetedProjectileComponent : Component
{
[DataField, AutoNetworkedField]
public EntityUid Target;
}
1 change: 1 addition & 0 deletions Content.Shared/Weapons/Ranged/Events/RequestShootEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public sealed class RequestShootEvent : EntityEventArgs
{
public NetEntity Gun;
public NetCoordinates Coordinates;
public NetEntity? Target;
}
2 changes: 2 additions & 0 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private void OnShootRequest(RequestShootEvent msg, EntitySessionEventArgs args)

gun.ShootCoordinates = GetCoordinates(msg.Coordinates);
Log.Debug($"Set shoot coordinates to {gun.ShootCoordinates}");
gun.Target = GetEntity(msg.Target);
AttemptShoot(user.Value, ent, gun);
}

Expand Down Expand Up @@ -200,6 +201,7 @@ private void StopShooting(EntityUid uid, GunComponent gun)
Log.Debug($"Stopped shooting {ToPrettyString(uid)}");
gun.ShotCounter = 0;
gun.ShootCoordinates = null;
gun.Target = null;
Dirty(uid, gun);
}

Expand Down
4 changes: 3 additions & 1 deletion Resources/Prototypes/Entities/Mobs/base.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The progenitor. This should only container the most basic components possible.
# The progenitor. This should only container the most basic components possible.
# Only put things on here if every mob *must* have it. This includes ghosts.
- type: entity
save: false
Expand Down Expand Up @@ -43,6 +43,8 @@
- type: MovementSpeedModifier
- type: Polymorphable
- type: StatusIcon
- type: RequireProjectileTarget
active: False

# Used for mobs that have health and can take damage.
- type: entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- type: entity
- type: entity
abstract: true
parent: BaseItem
id: BaseHandheldInstrument
Expand Down Expand Up @@ -71,6 +71,7 @@
- BulletImpassable
- type: StaticPrice
price: 300
- type: RequireProjectileTarget

- type: entity
parent: BasePlaceableInstrument
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- type: entity
abstract: true
id: ReagentDispenserBase
parent: ConstructibleMachine
parent: SmallConstructibleMachine
placement:
mode: SnapgridCenter
components:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@
ents: []
- type: LightningTarget
priority: 1
- type: RequireProjectileTarget
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: BaseTabletopChemicalMachine
parent: [ BaseMachinePowered, ConstructibleMachine ]
parent: [ BaseMachinePowered, SmallConstructibleMachine ]
abstract: true
components:
- type: Transform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: DiseaseDiagnoser
parent: [ BaseMachinePowered, ConstructibleMachine ]
parent: [ BaseMachinePowered, SmallConstructibleMachine ]
name: Disease Diagnoser Delta Extreme
description: A machine that analyzes disease samples.
placement:
Expand Down Expand Up @@ -43,5 +43,3 @@
contentMargin: 12.0, 0.0, 12.0, 0.0
# This is a narrow piece of paper
maxWritableArea: 128.0, 0.0


Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
containers:
machine_board: !type:Container
machine_parts: !type:Container
- type: RequireProjectileTarget
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: MachineArtifactAnalyzer
parent: [ BaseMachinePowered, ConstructibleMachine ]
parent: [ BaseMachinePowered, SmallConstructibleMachine ]
name: artifact analyzer
description: A platform capable of performing analysis on various types of artifacts.
components:
Expand Down Expand Up @@ -35,6 +35,7 @@
- Impassable
- MidImpassable
- LowImpassable
- BulletImpassable
hard: False
- type: Transform
anchored: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@
- machine_board
- type: LightningTarget
priority: 1

- type: entity
abstract: true
parent: ConstructibleMachine
id: SmallConstructibleMachine
components:
- type: RequireProjectileTarget
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
deviceNetId: Wireless
receiveFrequencyId: Fax
transmitFrequencyId: Fax
- type: RequireProjectileTarget

# Special
- type: entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@
- Sheet
- RawMaterial
- Ingot
- type: RequireProjectileTarget

- type: entity
id: ExosuitFabricator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
- type: entity
id: KitchenMicrowave
parent: [ BaseMachinePowered, ConstructibleMachine ]
parent: [ BaseMachinePowered, SmallConstructibleMachine ]
name: microwave
description: It's magic.
components:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: KitchenReagentGrinder
parent: [ BaseMachinePowered, ConstructibleMachine ]
parent: [ BaseMachinePowered, SmallConstructibleMachine ]
name: reagent grinder
description: From BlenderTech. Will It Blend? Let's find out!
suffix: grinder/juicer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
abstract: true
parent: [ BaseStructureDynamic, ConstructibleMachine ]
parent: [ BaseStructureDynamic, SmallConstructibleMachine ]
id: SurveillanceWirelessCameraBase
name: wireless camera
description: A camera. It's watching you. Kinda.
Expand All @@ -23,6 +23,8 @@
density: 80
mask:
- MachineMask
layer:
- BulletImpassable
- type: SurveillanceCameraMicrophone
blacklist:
components:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: PortableScrubber
parent: [BaseMachinePowered, ConstructibleMachine]
parent: [BaseMachinePowered, SmallConstructibleMachine]
name: portable scrubber
description: It scrubs, portably!
components:
Expand Down Expand Up @@ -120,7 +120,7 @@
layer:
- MachineLayer
- type: ApcPowerReceiver
powerDisabled: true #starts off
powerDisabled: true #starts off
- type: Sprite
sprite: Structures/Piping/Atmospherics/Portable/portable_sheater.rsi
noRot: true
Expand Down Expand Up @@ -195,4 +195,4 @@
suffix: Anchored, Enabled
components:
- type: ApcPowerReceiver
powerDisabled: false
powerDisabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
board: HellfireHeaterMachineCircuitBoard

- type: entity
parent: [ BaseMachinePowered, ConstructibleMachine ]
parent: [ BaseMachinePowered, SmallConstructibleMachine ]
id: BaseGasCondenser
name: condenser
description: Condenses gases into liquids. Now we just need some plumbing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
- key: enum.DisposalUnitUiKey.Key
type: DisposalUnitBoundUserInterface
- type: RatKingRummageable
- type: RequireProjectileTarget

- type: entity
id: MailingUnit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- type: entity
id: Emitter
name: emitter
parent: ConstructibleMachine
parent: SmallConstructibleMachine
description: A heavy duty industrial laser. Shoots non-stop when turned on.
placement:
mode: SnapgridCenter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
#
# You can use this Desmos sheet to calculate fuel burn rate values:
# https://www.desmos.com/calculator/qcektq5dqs
#

- type: entity
abstract: true
id: PortableGeneratorBase
parent: [ BaseMachine, ConstructibleMachine ]
parent: [ BaseMachine, SmallConstructibleMachine]
components:
# Basic properties
- type: Transform
Expand Down
Loading

0 comments on commit 40d411b

Please sign in to comment.