Command Parsing

Nathan Yospe yospe at hawaii.edu
Sun Nov 24 13:17:25 CET 1996


  Hi all. Either you've all been really quiet recently, or there is
something wrong with my mail server. In any case, I've been developing a
concept and wanted to toss it out to all of you before playing with it.
Incidentally, I know most of you prefer the server design for muds. Mine
is not, as you are probably aware, but is instead a hybrid of sorts, with
primary design in C++ but support for free swapping of C++ functions with
internal language functions that can be designed and activated without a
recompile or reboot, at a penalty of about 5x on speed. Any function
executable by a character class (or an item class bot, which exhibits
character behavior) is referenced, upon parsing, by its name, a unique
character array. There may be duplicate functions... function is a class
with a reference to a function of one of several types, and can all be
accessed by the internal language, provided the author has sufficient
clearance. I'll give an example here of the classes that serve character
execution functions, the ones used by the command parser.

class execfunction: public named{
  // this is a base class, and has no real members
public:
  virtual bool execute(character *ch, mudstring &input, 
                                      bool override, short mode);
};

class hardexec: public execfunction{
  bool (character::*execfunc)(mudstring &input, bool override, 
                                                     short mode);
public:
  bool execute(character *ch, mudstring &input, bool override,
                                                     short mode){
    return ch.*execfunc(input, override, mode);
  }
};

class softexec: public execfunction, public editable{
  program *execfunc;
public:
  bool execute(character *ch, mudstring &input, bool override, 
                                                     short mode){
    runtime *newprogram = execfunc.init();
    newprogram.initcharacter(ch);
    newprogram.initstring(input);
    newprogram.initbool(override);
    newprogram.initmode(mode);
    bool newprogram.launch();
  }
  void readin(ifstream &file);
  void writeout(ofstream &file);
  void edit(mudstring &input);
};

You get the idea. These can be attached to anything, for triggering, but
in the above case, will always fixate itself to the character 'ch' until
the runtime expires. A sample program for above use:

> hunt           // the 'hunt' program

expect
  character ch   // acting character
  string input   // input string
  bool override  // override of 'instincts'
  short mode     // skill based failure mode
end expect

begin
                 // parse the string
string parseword = input:extract()
                 // search through all backpacks, etc for a drone
character drone = ch:getcharfromcontents("drone")

if(drone == null)                 
  // this will only happen if something goes wrong. There should be a
  // check for these drones in the skill that launches this command.
  ch:show("You don't have any hunting drones to deploy.\r\n")
  terminate
end if

drone:moveto(ch:room())
ch:show("You deploy a hunting drone."\r\n)

drone:execute(hunt2, parseword)

terminate
&

> hunt2

expect:
  character drone
  string target
end expect

pause(1) // wait a beat

if(drone:room():getchar(target) != null)
  if(drone:parent() == null)
    drone:master():show("Your drones have aquired a target!!")
    if(drone:room() == drone:parent():room())
      drone:master():show("The target is in this room!!"
    end if
  else
    drone:execute(alert, drone:master())
  end if
  terminate
end if

traverse(exit door = drone:room():exits())
  character newdrone = drone:clone()
  newdrone:addlevel(-1)
  newdrone:move(door)
  newdrone:setparent(drone)
  newdrone:execute(hunt2, target)
end traverse

terminate
&


Still a little sketchy, but you get the idea. Not object oriented.. I was
trying for simplicity.. but a nice method of hybridization. These types of
functions can be called at every level of the code, but are limited to
existing classes. Maybe someone ambitious will correct that situation and
add object orientation in the future. I feel like I've made sufficient
contribution.

I'll post more later.



   __    _   __  _   _   ,  ,  , ,  
  /_  / / ) /_  /_) / ) /| /| / /\            First Light of a Nova Dawn
 /   / / \ /_  /_) / \ /-|/ |/ /_/            Final Night of a World Gone
Nathan F. Yospe - University of Hawaii Dept of Physics - yospe at hawaii.edu



More information about the mud-dev-archive mailing list