ROM question with aggr_update

Posted by Tidus on Thu 01 Apr 2004 06:24 PM — 2 posts, 11,483 views.

#0
I am running a ROM 2.4 derived codebase mud and it keeps lagging out altogether. So when I attach gdb to see where it hangs it tells me the error is in the aggr_update function in update.c which looks like this:

The line that it gives as the actual problem is:

ch_next = ch->next_in_room;

right after the 2nd for loop, I just don't understand why that line is a problem, it's stock rom. If anyone could help I would appreciate.


void aggr_update( void )
{
    CHAR_DATA *wch;
    CHAR_DATA *wch_next;
    CHAR_DATA *ch;
    CHAR_DATA *ch_next;
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    CHAR_DATA *victim;

    for ( wch = char_list; wch != NULL; wch = wch_next )
    {
	wch_next = wch->next;
	if ( IS_NPC(wch)
	||   wch->level >= LEVEL_IMMORTAL
	||   wch->in_room == NULL 
	||   wch->in_room->area->empty
	||   is_affected(wch, skill_lookup("deter"))
	||   is_affected(wch, skill_lookup("sneak")))
	    continue;

	for ( ch = wch->in_room->people; ch != NULL; ch = ch_next )
	{
		int count;

                ch_next	= ch->next_in_room;

	    if ( !IS_NPC(ch)
	    ||   !IS_SET(ch->act, ACT_AGGRESSIVE)
	    ||   IS_SET(ch->in_room->room_flags,ROOM_SAFE)
	    ||   IS_AFFECTED(ch,AFF_CALM)
	    ||   ch->fighting != NULL
	    ||   IS_AFFECTED(ch, AFF_CHARM)
	    ||   is_affected(ch, skill_lookup("charm"))
		||   !IS_AWAKE(ch)
	    ||   ( IS_SET(ch->act, ACT_WIMPY) && IS_AWAKE(wch) )
	    ||   !can_see( ch, wch ) 
	    ||   number_bits(1) == 0)
		continue;

	    
	    count	= 0;
	    victim	= NULL;
	    for ( vch = wch->in_room->people; vch != NULL; vch = vch_next )
	    {
		vch_next = vch->next_in_room;

		if ( !IS_NPC(vch)
		&&   vch->level < LEVEL_IMMORTAL
		&&   ch->level >= vch->level - 5 
		&&   ( !IS_SET(ch->act, ACT_WIMPY) || !IS_AWAKE(vch) )
		&&   can_see( ch, vch ) )
		{
		    if ( number_range( 0, count ) == 0 )
			victim = vch;
		    count++;
		}
	    }

	    if ( victim == NULL )
		continue;

		multi_hit( ch, victim, TYPE_UNDEFINED );		
	}
    }

    return;
}


Edited by Nick to add [code] and [/code].
Amended on Fri 02 Apr 2004 11:01 PM by Nick Gammon
Australia Forum Administrator #1
The code looks a bit convoluted but I would guess that the mucking around with the various character lists is ending up with a situation where it gets the "next in room" being the same person as itself, and thus loops indefinitely.

One way to break that loop, although it might not fix the reason it is happening would be something like this:

Instead of:


 ch_next = ch->next_in_room;


Have


 if (ch_next != ch->next_in_room)
   ch_next = ch->next_in_room;
 else
   ch_next = NULL;