## Javelin's Path Functions

Functions that can be used to find all rooms within a maximum distance away from a room.

Commands: @create, @lock, @set.

### Instructions

Copy and paste the below code into a compatible MUSH or MUX.

### MUSHCode for Javelin's Path Functions

@create Javelin's path functions
@lock Javelin's path functions==me
@set Javelin's path functions = !NO_COMMAND
&DESCRIBE Javelin's path functions=Functions to use here:%rgetrecurse(room#,max-distance) - returns an unsorted list of all rooms within max-distance rooms away from room#. May include duplicates%rgetall(room#,max-distance) - Same as getrecurse, with duplicates removed%rstartrecurse2(room#,max-distance) - returns the list sorted by distance (with a | between sublists of rooms at different distances), nearest to farthest. If a room can be reached through multiple paths, it appears at the shortest possible distance. This uses getrecurse2 and a bunch of temporary attributes named DIST-# to do its work. Doing this with big distances can easily hit the function invocation limit and/or lag the MUSH.
@set Javelin's path functions/DESCRIBE=no_command visual public nearby
&GETALL Javelin's path functions=[setunion(u(getrecurse,%0,%1),)]
&GETRECURSE Javelin's path functions=[switch(%1,<1,%0,iter(lexits(%0),u(getrecurse,loc(##),dec(%1))))]
&GETRECURSE2 Javelin's path functions=[set(me,dist-%2:[setunion(xget(me,dist-%2), %0)])][switch(%1,0,,iter(lexits(%0),[set(me,dist-[inc(%2)]:[setunion(xget(me,dist-[inc(%2)]),loc(##))])][u(getrecurse2,loc(##),dec(%1),inc(%2))]))]
&STARTRECURSE2 Javelin's path functions=[wipe(me/dist*)][trim(u(getrecurse2,%0,%1,0))][iter(lnum(0,%1),[setq(0,%q0 [v(DIST-[dec(##)])])][setdiff(v(DIST-##),%q0)], ,%b|%b)]

look Javelin's path functions