Adding Creation Spells (chapter 3, part 2)

The Rangers' weapon of choice should be a bow, and it would be nice if they did not have to worry about where to get one. There are two bows described in the object files included with the game, a hunting bow, which says it is not recommended for combat, and a golden bow, which is a special bow which must be earned in area 50. This being the case, we will build a special "Archer Bow" for their use, and code a spell that lets them conjure one.

Open the world object file "30.obj", and find the top of object #3030, the torch, at about line 177. Between the torch and the flail above it, insert the following section:

bow archer~
an Archer bow~
A green Archer bow is here.~
5 dmnopq 8193
0 3 5 11
3 30 20
bow archer~
This is an Archer bow, custom wrought for the Rangers' guild.  An
excellent weapon, but useful solely to members of that guild.  Every good
Ranger should learn to make and use one. 

This will create the Archer bow, and make it a weapon which can be wielded only by Rangers, cannot be sold to any shopkeeper and cannot be "donated". After all, the Rangers are all supposed to be able to make one themselves. At this point, you might also want to assign this weapon to the Huntress guildguard we built in the previous chapter. Close "30.obj" and open "30.zon". At about line 74, there is a pair of lines which places the guildguard and assigns her a sword:

M 0 3029 1 3070         Ranger Guard
E 1 3022 100 16                 Long Sword

Replace these with the following lines:

M 0 3029 1 3070         Ranger Guard
E 1 3026 999 16                 Archer Bow

Further down, let's do the same for the Rangers' waitress. The following group of lines, at about line 100, creates the waitress and gives her certain items, including her weapon:

M 0 3030 1 3071         Rangers' Waitress
G 1 3003 100                    Firebreather
G 1 3004 100                    Local Bottle
E 1 3021 100 16                 Small Sword

Replace these lines with the following:

M 0 3030 1 3071         Rangers' Waitress
G 1 3003 100                    Firebreather
G 1 3004 100                    Local Bottle
E 1 3026 999 16                 Archer Bow

These two characters will now be armed with bows instead of swords. This is not actually necessary, but under the circumstances that these characters are part of the Rangers guild it is a nice touch. To allow for players to have the bows and still have them equipped on the two non-player characters, the "maximum existing" values for the weapons have been boosted here from 100 to 999. Close "30.zon" and open "30.mob". We should make one last alteration to their descriptions here, and they will be all set. At about line 258, change the Huntress's short description line, the third line for mobile #3029 to the following: A huntress plays with her bow as she guards the entrance.

Now, at about line 274, change the long description for the waitress, mobile #3030, to the following:

This 14-year-old girl might fool a member of another guild, but you know that she's one tough cookie. She very friendly, a little flirtatious even, but woe to anyone who angers her. She specializes in punctured egos and Swiss cheese corpses.

Once that is done, close "30.mob" and we will start on adding the spell for the Rangers to create this bow for their own use.

Open "spells.h" and find the "SPELL_x" definitions, starting at line 39. After the last one, at around line 90, insert the following line:

#define SPELL_CREATE_BOW             52

Close "spells.h" and open "constants.c". Jump down to about line 701, where you will find the beginning of the spell_wear_off_msg string array constant:

const char *spell_wear_off_msg[] = {
  "RESERVED DB.C",              /* 0 */
  "You feel less protected.",   /* 1 */
  "You feel less righteous.",
  "You feel a cloak of blindness disolve."
  "!Burning Hands!",            /* 5 */
  "!Call Lightning",
  "You feel more self-confident.",
  "You feel your strength return.",
  "!Color Spray!",              /* 10 */
  "!Control Weather!",
  "!Create Food!",
  "!Create Water!",
  "!Cure Blind!",
  "!Cure Critic!",              /* 15 */
  "!Cure Light!",
  "You feel more optimistic.",
  "You feel less aware.",
  "Your eyes stop tingling.",
  "The detect magic wears off.",/* 20 */
  "The detect poison wears off.",
  "!Dispel Evil!",
  "!Enchant Weapon!",
  "!Energy Drain!",             /* 25 */
  "You feel yourself exposed.",
  "!Lightning Bolt!",           /* 30 */
  "!Locate object!",
  "!Magic Missile!",
  "You feel less sick.",
  "You feel less protected.",
  "!Remove Curse!",             /* 35 */
  "The white aura around your body fades.",
  "!Shocking Grasp!",
  "You feel less tired.",
  "You feel weaker.",
  "!Summon!",                   /* 40 */
  "!Word of Recall!",
  "!Remove Poison!",
  "You feel less aware of your suroundings.",
  "!Animate Dead!",             /* 45 */
  "!Dispel Good!",
  "!Group Armor!",
  "!Group Heal!",
  "!Group Recall!",
  "Your night vision seems to fade.",   /* 50 */
  "Your feet seem less boyant.",

While "create bow" isn't the type of spell that needs to wear off, we should nonetheless make a note of our new spell here. At about line 754, between the "Your feet seem less boyant.", line, which is the entry for the Waterwalk spell, and the "!UNUSED!" which follows it, insert the following line:

  "!Create Bow!",

Now close "constants.c" and open "spell_parser.c", and once again you will find spells defined starting on line 37. At about line 94, you will find the start of the "!UNUSED!", entries:

  "group recall",
  "infravision",                /* 50 */

Change the first one to "create bow", as follows:

  "group recall",
  "infravision",                /* 50 */
  "create bow",

Starting at about line 856, you will find the function mag_assign_spells, which registers spells and skills for player use. As with the "bearhug" skill, we need to add an entry for our "create bow" spell. This time, however, we are going to enter it as one of the magic abilities. Also, there is already a template in place for creating items, a group of functions which already are used by the "create food" spell, and which can be modified to also handle the "create bow" spell. Around line 1000, you will find the spello function calls for the last of the "castable" spells and the beginning of the non-castable spells and the skills:

  spello(SPELL_SENSE_LIFE, 20, 10, 2, POS_STANDING,

  /* NON-castable spells should appear here */
  spello(SPELL_IDENTIFY, 0, 0, 0, 0,

Between the last castable spell and the first non-castable spell, insert
the following lines: 

  spello(SPELL_CREATE_BOW, 30, 5, 4, POS_STANDING,

This registers the spell with the spell interpreter, and sets it to use the existing MAG_CREATIONS functions.

We now need to modify these functions to handle our new spell. Close "spell_parser.c" and open "magic.c". The function mag_creations starts at about line 1092. About 9 lines down is the following switch statement:

  switch (spellnum) {
    z = 10;
    send_to_char("Spell unimplemented, it would seem.\r\n", ch);

Right before the default case, we need to add the following lines to implement the "create bow" spell:

    z = 3026;

Now close "magic.c" and open "class.c". We need to enable the new spell for the Rangers to learn and use, so go down once again to the Rangers section of init_spell_levels at about line 562, and add the following line:


Finally, close "class.c", delete any compiler object files you might have in your "src" directory from previous compiles, and make or re-make the program. If everything is in order, your Rangers should now be able to cast "create bow" at any level.