Re: affect_join

From: Lincoln Chan (linc@CSUA.Berkeley.EDU)
Date: 04/18/95


Nah, not too newbie-ish either, though it *is* a simple subroutine to
figure out.  Look in handler.c and search for affect_join.

void affect_join(struct char_data * ch, struct affected_type * af,
                      bool add_dur, bool avg_dur, bool add_mod, bool avg_mod)
{
  struct affected_type *hjp;
  bool found = FALSE;

  for (hjp = ch->affected; !found && hjp; hjp = hjp->next) {
    if (hjp->type == af->type) {

      if (add_dur)
        af->duration += hjp->duration;
      if (avg_dur)
        af->duration >>= 1;

      if (add_mod)
        af->modifier += hjp->modifier;
      if (avg_mod)
        af->modifier >>= 1;

      affect_remove(ch, hjp);
      affect_to_char(ch, af);
      found = TRUE;
    }
  }
  if (!found)
    affect_to_char(ch, af);
}

Why, here it is.  Let's examine it, shall we?

Well, spell affects are created in some sort of structure.  One points at
another and another and another, I believe in the sequence you were affected
by them at.  What the first few lines do is search.  It searches the victim's
affected spells using the for loop, and it checks to see if this spell you
want to add has already been casted on you.  (it does this by checking to
see if the search 'type' is the same as the spell about to be casted 'type').

If the spell was found, then it checks the 4 bools in the declaration.
bool add_dur, bool avg_dur, bool add_mod, bool avg_mod.

if any add_ is booleaned TRUE, then it adds it, either duration or mod.
        af->duration += hjp->duration;
if any avg_ is booleaned TRUE, then it divides by 2 after it adds the change.
        af->duration >>= 1;

Finally, it removes the original spell completely, and affect_to_char()'s the
new spell.

As for checking to see if the spell's already affecting the person, well,
Chris has already responded with:
  if (affected_by_spell(victim, spellnum)) {
    send_to_char("Nothing happens.\n\r", ch);
    return;
  }

You can always consider going for the direct approach too and do an
affect_to_char() instead of an affect_join().  Don't bother mailing back
asking what affect_to_char() does.  This is something you can look in
handler.c for just like you did for affect_join().

linc aka Aladdin of Eternity DikuMUD



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