src/update.c
/*
 * Mob autonomous action.
 * This function takes 25% to 35% of ALL Merc cpu time.
 * -- Furey
 */
Mob autonomous action.
This function takes 25% to 35% of ALL Merc cpu time.
Furey
Mob autonomous action . This function takes 25% to 35% of ALL Merc cpu time . Furey
void mobile_update( void )
{
    CHAR_DATA *ch;
    CHAR_DATA *ch_next;
    EXIT_DATA *pexit;
    int door;
    for ( ch = char_list; ch != NULL; ch = ch_next )
    {
	ch_next = ch->next;
	if ( !IS_NPC(ch) || ch->in_room == NULL || IS_AFFECTED(ch,AFF_CHARM))
	    continue;
	if (ch->in_room->area->empty && !IS_SET(ch->act,ACT_UPDATE_ALWAYS))
	    continue;
	if ( ch->spec_fun != 0 )
	{
	    if ( (*ch->spec_fun) ( ch ) )
		continue;
	}
	if (ch->pIndexData->pShop != NULL) 
	    if ((ch->gold * 100 + ch->silver) < ch->pIndexData->wealth)
	    {
		ch->gold += ch->pIndexData->wealth * number_range(1,20)/5000000;
		ch->silver += ch->pIndexData->wealth * number_range(1,20)/50000;
	    }
	if ( ch->position != POS_STANDING )
	    continue;
	if ( IS_SET(ch->act, ACT_SCAVENGER)
	&&   ch->in_room->contents != NULL
	&&   number_bits( 6 ) == 0 )
	{
	    OBJ_DATA *obj;
	    OBJ_DATA *obj_best;
	    int max;
	    max         = 1;
	    obj_best    = 0;
	    for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
	    {
		if ( CAN_WEAR(obj, ITEM_TAKE) && can_loot(ch, obj)
		     && obj->cost > max  && obj->cost > 0)
		{
		    obj_best    = obj;
		    max         = obj->cost;
		}
	    }
	    if ( obj_best )
	    {
		obj_from_room( obj_best );
		obj_to_char( obj_best, ch );
		act( "$n gets $p.", ch, obj_best, NULL, TO_ROOM );
	    }
	}
	if ( !IS_SET(ch->act, ACT_SENTINEL) 
	&& number_bits(3) == 0
	&& ( door = number_bits( 5 ) ) <= 5
	&& ( pexit = ch->in_room->exit[door] ) != NULL
	&&   pexit->u1.to_room != NULL
	&&   !IS_SET(pexit->exit_info, EX_CLOSED)
	&&   !IS_SET(pexit->u1.to_room->room_flags, ROOM_NO_MOB)
	&& ( !IS_SET(ch->act, ACT_STAY_AREA)
	||   pexit->u1.to_room->area == ch->in_room->area ) 
	&& ( !IS_SET(ch->act, ACT_OUTDOORS)
	||   !IS_SET(pexit->u1.to_room->room_flags,ROOM_INDOORS)) 
	&& ( !IS_SET(ch->act, ACT_INDOORS)
	||   IS_SET(pexit->u1.to_room->room_flags,ROOM_INDOORS)))
	{
	    move_char( ch, door, FALSE );
	}
    }
    return;
}
void mobile_update ( void ) { CHAR_DATA * ch ; CHAR_DATA * ch_next ; EXIT_DATA * pexit ; int door ; for ( ch = char_list ; ch != NULL ; ch = ch_next ) { ch_next = ch -> next ; if ( ! IS_NPC ( ch ) || ch -> in_room == NULL || IS_AFFECTED ( ch , AFF_CHARM ) ) continue ; if ( ch -> in_room -> area -> empty && ! IS_SET ( ch -> act , ACT_UPDATE_ALWAYS ) ) continue ; if ( ch -> spec_fun != 0 ) { if ( ( * ch -> spec_fun ) ( ch ) ) continue ; } if ( ch -> pIndexData -> pShop != NULL ) if ( ( ch -> gold * 100 + ch -> silver ) < ch -> pIndexData -> wealth ) { ch -> gold += ch -> pIndexData -> wealth * number_range ( 1 , 20 ) / 5000000 ; ch -> silver += ch -> pIndexData -> wealth * number_range ( 1 , 20 ) / 50000 ; } if ( ch -> position != POS_STANDING ) continue ; if ( IS_SET ( ch -> act , ACT_SCAVENGER ) && ch -> in_room -> contents != NULL && number_bits ( 6 ) == 0 ) { OBJ_DATA * obj ; OBJ_DATA * obj_best ; int max ; max = 1 ; obj_best = 0 ; for ( obj = ch -> in_room -> contents ; obj ; obj = obj -> next_content ) { if ( CAN_WEAR ( obj , ITEM_TAKE ) && can_loot ( ch , obj ) && obj -> cost > max && obj -> cost > 0 ) { obj_best = obj ; max = obj -> cost ; } } if ( obj_best ) { obj_from_room ( obj_best ) ; obj_to_char ( obj_best , ch ) ; act ( " " , ch , obj_best , NULL , TO_ROOM ) ; } } if ( ! IS_SET ( ch -> act , ACT_SENTINEL ) && number_bits ( 3 ) == 0 && ( door = number_bits ( 5 ) ) <= 5 && ( pexit = ch -> in_room -> exit [ door ] ) != NULL && pexit -> u1 . to_room != NULL && ! IS_SET ( pexit -> exit_info , EX_CLOSED ) && ! IS_SET ( pexit -> u1 . to_room -> room_flags , ROOM_NO_MOB ) && ( ! IS_SET ( ch -> act , ACT_STAY_AREA ) || pexit -> u1 . to_room -> area == ch -> in_room -> area ) && ( ! IS_SET ( ch -> act , ACT_OUTDOORS ) || ! IS_SET ( pexit -> u1 . to_room -> room_flags , ROOM_INDOORS ) ) && ( ! IS_SET ( ch -> act , ACT_INDOORS ) || IS_SET ( pexit -> u1 . to_room -> room_flags , ROOM_INDOORS ) ) ) { move_char ( ch , door , FALSE ) ; } } return ; }
Mob autonomous action.
Mob autonomous action .
/* Examine all mobs. */ /* Examine call for special procedure */ /* give him some gold */ /* That's all for sleeping / busy monster, and empty zones */ /* Scavenge */ /* Wander */