Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thermals fix #1474

Merged
merged 9 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
175 changes: 175 additions & 0 deletions Content.Client/SS220/Overlays/IgnoreLightVisionOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Original code github.com/CM-14 Licence MIT, EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using System.Numerics;
using Content.Shared.SS220.Thermals;
using Content.Shared.Mobs.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Mobs;
using Content.Shared.Stealth.Components;
using Content.Client.Stealth;

namespace Content.Client.SS220.Overlays;

public abstract class IgnoreLightVisionOverlay : Overlay
{
[Dependency] protected readonly IEntityManager Entity = default!;
[Dependency] protected readonly IPlayerManager PlayerManager = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;

/// <summary> Defines radius in which you can see entities in containers </summary>
protected float ShowCloseRadius;
protected float ShowRadius;

private readonly ContainerSystem _container;
private readonly EntityLookupSystem _entityLookup;
private readonly StealthSystem _stealthSystem;
/// <summary> If use lesser value wierd thing happens with admin spawn menu and GetEntitiesInRange. </summary>
private const float MIN_CLOSE_RANGE = 1.5f;
/// <summary>Useless const due to how stealth work, but if they change it...</summary>
private const float STEALTH_VISION_TRESHHOLD = 0;
public override OverlaySpace Space => OverlaySpace.WorldSpace;

public IgnoreLightVisionOverlay(float showRadius)
{
IoCManager.InjectDependencies(this);

_container = Entity.System<ContainerSystem>();
_entityLookup = Entity.System<EntityLookupSystem>();
_stealthSystem = Entity.System<StealthSystem>();

ShowRadius = showRadius < MIN_CLOSE_RANGE ? MIN_CLOSE_RANGE : showRadius;
ShowCloseRadius = ShowRadius / 4 < MIN_CLOSE_RANGE ? MIN_CLOSE_RANGE : ShowRadius / 4;
}
protected override void Draw(in OverlayDrawArgs args)
{
if (PlayerManager.LocalEntity == null)
return;
if (!Entity.TryGetComponent<MobStateComponent>(PlayerManager.LocalEntity, out var mobstateComp))
return;
if (mobstateComp.CurrentState != MobState.Alive)
return;
if (!Entity.TryGetComponent(PlayerManager.LocalEntity, out ThermalVisionComponent? thermalVision) ||
thermalVision.State == ThermalVisionState.Off)
return;

if (!Entity.TryGetComponent<TransformComponent>(PlayerManager.LocalEntity,
out var playerTransform))
return; // maybe need to log it

var handle = args.WorldHandle;
var eye = args.Viewport.Eye;
var eyeRot = eye?.Rotation ?? default;

var entities = _entityLookup.GetEntitiesInRange<MobStateComponent>(playerTransform.Coordinates, ShowRadius);
var entitiesClose = _entityLookup.GetEntitiesInRange<MobStateComponent>(playerTransform.Coordinates, ShowCloseRadius);

foreach (var (uid, stateComp) in entities)
{
var isCloseToOwner = entitiesClose.Contains((uid, stateComp));

if (CantBeRendered(uid, out var sprite, out var xform))
continue;
if (CantBeSeenByThermals((uid, stateComp)))
continue;
if (IsStealthToThermals(uid, isCloseToOwner))
continue;
if (_container.IsEntityOrParentInContainer(uid))
if (CantBeVisibleInContainer(uid, isCloseToOwner))
continue;

Render((uid, sprite, xform), eye?.Position.MapId, handle, eyeRot);
}
handle.SetTransform(Matrix3x2.Identity);
}
protected abstract void Render(Entity<SpriteComponent, TransformComponent> ent,
MapId? map, DrawingHandleWorld handle, Angle eyeRot);
/// <summary>
/// function wich defines what entities can be seen, f.e. pai or human, bread dog or reaper
/// Also contains list of components which defines it
/// </summary>
/// <returns> True if entities could be seen by thermals. Without any other obstacles </returns>
private bool CantBeSeenByThermals(Entity<MobStateComponent> target)
{
var states = target.Comp.AllowedStates;

if (states.Contains(MobState.Dead) && states.Contains(MobState.Alive))
if (target.Comp.CurrentState == MobState.Dead)
Alwayswannahunt marked this conversation as resolved.
Show resolved Hide resolved
return true;
else
return false;

return true;
}
private bool CantBeRendered(EntityUid target, [NotNullWhen(false)] out SpriteComponent? sprite,
[NotNullWhen(false)] out TransformComponent? xform)
{
sprite = null;
xform = null;

if (!Entity.TryGetComponent<SpriteComponent>(target, out sprite))
return true;
if (!Entity.TryGetComponent<TransformComponent>(target, out xform))
return true;

return false;
}
/// <summary>
/// function wich defines what entities visible or not.
/// Also contains const values of invis perception
/// </summary>
/// <returns>True if entities could be seen by thermals. Without any other obstacles </returns>
private bool IsStealthToThermals(EntityUid target, bool isCloseToOwner)
{
if (!Entity.TryGetComponent<StealthComponent>(target, out var component))
return false;

if (!isCloseToOwner &&
_stealthSystem.GetVisibility(target, component) < STEALTH_VISION_TRESHHOLD)
return true;

return false;
}
/// <summary> function wich defines what entities visible or not.
/// Also contains const values of invis perception </summary>
/// <returns>True if entities could be seen by thermals. Without any other obstacles </returns>
private bool CantBeVisibleInContainer(EntityUid target, bool isCloseToOwner)
{
var blacklistComponentNames = new List<string>() { "DarkReaper", "Devourer" };

if (isCloseToOwner == false)
return true;

var currentEntUid = target;
while (_container.TryGetContainingContainer((currentEntUid, null, null), out var container))
{
currentEntUid = container.Owner;

if (currentEntUid == PlayerManager.LocalEntity )
return true;
if (HasComponentFromList(currentEntUid, blacklistComponentNames))
return true;
}

return false;
}
/// <summary> Checks if entity has a components from list </summary>
/// <returns> True if entity has any of the listed components </returns>
/// <exception cref="Exception"> Throw excep if List contains false comp name</exception>
private bool HasComponentFromList(EntityUid target, List<string> blacklistComponentNames)
{
foreach (var compName in blacklistComponentNames)
{
if (!_componentFactory.TryGetRegistration(compName, out var compReg))
throw new Exception($"Cant find registration for component {compName} in blacklistComponents");

if (Entity.HasComponent(target, compReg.Type))
return true;
}
return false;
}

}
28 changes: 28 additions & 0 deletions Content.Client/SS220/Overlays/ThermalVisionOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Original code github.com/CM-14 Licence MIT, EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Robust.Client.Graphics;
using Robust.Client.GameObjects;
using Robust.Shared.Map;

namespace Content.Client.SS220.Overlays;

public sealed class ThermalVisionOverlay : IgnoreLightVisionOverlay
{
private readonly TransformSystem _transformSystem = default!;

public ThermalVisionOverlay(float showRadius) : base(showRadius)
{
_transformSystem = Entity.System<TransformSystem>();
}
protected override void Render(Entity<SpriteComponent, TransformComponent> ent,
MapId? map, DrawingHandleWorld handle, Angle eyeRot)
{
var (uid, sprite, xform) = ent;
if (xform.MapID != map)
return;

var position = _transformSystem.GetWorldPosition(xform);
var rotation = _transformSystem.GetWorldRotation(xform);

sprite.Render(handle, eyeRot, rotation, position: position);
}
}
93 changes: 0 additions & 93 deletions Content.Client/SS220/Thermals/ThermalVisionOverlay.cs

This file was deleted.

1 change: 1 addition & 0 deletions Content.Client/SS220/Thermals/ThermalVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Original code github.com/CM-14 Licence MIT, All edits under © SS220, EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Shared.SS220.Thermals;
using Content.Client.SS220.Overlays;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;
Expand Down
12 changes: 0 additions & 12 deletions Content.Server/Mindshield/MindShieldSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Content.Shared.Mindshield.Components;
using Content.Shared.Revolutionary.Components;
using Content.Shared.Tag;
using Content.Server.SS220.Thermals;

namespace Content.Server.Mindshield;

Expand All @@ -33,10 +32,6 @@ public sealed class MindShieldSystem : EntitySystem
[ValidatePrototypeId<TagPrototype>]
public const string MindSlaveTag = "MindSlave";
//SS220-mindslave end
//SS220 Thermal implant begin
[ValidatePrototypeId<TagPrototype>]
public const string ThermalImplantTag = "ThermalImplant";
//SS220 Thermal implant ends

public override void Initialize()
{
Expand All @@ -62,13 +57,6 @@ public void ImplantCheck(EntityUid uid, SubdermalImplantComponent comp, ref Impl
_sharedSubdermalImplant.ForceRemove(ev.Implanted.Value, ev.Implant);
}
//SS220-mindslave end
//SS220 Thermalvisionimplant begins
if (_tag.HasTag(ev.Implant, ThermalImplantTag) && ev.Implanted != null)
{
EnsureComp<ThermalVisionImplantComponent>(ev.Implanted.Value);
}
// else (_tag.HasTag(ev.Implant, ThermalImplantTag) && ev.Implanted != null)
//SS220 Thermalvisionimplant ends
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Content.Server.SS220.Thermals;
[RegisterComponent]
public sealed partial class ThermalVisionClothingComponent : Component
{
[DataField, ViewVariables]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float ThermalVisionRadius = 8f;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Content.Server.SS220.Thermals;
public sealed partial class ThermalVisionImplantComponent : Component
{
[DataField]
public bool IsAcive = false;
public bool IsActive = false;
[DataField, ViewVariables]
public float ThermalVisionRadius = 8f;
}
Loading
Loading