Posted by
| David Haley
USA (3,881 posts) bio
|
Message
| A primitive solution would be to do something like the following:
- when a player command is interpreted, check to see if it's an alias.
- take a string, and put the alias's value to the beginning.
- then take the interpreted string, and add whatever "arguments" it has to the end of the string with the alias value.
For instance:
The player types "mm goblin".
The interpreter looks at the first word (the get_argument function would work) finds "mm" and says: "oh! this is an alias!"
It then looks up what this alias corresponds to, and finds "cast magic missile". So, it prints this to a string buffer.
It then goes back to what the player types. It removes the first word, and gets all the rest: in this case, "goblin". It then appends this to the string buffer, and we obtain "cast magic missle goblin".
This is less powerful than a proper alias because it can only append arguments at the end, but at least it works.
Off the top of my head, here is the code you would write once you've determined it's an alias. It is probably not completely correct. This would go somewhere in the interpret function. I'm assuming that "argument" is a char * that is the string being interpreted.
char newCommand[MAX_INPUT_LENGTH];
char command[MAX_INPUT_LENGTH];
char aliasArgs[MAX_INPUT_LENGTH];
// remove the command and store it
argument = one_argument(argument, command);
// store the arguments into aliasArgs
argument = one_argument(argument, aliasArgs);
// create the command buffer
sprintf(newCommand, "%s %s", command, aliasArgs);
// continue evaluating with newCommand
// one way to do this is simply replace argument with newCommand:
// sprintf(argument, "%s %s", command, aliasArgs);
// instead of printing it to newCommand
Now, before that you'd have to look through a table of alias definitions using the first word of the command, to make sure it is indeed an alias. I hope this helps you. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|