/
Cool3/bin/
 /***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/

/***************************************************************************
*       ROM 2.4 is copyright 1993-1995 Russ Taylor                         *
*       ROM has been brought to you by the ROM consortium                  *
*           Russ Taylor (rtaylor@pacinfo.com)                              *
*           Gabrielle Taylor (gtaylor@pacinfo.com)                         *
*           Brian Moore (rom@rom.efn.org)                                  *
*       By using this code, you have agreed to follow the terms of the     *
*       ROM license, in the file Rom24/doc/rom.license                     *
***************************************************************************/

/***************************************************************************
*  Automated Quest code written by Vassago of MOONGATE, moongate.ams.com   *
*  4000. Copyright (c) 1996 Ryan Addams, All Rights Reserved. Use of this  *
*  code is allowed provided you add a credit line to the effect of:        *
*  "Quest Code (c) 1996 Ryan Addams" to your logon screen with the rest    *
*  of the standard diku/rom credits. If you use this or a modified version *
*  of this code, let me know via email: moongate@moongate.ams.com. Further *
*  updates will be posted to the rom mailing list. If you'd like to get    *
*  the latest version of quest.c, please send a request to the above add-  *
*  ress. Quest Code v2.00.                                                 *
***************************************************************************/

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"

DECLARE_DO_FUN( do_say );

/* Object vnums for Quest Rewards */

#define QUEST_ITEM1 22107
#define QUEST_ITEM2 22108
#define QUEST_ITEM3 22111 /* Quest Rewards */
#define QUEST_ITEM4 22110
#define QUEST_ITEM5 22109
#define	QUEST_ITEM6 22112

/* Object vnums for object quest 'tokens'. In Moongate, the tokens are
   things like 'the Shield of Moongate', 'the Sceptre of Moongate'. These
   items are worthless and have the rot-death flag, as they are placed
   into the world when a player receives an object quest. */

#define QUEST_OBJQUEST1 22102
#define QUEST_OBJQUEST2 22103
#define QUEST_OBJQUEST3 22104
#define QUEST_OBJQUEST4 22105
#define QUEST_OBJQUEST5 22106

/* Local functions */

void generate_quest     args(( CHAR_DATA *ch, CHAR_DATA *questman ));
void quest_update       args(( void ));
bool chance             args(( int num ));

/* CHANCE function. I use this everywhere in my code, very handy :> */

bool chance(int num)
{
    if (number_range(1,100) <= num) return TRUE;
    else return FALSE;
}

/* The main quest function */

void do_quest(CHAR_DATA *ch, char *argument)
{
    CHAR_DATA *questman;
    OBJ_DATA *obj=NULL, *obj_next;
    char buf [MAX_STRING_LENGTH];
    char arg1 [MAX_INPUT_LENGTH];
    char arg2 [MAX_INPUT_LENGTH];

    argument = one_argument(argument, arg1);
    argument = one_argument(argument, arg2);

    if ( IS_NPC( ch ) )
    {
	send_to_char( "Sorry, only PCs can quest.\n\r", ch );
	if ( ch->master )
	    send_to_char( "Sorry, only PCs can quest.\n\r", ch->master );
	return;
    }

    if (!strcmp(arg1, "info"))
    {
        if ( IS_QUESTOR( ch ) )
        {
	    if ( ch->pcdata->questgiver == NULL
	      || ch->pcdata->questgiver->short_descr == NULL )
	    {
		send_to_char( "Your questgiver seems to have dissapeared. Please contact the imms.\n\r", ch );
		return;
	    }
	    if ( ch->pcdata->questtype == QUEST_MOB )
	    {
		if ( ch->pcdata->questmob == NULL )
		{
		    sprintf(buf, "Your quest is ALMOST complete!\n\rGet back to %s before your time runs out!\n\r",ch->pcdata->questgiver->short_descr);
		    send_to_char(buf, ch);
		}
		else
		{
		    sprintf(buf, "You are on a quest to slay the dreaded %s!\n\r",
				 ch->pcdata->questmob->short_descr );
		    send_to_char(buf, ch);
		    return;
		}
	    }
            else if ( ch->pcdata->questtype == QUEST_OBJ )
            {
		if ( ch->pcdata->questobj == NULL )
		{
		    sprintf(buf, "Your quest is ALMOST complete!\n\rGet back to %s before your time runs out!\n\r",ch->pcdata->questgiver->short_descr);
		    send_to_char(buf, ch);
		}
		else
		{
		    sprintf(buf, "You are on a quest to recover the fabled %s!\n\r",ch->pcdata->questobj->short_descr );
		    send_to_char(buf, ch);
		    return;
		}
            }
	    else
	    {
		send_to_char( "Bad questtype.  Resetting quest.\n\r", ch );
		ch->pcdata->questtype = QUEST_NONE;
		ch->pcdata->questobj = NULL;
		ch->pcdata->questmob = NULL;
		ch->pcdata->countdown = 0;
		ch->pcdata->nextquest = 1;
		REMOVE_BIT( ch->act, PLR_QUESTOR );
	    }
        }
	else
            send_to_char("You aren't currently on a quest.\n\r",ch);
        return;
    }
    if (!strcmp(arg1, "points"))
    {
        sprintf(buf, "You have %d quest points.\n\r",ch->questpoints);
        send_to_char(buf, ch);
        return;
    }
    else if (!strcmp(arg1, "time"))
    {
        if (!IS_SET(ch->act, PLR_QUESTOR))
        {
            send_to_char("You aren't currently on a quest.\n\r",ch);
            if (ch->pcdata->nextquest > 1)
            {
                sprintf(buf, "There are %d minutes remaining until you can go on another quest.\n\r",ch->pcdata->nextquest);
                send_to_char(buf, ch);
            }
            else if (ch->pcdata->nextquest == 1)
            {
                sprintf(buf, "There is less than a minute remaining until you can go on another quest.\n\r");
                send_to_char(buf, ch);
            }
        }
        else if (ch->pcdata->countdown > 0)
        {
            sprintf(buf, "Time left for current quest: %d\n\r",ch->pcdata->countdown);
            send_to_char(buf, ch);
        }
        return;
    }

/* Checks for a character in the room with spec_questmaster set. This special
   procedure must be defined in special.c. You could instead use an
   ACT_QUESTMASTER flag instead of a special procedure. */

    for ( questman = ch->in_room->people; questman != NULL; questman = questman->next_in_room )
    {
        if (!IS_NPC(questman)) continue;
        if (questman->spec_fun == spec_lookup( "spec_questmaster" )) break;
    }

    if (questman == NULL || questman->spec_fun != spec_lookup( "spec_questmaster" ))
    {
        send_to_char("You can't do that here.\n\r",ch);
        return;
    }

    if ( questman->fighting != NULL)
    {
        send_to_char("Wait until the fighting stops.\n\r",ch);
        return;
    }

    ch->pcdata->questgiver = questman;

/* And, of course, you will need to change the following lines for YOUR
   quest item information. Quest items on Moongate are unbalanced, very
   very nice items, and no one has one yet, because it takes awhile to
   build up quest points :> Make the item worth their while. */

    if (!strcmp(arg1, "list"))
    {
        act( "$n asks $N for a list of quest items.", ch, NULL, questman, TO_ROOM);
        act ("You ask $N for a list of quest items.",ch, NULL, questman, TO_CHAR);
        sprintf(buf, "Current Quest Items available for Purchase:\n\r"
"{RMask of Divinity{x.................3000\n\r"
"{GRing of Tranquility{x..............2500\n\r"
"{RB{rl{Ro{ro{Rd {BD{ba{Bg{bg{Be{Br{x.....................2000\n\r"
"{BSword of Power{x...................1800\n\r"
"{MAura{CShield{x.......................1200\n\r"
"{Y10,000 platinum pieces{x...........1000\n\r"
"{*Cloak of Deception{x...............800\n\r"
"{W100 Practices{x....................500\n\r\n\r"
"To buy an item, type \"QUEST BUY <item>\".\n\r");
        send_to_char(buf, ch);
        return;
    }

    else if (!strcmp(arg1, "buy"))
    {
	sprintf( buf, "Autoquest: %s trying to buy %s with %d qps.", ch->name, arg2, ch->questpoints );
	log_string( buf );
        if (arg2[0] == '\0')
        {
            send_to_char("To buy an item, type 'QUEST BUY <item>'.\n\r",ch);
            return;
        }
        if (is_name(arg2, "mask divinity divine"))
        {
            if (ch->questpoints >= 3000)
            {
                ch->questpoints -= 3000;
                obj = create_object(get_obj_index(QUEST_ITEM1),ch->level);
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "ring tranquility tranq"))
        {
            if (ch->questpoints >= 2500)
            {
                ch->questpoints -= 2500;
                obj = create_object(get_obj_index(QUEST_ITEM2),ch->level);
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "sword power"))
        {
            if (ch->questpoints >= 1800)
            {
                ch->questpoints -= 1800;
                obj = create_object(get_obj_index(QUEST_ITEM3),ch->level);
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "aura shield aurashield"))
        {
            if (ch->questpoints >= 1200)
            {
                ch->questpoints -= 1200;
                obj = create_object(get_obj_index(QUEST_ITEM4),ch->level);
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "cloak deception"))
        {
            if (ch->questpoints >= 800)
            {
                ch->questpoints -= 800;
                obj = create_object(get_obj_index(QUEST_ITEM5),ch->level);
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "dagger blood blooddagger daggerblood"))
        {
            if (ch->questpoints >= 2000)
            {
                ch->questpoints -= 2000;
                obj = create_object(get_obj_index(QUEST_ITEM6),ch->level);
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "practices pracs prac practice"))
        {
            if (ch->questpoints >= 500)
            {
                ch->questpoints -= 500;
                ch->practice += 100;
                act( "$N gives 100 practices to $n.", ch, NULL, questman, TO_ROOM );
                act( "$N gives you 100 practices.",   ch, NULL, questman, TO_CHAR );
                return;
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else if (is_name(arg2, "gold gp platinum"))
        {
            if (ch->questpoints >= 1000)
            {
                ch->questpoints -= 1000;
                ch->platinum += 5000;
                act( "$N gives 5,000 gold pieces to $n.", ch, NULL, questman, TO_ROOM );
                act( "$N has 5,000 in gold transfered from $s Swiss account to your balance.",   ch, NULL, questman, TO_CHAR );
                return;
            }
            else
            {
                sprintf(buf, "Sorry, %s, but you don't have enough quest points for that.",ch->name);
                do_say(questman,buf);
                return;
            }
        }
        else
        {
            sprintf(buf, "I don't have that item, %s.",ch->name);
            do_say(questman, buf);
        }
        if (obj != NULL)
        {
            act( "$N gives $p to $n.", ch, obj, questman, TO_ROOM );
            act( "$N gives you $p.",   ch, obj, questman, TO_CHAR );
            obj_to_char(obj, ch);
        }
        return;
    }
    else if (!strcmp(arg1, "request"))
    {
        act( "$n asks $N for a quest.", ch, NULL, questman, TO_ROOM);
        act ("You ask $N for a quest.",ch, NULL, questman, TO_CHAR);
        if (IS_SET(ch->act, PLR_QUESTOR))
        {
            sprintf(buf, "But you're already on a quest!");
            do_say(questman, buf);
            return;
        }
        if (ch->pcdata->nextquest > 0)
        {
            sprintf(buf, "You're very brave, %s, but let someone else have a chance.",ch->name);
            do_say(questman, buf);
            sprintf(buf, "Come back later.");
            do_say(questman, buf);
            return;
        }

        sprintf(buf, "Thank you, brave %s!",ch->name);
        do_say(questman, buf);

        generate_quest(ch, questman);

        if ( ch->pcdata->questmob || ch->pcdata->questobj )
        {
	    if ( ch->pcdata->questmob )
		ch->pcdata->questtype = QUEST_MOB;
	    else if ( ch->pcdata->questobj )
		ch->pcdata->questtype = QUEST_OBJ;
	    else
		ch->pcdata->questtype = QUEST_NONE;
            ch->pcdata->countdown = number_range(10,30);
            SET_BIT(ch->act, PLR_QUESTOR);
            sprintf(buf, "You have %d minutes to complete this quest.",ch->pcdata->countdown);
            do_say(questman, buf);
            sprintf(buf, "May the gods go with you!");
            do_say(questman, buf);
        }
        return;
    }
    else if (!strcmp(arg1, "giveup"))
    {
	if ( ch->pcdata->countdown <= 0 )
	{
	    sprintf( buf, "But you aren't even on a quest, %s!", ch->name );
	    do_say( questman, buf );
	    return;
	}
	send_to_char( "You give the questmaster five questpoints to try to bribe him.\n\r", ch );
	if ( ch->questpoints < -4 )
	    ch->questpoints = -10;
	else
	    ch->questpoints -= 5;
	if ( chance( 50 ) )
	{
	    sprintf( buf, "Well, %s, I'm sorry to hear that.  Perhaps we can find someone else to do the job... someone a tad more brave...", ch->name );
	    do_say( questman, buf );
	    ch->pcdata->countdown = 0;
	    ch->pcdata->nextquest = 2;
	}
	else
	    do_say( questman, "As if I would accept a bribe!  I'll take those questpoints, young adventurer!" );
	return;
    }
    else if (!strcmp(arg1, "complete"))
    {
        act( "$n informs $N $e has completed $s quest.", ch, NULL, questman, TO_ROOM);
        act ("You inform $N you have completed $s quest.",ch, NULL, questman, TO_CHAR);
        if (ch->pcdata->questgiver != questman)
        {
            sprintf(buf, "I never sent you on a quest! Perhaps you're thinking of someone else.");
            do_say(questman,buf);
            return;
        }

        if (IS_SET(ch->act, PLR_QUESTOR))
        {
            if ( ( ( ch->pcdata->questmob == NULL
		  && ch->pcdata->questtype == QUEST_MOB )
		|| ( ch->pcdata->questobj == NULL
		  && ch->pcdata->questtype == QUEST_OBJ ) )
	      && ch->pcdata->countdown > 0 )
            {
                int reward, pointreward, pracreward;

                reward = number_range(5,500);
                pointreward = number_range(10,40);

                sprintf(buf, "Congratulations on completing your quest!");
                do_say(questman,buf);
                sprintf(buf,"As a reward, I am giving you %d quest points, and %d platinum.",pointreward,reward);
                do_say(questman,buf);
                if (chance(9))
                {
                    pracreward = number_range(8,20);
                    sprintf(buf, "You gain %d practices!\n\r",pracreward);
                    send_to_char(buf, ch);
                    ch->practice += pracreward;
                }

                REMOVE_BIT(ch->act, PLR_QUESTOR);
		ch->pcdata->questtype = QUEST_NONE;
                ch->pcdata->questgiver = NULL;
                ch->pcdata->countdown = 0;
                ch->pcdata->questmob = NULL;
                ch->pcdata->questobj = NULL;
                ch->pcdata->nextquest = 10;
                ch->platinum += reward;
                ch->questpoints += pointreward;

                return;
            }
	    else if ( ch->pcdata->questtype == QUEST_OBJ
		   && ch->pcdata->questobj != NULL
		   && ch->pcdata->countdown > 0 )
            {
                bool obj_found = FALSE;

                for (obj = ch->carrying; obj != NULL; obj= obj_next)
                {
                    obj_next = obj->next_content;

                    if (obj != NULL && obj == ch->pcdata->questobj)
                    {
                        obj_found = TRUE;
                        break;
                    }
                }
                if (obj_found == TRUE)
                {
                    int reward, pointreward, pracreward;

                    reward = number_range(300,700);
                    pointreward = number_range(10,40);

                    act("You hand $p to $N.",ch, obj, questman, TO_CHAR);
                    act("$n hands $p to $N.",ch, obj, questman, TO_ROOM);

                    sprintf(buf, "Congratulations on completing your quest!");
                    do_say(questman,buf);
                    sprintf(buf,"As a reward, I am giving you %d quest points, and %d silver.",pointreward,reward);
                    do_say(questman,buf);
                    if (chance(15))
                    {
                        pracreward = number_range(8,20);
                        sprintf(buf, "You gain %d practices!\n\r",pracreward);
                        send_to_char(buf, ch);
                        ch->practice += pracreward;
                    }

                    REMOVE_BIT(ch->act, PLR_QUESTOR);
		    ch->pcdata->questtype = QUEST_NONE;
                    ch->pcdata->questgiver = NULL;
                    ch->pcdata->countdown = 0;
                    ch->pcdata->questmob = NULL;
                    ch->pcdata->questobj = NULL;
                    ch->pcdata->nextquest = 10;
		    ch->silver += reward;
                    ch->questpoints += pointreward;
                    extract_obj(obj);
                    return;
                }
                else
                {
                    sprintf(buf, "You haven't completed the quest yet, but there is still time!");
                    do_say(questman, buf);
                    return;
                }
                return;
            }
            else if ((ch->pcdata->questmob || ch->pcdata->questobj ) && ch->pcdata->countdown > 0)
            {
                sprintf(buf, "You haven't completed the quest yet, but there is still time!");
                do_say(questman, buf);
                return;
            }
        }
        if (ch->pcdata->nextquest > 0)
            sprintf(buf,"But you didn't complete your quest in time!");
        else sprintf(buf, "You have to REQUEST a quest first, %s.",ch->name);
        do_say(questman, buf);
        return;
    }

    send_to_char("QUEST commands: POINTS INFO TIME REQUEST COMPLETE GIVEUP LIST BUY.\n\r",ch);
    send_to_char("For more information, type 'HELP AUTOQUEST'.\n\r",ch);
    return;
}

void generate_quest(CHAR_DATA *ch, CHAR_DATA *questman)
{
    CHAR_DATA *vsearch;
    ROOM_INDEX_DATA *room;
    OBJ_DATA *questitem;
    char buf [MAX_STRING_LENGTH];
    long mcounter;
    int level_diff, recursions, looper;

    /*  Randomly selects a mob from the world mob list. If you don't
        want a mob to be selected, make sure it is immune to summon.
        Or, you could add a new mob flag called ACT_NOQUEST. The mob
        is selected for both mob and obj quests, even tho in the obj
        quest the mob is not used. This is done to assure the level
        of difficulty for the area isn't too great for the player. */

    for (mcounter = 0; mcounter < 200; mcounter ++)
    {
	recursions = number_range(1, top_mob_index);

	vsearch = char_list;

	for ( looper = 0; looper < recursions; looper++ )
	{
	    if ( vsearch == NULL )
		break;
	    else
		vsearch = vsearch->next;
	}

        if ( vsearch != NULL && vsearch != ch && vsearch->pIndexData != NULL )
        {
            level_diff = vsearch->level - ch->level;

                /* Level differences to search for. Moongate has 350
                   levels, so you will want to tweak these greater or
                   less than statements for yourself. - Vassago */

            if (((level_diff < 30 && level_diff > -30)
		|| ch->level > 99)
                && ( vsearch->pIndexData->pShop == NULL )
                && !IS_SET(vsearch->imm_flags, IMM_SUMMON)
                && !IS_SET(vsearch->act,ACT_TRAIN)
                && !IS_SET(vsearch->act,ACT_PRACTICE)
                && !IS_SET(vsearch->act,ACT_IS_HEALER)
		&& !IS_SET(vsearch->act,ACT_PET)
		&& IS_NPC(vsearch)
		&& !IS_SET(vsearch->pIndexData->area->area_flags, AREA_NOQUESTTO)) break;
                else vsearch = NULL;
        }
    }

    if ( vsearch == NULL )
    {
        sprintf(buf, "I'm sorry, but I don't have any quests for you at this time.");
        do_say(questman, buf);
        sprintf(buf, "Please try again later.");
        do_say(questman, buf);
        ch->pcdata->nextquest = 2;
        return;
    }

    if ( ( room = vsearch->in_room ) == NULL )
    {
        sprintf(buf, "I'm sorry, but I don't have any quests for you at this time.");
        do_say(questman, buf);
        sprintf(buf, "Try again later.");
        do_say(questman, buf);
        ch->pcdata->nextquest = 2;
        return;
    }

    /*  40% chance it will send the player on a 'recover item' quest. */

    if (chance(40))
    {
        int objvnum = 0;

        switch(number_range(0,4))
        {
            case 0:
            objvnum = QUEST_OBJQUEST1;
            break;

            case 1:
            objvnum = QUEST_OBJQUEST2;
            break;

            case 2:
            objvnum = QUEST_OBJQUEST3;
            break;

            case 3:
            objvnum = QUEST_OBJQUEST4;
            break;

            case 4:
            objvnum = QUEST_OBJQUEST5;
            break;
        }

        questitem = create_object( get_obj_index(objvnum), ch->level );
        obj_to_room(questitem, room);
        ch->pcdata->questobj = questitem;

        sprintf(buf, "Vile pilferers have stolen %s{S from the royal treasury!",questitem->short_descr);
        do_say(questman, buf);
        do_say(questman, "My court wizardess, with her magic mirror, has pinpointed its location.");

        /* I changed my area names so that they have just the name of the area
           and none of the level stuff. You may want to comment these next two
           lines. - Vassago */

        sprintf(buf, "Look in the general area of %s{S for %s{S!",room->area->name, room->name);
        do_say(questman, buf);
        return;
    }

    /* Quest to kill a mob */

    else
    {
    switch(number_range(0,1))
    {
        case 0:
        sprintf(buf, "An enemy of mine, %s{S, is making vile threats against the crown.", vsearch->short_descr);
        do_say(questman, buf);
        sprintf(buf, "This threat must be eliminated!");
        do_say(questman, buf);
        break;

        case 1:
        sprintf(buf, "Cool's most heinous criminal, %s{S, has escaped from the dungeon!", vsearch->short_descr);
        do_say(questman, buf);
        sprintf(buf, "Since the escape, %s has murdered %d{S civillians!", vsearch->short_descr, number_range(2,20));
        do_say(questman, buf);
        do_say(questman,"The penalty for this crime is death, and you are to deliver the sentence!");
        break;
    }

    if (room->name != NULL)
    {
        sprintf(buf, "Seek %s out somewhere in the vicinity of %s{S!", vsearch->short_descr,room->name);
        do_say(questman, buf);

        /* I changed my area names so that they have just the name of the area
           and none of the level stuff. You may want to comment these next two
           lines. - Vassago */

        sprintf(buf, "That location is in the general area of %s{S.",room->area->name);
        do_say(questman, buf);
    }
    ch->pcdata->questmob = vsearch;
    }
    return;
}

#define REAL_CHAR ( d->original != NULL ? d->original : d->character )

/* Called from update_handler() by pulse_area */

void quest_update(void)
{
    DESCRIPTOR_DATA *d;

    for ( d = descriptor_list; d != NULL; d = d->next )
    {
	if ( REAL_CHAR == NULL )
	    continue;

	if ( IS_SWITCHED( REAL_CHAR ) )
	    continue;

	if ( IS_SET( REAL_CHAR->act,PLR_QUESTOR )
	     || REAL_CHAR->pcdata->countdown > 0 )
        {
            if (--REAL_CHAR->pcdata->countdown <= 0)
            {
                char buf [MAX_STRING_LENGTH];

                REAL_CHAR->pcdata->nextquest = 10;
                sprintf( buf, "You have run out of time for your quest!\n\rYou may quest again in %d minutes.\n\r", REAL_CHAR->pcdata->nextquest );
                send_to_char(buf, d->character);
                REMOVE_BIT(REAL_CHAR->act, PLR_QUESTOR);
		REAL_CHAR->pcdata->questtype = QUEST_NONE;
		REAL_CHAR->pcdata->questgiver = NULL;
		REAL_CHAR->pcdata->countdown = 0;
		REAL_CHAR->pcdata->questmob = NULL;
		REAL_CHAR->pcdata->questobj = NULL;
            }
            if ( REAL_CHAR->pcdata->countdown > 0 && REAL_CHAR->pcdata->countdown < 6 )
	    {
                send_to_char("Better hurry, you're almost out of time for your quest!\n\r",d->character);
                return;
            }
        }
        else if ( REAL_CHAR->pcdata->nextquest > 0 )
        {
            REAL_CHAR->pcdata->nextquest--;

            if ( REAL_CHAR->pcdata->nextquest == 0 )
            {
                send_to_char( "You may now quest again.\n\r", d->character );
                return;
            }
        }
    }
    return;
}