Adding skills

From Wormhole Sci-Fi MUD Homepage

Jump to: navigation, search

Part of the coding knowledge base, by Artoo.

Today's class: adding a skill in Wormhole MUD:

In spells.h (yeah, really... skills need to be defined in with the "spells"), add a #define entry for the skill, at the bottom of the list. Give it a unique number, and add one to the entry for #define NUM_OF_SKILLS which you find at the bottom of the list. It'll always be the last skill's unique number minus 299, if you want to be picky.

In skillconst.c, add new entries for the three tables, detailing (1) which classes get the skill and at what level they can first practice it, (2) the maximum percentage to which they can learn the skill, and (3) the level of difficulty in practicing, where 1 is insanely hard and 10 is very easy. Note that the last line in each of these tables is not terminated with a comma... but all the preceding ones should be.

In interpreter.c, add a new entry at the bottom of the list of prototypes for all "do_x" functions. For example, here's how I added a 'Gunsmith' skill:

 ACMD (do_gunsmith);

In the same file, scroll down to the letter of the alphabet where your command belongs, and add to the command structure, so the game will know what piece of code to run when the command is typed. Put your command in the right place, alphabetically. The gunsmith skill will get:

 {"gunsmith",    POSITION_SITTING,   do_gunsmith,    1, 0},

Note that automatic skills (like dodge or explosives, for instance) require no new text in this file.

Now we need to write some C code to define what the skill does in skills.c. Skills are generally a lot more varied than powers (they don't just do damage...) so this is going to be complicated.

 ACMD (do_gunsmith)
 {
 	int nVal;
 	struct obj_data *obj;	
 	one_argument (argument, buf);
 	if (!*buf) /* Player didn't say what */
 	{
 		send_to_char ("Uh... which gun do you want to check over?\r\n", ch);
 		return;
 	}
 	generic_find (buf, FIND_OBJ_EQUIP | FIND_OBJ_INV | FIND_OBJ_ROOM, ch, NULL, &obj);
 	if (!obj) /* Player doesn't have what they said */
 	{
 		sprintf (buf2, "You can't seem to find a %s\r\n", buf);
 		send_to_char (buf2, ch);
 		return;
 	}
 	if (GET_ITEM_TYPE (obj) != ITEM_FIREWEAPON)
 	{
 		sprintf (buf, "Nice try, but after a brief investigation, you determine that it is not, in fact, a gun.\r\n");
 		send_to_char (buf, ch);
 		return;
 	}
 	if (number (1, 101) < GET_SKILL (ch, SKILL_GUNSMITH))	/* Success */

... do various things ...

 	else

... do something else ...

 	act (buf, FALSE, ch, obj, NULL, TO_CHAR);	
 }

For offensive skills, you will also want to add an entry in the messages file, detailing what the user, victim and onlookers see when the skill is demonstrated in combat.

Good practice: Work on a developer port, not on the real game. Save a copy of each file that you are about to change, so you can switch back to the old version(s) if you get into difficulties. Always be neat and tidy; put your new code in the right part of the file, in sequence. Indent your code properly, and include annotations to explain anything unusual about your new entries. Sign and date your work with a comment, too. Maintain a change log, because other developers may be making changes on other ports of the game, and will want to know which segments of the code they need to incorporate when uploading changes to the main game. Oh - and don't be an idiot: only add new features if they improve the game. No level 1 instadeath skills, please!

Note: Since adding the new power involves changes to a header file (spells.h) it is necessary to do a 'make clean' before you 'make' (recompile) the game, or your new skill won't take effect.

Personal tools