From 4b3a9f543026f99e84e7f0210a38a4d5a57bd2dd Mon Sep 17 00:00:00 2001 From: KasparoVy <12377767+KasparoVy@users.noreply.github.com> Date: Sun, 28 Apr 2019 00:25:59 -0400 Subject: [PATCH] Port Polaris darksight handling https://github.com/PolarisSS13/Polaris/pull/4626 by Arokha --- code/modules/mob/living/life.dm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/code/modules/mob/living/life.dm b/code/modules/mob/living/life.dm index 9378f29e365..146c5d700b4 100644 --- a/code/modules/mob/living/life.dm +++ b/code/modules/mob/living/life.dm @@ -189,6 +189,7 @@ if(!client) return 0 handle_vision() + handle_darksight() handle_hud_icons() return 1 @@ -206,6 +207,27 @@ if(!remote_view && !client.adminobs) reset_perspective(null) +/mob/living/proc/handle_darksight() + var/obj/screen/fullscreen/see_through_darkness/S = screens["see_through_darkness"] + if(!S) + return + var/darksightedness = min(see_in_dark / world.view, 1.0) //A ratio of how good your darksight is, from 'nada' to 'really darn good' + var/current = S.alpha / 255 //Our current adjustedness + + var/brightness = 0.0 //We'll assume it's superdark if we can't find something else. + + if(isturf(loc)) + var/turf/T = loc //Will be true 99% of the time, thus avoiding the whole elif chain + brightness = T.get_lumcount() + + var/darkness = 1 - brightness //Silly, I know, but 'alpha' and 'darkness' go the same direction on a number line + var/adjust_to = min(darkness, darksightedness)//Capped by how darksighted they are + var/distance = abs(current - adjust_to) //Used for how long to animate for + if(distance < 0.01) return //We're already all set + + //world << "[src] in B:[round(brightness,0.1)] C:[round(current,0.1)] A2:[round(adjust_to,0.1)] D:[round(distance,0.01)] T:[round(distance*10 SECONDS,0.1)]" + animate(S, alpha = (adjust_to*255), time = (distance*10 SECONDS)) + // Gives a mob the vision of being dead /mob/living/proc/grant_death_vision() sight |= SEE_TURFS