src/update.c
/*
 * Aggress.
 *
 * for each mortal PC
 *     for each mob in room
 *         aggress on some random PC
 *
 * This function takes 25% to 35% of ALL Merc cpu time.
 * Unfortunately, checking on each PC move is too tricky,
 *   because we don't the mob to just attack the first PC
 *   who leads the party into the room.
 *
 * -- Furey
 */
Aggress.
for each mortal PC
for each mob in room
aggress on some random PC

This function takes 25% to 35% of ALL Merc cpu time.
Unfortunately, checking on each PC move is too tricky,
because we don't the mob to just attack the first PC
who leads the party into the room.

Furey
Aggress . for each mortal PC for each mob in room aggress on some random PC This function takes 25% to 35% of ALL Merc cpu time . Unfortunately checking on each PC move is too tricky because we don ' t the mob to just attack the first PC who leads the party into the room . Furey
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)
	    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_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;
}
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 ) 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_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 ; }
Aggress.
Aggress .
/*
	     * Ok we have a 'wch' player character and a 'ch' npc aggressor.
	     * Now make the aggressor fight a RANDOM pc victim in the room,
	     *   giving each 'vch' an equal chance of selection.
	     */