I recently did a function to handle berserk (uncontrollable demon form), so they attack random things in the room, or travel elsewhere to find others. I am looking for comments on how to improve this function, problems it could cause, and so on. Basically, I'd like some criticism on it, so I can learn more.
Yes there are some obvious things, such as putting all the ifchecks in one ifcheck near the top.
void hanyou_dform_randoms( CHAR_DATA *ch )
{
int chars=0;
CHAR_DATA *rch;
sh_int door;
EXIT_DATA *pexit;
if ( IS_NPC( ch ) || ch->race != 2 || ch->fighting || (ch->race == 2 && !xIS_SET(ch->act, PLR_TFORMED) ) )
return;
if ( IS_SET(ch->in_room->room_flags, ROOM_SAFE ) )
return;
if ( number_percent() < 30 )
return;
for ( rch = ch->in_room->first_person; rch; rch = rch->next_in_room )
{
if ( ch == rch || xIS_SET(rch->act, ACT_PACIFIST) )
continue;
if ( can_see( ch, rch ) )
{
chars++;
if ( number_percent() < 20 )
{
act( AT_FIRE, "In a frenzy, you jump at $N!", ch, NULL, rch, TO_CHAR );
act( AT_FIRE, "In a frenzy, $n jumps at you!", ch, NULL, rch, TO_VICT );
act( AT_FIRE, "In a frenzy, $n jumps at $N!", ch, NULL, rch, TO_NOTVICT );
if ( IS_NPC(rch) )
do_kill( ch, rch->name );
else if ( !IS_NPC(rch) )
do_murder( ch, rch->name );
}
}
}
if ( chars < 1 )
{
door = number_door();
pexit = get_exit( ch->in_room, door );
if ( pexit != NULL && pexit->to_room )
{
act( AT_PLAIN, "Finding no victims, you wander elsewhere.", ch, NULL, NULL, TO_CHAR );
move_char( ch, get_exit( ch->in_room, door ), 0, FALSE );
}
}
return;
}Yes there are some obvious things, such as putting all the ifchecks in one ifcheck near the top.