--- Nitrocitrus <[EMAIL PROTECTED]> wrote:
>
> Here's what I've done now (in the spell functions for
> animate corpse and charm person):
>
> for (d = descriptor_list; d; d = d->next)
> {
> xch = ( d->original != NULL ) ? d->original :
> d->character;
>
> if (is_same_group (ch, xch))
> {
> if (IS_NPC(xch))
> {
> members++;
> total_levels += xch->level;
> }
> }
> }
As someone already mentioned you need to use char_list instead of
descriptor_list. However, I don't think cycling through every character in the
game every time someone charms/animates something is an effective use of your
time. A better idea might be to create a new linked list in the char_data
struct for charmies. Add something like :
CHAR_DATA * charmies;
CHAR_DATA * next_charmie;
to the char_data struct. (you should initialize both to NULL when you allocate
a new one). Then when you create a new charmie you can add it to the list with
:
vch->next_charmie = ch->charmies;
ch->charmies = vch;
search through the list with
for(xch = ch->charmies; xch != NULL; xch = xch->next)
{
if (IS_NPC(xch))
{
members++;
total_levels += xch->level;
}
}
and removal is
prev = NULL;
for(xch = ch->charmies; xch != NULL; xch = xch->next)
{
if(xch == vch)
{
if(!prev)
ch->charmies = xch->next;
else
prev->next_charmie = xch->next;
break;
}
prev = xch;
}
And so on. This saves you from cycling through (potentially) thousands of mobs
looking for charmies with the added expense of 2 pointers per CHAR_DATA. If you
wanted to save some of that you could incorporate the pointers into a spell
affect or something, but I'll leave that as an exercise for the reader.
~Kender
=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com