Skip to content

Commit

Permalink
Work towards cleaning up, making the Eye better.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pspritechologist committed Feb 8, 2024
1 parent 29de297 commit d29cb66
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Content.Server.Visible;
using Content.Shared.SimpleStation14.Holograms.Components;
using Content.Shared.SimpleStation14.Holograms;
using Content.Server.SimpleStation14.Holograms;
using Robust.Shared.Timing;

namespace Content.Server.SimpleStation14.StationAI
{
Expand Down Expand Up @@ -74,7 +76,10 @@ private void OnPowerUsed(EntityUid uid, AIEyePowerComponent component, AIEyePowe

// Hologram stuff.
if (TryComp<HologramServerLinkedComponent>(projection, out var serverLinkedComp))
{
serverLinkedComp.LinkedServer = uid;
Dirty(serverLinkedComp); //TODO: HOLO This should probably be handled in the system.
}

// Consistent name
_entityManager.GetComponent<MetaDataComponent>(projection).EntityName =
Expand Down Expand Up @@ -109,7 +114,6 @@ private void OnMindRemoved(EntityUid uid, AIEyeComponent component, MindRemovedM
QueueDel(uid);
}


private void OnMobStateChanged(EntityUid uid, StationAIComponent component, MobStateChangedEvent args)
{
if (!_mobState.IsDead(uid)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Robust.Shared.GameStates;

namespace Content.Shared.SimpleStation14.Holograms.Components;

/// <summary>
Expand All @@ -6,15 +8,16 @@ namespace Content.Shared.SimpleStation14.Holograms.Components;
/// <remarks>
/// This could be anything from a literal server, to an AICore, to the person a HoloParasite lives in.
/// </remarks>
[RegisterComponent]
public sealed class HologramServerLinkedComponent : Component
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class HologramServerLinkedComponent : Component
{
/// <summary>
/// Whether this Hologram is bound to the same grid as its server.
/// If true, it will be returned if it leaves the grid.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("gridBound")]
[AutoNetworkedField]
public bool GridBound = true;

/// <summary>
Expand All @@ -24,5 +27,6 @@ public sealed class HologramServerLinkedComponent : Component
/// This will be the lightbee if it's a lightbee hologram.
/// </remarks>
[ViewVariables(VVAccess.ReadOnly)]
[AutoNetworkedField]
public EntityUid? LinkedServer;
}
12 changes: 11 additions & 1 deletion Content.Shared/SimpleStation14/Holograms/HologramEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ public record struct HologramKillAttemptEvent(bool Cancelled = false);
/// </summary>
/// <remarks>
/// Setting override to 'True' will use whatever's in ProjectorOverride- including a null value, which allows cancelling the projector search.
/// A Component-set override will override this ovaerride.
/// A Component-set override will override this override.
/// </remarks>
[ByRefEvent]
public record struct HologramGetProjectorEvent(EntityUid? ProjectorOverride = null, bool Override = false);

/// <summary>
/// Sent directed at a Hologram when they're checking if a specific projector is valid.
/// Allows for manually determining if a projector is valid for a given Hologram.
/// </summary>
/// <remarks>
/// Valid is nullable, setting it to either value will force that behavior.
/// Leaving it null will allow the projector to determine its own validity based on normal rules.
/// </remarks>
[ByRefEvent]
public record struct HologramCheckProjectorValidEvent(EntityUid Projector, bool? Valid = null);
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,36 @@ public bool TryGetHoloProjector(EntityUid uid, float range, [NotNullWhen(true)]
/// </summary>
/// <param name="hologram">The hologram to check for, or its position.</param>
/// <param name="projector">The projector to compare on, or its position.</param>
/// <param name="range">The max range to allow. Ignored if occlude is false.</param>
/// <param name="occlude">Should it check only for unoccluded and in range projectors?</param>
/// <param name="range">The max range to allow, uses the Holo's range if null. Ignored if occlude is false.</param>
/// <param name="occlude">Should it check only for unoccluded and in range projectors?</param>.
/// <param name="raiseEvent">Should it raise the <see cref="HologramCheckProjectorValidEvent"/> event? Make sure this is set to false if you use this function in response to the event.</param>
/// <param name="projectedComp">The hologram's component. If provided, the hologram's list of allowed tags will be used.</param>
/// <returns>True if the projector is within range, and unoccluded to the hologram. Otherwise, false.</returns>
public bool IsHoloProjectorValid(EntityUid hologram, [NotNullWhen(true)] EntityUid? projector, float range = 18f, bool occlude = true, HologramProjectedComponent? projectedComp = null)
public bool IsHoloProjectorValid(EntityUid hologram, [NotNullWhen(true)] EntityUid? projector, float? range = null, bool occlude = true, bool raiseEvent = true, HologramProjectedComponent? projectedComp = null)
{
if (!Resolve(hologram, ref projectedComp))
if (!Resolve(hologram, ref projectedComp) || projector == null || !Exists(projector.Value))
return false;
return IsHoloProjectorValid(Transform(hologram).MapPosition, projector, range, occlude, projectedComp.ValidProjectorWhitelist);

if (raiseEvent)
{
Log.Error($"Raising event on hologram {ToPrettyString(hologram):player} to check if projector {ToPrettyString(projector.Value):entity} is valid."); //TODO: HOLO Debug stuff.
var validCheckEvent = new HologramCheckProjectorValidEvent(projector.Value);
RaiseLocalEvent(hologram, ref validCheckEvent);
Log.Error($"Result: {validCheckEvent.Valid}");
if (validCheckEvent.Valid != null)
return validCheckEvent.Valid.Value;
}

return IsHoloProjectorValid(Transform(hologram).MapPosition, projector, range ?? projectedComp.ProjectorRange, occlude, projectedComp.ValidProjectorWhitelist);
}

/// <inheritdoc cref="IsHoloProjectorValid"/>
/// <param name="whitelist">A whitelist to check for on projectors, to determine if they're valid. Usually found on the Holo's <see cref="HologramProjectedComponent"/>.</param>
public bool IsHoloProjectorValid(MapCoordinates hologram, EntityUid? projector, float range = 18f, bool occlude = true, EntityWhitelist? whitelist = null)
/// <remarks>
/// Note this this method won't raise the <see cref="HologramCheckProjectorValidEvent"/> event, as the Hologram entity is not known.
/// This is a limitation of the method, and should be kept in mind when using it.
/// </remarks> //TODO: HOLO Probably allow passing in a nullable UID for the hologram, and raise the event if it's not null.
public bool IsHoloProjectorValid(MapCoordinates hologram, [NotNullWhen(true)] EntityUid? projector, float range, bool occlude = true, EntityWhitelist? whitelist = null)
{
if (projector == null || !Exists(projector.Value))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Content.Shared.SimpleStation14.Holograms;

public partial class SharedHologramSystem
{
private void InitalizeServerLinked()
private void InitializeServerLinked()
{
SubscribeLocalEvent<HologramServerLinkedComponent, ChangedGridEvent>(OnGridChange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract partial class SharedHologramSystem : EntitySystem
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
private void hologramcomponentstartup(EntityUid a,HologramComponent b,ComponentStartup d){var c=EnsureComp<Stealth.Components.StealthComponent>(a);stl.SetVisibility(a, 0.8f, c);}[Dependency]private readonly Stealth.SharedStealthSystem stl = default!; // This line is because of Death.
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedPullingSystem _pulling = default!;
Expand All @@ -37,7 +38,8 @@ public override void Initialize()
SubscribeLocalEvent<HologramComponent, StoreMobInItemContainerAttemptEvent>(OnStoreInContainerAttempt);
SubscribeLocalEvent<HologramComponent, PreventCollideEvent>(OnHoloCollide);

InitalizeServerLinked();
InitializeServerLinked();
SubscribeLocalEvent<HologramComponent, ComponentStartup>(hologramcomponentstartup);
}

// Stops the Hologram from interacting with anything they shouldn't.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ namespace Content.Shared.SimpleStation14.StationAI
[RegisterComponent]
public sealed class AIEyeComponent : Component
{
/// <summary>
/// The grace period the eye gets once a new camera is found before it will switch to it, to avoid flickering.
/// </summary>
[DataField("gracePeriod"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan GracePeriod = TimeSpan.FromSeconds(0.65);

/// <summary>
/// The time at which the eye will switch to a new camera, assuming <see cref="GracePeriod"/> is used.
/// </summary>
public TimeSpan SwitchTime;

/// <summary>
/// Whether the grace period is currently ticking.
/// </summary>
public bool GracePeriodTicking = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.SimpleStation14.StationAI;
using Robust.Shared.Prototypes;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Content.Shared.Borgs;
using Content.Shared.SimpleStation14.Holograms.Components;
using Content.Shared.SimpleStation14.Holograms;
using Robust.Shared.Timing;

namespace Content.Shared.SimpleStation14.StationAI.Systems;

public sealed class SharedAiEyeSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedHologramSystem _hologramSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;

public override void Initialize()
{
SubscribeLocalEvent<AIEyeComponent, HologramGetProjectorEvent>(OnHologramGetProjector);
SubscribeLocalEvent<AIEyeComponent, HologramCheckProjectorValidEvent>(OnHologramCheckProjectorValid);
}

private void OnHologramGetProjector(EntityUid eyeUid, AIEyeComponent eyeComp, ref HologramGetProjectorEvent args)
{
if (!TryComp<HologramProjectedComponent>(eyeUid, out var projectedComp))
return;

if (!_hologramSystem.IsHoloProjectorValid(eyeUid, projectedComp.CurProjector, projectedComp: projectedComp))
return;


}

private void OnHologramCheckProjectorValid(EntityUid eyeUid, AIEyeComponent eyeComp, ref HologramCheckProjectorValidEvent args)
{
if (!HasComp<AIEyePowerComponent>(args.Projector) || !TryComp<HologramServerLinkedComponent>(eyeUid, out var serverLinkedComp) || !_hologramSystem.IsHoloProjectorValid(eyeUid, args.Projector, raiseEvent: false))
return;

if (serverLinkedComp.LinkedServer != args.Projector)
{
Log.Error($"Projector {args.Projector} is not valid for eye {eyeUid}");
args.Valid = false;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@
- type: DogVision
- type: RandomBark
- type: Hologram
- type: HologramProjected
# gracePeriod: 0.08
validProjectorWhitelist:
tags:
- HoloProjectorCamera
effectPrototype: EffectHologramProjectionBeam
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@
- NanoTrasen
- type: Laws
lawsID: LawsStationAIDefault
# - type: HologramServer
# - type: HologramProjector
# effectOffsets:
# North: "0, 0.40"
# East: "-0.15, 0"
# South: "0, -0.20"
# West: "-0.15, 0"
- type: HologramServer
- type: HologramProjector
effectOffsets:
North: "0, 0.40"
East: "-0.15, 0"
South: "0, -0.20"
West: "-0.15, 0"
- type: RandomSprite
available:
- enum.PowerDeviceVisualLayers.Powered:
Expand Down Expand Up @@ -332,7 +332,7 @@
layer: 4
# Can see through walls for now
- type: Eye
# drawFov: true
drawFov: true
- type: Input
context: "human"
- type: MobMover
Expand Down Expand Up @@ -380,15 +380,16 @@
keywords: ["AI", "console", "interface"]
priority: -1
event: !type:ToggleIntrinsicUIEvent
# - type: Hologram
# - type: HologramServerLinked
# - type: HologramProjected
# validProjectorWhitelist:
# components:
# - AICamera
# - AIEyePower
# effectPrototype: EffectHologramProjectionBeam
# setEyeTarget: true
- type: Hologram
- type: HologramServerLinked
- type: HologramProjected
validProjectorWhitelist:
components:
- AICamera
- AIEyePower
effectPrototype: EffectHologramProjectionBeam
setEyeTarget: true
gracePeriod: 0.3

# Mostly works, just not as I wish, so I'm disabling it for now.
# Need to split this into two PRs,
Expand Down

0 comments on commit d29cb66

Please sign in to comment.