ID:139580
 
Code:
mob
Login()
..()
var/icon/I = icon(icon,icon_state)
I.Flip(SOUTH)
var/image/i = image(I,src,layer=TURF_LAYER-2)
i.pixel_y -= 30
underlays += i
turf
city
icon = 'humancity.dmi'
floor
icon_state = "1"
water
icon_state = "w"
layer=TURF_LAYER-3
New()
icon_state = "wu"
overlays += image('humancity.dmi',src,"water",layer=TURF_LAYER-1)


Problem description:
What I'm attempting to do here is to have a water reflection of the player's image.
The idea is simple: I give the player an underlay whose layer is TURF_LAYER-2.
The floor which the water is on is TURF_LAYER-3, and the transparent overlay of the water is TURF_LAYER-1, thus giving me:

LAYER(0) = (NULL)
LAYER(-1) = Transparent Overlay
LAYER(-2) = Reflection
LAYER(-3) = Floor

The problem is, however, when I run he code, the mob's underlay (the reflection) is actually on top of all of the turf, including /turf/city/floor , whose layer is TURF_LAYER.

I've tried changing the layers (tried to change values, and then layer type, etc.), but I didn't get any good results.

Any ideas as to why this is happening?

Thanks!
You're doing it backwards. A better way would be to make the water transparent, and have it overtop a semi-transparent image of the player.
layer -1 is FLOAT_LAYER, which is a special layer which means "always above whatever I'm overlayed on". Since TURF_LAYER is 2, TURF_LAYER-3 is -1 and things break. The solution is to use fractional values for the layer. So, TURF_LAYER - 0.75, 0.5, 0.25, etc. (multiples of 0.5, 0.25, 0.125, etc. are preferred).
In response to Garthor
Garthor wrote:
layer -1 is FLOAT_LAYER, which is a special layer which means "always above whatever I'm overlayed on". Since TURF_LAYER is 2, TURF_LAYER-3 is -1 and things break. The solution is to use fractional values for the layer. So, TURF_LAYER - 0.75, 0.5, 0.25, etc. (multiples of 0.5, 0.25, 0.125, etc. are preferred).

Thanks a lot! Your solution worked beautifully.

Just to make sure, then:
1 (AREA_LAYER)
2 (TURF_LAYER)
3 (OBJ_LAYER)
4 (MOB_LAYER)


AREA_LAYER+1 = TURF_LAYER
TURF_LAYER+1 = OBJ_LAYER

Is that how layers actually work?
In response to Popisfizzy
How and why would it be better to do this your way?
As in, is it better at CPU usage, memory handling... ?

In response to Gooseheaded
Gooseheaded wrote:
Just to make sure, then:
1 (AREA_LAYER)
2 (TURF_LAYER)
3 (OBJ_LAYER)
4 (MOB_LAYER)


AREA_LAYER+1 = TURF_LAYER
TURF_LAYER+1 = OBJ_LAYER

Is that how layers actually work?

Yes. Things like AREA_LAYER and TURF_LAYER, as well as others like TRUE and FALSE are simply text-substituted constants, no different than if you had done the following:
#define AREA_LAYER 1
#define TURF_LAYER 2
#define OBJ_LAYER 3
#define MOB_LAYER 4

#define TRUE 1
#define FALSE 0

So when you press compile, all instances of AREA_LAYER or TRUE are immediately text-swapped as if you had simply typed "1" instead. You can test this for yourself:
mob/verb/orly()
usr << AREA_LAYER
usr << isnum(AREA_LAYER)


This also applies to directions as well: NORTH, SOUTH, EAST, WEST, ...