Re: [NEWBIE] [CODE] Vampires

From: Daniel A. Koepke (dkoepke@california.com)
Date: 05/15/99


On Sat, 15 May 1999, Chuck Reed wrote:

> for (every player offline)
>   if (GET_MAST_VAMP(player) == GET_IDNUM(ch))

Just a few notes on implementation.  This would be accomplished using the
player_table.  Add GET_MAST_VAMP() to the player_index_element (db.h) and
a flag, PLR_MADE_VAMP, for player's that have made other vampires.  I
would create a function along these lines,

    void destroy_vampire(struct char_data * ch)
    {
      struct char_file_u chdata;
      struct char_data * vamp;
      int i, player_i, tmp = sizeof(struct char_file_u);

      /* normal vampire destruction code here */
      REMOVE_BIT(PLR_FLAGS(ch), PLR_VAMPIRE);
      GET_MAST_VAMP(ch) = -1;
      make_ashes(ch);

      if (PLR_FLAGGED(ch, PLR_MADE_VAMP)) {
        for (i = 0; i <= top_of_p_table; i++) {
          if (player_table[i].master_vamp == GET_IDNUM(ch)) {
            CREATE(vamp, struct char_data, 1);
            clear_char(vamp);
            player_i = load_char(player_table[i].name, &chdata);

            if (player_i > -1) {
              store_to_char(&chdata, vamp);
              destroy_vampire(vamp);
              char_to_store(vamp, &chdata);
              fseek(player_fl, (player_i) * tmp, SEEK_SET);
              fwrite(&chdata, tmp, 1, player_fl);
            }

            free_char(vamp);
          }
        }
      }
    }

Of course, this could get *really* inefficient if you have a lot of
players and a long inherentence tree.  That is, if you have something
like,

                                  Root
                                 / |  \
                               /   |   \
                             A     B     C
                             |     |     |
                            /|\    |    /|\
                           D | E  /|\  F | G
                           | H   I | J   K |
                           L       M    /| N
                          /|\     / \  O P |\
                         Q R S   T   U   | V W
                         |   |           X
                         Y   Z

Watch out when Root dies.  If you have 1000 players in your database,
active or not, you have trouble.  Root dies.  Okay, so let's find the
vampires he has made.  A, B, C.  Depending upon their placement in the
player_table, you could do a lot of searching just for them.  But wait,
they each have children, and so you start from the beginning through the
index again...and, oh, dear, these new vampires have children as well.
And it goes on and on and on...

-dak


     +------------------------------------------------------------+
     | 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