From john@ulantris.csci.unt.edu
Date: Thu, 31 Aug 1995 13:51:32 -0500 (CDT)
From: "John A. Booth" <john@ulantris.csci.unt.edu>
To: Alexanter T Fader <afader@janus.saturn.net>
Cc: merc-l@webnexus.com
Subject: Re: Aggr_update() (was: Re: Exits)


> 	One problem with the Descriptor Loop:
> A bug in Rom2.3:  victim selection doesn't work.
> 	(my fix, common routine CHAR_DATA * target_harm ( ch ); creates a table
What?  The descriptor loop isn't even used for victim selection in 2.3.

Here's are aggr routine on EOD it's called from do_enter, doesn't have to be
called periodically--doesn't get used more than needed.  Just checks
people in the room and not the whole char list.

    /* aggressive routine  */
 
 void move_aggr(CHAR_DATA *ch) {

    CHAR_DATA *fch;
    CHAR_DATA *fch_next;
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    CHAR_DATA *victim;
 
	for ( fch = ch->in_room->people; fch != NULL; fch = fch_next )
	{
	    int count;

	    fch_next	= fch->next_in_room;

       	    if ( !IS_NPC(fch)
	    ||   !EXTENDED_IS_SET(fch->act, ACT_AGGRESSIVE)
            ||   IS_SET(fch->in_room->room_flags,ROOM_LAW)	    	    
 	    ||   IS_SET(fch->in_room->room_flags,ROOM_SAFE)
	    ||   IS_AFFECTED(fch,AFF_CALM)
	    ||   fch->fighting != NULL
	    ||   IS_AFFECTED(fch, AFF_CHARM)
	    ||   !IS_AWAKE(fch)
	    ||   ( EXTENDED_IS_SET(fch->act, ACT_WIMPY) && IS_AWAKE(ch) )
	    ||   !can_see( fch, ch ) 
	    ||   number_bits(1) == 0)
		continue;

	    /*
	     * Ok we have a 'ch' player character and a 'fch' npc aggressor.
	     * Now make the aggressor fight a RANDOM pc victim in the room,
	     *   giving each 'vch' an equal chance of selection.
	     */
	    count	= 0;
	    victim	= NULL;
	    for ( vch = ch->in_room->people; vch != NULL; vch = vch_next )
	    {
		vch_next = vch->next_in_room;

		if( 
		 vch->level < LEVEL_IMMORTAL
		&&   fch->hit*1.2 >= vch->hit 
		&&   ( !EXTENDED_IS_SET(fch->act, ACT_WIMPY) || !IS_AWAKE(vch) )
		&&   can_see( fch, vch )
		&&   !IS_NPC(vch)  )
		{
		    if ( number_range( 0, count ) == 0 )
			victim = vch;
		    count++;
		}
	    }

	    if ( victim == NULL )
		continue;

            if (RIDDEN(fch)) {
              if (!mount_success(RIDDEN(fch), fch, FALSE)) {
                send_to_char("Your mount escapes your control!\n\r",
                             RIDDEN(fch));
                multi_hit( fch, victim, TYPE_UNDEFINED ); 
              } else {
                send_to_char("You manage to keep your mount under control.\n\r",
                             RIDDEN(fch));
              }  
            } else 
   	      multi_hit( fch, victim, TYPE_UNDEFINED );
    }
    /* aggressive routine end */
    
}


 =============================================================================
/   ______ _______ ____   _____   ___ __    _ ______    ____  ____   _____   /
\  |  ____|__   __|  _ \ / ____\ / _ \| \  / |  ____|  / __ \|  _ \ / ____\  \
/  | |__     | |  | |_| | |     | |_| | |\/| | |___   | |  | | |_| | |       /
/  | ___|    | |  | ___/| |   __|  _  | |  | | ____|  | |  | |  __/| |   ___ \
\  | |       | |  | |   | |___| | | | | |  | | |____  | |__| | |\ \| |___| | /
/  |_|       |_|  |_|  o \_____/|_| |_|_|  |_|______|o \____/|_| \_|\_____/  \
\                                                                            /
 ============================================================================

------------------------------------------------------------------------------
ftp://ftp.game.org/pub/mud      FTP.GAME.ORG      http://www.game.org/ftpsite/
------------------------------------------------------------------------------

 This archive came from FTP.GAME.ORG, the ultimate source for MUD resources.

------------------------------------------------------------------------------