Greetings.
I've attempted to write a function to combine the affects on objects. It works
in that it does infact combine affects, but unfortunately, the phantom affects
stick around and cause problems later.
Gist of what I'm attempting:
Example:
Affects strength by 3.
Affects strength by 3.
Affects damage roll by 4.
Affects damage roll by 4.
combined=========
Affects damage roll by 8.
Affects strength by 6.
This I've done. It works.
However, if I disconnect, add a new affect to it, and combine again, it
does...this.
Affects damage roll by 8.
Affects strength by 6.
Affects damage roll by 8.
Affects strength by 228.
Oops. At first I thought it was because the object wasn't saved, but then,
after adding save_char_obj it still persists.
===============
Here's how I systematically go through and remove and add affects:
First, I do this:
void ucombine (CHAR_DATA *ch, CHAR_DATA *mob, OBJ_DATA *obj, char *argument)
{
....
affect_enchant (obj);
Then:
for (afftype = 1; afftype <= APPLY_SAVING_SPELL; afftype++)
{
counter = 0;
for (paf = obj->affected; paf != NULL; paf = paf->next)
{
if (!NegNormal && paf->modifier > 0 && paf->location == afftype)
{
counter += paf->modifier;
affect_remove_obj(obj, paf);
}
}
if (counter != 0) /*Found affects so we need to make a new one.*/
{
paf = new_affect ();
paf->type = 0;
paf->level = obj->level;
paf->duration = -1;
paf->location = afftype;
paf->modifier = counter;
paf->bitvector = 0;
paf->next = obj->affected;
affect_to_obj(obj,paf);
paf->next = obj->affected;
}
}
save_char_obj (ch);
return;
}
It only removes and makes a new totaled affect when the affects are above 0.
(Except saves and AC, which I left out of the above code for brevity's sake.)
===========
Relatedly, here's what the logs say:
Tue Jul 30 14:57:53 2002 :: [*****] BUG: Affect_remove_object: cannot find paf.
Tue Jul 30 14:57:53 2002 :: [*****] BUG: Affect_remove_object: cannot find paf.
Tue Jul 30 14:57:53 2002 :: [*****] BUG: Affect_remove_object: cannot find paf.
3 of them. Not sure why.
After the newest erroneous combine, the object looks like this in the pfile:
#O
Vnum 7700
Enchanted
Nest 0
Cond 0
Wear -1
Cost 5200
Affc 'reserved' 0 38 -1 8 19 0
Affc 'reserved' 0 38 -1 228 1 0
End
Looks okay. I disconnected and reconnected again. This time after ucombining,
Tue Jul 30 15:09:58 2002 :: [*****] BUG: Affect_remove_object: cannot find paf.
And the obj looks like this now:
#O
Vnum 7700
Enchanted
Nest 0
Cond 0
Wear -1
Cost 5200
Affc 'reserved' 0 38 -1 8 19 0
Affc 'reserved' 0 38 -1 456 1 0
End
=============================
I am very, very confused. What's going on?