From 0a3bd9babafd462f760723ac81b35766e1207577 Mon Sep 17 00:00:00 2001 From: Red <96445749+TheShuEd@users.noreply.github.com> Date: Mon, 25 Aug 2025 02:03:24 +0300 Subject: [PATCH] Adjust day/night cycle logic and lighting parameters (#1705) Increased minimum light level and updated sun shadow directions for smoother transitions. Changed light curve calculation to use cosine, adjusted day detection threshold, and added a console command to check current light level. Renamed and fixed logic in CP14IsNight rule. Updated map and prototype files to use new ambient light colors and ensure consistency. --- .../Light/Components/LightCycleComponent.cs | 2 +- .../Components/SunShadowCycleComponent.cs | 10 ++--- .../EntitySystems/SharedLightCycleSystem.cs | 4 +- .../_CP14/DayCycle/CP14DayCycleSystem.cs | 41 +++++++++++++++++-- .../Rules/{IsDaylight.cs => CP14IsNight.cs} | 2 +- Resources/Maps/_CP14/venicialis.yml | 2 +- .../Demiplane/Modifiers/MapLight/mapLight.yml | 6 +++ 7 files changed, 55 insertions(+), 12 deletions(-) rename Content.Shared/_CP14/Random/Rules/{IsDaylight.cs => CP14IsNight.cs} (94%) diff --git a/Content.Shared/Light/Components/LightCycleComponent.cs b/Content.Shared/Light/Components/LightCycleComponent.cs index a6ce63bdbc..9389eb5788 100644 --- a/Content.Shared/Light/Components/LightCycleComponent.cs +++ b/Content.Shared/Light/Components/LightCycleComponent.cs @@ -34,7 +34,7 @@ public sealed partial class LightCycleComponent : Component /// Trench of the oscillation. /// [DataField, AutoNetworkedField] - public float MinLightLevel = 0f; + public float MinLightLevel = 0.3f; //CP14 increase from 0 to 0.3 /// /// Peak of the oscillation diff --git a/Content.Shared/Light/Components/SunShadowCycleComponent.cs b/Content.Shared/Light/Components/SunShadowCycleComponent.cs index f8d39da850..a57ed4c137 100644 --- a/Content.Shared/Light/Components/SunShadowCycleComponent.cs +++ b/Content.Shared/Light/Components/SunShadowCycleComponent.cs @@ -26,12 +26,12 @@ public sealed partial class SunShadowCycleComponent : Component /// Time to have each direction applied. Will lerp from the current value to the next one. /// [DataField, AutoNetworkedField] - public List Directions = new() + public List Directions = new() //CP14 replaced vectors { - new SunShadowCycleDirection(0f, new Vector2(0f, 3f), 0f), - new SunShadowCycleDirection(0.25f, new Vector2(-3f, -0.1f), 0.5f), - new SunShadowCycleDirection(0.5f, new Vector2(0f, -3f), 0.8f), - new SunShadowCycleDirection(0.75f, new Vector2(3f, -0.1f), 0.5f), + new SunShadowCycleDirection(0f, new Vector2(0.1f, 3f), 0f), + new SunShadowCycleDirection(0.25f,new Vector2(3f, 0f), 0.5f), + new SunShadowCycleDirection(0.5f, new Vector2(-0.1f,-3f), 0.8f), + new SunShadowCycleDirection(0.75f,new Vector2(-3f, 0f), 0.5f), }; }; diff --git a/Content.Shared/Light/EntitySystems/SharedLightCycleSystem.cs b/Content.Shared/Light/EntitySystems/SharedLightCycleSystem.cs index 3bd0d5b5fb..2a467b7197 100644 --- a/Content.Shared/Light/EntitySystems/SharedLightCycleSystem.cs +++ b/Content.Shared/Light/EntitySystems/SharedLightCycleSystem.cs @@ -124,7 +124,9 @@ public abstract class SharedLightCycleSystem : EntitySystem float exponent, float phase = 0) { - var sen = MathF.Pow(MathF.Sin((MathF.PI * (phase + x)) / waveLength), exponent); + //var sen = MathF.Pow(MathF.Sin((MathF.PI * (phase + x)) / waveLength), exponent); + var sen = MathF.Pow(MathF.Cos((MathF.PI * (phase + x)) / waveLength), exponent); //CP14 edited light curve calculation + return (crest - shift) * sen + shift; } } diff --git a/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs b/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs index 8a6f3ac168..75c32faa0b 100644 --- a/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs +++ b/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs @@ -2,6 +2,9 @@ using Content.Shared.GameTicking; using Content.Shared.Light.Components; using Content.Shared.Storage.Components; using Content.Shared.Weather; +using Robust.Client.GameObjects; +using Robust.Client.Player; +using Robust.Shared.Console; using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Timing; @@ -83,14 +86,13 @@ public sealed class CP14DayCycleSystem : EntitySystem .TotalSeconds; var normalizedTime = time % map.Comp.Duration.TotalSeconds; - var lightLevel = Math.Sin((normalizedTime / map.Comp.Duration.TotalSeconds) * MathF.PI); + var lightLevel = 1 - Math.Sin((normalizedTime / map.Comp.Duration.TotalSeconds) * MathF.PI); return (float)lightLevel; } public bool IsDayNow(Entity map) { - var lightLevel = GetLightLevel(map); - return lightLevel >= 0.5; + return GetLightLevel(map) >= 0.4; } /// @@ -134,3 +136,36 @@ public sealed class CP14StartDayEvent(EntityUid map) : EntityEventArgs { public EntityUid Map = map; } + +internal sealed class CheckLightLevel : LocalizedCommands +{ + [Dependency] private readonly IEntitySystemManager _entityManager = default!; + + public override string Command => "cp14_check_light"; + + public override string Help => "Checks the light level of the map you are on."; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) + { + var entity = shell.Player?.AttachedEntity; + + if (entity is null) + { + shell.WriteLine("You don't have an attached entity."); + return; + } + + var transformSys = _entityManager.GetEntitySystem(); + + var map = transformSys.GetMap(entity.Value); + + if (map is null) + { + shell.WriteLine("You are not on a map."); + return; + } + + var dayCycle = _entityManager.GetEntitySystem(); + shell.WriteLine("Current light level: " + dayCycle.GetLightLevel(map.Value)); + } +} diff --git a/Content.Shared/_CP14/Random/Rules/IsDaylight.cs b/Content.Shared/_CP14/Random/Rules/CP14IsNight.cs similarity index 94% rename from Content.Shared/_CP14/Random/Rules/IsDaylight.cs rename to Content.Shared/_CP14/Random/Rules/CP14IsNight.cs index 3ad869d0f5..32a7870790 100644 --- a/Content.Shared/_CP14/Random/Rules/IsDaylight.cs +++ b/Content.Shared/_CP14/Random/Rules/CP14IsNight.cs @@ -20,6 +20,6 @@ public sealed partial class CP14IsNight : RulesRule var isDay = dayCycle.IsDayNow(map.Value); - return Inverted ? !isDay : isDay; + return Inverted ? isDay : !isDay; } } diff --git a/Resources/Maps/_CP14/venicialis.yml b/Resources/Maps/_CP14/venicialis.yml index fdce828959..a8117a51b7 100644 --- a/Resources/Maps/_CP14/venicialis.yml +++ b/Resources/Maps/_CP14/venicialis.yml @@ -332,7 +332,7 @@ entities: - type: GridPathfinding - type: CP14CloudShadows - type: MapLight - ambientLightColor: '#D8B059FF' + ambientLightColor: "#7bc2e0" - type: Gravity gravityShakeSound: !type:SoundPathSpecifier path: /Audio/Effects/alert.ogg diff --git a/Resources/Prototypes/_CP14/Procedural/Demiplane/Modifiers/MapLight/mapLight.yml b/Resources/Prototypes/_CP14/Procedural/Demiplane/Modifiers/MapLight/mapLight.yml index 64db984351..66ac4e2c39 100644 --- a/Resources/Prototypes/_CP14/Procedural/Demiplane/Modifiers/MapLight/mapLight.yml +++ b/Resources/Prototypes/_CP14/Procedural/Demiplane/Modifiers/MapLight/mapLight.yml @@ -88,6 +88,8 @@ components: - type: LightCycle originalColor: "#7bc2e0" + - type: MapLight + ambientLightColor: "#7bc2e0" - type: cp14LocationModifier id: MapLightCycleHot @@ -102,6 +104,8 @@ components: - type: LightCycle originalColor: "#ff8929" + - type: MapLight + ambientLightColor: "#ff8929" - type: cp14LocationModifier id: MapLightCycleHot2 @@ -116,4 +120,6 @@ components: - type: LightCycle originalColor: "#d68787" + - type: MapLight + ambientLightColor: "#d68787"