Re: Timing bugs - fleeing

From: Antioch (jeremy@YAKKO.CS.WMICH.EDU)
Date: 12/21/97


On Sat, 13 Dec 1997, Brian Williams - Nashak wrote:

>           ...and if you have someone look RIGHT after you flee, it'll
> say yer still fighting, etc.. does anyone know a fix for any of these
> annoying bugs?

Hi Jeremy,

  A recent query about a certain quirk in do_flee by Brian Williams
prompted me to do a little investigative work.  His complaint was that if
a person flees from a fight and returns to the same room immediately, the
monster acts as if the player never left the room and the fight resumes.
I've accepted this for years as just "one of those quirks", however, I've
just discovered that it is indeed a "bug".  It seems that the FIGHTING(ch)
pointer gets trashed before we're through making all the comparisons we
need.  To elaborate further, line 260 in an un-modified act.offensive.c
from patch level 12 reads:
                           if (FIGHTING(ch)) {
line 262: loss = GET_MAX_HIT(FIGHTING(ch))...
line 263  loss *= GET_LEVEL(FIGHTING(ch))...

and more importantly,

line 266:  if (FIGHTING(FIGHTING(ch)) == ch)
line 267:      stop_fighting(FIGHTING(ch))

as you can see (and most assuredly allready know), you depend upon that
pointer to do two important things:  calculate exp loss and stop the
fighting.  However, you'll notice that do_simple_move gets called before
any of these comparisons (line 258).  The problem lies in the fact that
do_simple_move calls the char_from_room routine.  In char_from_room on
line 364 we find this:
                       if (FIGHTING(ch) != NULL)
                           stop_fighting(ch);

The stop_fighting routine, of course, sets the FIGHTING(ch) pointer to
NULL.  This is all fine and dandy, but if you remember that we still need
this pointer for the rest of do_flee, you'll see that we have a problem.
When the check for FIGHTING(ch) in line 260 (act.offensive.c) the computer
jumps past those two important parts because FIGHTING(ch) was set to NULL
in char_from_room.

Now I don't know if you allready know this or not...if you do, then i
apologize for wasting your time.  Also, for what it's worth, i've included
my "fix" for the do_flee routine.  I have no idea if it's the "best" way,
and I apologize if I've made any errors, but it works dandy on my system.
Oh btw, the OS i'm using is Linux Slackware, if that makes any difference.

Thank you for your time,

Jeremy Jubenville (Antioch@Dark Chronicles MUD)


ACMD(do_flee)
{
  int i, attempt, loss;
  struct char_data *vict = FIGHTING(ch); /* make a copy of our pointer -jjj */

  for (i = 0; i < 6; i++) {
    attempt = number(0, NUM_OF_DIRS - 1);       /* Select a random direction */
    if (CAN_GO(ch, attempt) &&
        !IS_SET(ROOM_FLAGS(EXIT(ch, attempt)->to_room), ROOM_DEATH)) {
      act("$n panics, and attempts to flee!", TRUE, ch, 0, 0, TO_ROOM);
      if (do_simple_move(ch, attempt, TRUE)) {
        send_to_char("You flee head over heels.\r\n", ch);
    /*
     * do_simple_move NULL's our FIGHTING(ch) pointer, so we'll use
     * 'vict' from here on out. -jjj
     */
        if (vict) {    /* maybe this should be:  if (vict != NULL) -jjj */
          if (!IS_NPC(ch)) {
            loss = GET_MAX_HIT(vict) - GET_HIT(vict);
            loss *= GET_LEVEL(vict);
            gain_exp(ch, -loss);
          }
          if (FIGHTING(vict) == ch)
             stop_fighting(vict);
          stop_fighting(ch);
        }
      } else {
        act("$n tries to flee, but can't!", TRUE, ch, 0, 0, TO_ROOM);
      }
      return;
    }
  }
  send_to_char("PANIC!  You couldn't escape!\r\n", ch);
}

---------------------------------------------------------------------------
<> Jeremy J. Jubenville                  Email: jeremy@yakko.cs.wmich.edu
<> 609 W. Lovell #10                     Phone: (616) 341-4238
<> Kalamazoo, Michigan 49007             Fax:   (616) 324-4094

 - After silence, that which comes nearest to expressing the inexpressable
   is music...
___________________________________________________________________________


     +------------------------------------------------------------+
     | 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/08/00 PST