ID:155859
 
I am aware that you can set luminosity and so forth and have the map go 'black' in areas you cannot see and surround the player with their field of view - or have an object emit light and have similar aura/field of view.

However, what if you wish to have turf change states instead of simply being black. If I want both a 'Dark' and 'Light' version of a TURF to change with that field of view?

I have created something that does this. However its not perfect, and I am thinking there must be a better way...

turf
FLOOR
L1/icon_state = "Stone_1"
L2/icon_state = "Stone_2"
L3/icon_state = "Stone_3"
L4/icon_state = "Stone_4"
L5/icon_state = "Stone_5"
L6/icon_state = "Stone_6"

Entered(atom/M) // Something walked on the turf!
..()

if(icon_state == initial(icon_state)) icon_state = "[icon_state]_L" // Set its icon_state to its original icon_state +_L (the LIGHT version)

for(var/turf/FLOOR/STONE/S in view(4,src))
if(S.icon_state == initial(S.icon_state)) S.icon_state = "[S.icon_state]_L" // Check 4 tiles around it and set those icon_states to +_L as well

return

Exited(atom/M) // Something stepped off the turf
..()

if(icon_state != initial(icon_state)) icon_state = initial(icon_state) // Reset the turfs icon_state back to its initial value

for(var/turf/FLOOR/STONE/S in view(4,src))
if(S.icon_state != initial(S.icon_state)) S.icon_state = initial(S.icon_state) // Reset the turfs around it in a 4 tile radius back to its initial value

return


The main issues are, that if two mobs walk towards each other it clashs and the turf will be set to dark/light.

The field of view is not constant.

I want it to behave like the luminosity. You would walk towards a player and their aura would merge with yours. I guess I *could* set some sort of mob reference in the turf so only the original mob can set it back to darkness, which in theory should stop that problem.

However, is there a better way I am overlooking? I have not really had the need for such functions before, and not I am playing around a little and would like to know what other ways there might be to do this - especially if those ways are better and more functional :)
Try taking a look at Shadowdarke's sd_DAL library: http://www.byond.com/developer/Shadowdarke/ sd_DynamicAreaLighting

It can do pretty much everything you're asking for. Even if you decide not to use the library itself, you can look at how Shadowdarke went about doing lighting.
In response to Skyspark (#1)
That's quite a comprehensive lib. I decided it was really too complex for the simple task I wanted, though def useful thanks.

turf
STONE

icon = 'floor.dmi'

icon_state = "DARK"
luminosity = 0

var/atom/lightsrc

Entered(atom/A)

for(var/turf/STONE/T in view(A.luminosity-2,src)) if(!T.lightsrc)

if(T.icon_state == initial(T.icon_state))

T.icon_state = "LIGHT"
T.lightsrc = A
return

Exited(atom/A)

for(var/turf/STONE/T in view(A.luminosity-2,src)) if(T.lightsrc == A)

if(T.icon_state != initial(T.icon_state))

T.icon_state = initial(icon_state)
T.lightsrc = null

return


Seem's to work quite well. Leaving a nice little 'dark' turf just before total blackness. I decided to work with luminosity instead of against it :)

Would need to work out how to work with opacity etc though. But maybe I can get some info from that LIB on that.

EDIT:

Oh and as long as I make sure an obj uses Move() when its placed, it should cast light too.

If I am pre-placing the Obj/ on the map before hand, I think that I can simply add Move() to its New() and that should do it as well.
In response to UnknownDuelist (#2)
You could set different shaded overlay's for each turf?

Just a thought