Re: [CODE] [QUESTION]: Reagent-based spells

From: Edward Glamkowski (EGlamkowski@MATHEMATICA-MPR.COM)
Date: 01/09/98


This almost oughta have it's own snippet (hint, hint, Alex =)
It's actually not too difficult, although it can be time consuming.
First, create the objects that are the material components (this is
particularly time consuming if you have a lot of them...).
Write down the vnums of each one as you go along (1 = silver powder,
2 = vampire ichor, etc.)

Then, in order to use mag_materials: first, create a function something
to the effect of:

/* return 1 if caster has components, 0 if they don't */
int has_material(struct char_data *caster, int spellnum) {
  int x = 0;

/* prototype for mag_materials, for reference:
int mag_materials(struct char_data *ch, int item0, int item1,
                        int item2, int extract, int verbose);
*/
  switch(spellnum) {
    SPELL_FIREBALL:
      x = mag_materials(caster, 1, 2, NULL, TRUE, FALSE);
      break;
    SPELL_HEAL:
      x = mag_materials(caster, 3, NULL, NULL, TRUE, TRUE);
      break;
    default:
      x = 1; /* No material components necessary, so check successful */
      break;
  }

  /* You may want a check for clerics that they have a holy symbol,
   * and if not, set x = 0. Alternately, make another function,
   * similar to this one, that checks for holy symbols for clerics
   * only for certain spells... For example: */
  if (IS_CLERIC(caster) && x == 1) { /* If x == 0, we already failed
anyway */
    x = has_holy_symbol(caster, spellnum);
  }

  return x;
}

/* Return 1 if carrying holy symbol, 0 otherwise */
/* Can theoretically be used for other things (warding off vampires),
 * and not just spell casting (just call with spellnum = -1)... */
/* In fact, it might be good to make a generalized function:
   int has_object(struct char_data *caster, int vnum); assuming this
   doesn't already exist, which it might - I haven't looked ;)  */
int has_holy_symbol(struct char_data *caster, int spellnum) {
  /* Go through caster's inventory and check for holy symbol - *
   * code for doing this exists elsewhere, so find it and copy *
   * it accordingly ;P    Pseudo-code: */
  int y = 0;

  search inventory and equipped for holy symbol;

  if (holy symbol is found)
    y = 1;
  else
    y = 0;

  switch (spellnum) {
    SPELL_HEAL:
    SPELL_CURE_BLIND:
    SPELL_TURN_UNDEAD:
      return y;
      break;
    default:  /* No holy symbol required, so always return success */
      return 1;
      break;
  }
}


Then in do_cast() in spell_parser.c, right before "You throws the
dice and takes your chances" ;)  add in a call to this function:

  if (has_material(ch, spellnum)) {
    /* throws the dice... */
  } else {
    /* leave do_cast without casting the spell */
    /* Probably want to send some sort of message to caster, and
     * maybe to room as well? */
  }

That should do it.  I'm doing all this in the mailer, so I may easily
have overlooked something, but this should be at least 99% of it...

>----------
>From:  Christoffer Lundberg[SMTP:avatar@ORION.BODEN.SE]
>Sent:  Friday, January 09, 1998 3:32 AM
>To:    CIRCLE@POST.QUEENSU.CA
>Subject:        [CODE] [QUESTION]: Reagent-based spells
>
>As some, if not all of you, know that there is a mag-function called
>mag_ingredients or something. I've tried to add a spell in this function,
>but probably I must have put it in the wrong place.
>Where should I put a spell in mag_ingredients?
>
>There must be a switch(spellnum) somewhere, but where?
>Could anybody who have done this help me out and tell me where
>the switch should be placed...
>
>/Avatar
>
>                #############################################
>                #       You have recieved this E-mail       #
>                #    from Avatar at avatar@orion.boden.se   #
>                #       If you want you can write back      #
>                # if you don't want to then get outta here  #
>                #         (Ouch, me 'urt me 'ead)           #
>                #############################################
>
>
>     +------------------------------------------------------------+
>     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
>     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
>     +------------------------------------------------------------+
>


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST