 |
|
 |
 |
 |
| |
If you would like to contribute to Planetary Aggression, download the code and add some cool features. To get used to the data structures, organization and algorithms, a good place to start is by adding shell commands. Here's how to get started:
-
Open the files ShellCommands.cpp and ShellCommands.h.
- You'll need to create a function which will implement your command. Create a function prototype for your command in the private section of ShellCommands.h. The function prototype should be:
bool myShellCommand(int argc, char **args);
The function should return true if the command was able to be processed and false if an error occured or if the syntax is incorrect. The shell will display an error automatically if your function returns false. The parameter argc is the number of command line arguments typed into the shell. The parameter args is an array of strings, each of which corresponds to the arguments typed into the shell. I.E. args[0] is the first argument, args[1] is the second, and so on.
- Implement your function in ShellComands.cpp. You should check to make sure you have the appropriate number of arguments for your command to avoid an error. This is where you'll need to access and possibly manipulate the game's data structures to achieve the desired command's functionality. View the other shell commands (search, attack, make, etc) for hints on how get started.
- After you've written your function, you'll need to make sure your function is called when a shell command is entered. To do this, locate the function:
bool callCommand(const char *buffer);
and add a case to the long list of if-else statements that will call your function. For example, if you're shell command is named "myCommand", then you'll need to add the following case to this function:
if (strcmp(args[0], "myCommand") == 0) {
| |
return myCommand(argc, args); |
}
- That's it! Simply type your command into the shell, and if everything is setup properly, your function will be called to handle the command.
 |
2005 |
|
 |
|
 |
|