Index · Preferences · Help
Policy · Discussion · AI · Calculations · Engine · Graphics · Interface · Lists · Movement · Objects · Players · Samples · Saving · Sound · Text · Time · Turfs · Utility
Forum Search:

[Advanced Search]

[Messages in this Thread] [Show All (4)] [Return to Turfs]

Author:Shadowdarke [Posts]
Date:11/28/06 9:58 am
Topic:Re: Turf Borders
Post ID:110
Parent ID:98
Next ID:99
Very handy snippet, but I have a few comments. I hope you won't take offense at my tampering!

>
atom/movable/Move(nLoc, nDir)
    if(nDir)
The nDir may not correspond to the direction of movement. For instance some movement systems allow you to strafe sideways and backwards or move completely independently of your facing. Most of my projects use the Dir argument to keep the mob facing the correct direction when they teleport to far off turfs.

I would check if nLoc and loc are turfs at the beginning, then see if they are at a distance of 1 before proceeding with the border check. If so, nDir should be set to get_dir(loc, nLoc).

You don't really need to split the component directions out of the original. You want to see if the turf's border completely occludes the direction of movement. You can just check
        if((T.borders & nDir) == nDir)


The full proc with my changes:
//	Title: Turf Borders
//	Credit to: Hiead (modified by Shadowdarke)
//	Contributed by: Hiead

/*
        This snippet was written to show an example of how one
    can apply imaginary "borders" to turfs, disallowing movable
    atoms from entering or exiting from specific directions.
    
    For example, a turf with NORTH and EAST borders:
        borders = NORTH|EAST
    
    will not allow movable atoms to enter from a NORTH, EAST,
    or NORTHEAST direction, and it will prevent movable atoms
    from exiting in a NORTH, EAST, or NORTHEAST direction.
*/

turf/var/borders = 0	// bit-flagged value determining directional

atom/movable/Move(nLoc)
    if(isturf(loc) && isturf(nLoc) && get_dist(loc, nLoc) == 1)
        var/nDir = get_dir(loc, nLoc)

        var/turf/T = loc
        if((T.borders & nDir) == nDir)
            return FALSE

        T = nLoc
        nDir = turn(nDir,180)
        if((T.borders & nDir) == nDir)
            return FALSE
    . = ..()

///*
//	Testing Code/Sample Implementation:

turf/limited_exit/borders = EAST|NORTH|WEST

//*/

Messages in this Thread: [Show All (4)]

  Turf Borders Hiead (11/25/06 12:10 am)
      Re: Turf Borders Shadowdarke (11/28/06 9:58 am)
      Re: Turf Borders DivineO'peanut (11/25/06 12:33 am)
          Re: Turf Borders Hiead (11/25/06 12:57 am)