Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
TiberSeptim
Beginner


Joined: 20 Jun 2006
Posts: 24

PostPosted: Wed Dec 19, 2007 8:25 pm   

Capturing Unconventional Exits
 
This is probably a really simple problem for you experts but I'm just getting started with CMUD mapping.

The exits in my MUD show up like:

[Exits: north south east]

However, there are two types of exits which appear differently - doors and water (which requires swimming skill to cross).

[Exits: [north] south west] <-- Door to the north.
[Exits: west /south\ east] <-- Water to the south.

I would like to be able to capture these exits normally and also create a door automatically when one shows up as above.

Any help would be appreciated.
Reply with quote
rck
Novice


Joined: 26 Oct 2005
Posts: 32
Location: California

PostPosted: Thu Dec 20, 2007 5:50 am   
 
I play a mud that does something similar, here's some example code based on mine for your situation (lua code):

Code:
local exitline = zs.param(1)
local exits = {};
local doors = {};
local waters = {};

local current = 1;
-- break up exit line into a table of exit names
while (current <= #exitline) do
  local start, stop = string.find(exitline, "%s+", current);
 
  if (start == nil) then
    table.insert(exits, string.sub(exitline, current));
    break;
  end
 
  table.insert(exits, string.sub(exitline, current, start - 1));
  current = stop + 1;
end

-- process exit names
for i = 1, #exits do
  name = exits[i];
 
  -- a door exit
  if (string.match(name, "%[%w+%]") ~= nil) then
    name = string.sub(name, 2, -2);
    table.insert(doors, name);
  -- a water exit
  elseif (string.match(name, "/%w+\\") ~= nil) then
    name = string.sub(name, 2, -2);
    table.insert(waters, name);
  end
 
  exits[i] = name;
end

local cmudline = table.concat(exits, "|"); -- create a nice list for CMUD, you could zs.tag("exit", cmudline); for example so cmud understands the exits
What this does is takes the exit data from the trigger and builds a list of exits, it then processes that list checking for special characters and removing them and then building a list that CMUD understands.

You could then save the doors / waters list for post-processing (eg, after the room has been created or identified in the automapper) and create doors / color rooms, etc based on that information.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Dec 20, 2007 10:21 pm   
 
I was going to suggest building a complex, specific regex, but it does seem simpler to do the processing after the trigger's matched. This way you can use a much simpler pattern like ~[Exits: (*)~] and use rck's excellent code.

One thing I do wonder about that code though is if it wouldn't be easier to do all the processing at once:

Code:
for match in string.gmatch(exitline,"%S+")
  local name
  if (string.match(match, "%[%w+%]") ~= nil) then
    name = string.sub(match, 2, -2);
    table.insert(doors, match);
  elseif (string.match(match, "/%w+\") ~= nil) then
    name = string.sub(match, 2, -2);
    table.insert(waters, match);
  end
  exits[i] = name or match
end


I think that's the proper way to convert your code. I've never tried editing the local variable that the for is setting during the for's execution - you certainly shouldn't do it with numeric for, so I didn't do it in this case just to make sure. Just a thought anyway.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
TiberSeptim
Beginner


Joined: 20 Jun 2006
Posts: 24

PostPosted: Fri Dec 21, 2007 1:14 am   
 
Thanks for the tips guys.

I'm an experienced programmer but new to CMUD and lua; can you advise me how to implement these scripts? i.e., where do I add them and how do I ensure they "take over" the normal function of the automapper as I map the MUD?
Reply with quote
rck
Novice


Joined: 26 Oct 2005
Posts: 32
Location: California

PostPosted: Fri Dec 21, 2007 2:24 am   
 
TiberSeptim wrote:
Thanks for the tips guys.

I'm an experienced programmer but new to CMUD and lua; can you advise me how to implement these scripts? i.e., where do I add them and how do I ensure they "take over" the normal function of the automapper as I map the MUD?
In CMUD there is a dropdown list of script type in the editor now, just set to Lua and you can write lua code.

Overriding the normal behavior of the automapper is a complex beast and it seemingly likes to do things even if you override its behavior unfortunately. What I would do is save the exits to a variable then have an onRoomCreate event that makes the links (%roomlink I think it is?) based on what was in the exit list variable, after verifying it's the correct room of course.

Fang Xianfu wrote:
I've never tried editing the local variable that the for is setting during the for's execution - you certainly shouldn't do it with numeric for, so I didn't do it in this case just to make sure. Just a thought anyway.
The for loop (in my original code) itself isn't doing anything with the exits list other than iterating 1 - exit count, the # is the 'length' operator in Lua, so it's safe.

For yours I would
Code:
table.insert(exits, match or name);


Your example is much better (I'm going to update mine now). Thanks!

I would however, add name to the doors/waters list, as if we know what kind it is we don't need the extra bits.
Code:
for match in string.gmatch(exitline, "%S+")
  local name;
  if (string.match(match, "%[%w+%]") ~= nil) then
    name = string.sub(match, 2, -2);
    table.insert(doors, name);
  elseif (string.match(match, "/%w+\") ~= nil) then
    name = string.sub(match, 2, -2);
    table.insert(waters, name);
  end
  table.insert(exits, name or match);
end
Reply with quote
TiberSeptim
Beginner


Joined: 20 Jun 2006
Posts: 24

PostPosted: Fri Dec 21, 2007 11:44 pm   
 
So if I wanted to implement a temporary solution, would it be possible to gag or replace the /\ and [] in the exit names so CMUD sees only standard format exits and interprets them as such?

e.g., can I turn a line like: [Exits: north [south] east /west]

And turn it into: [Exits: north south east west]

Before CMUD even sees it to process it for the automapper?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Dec 22, 2007 12:16 am   
 
Not easily, no. I'm sure Viji could think of some crazy way to do it, but the easy way to solve this problem is by using the #tag command to tell CMUD exactly what exits are in the room, and that's the aim of this code.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Dec 22, 2007 1:08 am   
 
Hrm, as its Cmud thread and I'm not using it (yet!), I may very well be off course entirely, but.

Figured I'd give some minor insight regardless.

I just did a test trigger like this:

Code:


#regex {^\[Exits\: (.*)\]$}



Its supposed to capture the directions data in the exits line into a variable.

This is the code.

Code:


standard_exits=%subchar( %1, "[/]\", "")
standard_exits=%replace( @standard_exits, " ", "|")



This strips the odd chars and then replaces voids with pipes to make a clean list of standard directions.

As I said, I started to think right now so I may have mis-followed the thread and/or misunderstand the greater concept.


Prog
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Dec 22, 2007 12:00 pm   
 
You could add the %replace into the %subchar actually: standard_exits = %subchar(%1," []\/", "|")

But part of the request was that the script would know which exits were water and which were doors, so the code above does that too.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net