| Message
| For anyone that wants to play with it, the plugin is currently this:
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, March 22, 2004, 4:43 PM -->
<!-- MuClient version 3.47 -->
<!-- Plugin "Automap" generated by Plugin Wizard -->
<muclient>
<plugin
name="Automap"
author="Nick Gammon"
id="23a544e6b6eeb7ea26c29b7d"
language="VBscript"
purpose="Creates speedwalks from one checkpoint to another one"
save_state="y"
date_written="2004-03-22 16:38:10"
requires="3.47"
version="1.1"
>
<description trim="y">
<![CDATA[
cp - add a checkpoint
cl - list checkpoints from this location
cg x - go to checkpoint x (eg. cg 5)
cc - clear current speedwalk - start new checkpoint
Automap:help - this description
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.vbs"/>
<!-- Triggers -->
<triggers>
<trigger
back_colour="8"
bold="y"
enabled="y"
match="*"
match_back_colour="y"
match_bold="y"
match_inverse="y"
match_italic="y"
match_text_colour="y"
send_to="9"
sequence="100"
text_colour="9"
variable="room"
>
<send>%1</send>
</trigger>
<trigger
enabled="y"
match="<*>*"
script="OnGetRoomFromPrompt"
sequence="100"
>
</trigger>
<trigger
back_colour="8"
bold="y"
enabled="y"
match="The reddish sun sets past the horizon."
match_back_colour="y"
match_bold="y"
match_inverse="y"
match_italic="y"
match_text_colour="y"
sequence="90"
text_colour="9"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
script="OnClearcheckpoint"
match="cc"
enabled="y"
sequence="100"
>
</alias>
<alias
script="OnCheckpointlist"
match="cl"
enabled="y"
sequence="100"
>
</alias>
<alias
script="OnCheckpoint"
match="cp"
enabled="y"
sequence="100"
>
</alias>
<alias
script="OnCheckpointgoto"
match="cg *"
enabled="y"
sequence="100"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
'----------------------------------------------------------
' Load mapping array
'----------------------------------------------------------
Sub OnPluginInstall
ArrayCreate "map"
ArrayImport "map", GetVariable ("map"), ","
ArrayCreate "" ' work array
ArrayCreate "dest" ' destinations array
'
' turn auto-mapping on
'
EnableMapping vbTrue
End Sub
'----------------------------------------------------------
' The plugin is saving its state
'----------------------------------------------------------
sub OnPluginSaveState
'
' Save mapping array
'
SetVariable "map", ArrayExport ("map", ",")
end sub
'----------------------------------------------------------
' helper routine to add a new path to the array
'----------------------------------------------------------
Sub AddPath (from_location, to_location, speedwalk)
dim currspeedwalk, currpath, newpath
newpath = EvaluateSpeedwalk (speedwalk)
ArrayClear "" ' get rid of previous stuff
'
' get current entries into work array
'
ArrayImport "", ArrayGet ("map", from_location), ","
'
' see what the current path there is
'
currspeedwalk = ArrayGet ("", to_location)
If currspeedwalk <> "" Then
currpath = EvaluateSpeedwalk (currspeedwalk)
If Len (newpath) > Len (currpath) Then
ColourNote "white", "red", "New path is: " & speedwalk
ColourNote "white", "red", "Old path is: " & currspeedwalk
ColourNote "white", "red", "Retaining older, shorter, path."
Exit Sub
End If ' new path longer
End If ' have an old path
'
' note path from last checkpoint
'
ArraySet "", to_location, speedwalk
ColourNote "white", "blue", "Path from '[" & _
from_location & "] to [" & _
to_location & "] noted as " & _
speedwalk
'
' put back new destinations
'
ArraySet "map", from_location, ArrayExport ("", ",")
End Sub ' AddPath
'----------------------------------------------------------
' Make a checkpoint (node)
'----------------------------------------------------------
Sub OnCheckpoint (name, line, wildcards)
Dim room, checkpoint, mapstring
'
' get into variables to save time and confusion
'
room = trim (GetVariable ("room"))
checkpoint = trim (GetVariable ("checkpoint"))
mapstring = GetMappingString
If Mapping Then
If checkpoint <> "" And _
room <> "" And _
mapstring <> "" Then
AddPath checkpoint, room, mapstring
'
' now add reverse path
'
AddPath room, checkpoint, "{auto}" & ReverseSpeedwalk (mapstring)
End If ' already have a checkpoint
'
' note new checkpoint
'
OnClearcheckpoint "", "", ""
Else
ColourNote "white", "red", "Auto-mapper not active"
End If ' mapping
End Sub ' OnCheckpoint
'----------------------------------------------------------
' Clear a checkpoint
'----------------------------------------------------------
Sub OnClearcheckpoint (name, line, wildcards)
'
' clear checkpoint (start from here)
'
SetVariable "checkpoint", GetVariable ("room")
'
' start mapping again from here
'
DeleteAllMapItems
ColourNote "white", "blue", "New checkpoint started at: " _
& GetVariable ("room")
End Sub ' OnClearcheckpoint
'----------------------------------------------------------
' Remove backtracks from a speedwalk
'----------------------------------------------------------
Function RemoveBacktracks (path)
dim topkey, topitem, w, k, result, count, prev
RemoveBacktracks = ""
ArrayCreate "q"
ArrayCreate "walk"
ArrayClear "q"
ArrayClear "walk"
w = Split (EvaluateSpeedwalk (path), vbCrLf)
If IsEmpty (w) Then Exit Function
for each k in w
if ArraySize ("q") > 0 then
'
' what is currently at top of queue? (actually a stack)
'
topkey = CInt (ArrayGetLastKey ("q"))
topitem = ArrayGet ("q", topkey)
'
' If we are about to add inverse direction, just discard both
'
if (topitem = "n" and k = "s") _
or (topitem = "s" and k = "n") _
or (topitem = "e" and k = "w") _
or (topitem = "w" and k = "e") _
or (topitem = "ne" and k = "sw") _
or (topitem = "sw" and k = "ne") _
or (topitem = "nw" and k = "se") _
or (topitem = "se" and k = "nw") _
or (topitem = "up" and k = "down") _
or (topitem = "down" and k = "up") Then
ArrayDeleteKey "q", topkey
Else
ArraySet "q", topkey + 1, k
End If
Else
'
' Nothing in queue - just add it
'
ArraySet "q", 1, k
end if ' anything in queue
next
'
' now we have the cleaned up walk in the queue, pull it out again
' and turn back into a speedwalk string
'
w = ArrayListValues ("q")
If IsEmpty (w) Then Exit Function
result = ""
prev = ""
for each k in w
k = trim (k)
if k <> "" then
'
' multiple length movements must be put in brackets, if not already
' (eg. up, down, ne, nw)
'
if len (k) > 1 and InStr (k, "(") = 0 then
k = "(" & k & ")"
end if
if k = prev Then
count = count + 1
else
if prev <> "" then
if count > 1 then
result = result & CStr (count) & prev & " "
else
result = result & prev & " "
end if ' more than 1
end if ' having a previous one
prev = k
count = 1
end if ' change in k
end if ' not blank k
next ' processing each one
'
' do final one
'
if prev <> "" then
if count > 1 then
result = result & CStr (count) & prev & " "
else
result = result & prev & " "
end if ' more than 1
end if ' having a previous one
RemoveBacktracks = result
End Function ' RemoveBacktracks
'----------------------------------------------------------
' Add destinations to "dest" array from location "from"
'----------------------------------------------------------
Sub GetDestinations (orig, from, speedwalk, indent, level)
dim d, k, existing, path
'debug Note indent & "finding destinations from " & from & " prefix " & speedwalk
ArrayCreate level
ArrayClear level ' get rid of previous stuff
ArrayImport level, ArrayGet ("map", from), ","
'
' check each one
'
d = ArrayListKeys (level)
If IsEmpty (d) Then Exit Sub
For Each k In d
if k <> orig then
path = ArrayGet (level, k)
existing = ArrayGet ("dest", k)
'debug Note indent & "considering " & k & " path " & path
'debug Note indent & "existing = " & existing
If existing = "" Then
ArraySet "dest", k, speedwalk & path
'debug Note indent & "** addding destination " & k & " path = " & speedwalk & path
'
' recurse to get destinations from *this* destination
'
If k <> from Then
'debug Note indent & "recursing to find walks from " & k & " with prefix " & speedwalk & path
GetDestinations orig, k, speedwalk & path, indent & " ", level + 1
End If
End If ' not already having a path there
End If ' not going to where we started
Next ' end of doing each destination
End Sub ' GetDestinations
'----------------------------------------------------------
' List available checkpoints
'----------------------------------------------------------
Sub OnCheckpointlist (name, line, wildcards)
Dim room, destinations, count, k
room = trim (GetVariable ("room"))
count = 0
ColourNote "white", "blue", "Current room believed to be [" & _
room & "]"
'
' get current entries into work array
'
ArrayClear "dest"
GetDestinations room, room, "", "", 1
destinations = ArrayListKeys ("dest")
If Not IsEmpty (destinations) Then
For Each k In destinations
count = count + 1
world.ColourNote "white", "blue", " " & _
CStr (count) & ": " & k & " (" & _
RemoveBacktracks (ArrayGet ("dest", k)) & ")"
Next
Else
ColourNote "white", "blue", "No known destinations from here"
End If
End Sub ' OnCheckpointlist
'----------------------------------------------------------
' go to a checkpoint
'----------------------------------------------------------
Sub OnCheckpointgoto (name, line, wildcards)
Dim room, destinations, which
room = trim (GetVariable ("room"))
which = CInt (wildcards (1)) - 1 ' which choice, make zero-relative
'
' get current entries into work array
'
ArrayClear "dest"
GetDestinations room, room, "", "", 1
destinations = ArrayListKeys ("dest")
If Not IsEmpty (destinations) Then
If which < lbound (destinations) or _
which > ubound (destinations) Then
ColourNote "white", "red", "Destination " & wildcards (1) & _
" out of range " & CStr (lbound (destinations) + 1) & " to " & _
CStr (ubound (destinations) + 1)
Exit Sub
End If
'
' go there :)
'
Send EvaluateSpeedwalk (RemoveBacktracks (ArrayGet ("dest", destinations (which))))
Else
ColourNote "white", "blue", "No known destinations from here"
End If
End Sub ' OnCheckpointgoto
'----------------------------------------------------------
' deduce room name if on same line as prompt
'----------------------------------------------------------
Sub OnGetRoomFromPrompt (name, line, wildcards)
dim lines, styles, text
line = GetLinesInBufferCount
styles = GetLineInfo (line, 11)
'
' Should be 2 styles, the prompt and the room name
'
If Styles <> 2 Then Exit Sub
'
' Room name is bold
'
If Not GetStyleInfo (line, 2, 8) Then Exit Sub
'
' Room name is red text
'
If Not GetStyleInfo (line, 2, 14) = BoldColour (2) Then Exit Sub
'
' Room name is black background
'
If Not GetStyleInfo (line, 2, 15) = NormalColour (1) Then Exit Sub
'
' Get name
'
SetVariable "room", GetStyleInfo (line, 2, 1)
End Sub ' OnGetRoomFromPrompt
]]>
</script>
<!-- Plugin help -->
<aliases>
<alias
script="OnHelp"
match="Automap:help"
enabled="y"
>
</alias>
</aliases>
<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|