ID:2074329
 
(See the best response by FKI.)
Code:
obj/Projectiles
Cross(atom/a)
//doesn't seem to inluence anything it is crossing
//only other /obj/projectiles that cross it.
if(istype(a,/obj/IntangibleObject))
return 1
if(istype(a,/obj/Projectiles))
return 1
else
return 0

Bump(atom/a)
if(istype(a,/obj/IntangibleObject))
var/s = src.step_size
switch(dir)
if(EAST) src.step_x+=s
if(WEST) src.step_x-=s
if(NORTH) src.step_y+=s
if(SOUTH) src.step_y-=s
if(NORTHEAST) {src.step_x+=s; src.step_y+=s}
if(SOUTHEAST) {src.step_x+=s; src.step_y-=s}
if(NORTHWEST) {src.step_x-=s; src.step_y+=s}
if(SOUTHWEST) {src.step_x-=s; src.step_y-=s}
else
del src


Problem description:

The desired outcome is that when a projectile hits certain certain turfs/objs/mobs, certain specified things happen. Including things like deletion and passing through the obstacle.

The code presented above gives the desired results, but confuses me a bit and seems wrong/bad.

Firstly, the Cross() procedure doesn't work as I'm used to with Bump()...Ergo, the way I've got Cross() here essentially contributes nothing other than managing inter-projectile collisions.

This leaves Bump() as my sole source for managing collisions as well as pass-throughs. As I said, it works as intended, but I'm sure there must be a simpler or better way to handle this?
Best response
obj/Projectiles
Cross(atom/a)
//doesn't seem to inluence anything it is crossing
//only other /obj/projectiles that cross it.
...


Cross() literally only affects movables that are crossing it. Likewise, Crossed() reacts to things that have crossed it.

If you want the object being crossed to react when Cross()ed, I would suggest adding hooks that do just that. Here's an implementation I use in my own projects:

atom
proc
on_bumped(atom/movable/moving)

movable
Cross(atom/movable/crossing)
return crossing.on_cross(src, ..())

Crossed(atom/movable/crossing)
crossing.on_crossed(src)


Uncross(atom/movable/uncrossing)
return uncrossing.on_uncross(src, ..())

Uncrossed(atom/movable/uncrossing)
uncrossing.on_uncrossed(src)


Bump(atom/obstacle)
. = ..()
obstacle.on_bumped(src)


proc/on_cross(atom/movable/crossed, supercall)
return supercall

proc/on_crossed(atom/movable/crossed)


proc/on_uncross(atom/movable/uncrossed, supercall)
return supercall

proc/on_uncrossed(atom/movable/uncrossed)


Also note that my setting of the return value in Bump(), by default, has no significance, because Bump() doesn't return anything.
Another addition: your Bump() proc could be simplified by using bitflags. An example:

    var s_x = (dir & (EAST | WEST)) ? (dir & EAST) ? (step_size) : -(step_size) : (0)
var s_y = (dir & (NORTH | SOUTH)) ? (dir & NORTH) ? (step_size) : -(step_size) : (0)
step_x += s_x
step_y += s_y
In response to FKI
Sooo... I was handling the pass-through mechanic correctly? IDK... I feel like its something that will cause me grief/bugs as movements and Bumps become more complex later... Guess we'll see!

Thanks for this, IDK if that's "simplified" haha. Does it use less overhead though?
In response to Saucepan Man
Saucepan Man wrote:
Sooo... I was handling the pass-through mechanic correctly? IDK... I feel like its something that will cause me grief/bugs as movements and Bumps become more complex later... Guess we'll see!

Thanks for this, IDK if that's "simplified" haha. Does it use less overhead though?

You were handling it correctly; I was just making sure you understood that Cross()/Crossed() aren't meant to replace Bump() - however, you can use the former procs for collision if you wanted to.

My approach isn't exactly "simpler" than yours, but I'd say it's easier to work with for the long-run.

And no, it doesn't use less overhead; if anything it uses more overhead since there are more procs involved. I don't mind this tradeoff though since, like I said, it's easier to work with.