ID:1849266
 
(See the best response by FKI.)
Code:
turf
Enter(atom/movable/O)
if(ismob(O))
var/mob/M=O
if(src.density==1)
if(M.fly==1)
return 1
else
return 0
else
var/mobss=0
var/objss=0
for(var/mob/L in src)
mobss++
for(var/obj/N in src)
if(N.density==1 || N.unpassable==1)
objss++
if(mobss==0 && objss==0)
return 1
else
if(M.fly==1)
for(var/mob/L in src)
if(L.fly==1)
return 0
return 1
..()
if(isobj(O))
var/obj/o=O
var/mobss=0
var/objss=0
for(var/mob/L in src)
mobss++
for(var/obj/N in src)
if(N.unpassable==1)
objss++
if(mobss==0 && objss==0)
return 1
else
..()


Problem description:
Just implemented a flying system for my game and because changing the density value is bound to make some problems sooner or later in a pvp world where someone may get killed while in a situation I didn't predict leading and also because they are projectile attacks, which would miss the target even if the shooter is flying also. Therefore, I decided to let the turfs do all the bothersome stuff by changing the Enter() proc. However, now projectile attacks either pass through mobs or disappear on what should be contact with the mob... any suggestions to fix this problem?
Best response
Off top, this is what I came up with.

First I'd override the collision procs as seen below, and add a fly_layer to control what "level" each movable atom is flying on. An object flying on a higher level than another essentially flies over it (no collision).

atom
var/fly_layer = 0


atom/movable
Cross(atom/movable/m)
. = m.on_cross(src, ..())

Uncross(atom/movable/m)
. = m.on_uncross(src, ..())

proc
on_cross(atom/obstacle, r)
return r

on_uncross(atom/obstacle, r)
return r


Then we override our on_cross/on_uncross procs to allow a mob that's flying to pass through obstacles that are "below" them.

mob
var/tmp/flying = 0

verb
// testing purposes...
fly()
if(!flying)
flying = 1
fly_layer = 2
else
flying = 0
fly_layer = 0


on_cross(atom/obstacle, r)
if(flying)
if(fly_layer > obstacle.fly_layer) return 1
. = ..()

on_uncross(atom/obstacle, r)
if(flying)
if(fly_layer > obstacle.fly_layer) return 1
. = ..()


This is what I would do more or less in your situation. Feel free to ask questions if you have any.
Thanks, it worked. I probably wouldnt have figured that out because using cross and uncross procs hadn't even crossed my mind. (Get it? xD)
In response to Cheesy pants
No problem haha (definitely cheesy). Glad I could help.