Re: [CODE] [NEWBIE] Spec_assign.c

From: Patrick Dughi (dughi@imaxx.net)
Date: 04/29/99


< reformatted for personal peace of mind >

> if (IS_SET(MOB_FLAGS(mob_proto + m), MOB_SPEC)) {
>   for (m = 0; m < top_of_mobt; m++) {
>     if (mob_proto[m].player.class == CLASS_MAGIC_USER)
>       mob[m].func = magic_user;
>   }
> }
        Looks fine to me, however, I'm curious. We start out with the
line:
 if (IS_SET(MOB_FLAGS(mob_proto + m), MOB_SPEC)) {

        So, we know that 'm' is being set above to something reasonable.
Then, right below, you iterate through all mobs, using 'm' as your
iterator, and leave it as top_of_mobt.  Now, since we don't have any
actual debugging information, I'm going to assume that there's more code
below those things, that it crashes on, code that is dependant on 'm'
being that reasonable value.  Perhaps it even makes it through that
particular loop of 'm' and crashes when it tries to access the mob_proto
array out of bounds.  In anycase, it looks like you're initilizing every
mob for each mob you parse.  You could probably just get away with
something like:

  if (IS_SET(MOB_FLAGS(mob_proto + m), MOB_SPEC)) {
    if (mob_proto[m].player.class == CLASS_MAGIC_USER)
      mob[m].func = magic_user;
  }

        Of course, i'd also change that so it looks like this:

  if (!IS_SET(MOB_FLAGS(mob_proto + m), MOB_SPEC)) {
    if (mob_proto[m].player.class == CLASS_MAGIC_USER) {
      mob[m].func = magic_user;
      SET_BIT(MOB_FLAGS(mob_proto + m), MOB_SPEC);
    }
  }

        So that way if I set a spec proc already on it, it won't get
overwritten.  This may or may not be relevent depending on where in your
code you actually put it.

                                                PjD


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



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