1stMUD4.0/bin/
1stMUD4.0/doc/MPDocs/
1stMUD4.0/player/
1stMUD4.0/win32/
1stMUD4.0/win32/rom/
/**************************************************************************
*  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
*  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
*                                                                         *
*  Merc Diku Mud improvements 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          *
*  benefiting.  We hope that you share your changes too.  What goes       *
*  around, comes around.                                                  *
***************************************************************************
*       ROM 2.4 is copyright 1993-1998 Russ Taylor                        *
*       ROM has been brought to you by the ROM consortium                 *
*           Russ Taylor (rtaylor@hypercube.org)                           *
*           Gabrielle Taylor (gtaylor@hypercube.org)                      *
*           Brian Moore (zump@rom.org)                                    *
*       By using this code, you have agreed to follow the terms of the    *
*       ROM license, in the file Rom24/doc/rom.license                    *
***************************************************************************
*       1stMUD ROM Derivative (c) 2001-2003 by Ryan Jennings              *
*            http://1stmud.dlmud.com/  <r-jenn@shaw.ca>                   *
***************************************************************************/
#include "merc.h"
#include "recycle.h"

typedef struct gquest_hist GQUEST_HIST;

struct gquest_hist
{
	GQUEST_HIST *next;
	GQUEST_HIST *prev;
	const char *short_descr;
	const char *text;
};

GQUEST_HIST *gqhist_first = NULL;
GQUEST_HIST *gqhist_last = NULL;

bool start_gquest(CHAR_DATA * ch, const char *argument)
{
	char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
	char arg3[MAX_INPUT_LENGTH];
	char buf[MAX_STRING_LENGTH];
	CHAR_DATA *registar = NULL;
	int mobs, blevel, elevel, cost;

	for (registar = ch->in_room->first_person; registar != NULL;
		 registar = registar->next_in_room)
	{
		if (!IS_NPC(registar))
			continue;
		if (registar->spec_fun == spec_lookup("spec_registar"))
			break;
	}

	if (!IS_IMMORTAL(ch) &&
		(registar == NULL ||
		 registar->spec_fun != spec_lookup("spec_registar")))
	{
		chprintln(ch, "You can't do that here.");
		return FALSE;
	}

	if (!IS_IMMORTAL(ch))
	{
		if (registar->fighting != NULL)
		{
			chprintln(ch, "Wait until the fighting stops.");
			return FALSE;
		}
		if (gquest_info.last_registar == ch)
		{
			chprintln(ch, "Let someone else have a chance.");
			return FALSE;
		}
	}
	argument = one_argument(argument, arg1);
	argument = one_argument(argument, arg2);
	argument = one_argument(argument, arg3);

	if (IS_NULLSTR(arg1) || IS_NULLSTR(arg2) || IS_NULLSTR(arg3))
	{
		chprintln(ch, "Syntax: gquest start <min level> <max level> <#mobs>");
		return FALSE;
	}

	blevel = atoi(arg1);
	elevel = atoi(arg2);
	mobs = atoi(arg3);

	if (blevel <= 0 || blevel > MAX_LEVEL)
	{
		chprintlnf(ch, "Level must be between 1 and %d.", MAX_LEVEL);
		return FALSE;
	}

	if (blevel <= 0 || elevel > MAX_LEVEL)
	{
		chprintlnf(ch, "Level must be between 1 and %d.", MAX_LEVEL);
		return FALSE;
	}

	if (elevel <= blevel)
	{
		chprintln(ch, "Max level must be greater than the min level.");
		return FALSE;
	}

	if (elevel - blevel < 10)
	{
		chprintln(ch, "Level difference must 10 levels or higher.");
		return FALSE;
	}

	if (mobs < 5 || mobs > (IS_IMMORTAL(ch) ? (mobile_count / 2) : 25))
	{
		chprintlnf(ch, "Number of mobs must be between 5 and %d.",
				   IS_IMMORTAL(ch) ? (mobile_count / 2) : 25);
		return FALSE;
	}

	if (gquest_info.running != GQUEST_OFF)
	{
		chprintln(ch, "There is already a global quest running!");
		return FALSE;
	}

	cost = 5 + (mobs / 5);

	if (!IS_IMMORTAL(ch))
	{
		if (ch->pcdata->trivia < cost)
		{
			sprintf(buf,
					"$N tells you 'It costs %d Trivia Points to start a global quest with %d mobs.'",
					cost, mobs);
			act(buf, ch, NULL, registar, TO_CHAR);
			return FALSE;
		}
		else
		{
			sprintf(buf,
					"$N tells you '%d mobs have cost you %d trivia points.'",
					mobs, cost);
			act(buf, ch, NULL, registar, TO_CHAR);
			ch->pcdata->trivia -= cost;
		}
	}

	gquest_info.running = GQUEST_WAITING;
	gquest_info.minlevel = blevel;
	gquest_info.maxlevel = elevel;
	gquest_info.mob_count = mobs;
	replace_string(gquest_info.who, ch->name);
	if (!generate_gquest(ch))
	{
		if (!IS_IMMORTAL(ch))
		{
			chprintlnf(ch,
					   "Failed to start Gquest, you are being reimbursed %d TP.",
					   cost);
			ch->pcdata->trivia += cost;
		}
		else
			chprintln(ch, "Failed to start a gquest, not enogh mobs found.");
		return FALSE;
	}
	return TRUE;
}

void auto_gquest(void)
{
	CHAR_DATA *wch = NULL;
	static CHAR_DATA *registar = NULL;
	int middle = MAX_MORTAL_LEVEL / 2, maxlvl = 0;
	int minlvl = MAX_LEVEL, count = 0, lbonus = 0, half = 0;

	if (gquest_info.running != GQUEST_OFF)
		return;

	for (wch = player_first; wch != NULL; wch = wch->next_player)
	{
		if (!IS_IMMORTAL(wch))
		{
			count++;
			maxlvl = UMAX(maxlvl, wch->level);
			minlvl = UMIN(minlvl, wch->level);
		}
	}
	if (count < 1)
	{
		end_gquest(gquest_info.last_registar);
		return;
	}

	/* all this is basically so level ranges aren't to far apart */
	lbonus = number_range(5, 10);
	minlvl = UMAX(1, minlvl - lbonus);
	maxlvl = UMIN(MAX_MORTAL_LEVEL, maxlvl + lbonus);
	half = ((maxlvl - minlvl) / 2);
	middle = URANGE(minlvl, maxlvl - half, maxlvl);
	minlvl = number_range(minlvl, middle - lbonus);
	maxlvl = number_range(middle + lbonus, maxlvl);
	/* find the registar mob if he exits, (not needed only put in for RP aspects) */
	if (registar == NULL)
	{
		for (registar = char_first; registar != NULL; registar = registar->next)
		{
			if (!IS_NPC(registar))
				continue;
			if (registar->pIndexData->vnum == MOB_VNUM_REGISTAR)
				break;
		}
	}
	gquest_info.running = GQUEST_WAITING;
	gquest_info.mob_count = number_range(5, 30 - lbonus);
	gquest_info.minlevel = UMAX(1, minlvl);
	gquest_info.maxlevel = UMIN(MAX_MORTAL_LEVEL, maxlvl);
	replace_string(gquest_info.who,
				   !registar ? "AutoQuest" : registar->short_descr);
	generate_gquest(registar);
	return;
}

void post_gquest(CHAR_DATA * ch)
{
	BUFFER *output;
	GQ_DATA *gql;
	MOB_INDEX_DATA *mob;
	int i;
	GQUEST_HIST *hist;
	char shortd[MAX_INPUT_LENGTH];

	if (gquest_info.running == GQUEST_OFF || gquest_info.involved == 0)
		return;

	alloc_mem(hist, GQUEST_HIST, 1);
	sprintf(shortd, "%24s %3d %3d %4d %12s\n\r",
			str_time(current_time, -1, NULL), gquest_info.minlevel,
			gquest_info.maxlevel, gquest_info.mob_count, ch->name);
	hist->short_descr = str_dup(shortd);
	output = new_buf();
	bprintln(output, "GLOBAL QUEST INFO\n\r-----------------");
	bprintlnf(output, "Started by  : %s",
			  IS_NULLSTR(gquest_info.who) ? "Unknown" : gquest_info.who);
	bprintlnf(output, "Levels      : %d - %d", gquest_info.minlevel,
			  gquest_info.maxlevel);
	bprintln(output, "Those Playing\n\r-------------");
	for (gql = gquest_info.first; gql != NULL; gql = gql->next)
		if (gql->ch != ch)
			bprintlnf(output, "%s [%d mobs left]", gql->ch->name,
					  gquest_info.mob_count - count_gqmobs(gql));
	bprintlnf(output, "%s won the GQuest.", ch->name);
	bprintln(output, "Quest Rewards\n\r-------------");
	bprintlnf(output, "Qp Reward   : %d + 3 QPs for each target.",
			  gquest_info.qpoints);
	bprintlnf(output, "Gold Reward : %d", gquest_info.gold);
	bprintln(output, "Quest Targets\n\r-------------");
	for (i = 0; i < gquest_info.mob_count; i++)
	{
		if (gquest_info.mobs[i] < 0)
			continue;

		if ((mob = get_mob_index(gquest_info.mobs[i])) != NULL)
		{
			bprintlnf(output, "%2d) [%-20s] %-30s (level %3d)", i + 1,
					  mob->area->name, mob->short_descr, mob->level);
		}
	}
	hist->text = str_dup(buf_string(output));
	LINK(hist, gqhist_first, gqhist_last, next, prev);
	free_buf(output);
	return;
}

void new_gqlist(CHAR_DATA * ch)
{
	GQ_DATA *gql;
	int i;

	if (!ch)
		return;

	alloc_mem(gql, GQ_DATA, 1);
	alloc_mem(gql->gq_mobs, vnum_t, gquest_info.mob_count);
	for (i = 0; i < gquest_info.mob_count; i++)
		gql->gq_mobs[i] = gquest_info.mobs[i];
	gql->ch = ch;
	ch->gquest = gql;
	LINK(gql, gquest_info.first, gquest_info.last, next, prev);
	return;
}

void free_gqlist(GQ_DATA * gql)
{
	free_mem(gql->gq_mobs);
	if (gql->ch)
		gql->ch->gquest = NULL;
	UNLINK(gql, gquest_info.first, gquest_info.last, next, prev);
	free_mem(gql);
}

CH_CMD(do_gquest)
{
	char arg1[MAX_INPUT_LENGTH];
	CHAR_DATA *wch;
	MOB_INDEX_DATA *mob;
	int i = 0;
	BUFFER *output;

	if (IS_NPC(ch))
	{
		chprintln(ch, "Your the victim not the player.");
		return;
	}

	argument = one_argument(argument, arg1);

	if (IS_NULLSTR(arg1))
	{
		chprintln(ch, "Syntax: gquest join     - join a global quest\n\r"
				  "        gquest quit     - quit the global quest\n\r"
				  "        gquest info     - show global quest info\n\r"
				  "        gquest time     - show global quest time\n\r"
				  "        gquest check    - show what targets you have left\n\r"
				  "        gquest progress - show progress of other players\n\r"
				  "        gquest complete - completes the current quest\n\r"
				  "        gquest hist     - shows gquest history since last reboot\n\r"
				  "        gquest start    - starts a gquest");
		if (IS_IMMORTAL(ch))
		{
			chprintln(ch, "        gquest end      - ends the gquest (IMM)");
			chprintln(ch,
					  "        gquest next     - sets time to next gquest.");
		}

		return;
	}
	else if (!str_prefix(arg1, "start"))
	{
		start_gquest(ch, argument);
		return;
	}
	else if (!str_prefix(arg1, "next") && IS_IMMORTAL(ch))
	{
		if (gquest_info.running != GQUEST_OFF)
		{
			chprintln(ch, "Not while a gquest is running.");
			return;
		}

		i = is_number(argument) ? atoi(argument) : number_range(30, 100);
		gquest_info.timer = i;
		chprintlnf(ch, "The next gquest will start in %d minutes.",
				   gquest_info.timer);
		return;
	}
	else if (!str_prefix(arg1, "hist"))
	{
		GQUEST_HIST *hist;
		int count = 0;

		if (!gqhist_first)
		{
			chprintln(ch, "No global quests completed yet.");
			return;
		}

		output = new_buf();

		if (IS_NULLSTR(argument))
		{
			bprintln(output,
					 "Num Finished Time            Levels  Mobs Completed by\n\r"
					 "--- ------------------------ ------- ---- ------------");
			for (hist = gqhist_first; hist != NULL; hist = hist->next)
			{
				bprintf(output, "%2d) ", ++count);
				bprint(output, hist->short_descr);
			}
			bprintln(output, "Type 'gquest hist #' to view details.");
		}
		else
		{
			bool found = FALSE;

			if (!is_number(argument))
			{
				chprintln(ch, "Syntax: gquest hist #");
				return;
			}

			for (hist = gqhist_first; hist != NULL; hist = hist->next)
				if (++count == atoi(argument))
				{
					bprint(output, hist->text);
					found = TRUE;
				}

			if (!found)
				bprintln(output, "History data not found.");
		}
		sendpage(ch, buf_string(output));
		free_buf(output);
		return;
	}
	else if (gquest_info.running == GQUEST_OFF)
	{
		chprintlnf(ch,
				   "There is no global quest running.  The next Gquest will start in %d minutes.",
				   gquest_info.timer);
		return;
	}
	else if (!str_prefix(arg1, "end") && IS_IMMORTAL(ch))
	{
		end_gquest(gquest_info.last_registar);
		chprintlnf(ch,
				   "You end the global quest. Next autoquest in %d minutes.",
				   gquest_info.timer);
		announce(ch, INFO_GQUEST,
				 "$n has ended the global quest. Next gquest in %d minutes.",
				 gquest_info.timer);
		return;
	}
	else if (!str_prefix(arg1, "join"))
	{
		if (IS_QUESTOR(ch))
		{
			chprintln(ch, "Why don't you finish your other quest first.");
			return;
		}
		if (ON_GQUEST(ch))
		{
			chprintln(ch, "Your allready in the global quest.");
			return;
		}

		if (gquest_info.minlevel > ch->level ||
			gquest_info.maxlevel < ch->level)
		{
			chprintln(ch, "This gquest is not in your level range.");
			return;
		}

		if (ch->war)
		{
			chprintlnf(ch, "Your %s combat right now.\n\r",
					   war_info.status == WAR_WAITING ? "waiting for" : "in");
			return;
		}

		new_gqlist(ch);
		gquest_info.involved++;
		chprintln
			(ch,
			 "Your global quest flag is now on. Use 'gquest info' to see the quest(s).");
		announce(ch, INFO_GQUEST, "$n has joined the global quest.");
		return;
	}
	else if (!str_prefix(arg1, "quit"))
	{
		if (!ON_GQUEST(ch))
		{
			chprintln(ch, "Your not in a global quest.");
			return;
		}
		free_gqlist(ch->gquest);
		gquest_info.involved--;
		chprintln(ch,
				  "Your global quest flag is now off. Sorry you couldn't complete it.");
		announce(ch, INFO_GQUEST,
				 "$n has quit the global quest, what a sore loser.");
		return;
	}
	else if (!str_prefix(arg1, "info"))
	{
		output = new_buf();

		bprintln(output, "[ GLOBAL QUEST INFO ]");
		bprintlnf(output, "Started by  : %s",
				  IS_NULLSTR(gquest_info.who) ? "Unknown" : gquest_info.who);
		bprintlnf(output, "Playing     : %d player%s.",
				  gquest_info.involved, gquest_info.involved == 1 ? "" : "s");
		bprintlnf(output, "Levels      : %d - %d", gquest_info.minlevel,
				  gquest_info.maxlevel);
		bprintlnf(output, "Status      : %s for %d minute%s.",
				  gquest_info.running ==
				  GQUEST_WAITING ? "Waiting" : "Running",
				  gquest_info.timer, gquest_info.timer == 1 ? "" : "s");
		bprintln(output, "[ Quest Rewards ]");
		bprintlnf(output, "Qp Reward   : %d", gquest_info.qpoints);
		bprintlnf(output, "Gold Reward : %d", gquest_info.gold);
		bprintln(output, "[ Quest Targets ]");
		for (i = 0; i < gquest_info.mob_count; i++)
		{
			if (gquest_info.mobs[i] < 0)
				continue;

			if ((mob = get_mob_index(gquest_info.mobs[i])) != NULL)
			{
				bprintlnf(output,
						  "%2d) [%-20s] %-30s (level %3d)",
						  i + 1, mob->area->name,
						  smash_colour(mob->short_descr), mob->level);
			}
		}
		sendpage(ch, buf_string(output));
		free_buf(output);
		return;
	}
	else if (!str_prefix(arg1, "time"))
	{
		if (gquest_info.running == GQUEST_OFF)
			chprintlnf(ch,
					   "The next Global Quest will start in %d minute%s.\n\r",
					   gquest_info.timer, gquest_info.timer == 1 ? "" : "s");
		else
			chprintlnf(ch, "The Global Quest is %s for %d minute%s.",
					   gquest_info.running ==
					   GQUEST_WAITING ? "Waiting" : "Running",
					   gquest_info.timer, gquest_info.timer == 1 ? "" : "s");
		return;
	}
	else if (!str_prefix(arg1, "progress"))
	{
		GQ_DATA *gql;

		if (gquest_info.running != GQUEST_RUNNING)
		{
			chprintln(ch, "The global quest hasn't started yet.");
			return;
		}
		for (gql = gquest_info.first; gql != NULL; gql = gql->next)
		{
			if (gql->ch != ch)
			{
				chprintlnf(ch, "%-12s has %d of %d mobs left.",
						   gql->ch->name,
						   gquest_info.mob_count -
						   count_gqmobs(gql), gquest_info.mob_count);
			}
		}
		return;
	}
	else if (!str_prefix(arg1, "check"))
	{
		int count = 0;

		if (IS_IMMORTAL(ch) && !IS_NULLSTR(argument))
		{
			if ((wch = get_char_world(ch, argument)) == NULL || IS_NPC(wch))
			{
				chprintln(ch, "That player is not here.");
				return;
			}
		}
		else
			wch = ch;

		if (!ON_GQUEST(wch))
		{
			chprintlnf(ch, "%s aren't on a global quest.",
					   wch == ch ? "You" : wch->name);
			return;
		}

		output = new_buf();
		bprintlnf(output, "[ %s have %d of %d mobs left ]",
				  wch == ch ? "You" : wch->name,
				  gquest_info.mob_count - count_gqmobs(wch->gquest),
				  gquest_info.mob_count);
		for (i = 0; i < gquest_info.mob_count; i++)
		{
			if (wch->gquest->gq_mobs[i] == -1)
				continue;

			if ((mob = get_mob_index(wch->gquest->gq_mobs[i])) != NULL)
			{
				count++;
				bprintlnf(output,
						  "%2d) [%-20s] %-30s (level %3d)",
						  count, mob->area->name, mob->short_descr, mob->level);
			}
		}
		sendpage(ch, buf_string(output));
		free_buf(output);
		return;
	}
	else if (!str_prefix(arg1, "complete"))
	{
		int mobs;

		if (!ON_GQUEST(ch))
		{
			chprintln(ch, "Your not in a global quest.");
			return;
		}

		if ((mobs = count_gqmobs(ch->gquest)) != gquest_info.mob_count)
		{
			chprintlnf(ch,
					   "You haven't finished just yet, theres still %d mobs to kill.",
					   gquest_info.mob_count - mobs);
			return;
		}
		chprintln(ch, "YES! You have completed the global quest.");
		ch->pcdata->questpoints += gquest_info.qpoints;
		ch->gold += gquest_info.gold;
		post_gquest(ch);
		chprintlnf(ch, "You receive %d gold and %d quest points.",
				   gquest_info.gold, gquest_info.qpoints);
		end_gquest(gquest_info.last_registar);
		announce(ch, INFO_GQUEST,
				 "$n has completed the global quest, next gquest in %d minutes.",
				 gquest_info.timer);
		return;
	}
	else
		do_gquest(ch, "");
	return;
}

void end_gquest(CHAR_DATA * who)
{
	GQ_DATA *gql, *gql_next;

	gquest_info.running = GQUEST_OFF;
	replace_string(gquest_info.who, "");
	gquest_info.mob_count = 0;
	gquest_info.timer = number_range(100, 200);
	gquest_info.involved = 0;
	gquest_info.qpoints = 0;
	gquest_info.gold = 0;
	gquest_info.minlevel = 0;
	gquest_info.maxlevel = 0;
	if (gquest_info.mobs)
		free_mem(gquest_info.mobs);
	gquest_info.last_registar = who;

	for (gql = gquest_info.first; gql != NULL; gql = gql_next)
	{
		gql_next = gql->next;
		free_gqlist(gql);
	}
}

void gquest_update(void)
{
	if (gquest_info.running == GQUEST_OFF)
	{
		if (--gquest_info.timer <= 0)
			auto_gquest();
	}

	else if (gquest_info.running == GQUEST_WAITING)
	{

		gquest_info.timer--;

		if (gquest_info.timer > 0)
		{
			announce(NULL, INFO_GQUEST,
					 "%d minute%s left to join the global quest. (Levels %d - %d)",
					 gquest_info.timer, gquest_info.timer == 1 ? "" : "s",
					 gquest_info.minlevel, gquest_info.maxlevel);
		}
		else
		{
			if (gquest_info.involved == 0)
			{
				end_gquest(gquest_info.last_registar);
				announce(NULL, INFO_GQUEST,
						 "Not enough people for the global quest. The next quest will start in %d minutes.",
						 gquest_info.timer);
			}
			else
			{
				gquest_info.timer =
					number_range(4 * gquest_info.mob_count,
								 6 * gquest_info.mob_count);
				gquest_info.running = GQUEST_RUNNING;
				announce(NULL, INFO_GQUEST,
						 "The Global Quest begins! You have %d minutes to complete the task!",
						 gquest_info.timer);
			}
		}
	}
	else if (gquest_info.running == GQUEST_RUNNING)
	{
		if (gquest_info.involved == 0)
		{
			end_gquest(gquest_info.last_registar);
			announce(NULL, INFO_GQUEST,
					 "No one left in the Global Quest, next quest will start in %d minutes.",
					 gquest_info.timer);
			return;
		}

		switch (gquest_info.timer)
		{
		case 0:
			end_gquest(gquest_info.last_registar);
			announce(NULL, INFO_GQUEST,
					 "Time has run out on the Global Quest, next quest will start in %d minutes.",
					 gquest_info.timer);
			return;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 10:
		case 15:
			announce(NULL, INFO_GQUEST,
					 "%d minute%s remaining in the global quest.",
					 gquest_info.timer, gquest_info.timer > 1 ? "s" : "");
		default:
			gquest_info.timer--;
			break;
		}
		return;
	}
}

#define MAX_GQUEST_MOB_SEARCH    mobile_count

bool generate_gquest(CHAR_DATA * who)
{
	CHAR_DATA *victim = NULL;
	vnum_t *vnums;
	int mob_count, randm;
	int i;

	mob_count = 0;
	alloc_mem(vnums, vnum_t, MAX_GQUEST_MOB_SEARCH);

	for (victim = char_first; victim; victim = victim->next)
	{
		if (!IS_NPC(victim) || victim->gquest
			|| victim->level > (gquest_info.maxlevel + 10)
			|| victim->level < (gquest_info.minlevel - 10)
			|| (victim->pIndexData == NULL
				|| victim->in_room == NULL
				|| victim->pIndexData->pShop != NULL)
			|| victim->pIndexData->vnum < 100
			|| IS_SET(victim->in_room->room_flags, ROOM_PET_SHOP)
			|| victim->in_room->clan != NULL
			|| IS_SET(victim->imm_flags, IMM_WEAPON | IMM_MAGIC)
			|| IS_SET(victim->act,
					  ACT_TRAIN | ACT_PRACTICE | ACT_IS_HEALER |
					  ACT_PET | ACT_GAIN)
			|| IS_SET(victim->affected_by, AFF_CHARM)
			|| (IS_SET(victim->act, ACT_SENTINEL)
				&& IS_SET(victim->in_room->room_flags,
						  ROOM_PRIVATE | ROOM_SOLITARY | ROOM_SAFE)))
			continue;
		vnums[mob_count] = victim->pIndexData->vnum;
		mob_count++;
		if (mob_count >= MAX_GQUEST_MOB_SEARCH)
			break;
	}

	if (mob_count < 5)
	{
		end_gquest(who);
		free_mem(vnums);
		return FALSE;
	}
	else if (mob_count < gquest_info.mob_count)
	{
		gquest_info.mob_count = mob_count;
	}

	alloc_mem(gquest_info.mobs, vnum_t, gquest_info.mob_count);

	for (i = 0; i < gquest_info.mob_count; i++)
	{
		randm = number_range(0, mob_count - 1);
		while (!is_random_gqmob(vnums[randm]))
			randm = number_range(0, mob_count - 1);

		gquest_info.mobs[i] = vnums[randm];
	}

	gquest_info.qpoints = number_range(15, 30) * gquest_info.mob_count;
	gquest_info.gold = number_range(100, 150) * gquest_info.mob_count;
	gquest_info.timer = 3;
	announce(who, INFO_GQUEST,
			 "%s Global Quest for levels %d to %d%s.  Type 'GQUEST INFO' to see the quest.",
			 !who ? "A" : "$n announces a", gquest_info.minlevel,
			 gquest_info.maxlevel, !who ? " has started" : "");
	announce(who, INFO_GQUEST | INFO_PRIVATE,
			 "You announce a Global Quest for levels %d to %d with %d targets.\n\r",
			 gquest_info.minlevel, gquest_info.maxlevel, gquest_info.mob_count);
	free_mem(vnums);
	return TRUE;
}

int is_gqmob(GQ_DATA * gql, vnum_t vnum)
{
	int i;

	if (gquest_info.running == GQUEST_OFF)
		return -1;

	for (i = 0; i < gquest_info.mob_count; i++)
	{
		if (gql)
		{
			if (gql->gq_mobs[i] == vnum)
				return i;
		}
		else
		{
			if (gquest_info.mobs[i] == vnum)
				return i;
		}
	}

	return -1;
}

int count_gqmobs(GQ_DATA * gql)
{
	int i, count = 0;

	if (gquest_info.running == GQUEST_OFF || !gql)
		return 0;

	for (i = 0; i < gquest_info.mob_count; i++)
		if (gql->gq_mobs[i] == -1)
			count++;

	return count;
}

bool is_random_gqmob(vnum_t vnum)
{
	int i;

	if (gquest_info.running == GQUEST_OFF)
		return FALSE;

	if (vnum == -1 || get_mob_index(vnum) == NULL)
		return FALSE;

	for (i = 0; i < gquest_info.mob_count; i++)
		if (gquest_info.mobs[i] == vnum)
			return FALSE;

	return TRUE;
}