ID:1533820
 
(See the best response by Kaiochao.)
Code:
N/A


Problem description:

In TOPDOWN_MAP format it seems that objects on the same tile with the same layer but different pixel offsets fight for layer dominance. How can I fix this without switching to SIDE_MAP?
Um... You could do a complex method such as a layering system that updates every time the player moves. Although, even that could cause problems.

mob/Move()
..()
layer=(step_y+y*32)/1000


Honestly, I'm not entirely sure how effective something like that would be, or even how practical. I'm assuming your problem is they are on the same block, but one is above the other?

*edit* After I posted I realized the script I supplied works in reverse of the desired effect, placing the top-most MOB's layer higher then the one below it.

mob/Move()
..()
var/mY=world.maxy*32+32
layer=(mY-(step_y+y*32))/1000
layer+=MOB_LAYER


There could be a better way to calculate this, but that's what I came up with. Also, I'd advice using decimals because it makes things easier when altering layers. Especially if you have objects that should always be on top.
Best response
I have a library for standing layers here, but that's irrelevant.

Fighting for layer dominance happens when objects overlap and have the exact same layer. You can avoid this by adding a random amount to every object's layer:
atom/New()
..()
layer += rand() * 1e-2 // add between 0 and 0.01 to layer

Of course, this means you can't do layer equality checks (this.layer == that.layer), but who does that anyway?

@toby: Don't forget to return the value in Move(). Skip that in a single override and your calls to Move() and step() won't return a usable value.
In response to Kaiochao
You're completely right, an oversight on my part.

I'm assuming you're talking about this:
mob/Move()
.=..()
var/mY=world.maxy*32+32
layer=(mY-(step_y+y*32))/1000
layer+=MOB_LAYER
In response to Kaiochao
Kaiochao wrote:
I have a library for standing layers here, but that's irrelevant.

Fighting for layer dominance happens when objects overlap and have the exact same layer. You can avoid this by adding a random amount to every object's layer:
> atom/New()
> ..()
> layer += rand() * 1e-2 // add between 0 and 0.01 to layer
>

Of course, this means you can't do layer equality checks (this.layer == that.layer), but who does that anyway?

@toby: Don't forget to return the value in Move(). Skip that in a single override and your calls to Move() and step() won't return a usable value.

I didn't even consider that layers could be irrational values. Thanks. :P