void do_retreat( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *was_in;
    ROOM_INDEX_DATA *now_in;
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];
    int attempt, chance, dir;

    if ( ( victim = ch->fighting ) == NULL )
    {
        if ( ch->position == POS_FIGHTING )
            ch->position = POS_STANDING;
        send_to_char( "You aren't fighting anyone.\n\r", ch );
        return;
    }

    one_argument(argument,arg);
    chance = get_skill(ch,gsn_retreat);
    if (chance > 90)
        chance = 90;

    dir = 10;

    if (arg[0] == '\0')
        dir = 10;
    else if (!str_cmp(arg,"north"))
        dir = 0;
    else if (!str_cmp(arg,"east"))
        dir = 1;
    else if (!str_cmp(arg,"south"))
        dir = 2;
    else if (!str_cmp(arg,"west"))
        dir = 3;
    else if (!str_cmp(arg,"up"))
        dir = 4;
    else if (!str_cmp(arg,"down"))
        dir = 5;
    else
        dir = 10;
 
    was_in = ch->in_room;
    for ( attempt = 0; attempt < 6; attempt++ )
    {
        EXIT_DATA *pexit;
        int door;

        if (dir == 10 || number_percent() > chance)
            door = number_door( );
        else
            door = dir;
        if ( ( pexit = was_in->exit[door] ) == 0
        ||   pexit->u1.to_room == NULL
        ||   ( IS_SET(pexit->exit_info, EX_CLOSED)
	&& (!IS_AFFECTED(ch,AFF_PASS_DOOR) ))
        ||   number_range(0,ch->daze) != 0
        || ( IS_NPC(ch)
        &&   IS_SET(pexit->u1.to_room->room_flags, ROOM_NO_MOB) ) )
            continue;

    stop_fighting(ch,TRUE);

        move_char( ch, door, FALSE );
	
        if ( ( now_in = ch->in_room ) == was_in )
            continue;

	ch->last_fought = NULL;
        ch->in_room = was_in;
        act( "{Y$n has retreated!{x", ch, NULL, NULL, TO_ROOM );
        ch->in_room = now_in;

        if ( !IS_NPC(ch) )
        {
            send_to_char( "You retreat from combat!\n\r", ch );
            send_to_char( "You lost 30 exp.\n\r", ch); 
            gain_exp( ch, -30 );

        if (dir != 10 && get_skill(ch,gsn_retreat) > 2)
        check_improve(ch,gsn_retreat,2,TRUE);
        }

        return;
    }

    send_to_char( "PANIC! You couldn't retreat!\n\r", ch );
    return;
}
