Switch to edit mode.
Name(s): @which1: "Copied from Generic Programmer (#14):@which by Dax (#789)Nov 27 12:55:07 2001"
2: "Finds the location of the specified command"
3: "Looks through the player, the room, dobj, iobj and the player's features."
4: if (!argstr)
5: player:tell("Finds the location of the specified command.")
6: player:tell("Usage: ", verb, " <command>")
7: return
8: endif
9: debug = 0
10: {vname, d, p, i, a, @junk} = $string_utils:parse_command(argstr)
11: {dobj, dobjstr} = d
12: {prep, prepstr} = p
13: {iobj, iobjstr} = i
14: prepstr = $code_utils:full_prep(prepstr) || "none"
15: iobj = player:my_match_object(iobjstr)
16: player:tell("Searching for command named '", vname, "' with ", a[2] ? tostr("arguments '", a[2], "'") | "no arguments", "...")
17: searchlist = {player, @player:ancestors(), player.location, @player.location:ancestors()}
18: if (valid(dobj))
19: searchlist = {@searchlist, dobj, @dobj:ancestors()}
20: endif
21: if (valid(iobj))
22: searchlist = {@searchlist, iobj, @iobj:ancestors()}
23: endif
24: for o in (searchlist)
25: "switch 'this' every time we change object classes"
26: if (o == player)
27: this = player
28: elseif (o == player.location)
29: this = player.location
30: elseif (o == dobj)
31: this = dobj
32: elseif (o == iobj)
33: this = iobj
34: endif
35: debug && player:tell("... ", o:nn(), "...")
36: n = 0
37: $command_utils:suspend_if_needed()
38: while (n != -1)
39: n = $code_utils:find_verb_named(o, vname, n + 1)
40: if (n != -1)
41: debug && player:tell("... :", n, "...")
42: {o_d, o_p, o_i} = verb_args(o, n)
43: if (o_p == "none" && o_i != "none")
44: "Not a command verb."
45: elseif (o_d == "none" && dobjstr || (o_i == "none" && iobjstr))
46: "Arguments where there shouldn't be any."
47: elseif (o_p != prepstr && o_p != "any")
48: "Preposition doens't match."
49: elseif (o_d == "this" && dobj != this || (o_i == "this" && iobj != this))
50: "Argument doesn't match 'this'."
51: else
52: player:tell("...", o:nn(), ":", verbs(o)[n], " (", o_d, " ", o_p, " ", o_i, ")")
53: return
54: endif
55: endif
56: endwhile
57: endfor
58: player:tell("...checking feature list...")
59: plist = {"any", prepstr}
60: dlist = dobjstr ? {"any"} | {"none", "any"}
61: ilist = iobjstr ? {"any"} | {"none", "any"}
62: for o in (player.features)
63: debug && $recycler:valid(o) && player:tell("... ", o:nn(), "...")
64: $command_utils:suspend_if_needed()
65: if (!$recycler:valid(o))
66: continue
67: elseif ((loc = o:has_callable_verb(vname)) && valid(loc = loc[1]))
68: debug && player:tell("... :", loc, "...")
69: vargs = verb_args(loc, vname)
70: if (vargs[2] in plist && (vargs[1] in dlist && vargs[3] in ilist))
71: player:tell("...", loc:nn(), ":", vname, " (", vargs[1], " ", vargs[2], " ", vargs[3], ")")
72: return
73: endif
74: endif
75: endfor
76: player:tell("...command not found.")
77: "Last modified by Dax (#789) on Mon Dec 10 21:01:11 2001 MST."