Walker's Pathfinder
This is a demonstration of a softcoded pathfinder: How to get from one room to another via exits. It just a demonstration: It can be used as is, but ideally, you can just rip code from it =).
Functions:
after(),
ansi(),
before(),
cand(),
cor(),
create(),
default(),
first(),
firstof(),
if(),
iter(),
last(),
lcon(),
lexits(),
lflags(),
loc(),
locate(),
map(),
member(),
name(),
not(),
null(),
repeat(),
setdiff(),
setq(),
setr(),
squish(),
strcat(),
strmatch(),
switch(),
t(),
type(),
u(),
v().
Features:
#lambda.
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for Walker's Pathfinder
@@ Project walkerPathfinder
@@ Version 6
@@
@@ Description:
@@ This is a demonstration of a softcoded pathfinder: How to
@@ get from one room to another via exits.
@@ It just a demonstration: It can be used as is, but ideally,
@@ you can just rip code from it =).
@@
@@ Version log:
@@ Author: Walker <Mush>
@@ Date: Mon Dec 13 09:12:40 2010 -0800
@@ v6v
@@
@@ Removing test svc`on* attributes.
@@
@@ Readme:
@@ Provides two functions: find_path and find_exits. Both are
@@ described in detail in the @desc.
@@
@@ Language: MushCode
@@ Installer file created by RubySVC (Softcode Version Control)
@@
@@
@@
@@ Creating Rooms, Things and Exits.
@@
@@
@set me=SVC`Tc4db9432232fcf09fc81:[default(SVC`Tc4db9432232fcf09fc81,create(Tc4db9432232fcf09fc81))]
@@
@@
@@ Objects created, now setting attributes, locks, etc.
@@
@@
@@
@@ Filling out Pathfinder
@@
@name [v(SVC`Tc4db9432232fcf09fc81)]=Pathfinder
@lock/Basic [v(SVC`Tc4db9432232fcf09fc81)]=%!
@set [v(SVC`Tc4db9432232fcf09fc81)]=iter(setdiff(lflags([v(SVC`Tc4db9432232fcf09fc81)]),VISUAL),!##) [setdiff(VISUAL,lflags([v(SVC`Tc4db9432232fcf09fc81)]))]
&USE [v(SVC`Tc4db9432232fcf09fc81)]=@pemit %#=u(describe)
&UFAIL [v(SVC`Tc4db9432232fcf09fc81)]=@pemit %#=u(describe)
&PROCESS_NODE [v(SVC`Tc4db9432232fcf09fc81)]=if(cand(%qr,u(check`%qt,last(%0,:),%qw)),setq(p,%0,r,0),map(#lambda/if(cor(member(\%qc,loc(\%0)),u(ignore_room,loc(\%0))),,%0.\%0:\[loc(\%0)\]\[setq(c,\%qc \[loc(\%0)\])\]),lexits(last(%0,:))))
&NICE_PATH [v(SVC`Tc4db9432232fcf09fc81)]=map(nice_line,%0,:,%r)
&NICE_LINE [v(SVC`Tc4db9432232fcf09fc81)]=if(strmatch(%0,*.*),From [name(before(%0,.))]\, go [name(after(%0,.))].,... and there it is\, in [name(%0)]!)
&IGNORE_ROOM [v(SVC`Tc4db9432232fcf09fc81)]=member(#2638,%0)
&FUN_FINDPATH [v(SVC`Tc4db9432232fcf09fc81)]=strcat(setq(0,locate(%#,%0,*)),if(not(%q0),#-1 INVALID OBJECT,switch(setr(r,u(find_path,%q0)),#-1*,There is no such path. :-/.,u(nice_path,%qr)) with [first(%?)] function invocations.)
&FIND_PATH [v(SVC`Tc4db9432232fcf09fc81)]=null(setq(w,%0,t,type(%0),l,firstof(%1,loc(%@)),c,firstof(%1,loc(%@)) #-1,p,,r,1),@@(%ql is the list, %qc is completed rooms. %qp is the found path. %qr is true if we should keep checking. %qw is what we're looking for, %qt is the type of it),map(finder,repeat(x%b,1000)))[firstof(%qp,#-1 NO PATH)]
&FIND_EXITS [v(SVC`Tc4db9432232fcf09fc81)]=if(setr(1,u(find_path,%0,%1)),squish(iter(%q1,after(##,.),:,%b)),%q1)
&FINDER [v(SVC`Tc4db9432232fcf09fc81)]=if(%qr,setq(l,map(process_node,%ql)))
&DESCRIBE [v(SVC`Tc4db9432232fcf09fc81)]=Use [ansi(h,+path to <dbref>)] to track down anything or anyone up to 4 rooms away.%r%rUsage:%r%r%b%bu(%!/find_path,#targetdbref,#searcherdbref) - Get a path from searcher to target, in a :-separated list of #roomdbref.#exitdbref.%r%r%b%bu(%!/find_exits,#targetdbref,#searcherdbref) - Like find_path, but only returns a space-separated list of dbref exits for the searcher to take.%r%r%r&ignore_room pathfinder=<code> - Return 1 if the pathfinder should ignore a given room dbref (in \%0) when pathfinding.
&CMD.FINDPATH [v(SVC`Tc4db9432232fcf09fc81)]=$+path to *:@assert t(setr(0,locate(%#,%0,*)))=@pemit %#=You must provide a valid object that I can find! ; @pemit %#=switch(setr(r,u(find_path,%q0,%l)),#-1*,There is no such path. :-/.,u(nice_path,%qr)) with [first(%?)] function invocations
&CHECK`THING [v(SVC`Tc4db9432232fcf09fc81)]=member(lcon(%0),%1)
&CHECK`ROOM [v(SVC`Tc4db9432232fcf09fc81)]=member(%0,%1)
&CHECK`PLAYER [v(SVC`Tc4db9432232fcf09fc81)]=member(lcon(%0),%1)
&CHECK`EXIT [v(SVC`Tc4db9432232fcf09fc81)]=member(lexits(%0),%1)
&CHECK [v(SVC`Tc4db9432232fcf09fc81)]=
&AUTHOR [v(SVC`Tc4db9432232fcf09fc81)]=Walker @ M*U*S*H
@set [v(SVC`Tc4db9432232fcf09fc81)]/USE=no_command prefixmatch
@set [v(SVC`Tc4db9432232fcf09fc81)]/UFAIL=no_command prefixmatch
@set [v(SVC`Tc4db9432232fcf09fc81)]/DESCRIBE=no_command visual prefixmatch public nearby
@@
@@ Triggering all startups, oncreates, onupdates.
@@
@@ Version 6
@@
@@ Description:
@@ This is a demonstration of a softcoded pathfinder: How to
@@ get from one room to another via exits.
@@ It just a demonstration: It can be used as is, but ideally,
@@ you can just rip code from it =).
@@
@@ Version log:
@@ Author: Walker <Mush>
@@ Date: Mon Dec 13 09:12:40 2010 -0800
@@ v6v
@@
@@ Removing test svc`on* attributes.
@@
@@ Readme:
@@ Provides two functions: find_path and find_exits. Both are
@@ described in detail in the @desc.
@@
@@ Language: MushCode
@@ Installer file created by RubySVC (Softcode Version Control)
@@
@@
@@
@@ Creating Rooms, Things and Exits.
@@
@@
@set me=SVC`Tc4db9432232fcf09fc81:[default(SVC`Tc4db9432232fcf09fc81,create(Tc4db9432232fcf09fc81))]
@@
@@
@@ Objects created, now setting attributes, locks, etc.
@@
@@
@@
@@ Filling out Pathfinder
@@
@name [v(SVC`Tc4db9432232fcf09fc81)]=Pathfinder
@lock/Basic [v(SVC`Tc4db9432232fcf09fc81)]=%!
@set [v(SVC`Tc4db9432232fcf09fc81)]=iter(setdiff(lflags([v(SVC`Tc4db9432232fcf09fc81)]),VISUAL),!##) [setdiff(VISUAL,lflags([v(SVC`Tc4db9432232fcf09fc81)]))]
&USE [v(SVC`Tc4db9432232fcf09fc81)]=@pemit %#=u(describe)
&UFAIL [v(SVC`Tc4db9432232fcf09fc81)]=@pemit %#=u(describe)
&PROCESS_NODE [v(SVC`Tc4db9432232fcf09fc81)]=if(cand(%qr,u(check`%qt,last(%0,:),%qw)),setq(p,%0,r,0),map(#lambda/if(cor(member(\%qc,loc(\%0)),u(ignore_room,loc(\%0))),,%0.\%0:\[loc(\%0)\]\[setq(c,\%qc \[loc(\%0)\])\]),lexits(last(%0,:))))
&NICE_PATH [v(SVC`Tc4db9432232fcf09fc81)]=map(nice_line,%0,:,%r)
&NICE_LINE [v(SVC`Tc4db9432232fcf09fc81)]=if(strmatch(%0,*.*),From [name(before(%0,.))]\, go [name(after(%0,.))].,... and there it is\, in [name(%0)]!)
&IGNORE_ROOM [v(SVC`Tc4db9432232fcf09fc81)]=member(#2638,%0)
&FUN_FINDPATH [v(SVC`Tc4db9432232fcf09fc81)]=strcat(setq(0,locate(%#,%0,*)),if(not(%q0),#-1 INVALID OBJECT,switch(setr(r,u(find_path,%q0)),#-1*,There is no such path. :-/.,u(nice_path,%qr)) with [first(%?)] function invocations.)
&FIND_PATH [v(SVC`Tc4db9432232fcf09fc81)]=null(setq(w,%0,t,type(%0),l,firstof(%1,loc(%@)),c,firstof(%1,loc(%@)) #-1,p,,r,1),@@(%ql is the list, %qc is completed rooms. %qp is the found path. %qr is true if we should keep checking. %qw is what we're looking for, %qt is the type of it),map(finder,repeat(x%b,1000)))[firstof(%qp,#-1 NO PATH)]
&FIND_EXITS [v(SVC`Tc4db9432232fcf09fc81)]=if(setr(1,u(find_path,%0,%1)),squish(iter(%q1,after(##,.),:,%b)),%q1)
&FINDER [v(SVC`Tc4db9432232fcf09fc81)]=if(%qr,setq(l,map(process_node,%ql)))
&DESCRIBE [v(SVC`Tc4db9432232fcf09fc81)]=Use [ansi(h,+path to <dbref>)] to track down anything or anyone up to 4 rooms away.%r%rUsage:%r%r%b%bu(%!/find_path,#targetdbref,#searcherdbref) - Get a path from searcher to target, in a :-separated list of #roomdbref.#exitdbref.%r%r%b%bu(%!/find_exits,#targetdbref,#searcherdbref) - Like find_path, but only returns a space-separated list of dbref exits for the searcher to take.%r%r%r&ignore_room pathfinder=<code> - Return 1 if the pathfinder should ignore a given room dbref (in \%0) when pathfinding.
&CMD.FINDPATH [v(SVC`Tc4db9432232fcf09fc81)]=$+path to *:@assert t(setr(0,locate(%#,%0,*)))=@pemit %#=You must provide a valid object that I can find! ; @pemit %#=switch(setr(r,u(find_path,%q0,%l)),#-1*,There is no such path. :-/.,u(nice_path,%qr)) with [first(%?)] function invocations
&CHECK`THING [v(SVC`Tc4db9432232fcf09fc81)]=member(lcon(%0),%1)
&CHECK`ROOM [v(SVC`Tc4db9432232fcf09fc81)]=member(%0,%1)
&CHECK`PLAYER [v(SVC`Tc4db9432232fcf09fc81)]=member(lcon(%0),%1)
&CHECK`EXIT [v(SVC`Tc4db9432232fcf09fc81)]=member(lexits(%0),%1)
&CHECK [v(SVC`Tc4db9432232fcf09fc81)]=
&AUTHOR [v(SVC`Tc4db9432232fcf09fc81)]=Walker @ M*U*S*H
@set [v(SVC`Tc4db9432232fcf09fc81)]/USE=no_command prefixmatch
@set [v(SVC`Tc4db9432232fcf09fc81)]/UFAIL=no_command prefixmatch
@set [v(SVC`Tc4db9432232fcf09fc81)]/DESCRIBE=no_command visual prefixmatch public nearby
@@
@@ Triggering all startups, oncreates, onupdates.
@@