ID:137481
 
It would be very helpful to check to see if certain objects enter the same location in cases where Bump() would be inadequate, due to one or both objects being non-dense.

I suggest Collide(), used as below:
obj
whoopie_cushion
icon='whoopie.dmi'
Collide(who)
view() << "[who] stepped on a whoopie cushion!"


Otherwise it's a little clunky to code things you want to be objects as turfs, so that you can use entered, or do a check each time someone moves, etc.
Otherwise it's a little clunky to code things you want to be objects as turfs, so that you can use entered, or do a check each time someone moves, etc.

What if you overrode turf.Entered(moving_thing) to call Collide(moving_thing, item_in_turf) for every item in the turf?


In response to Gughunter
I would like a collide-type proc... it would make things a lot easier for me and undoubtably others. Also, consider this: I heard it somwhere, though I can't remember...

"If somthing is really worth doing, why not make it easier to do?"

I hope to see a command that can duplicate the <font color='white'>when touching? "obj1 "obj2</font> command in Logo (which is the only place I've seen it used.)

See you later!
In response to Lord of Water
I should round up my basic movement supplements and package them into a file.
In response to Gughunter
Gughunter wrote:
Otherwise it's a little clunky to code things you want to be objects as turfs, so that you can use entered, or do a check each time someone moves, etc.

What if you overrode turf.Entered(moving_thing) to call Collide(moving_thing, item_in_turf) for every item in the turf?

The answer to this "what if" is that you could be adding a lot of extra processing time, especially in a game with a lot of players, npcs, and objects.

I have ways to do what I want here (see my old traps library for one version), just wanted a more elegant answer that wouldn't add a lot of overhead.
In response to Skysaw
Skysaw wrote:
Gughunter wrote:
Otherwise it's a little clunky to code things you want to be objects as turfs, so that you can use entered, or do a check each time someone moves, etc.

What if you overrode turf.Entered(moving_thing) to call Collide(moving_thing, item_in_turf) for every item in the turf?

The answer to this "what if" is that you could be adding a lot of extra processing time, especially in a game with a lot of players, npcs, and objects.

Unfortunately, I don't know that there's a whole lot that could be done to speed this up. It may or may not be faster to have the /turf Entered() and Exited() procs maintain a list of Collide()-able objects in them and only loop through those, but you very well might be doing that already.
In response to Leftley

Good idea. If I were to implement this (either internally or as a DM library or something), I would do it something like this:

atom/movable
   var
      touchy   //assign to 1 to enable Touch()
   proc
      Touch(atom/movable/Toucher)

turf
   var
      touchy_contents  //count of touchy items

   Entered(atom/movable/O)
      touchy_contents += O.touchy
      if(touchy_contents > O.touchy)
         for(atom/movable/C in contents)
            if(C.touchy && C != O) C.Touch(O)
      return ..()

   Exited(atom/movable/O)
      touchy_contents -= O.touchy
      return ..()



One little problem with this code is that objects which are created inside of a turf do not call Entered(), so I suppose atom/movable/New() would have to be modified to adjust turf.touchy_contents.

The main point in this little snippet is that the overhead you want to avoid is looping through the turf contents list on every single movement. When there are touchy contents, it's not much extra overhead to loop over all of the contents. Of course, that assumes that touchy items are rare and that turf contents lists are generally not enormous.

It would be nice to extend this to work over a distance. For example, monsters that are very touchy would be able to respond to Touch() over a distance. That would avoid the need to continually poll the monster's surroundings for prey. That's a little trickier, but it could be done. This would only be advantageous if movements are rare compared to the number of monsters on the map, which might not always be the case--especially if you have monsters running all over the place. In that case, one might want to just limit the things which can trigger touchy behavior to players.

--Dan
In response to Dan

Another note: you can also cheat and use Bump() for this purpose. When your touchy object gets bumped, you can just force a movement:

obj/whoopie_cushion/Bump(atom/movable/O)
   O.loc = loc //force it to move here
   O << "Pfffttt!"


The trick is to assign loc directly rather than do O.Move(loc) or you generate an infinite recursion:)

--Dan
h
In response to Dan
Dan wrote:
Another note: you can also cheat and use Bump() for this purpose. When your touchy object gets bumped, you can just force a movement:

> obj/whoopie_cushion/Bump(atom/movable/O)
>    O.loc = loc //force it to move here
>    O << "Pfffttt!"
>

The trick is to assign loc directly rather than do O.Move(loc) or you generate an infinite recursion:)

--Dan
h

This works up to the point where the object moving onto the whoopie cushion is itself dense. Usable in most cases, I guess.