Adding powers

From Wormhole Sci-Fi MUD Homepage

Jump to: navigation, search

Part of the coding knowledge base, by Artoo.

Today's class: adding a new psi power in Wormhole MUD:

In spells.h, add a #define entry for the power, at the bottom of the list. Give it a unique number, and add one to the entry for MAX_SPELLS at the top of the list. Note that MAX_SPELLS can't go over 200.

In spellconst.c, add the name of the spell to the list, on the line that corresponds to the unique number you have selected. The lines are numbered with /*comments*/ to make this easer. Now, add new entries for the three tables below, detailing (1) which classes get the power and at what level, (2) the maximum percentage to which they can learn the power, and (3) the level of difficulty in practicing, where 1 is insanely hard and 9 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.

If the new power is an offensive one, it's simple to add a new case in magic.c, for example:

       case SPELL_ARC_FIRE:
               dam = dice (1, 12) + MIN (level, 50);
               savetype = SAVING_FIRE;
               break; 

Note that for area powers spells like 'earthquake', these must be entered in two places within magic.c - you need to add a case within the 'void mag_areas' section to make the power do damage to everyone in the room.

If the new power is an 'affects' one, add a new case in the corresponding part of magic.c, for example:

       case SPELL_DETECT_INVISIBLE:
               af.duration = 12 + level;
               af.bitvector = AFF_DETECT_INVISIBLE;
               if (casttype == SPELL_TYPE_INNATE)
                       af.duration = DURATION_INNATE;
               affect_join (victim, &af, TRUE, TRUE);
               send_to_char ("Your eyes tingle.\r\n", victim);
               break;

Some powers are 'manual' ones that are less generic, and require special coding. Teleport, clone and enchant weapon are examples of these. If your power is a 'manual' one, add the C code for the spell in the right place towards the bottom of the magic.c file. Note that 'manual' powers must also be listed at the bottom of the spells.h file.

In spell_parser.c you need to add an entry so the game knows how much mana the power uses, whether it can be cast in combat, its cost when buying with remort points and so on. Search for an existing power that is similar to the type of power you are creating, to make sure your entry goes in the right place, copy that entry and adapt it to suit. For example:

       spello (SPELL_ARC_FIRE, MAG_DAMAGE, POSITION_FIGHTING, 11, 6,
                       TAR_CHAR_ROOM | TAR_FIGHT_VICT, TRUE, 2, 0, NULL);

The entries you see here are as follows:

  • The name, exactly as it appears in spells.h
  • The type of power (MAG_DAMAGE, MAG_UNAFFECTS, MAG_POINTS, MAG_MANUAL etc.)
  • The minimum position you need to be in to use the psi power (normally POSITION_STANDING or POSITION_FIGHTING)
  • The mana cost to use the power
  • The time it takes to use the power, measured in beats (game combat segments)
  • The targets (normally TAR_CHAR_ROOM, TAR_FIGHT_VICT or TAR_SELF_ONLY; entries like TAR_OBJ_EQUIP are also possible. Note that '|' separates multiple entries.)
  • The boolean for 'offensive' - can this power be used in a LAWFUL flagged room? Note that to make the use of a power start a fight, you need to make it do some MAG_DAMAGE.
  • The remort point cost to have this power in castable form (0 = not available)
  • The remort point cost to have this power as an innate (if appropriate; 0 = not available)

For offensive combat powers, you will also want to add an entry in the messages file, detailing what the user, victim and onlookers see when your new power is cast.

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 powers, please!

Note: For your new power to appear in the game, experience has shown that it is necessary to do a 'make clean' before you 'make' (recompile) the game.

Personal tools