Swalec's srun plugin

Status: srun is currenly in early, or beta release. I use it, it works, and it rarely crashes. But it's a bit quirky. Use it at your risk. Limitations are described.

Aardwolf's runto command is excellent. It's one of the reasons that I started playing Aard -- why cut and paste from a website, when it should be supported on the mud?

But there are limitations. First, it only works from one place (even if you can change that place with runprefix). Second, there are often shorter routes available with the use of clan portals. Third, you can't add new locations to places within the areas. srun solves all these problems.

How to use it (basic)

First install the plugin as described here. Now, we need to read all the speedwalks from the mud, so that srun knows about all these directions. Type:
srun read_speedwalk
you should get the response
Srun: Read 234 speedwalks

-- other stuff --

Srun: Current Location
ID: 1
Area name: nil
Room title:  Unknown Location
Given Name:  nil
Coords: 0, 0, Unknown
There are 0 outgoing routes
There are 0 incoming routes
There are 0 portals ending here
Srun: Complete
Srun has read the speedwalks and tried to guess where you are; as you can see, it doesn't know (unless you are at recall, in which case it should say). Now, we want to run somewhere. Just use the standard mud command:
runto camps
If you are at recall, then runto will work (nearly) as normal. Otherwise, you will get this:
Srun: Location is not known to srun: camps
Srun: Repeat command to retry from recall
Unfortunately, srun can't work out what the short cuts that Aardwolf uses; it just doesn't know where "camps" is. Don't worry, over time it will learn these. For now follow the advice and do
runto camps
again. You can use the command history (up-arrow) to do this quickly. Now, srun nows what to do; it runs the commands
recall
runto camps
At the end of the speedwalk, the following will be printed out.
Srun: Ending mud runto command
New details discovered
ID: 8
Area name: Tournament Camps
Room title:  A small bridge over the river
Given Name:  nil
Coords: 31, 25, 0
There are 0 outgoing routes
There are 1 incoming routes
There are 0 portals ending here

Added: camps as shortcut for:  Tournament Camps
Srun: mud runto complete
As a result of the run, srun has recorded the details of the location of "Tournament Camps" and also that "camps" is a shortcut for it. Let's run to verume with:
 
runto verume
runto verume
As before, you will have to type this twice, because srun doesn't know where verume is. Now, lets run back to camps (runto camps). This time, srun knows where we are going to; it sends the following commands.
Srunning to: Tournament Camps
recall
run 2s9e5sw
And that's it, the basic usage.

How to use it (advanced)

Okay, so srun does runto mildly better than the mud. Is that it? Well, no, not quite, there is more. First, let's add a new location and new direction.
srun add_location peto
srun add_direction recall peto 2wn
You will get this output.
Srun: Adding Location
ID: 236
Area name: nil
Room title:  nil
Given Name:  peto
Coords: Unknown, Unknown, Unknown
There are 0 outgoing routes
There are 0 incoming routes
There are 0 portals ending here


Srun: Adding direction
sw 2wn
ID: 0
Area name: recall
Room title:  The Grand City of Aylor (G)
Given Name:  nil
Coords: 30, 20, 0
There are 89 outgoing routes
There are 0 incoming routes
There are 1 portals ending here
Now type runto peto. srun will execute a set of commands and you will get this info back. As before, srun has grabbed information about the location from the mud.
Peto's Cornucopia O' Corn (G)

[Exits: east south west]
Peto, the Bard Hall Cook, ladles out some more goodies.

New details discovered
ID: 236
Area name: nil
Room title:  Peto's Cornucopia O' Corn (G)
Given Name:  peto
Coords: 30, 20, 0
There are 0 outgoing routes
There are 1 incoming routes
There are 0 portals ending here
What does srun do with all the information that it takes from the mud? Well, let's move back to recall by hand. Do run s2e. We are now at recall but srun doesn't know this; so type srun guess. Now, srun prints
Srun: Current Location
ID: 0
Area name: recall
Room title:  The Grand City of Aylor (G)
Given Name:  nil
Coords: 30, 20, 0
There are 89 outgoing routes
There are 0 incoming routes
There are 1 portals ending here
Srun: Complete
because it's worked out where you are. Now, let's runto peto again. Let's run back to recall with runto recall. This works well, but it uses "recall" which is an expensive way to get around. Surely, it would make more sense to use a garbage can? Well, srun can do this also; to do this, we need to create a single alias which does this: if you don't know how to do this read this. This is slightly complicated but this is because people want to do many different things to use a portal (I drop my second, get portal from bag, hold portal, enter portal, second my usual weapon, put the portal back into the bag, with my single alias). Let's assume that you now have a alias called enter_garbage which uses the garbage can. Now, you can type srun add_portal enter_garbage recall which adds a portal ending at recall. You know get this...
Srun: Adding portal
portal added
ID: 0
Area name: recall
Room title:  The Grand City of Aylor (G)
Given Name:  nil
Coords: 30, 20, 0
There are 89 outgoing routes
There are 0 incoming routes
There are 2 portals ending here
Now if you type
runto peto
runto recall
You will see that instead of recall, we use the garbage can. Finally, we might want to add a new route to a location that the mud already knows about. So, let's try this:
runto wobbly
You should end up at Wobbly Woes and get the expected "New details discovered" message from srun. Well this is fine, but it's a long way around. Let's try this:
runto recall
srun add_direction recall wobbly 6sued
srun showpath wobbly
You should get back from the final command:
Srun: showpath
Path is:
recall  ->  The World of the Watchmen Dir: run 6su Dis: 7
The World of the Watchmen  ->  The Wobbly Woes of Woobleville Dir: run ed Dis: 2
Complete Route: run 6sued
Srun: showpath complete
Srun now knows about the new route. Type runto wobbly and you will actually run there. You'll notice that it's also worked out that run 6sued overlaps with the speedwalk to Watchmen (run 6su), so actually calculates the route as two steps. So if you try
 
runto watchmen
runto watchmen 
runto wobbly
You will see that running from watchmen to wobbly does not pass through recall. Congratulations, you're now an advanced user.

Configuring from scripts

Srun has a number of limitations at the current time. One of them is that you can't delete anything that you've done. This means getting commands wrong can be bad. I like to configure srun from the normal lua configuration script. If you know how to use this, you might be interested in this script which puts srun into the state that you get from following the tutorial, plus a location for the Hotel which you will probably want. It demonstrates the use of all the srun commands.

-- we will define two new locations
locations = {
   "aardh",
   "peto",
}

-- we add a shortcut for a location which ccomes from the mud. All the srun
-- commands work on shortcuts, which srun ddoesn't know yet. 
runto_names = {
   "wobbly The Wobbly Woes of Woobleville",
}

-- We add two portals. You should have addeed the two alias yourself. 
portals = {
   "enter_garbage recall",
   "enter_amulet aardh",
}

-- add some new directions -- aardh to recaall, recall to peto, recall to wobbly
directions = {
   "aardh recall d",
   "recall peto 2wn",

   "recall wobbly 6sued",
}

-- add a new alias to reload the config
addxml.alias{
   enabled = 'y', 
   match = "srun_conf",
   script = "srun_conf",
   group = "aardwolf",

}

-- add a trigger. 
addxml.trigger{
   enabled = 'y',
   match = '{srunconf}',
   script = "srun_conf_trigger",
   group = 'aardwolf'
}


function srun_conf( name, line, wildcards )
   -- clear the srun conf, and read speedwalks. 
   Execute( "srun clearall" )
   Execute( "srun read_speedwalk" )
   
   -- load configuration after speedwalks have been read
   Execute( "echo {srunconf}" )
end

function srun_conf_trigger( name, line, wildcards, styles )
   print( "Configuring Srun" )
   
   for i,v in ipairs( locations ) do
      print( "Adding loc:", v )
      Execute( "srun add_location " .. v )
   end
   
   for i, v in ipairs( runto_names ) do
      print( "Adding runto:",  v )
      print( "srun add_runto "  .. v  )
      Execute( "srun add_runto " .. v  )
   end
   
   for i,v in ipairs( portals ) do
      print( "Adding portal:", v )
      Execute( "srun add_portal " .. v )
   end
   
   for i,v in ipairs( directions ) do
      print( "Adding direction:", v )
      Execute( "srun add_direction " .. v )
   end

   Execute( "srun guess" )
end

Limitations

The biggest limitation srun has at the moment is that you can't delete routes or directions that you have added; you have to run srun clearall and start again. This will be fixed sometime soon, but you can work out how to get around this in the Configuration section. The error handling is a bit broken at the moment; in some cases I know about this, but now always, so please feel free to tell me where it doesn't work. On saving the state of the mud, if you are on a slower machine srun can cause quite a harsh lag. This is because srun saves lots of info (type srun dumpall if you want to see). I might change srun later so that it does not save all the information it works on, but recreates it all.

Future work

Besides fixing the limitations, I want to add a few things to srun; most important would be the use of area triggers (do things when you enter an area). Other ideas welcome. 1