raferquest.c

toc/code/raferquest.c · 251.4 KB

From the archive fear2.1.3.tar.gz

Download the archive   « Back to the archive contents

/****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |   \\._.//   *
 * -----------------------------------------------------------|   (0...0)   *
 * SMAUG 1.4 (C) 1994, 1995, 1996, 1998  by Derek Snider      |    ).:.(    *
 * -----------------------------------------------------------|    {o o}    *
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |   / ' ' \   *
 * Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek,      |~'~.VxvxV.~'~*
 * Tricops and Fireblade                                      |             *
 * ------------------------------------------------------------------------ *
 * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
 * Chastain, Michael Quan, and Mitchell Tse.                                *
 * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
 * Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
 * ------------------------------------------------------------------------ *
 * Rafermand Coded by: Xerves                                               *
 * --------------------------------------------------------------------------
 *			                   Quest System for 2.1                         *
 ****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#include <dirent.h>
#include "mud.h"

int top_area;
int top_quest_vnum;
int eqload;
extern int top_affect;
int ochange;
int raferquest_local_ovnum;
int global_drop_equip_message;

void adjust_static_quest_mob(CHAR_DATA *ch)
{
   MOB_INDEX_DATA *pMobIndex = ch->pIndexData;
   int hit;
   
   STRFREE(pMobIndex->player_name);
   STRFREE(pMobIndex->short_descr);
   STRFREE(pMobIndex->long_descr);
   STRFREE(pMobIndex->description);
   pMobIndex->player_name = STRALLOC(ch->name);
   pMobIndex->short_descr = STRALLOC(ch->short_descr);
   pMobIndex->long_descr = STRALLOC(ch->long_descr);
   pMobIndex->description = STRALLOC(ch->description);
   pMobIndex->miflags = ch->miflags;
   pMobIndex->act = ch->act;
   pMobIndex->affected_by = ch->affected_by;
   pMobIndex->spec_fun = ch->spec_fun;
   pMobIndex->tohitbash = ch->tohitbash;
   pMobIndex->tohitslash = ch->tohitslash;
   pMobIndex->tohitstab = ch->tohitstab;
   pMobIndex->ac = ch->armor;
   pMobIndex->max_move = ch->max_move;
   pMobIndex->gold = ch->gold;
   pMobIndex->position = ch->position;
   pMobIndex->defposition = ch->defposition;
   pMobIndex->perm_str = ch->perm_str;
   pMobIndex->perm_dex = ch->perm_dex;
   pMobIndex->perm_int = ch->perm_int;
   pMobIndex->perm_wis = ch->perm_wis;
   pMobIndex->perm_cha = ch->perm_cha;
   pMobIndex->perm_con = ch->perm_con;
   pMobIndex->perm_lck = ch->perm_lck;
   pMobIndex->perm_agi = ch->perm_agi;
   pMobIndex->race = ch->race;
   pMobIndex->xflags = ch->xflags;
   pMobIndex->resistant = ch->resistant;
   pMobIndex->immune = ch->immune;
   pMobIndex->susceptible = ch->susceptible;
   pMobIndex->attacks = ch->attacks;
   pMobIndex->defenses = ch->defenses;   
   hit = ch->hit * 2 / 10;
   pMobIndex->hitnodice = UMAX(1, hit / 10);
   pMobIndex->hitsizedice = UMAX(1, ((hit*2) - UMAX(1, (hit/10))) / UMAX(1, (hit/10)));
   pMobIndex->hitplus = ch->hit * 8 / 10;
   return;
}
//Need to copy the obj values over the the pIndexData to make sure they save...
void adjust_static_area_obj(OBJ_DATA *obj)
{ 
   OBJ_INDEX_DATA *iobj;
   AFFECT_DATA *paf, *cpaf;
   
   iobj = obj->pIndexData;
   STRFREE(iobj->name);
   STRFREE(iobj->short_descr);
   STRFREE(iobj->description);
   STRFREE(iobj->action_desc);
   iobj->name = STRALLOC(obj->name);
   iobj->short_descr = STRALLOC(obj->short_descr);
   iobj->description = STRALLOC(obj->description);
   iobj->action_desc = STRALLOC(obj->action_desc);
   iobj->item_type = obj->item_type;
   iobj->extra_flags = obj->extra_flags;
   iobj->wear_flags = obj->wear_flags;
   iobj->value[0] = obj->value[0];
   iobj->value[1] = obj->value[1];
   iobj->value[2] = obj->value[2];
   iobj->value[3] = obj->value[3];
   iobj->value[4] = obj->value[4];
   iobj->value[5] = obj->value[5];
   iobj->value[6] = obj->value[6];
   iobj->value[7] = obj->value[7];
   iobj->value[8] = obj->value[8];
   iobj->value[9] = obj->value[9];
   iobj->value[10] = obj->value[10];
   iobj->value[11] = obj->value[11];
   iobj->value[12] = obj->value[12];
   iobj->value[13] = obj->value[13];
   iobj->imbueslots = obj->imbueslots;
   iobj->weight = obj->weight;
   iobj->cost = obj->cost;
   iobj->first_affect = NULL;
   iobj->last_affect = NULL;
   for (cpaf = obj->first_affect; cpaf; cpaf = cpaf->next)
   {
      CREATE(paf, AFFECT_DATA, 1);
      paf->type = cpaf->type;
      paf->duration = cpaf->duration;
      paf->location = cpaf->location;
      paf->modifier = cpaf->modifier;
      paf->bitvector = cpaf->bitvector;
      LINK(paf, iobj->first_affect, iobj->last_affect, next, prev);
      top_affect++;
   }
   return;
}

void copy_static_area_obj(CHAR_DATA *ch, OBJ_DATA *obj)
{
   OBJ_INDEX_DATA *nobj;
   OBJ_DATA *iobj;
   AFFECT_DATA *paf, *cpaf;
   
   nobj = make_object(raferquest_local_ovnum++, 0, "Quest Obj", 0);
   xREMOVE_BIT(nobj->extra_flags, ITEM_PROTOTYPE);
   iobj = create_object(nobj, 1);
   STRFREE(iobj->name);
   STRFREE(iobj->short_descr);
   STRFREE(iobj->description);
   STRFREE(iobj->action_desc);
   iobj->name = STRALLOC(obj->name);
   iobj->short_descr = STRALLOC(obj->short_descr);
   iobj->description = STRALLOC(obj->description);
   iobj->action_desc = STRALLOC(obj->action_desc);
   iobj->item_type = obj->item_type;
   iobj->extra_flags = obj->extra_flags;
   iobj->wear_flags = obj->wear_flags;
   iobj->value[0] = obj->value[0];
   iobj->value[1] = obj->value[1];
   iobj->value[2] = obj->value[2];
   iobj->value[3] = obj->value[3];
   iobj->value[4] = obj->value[4];
   iobj->value[5] = obj->value[5];
   iobj->value[6] = obj->value[6];
   iobj->value[7] = obj->value[7];
   iobj->value[8] = obj->value[8];
   iobj->value[9] = obj->value[9];
   iobj->value[10] = obj->value[10];
   iobj->value[11] = obj->value[11];
   iobj->value[12] = obj->value[12];
   iobj->value[13] = obj->value[13];
   iobj->weight = obj->weight;
   iobj->cost = obj->cost;
   iobj->first_affect = NULL;
   iobj->last_affect = NULL;
   for (cpaf = obj->first_affect; cpaf; cpaf = cpaf->next)
   {
      CREATE(paf, AFFECT_DATA, 1);
      paf->type = cpaf->type;
      paf->duration = cpaf->duration;
      paf->location = cpaf->location;
      paf->modifier = cpaf->modifier;
      paf->bitvector = cpaf->bitvector;
      LINK(paf, iobj->first_affect, iobj->last_affect, next, prev);
      top_affect++;
   }
   adjust_static_area_obj(iobj);
   unequip_char(ch, obj);
   separate_obj(obj);
   obj_from_char(obj);
   extract_obj(obj);
   obj_to_char(iobj, ch);
   wear_obj(ch, iobj, TRUE, -1);
}
   

void fwrite_qmob_data()
{
   FILE *fp;
   char filename[MIL];
   QMOB_DATA *qmob;
   
   sprintf(filename, "%s", QMOB_FILE);
   if ((fp = fopen(filename, "w")) == NULL)
   {   
      bug("Cannot open: %s for writing", filename);
      return;
   }
   for (qmob = first_qmob; qmob; qmob = qmob->next)
   {
      fprintf(fp, "#MOB\n\r");
      fprintf(fp, "Boss         %d\n", qmob->boss);
      fprintf(fp, "Hidiff       %d\n", qmob->hidiff);
      fprintf(fp, "Lowdiff      %d\n", qmob->lowdiff);
      fprintf(fp, "Name         %s~\n", qmob->name);
      fprintf(fp, "Race         %d\n", qmob->race);
      fprintf(fp, "Sex          %d\n", qmob->sex);
      fprintf(fp, "Flags        %s\n", print_bitvector(&qmob->flags));
      fprintf(fp, "End\n\n");
   }
   fprintf(fp, "#END\n");
   fclose(fp);
   return;
}

int is_in_range(int lowx, int hix, int lowy, int hiy)
{
   int x;
   
   for (x = lowy; x <= hiy; x++)
   {
      if (x >= lowx && x <= hix)
         return 1;
   }
   return 0;
}

char *print_qmob_flags(QMOB_DATA *qmob)
{
   static char buf[MSL];
   char sbuf[10];
   int x;
   
   strcpy(buf, "");
   
   for (x = 0; x < MAX_BITS; x++)
   {
      if (xIS_SET(qmob->flags, x))
      {
         sprintf(sbuf, "%d ", x+1);
         strcat(buf, sbuf);
      }
   }
   return buf;
}

char *print_qobj_flags(QOBJ_DATA *qobj)
{
   static char buf[MSL];
   char sbuf[10];
   int x;
   
   strcpy(buf, "");
   
   for (x = 0; x < MAX_BITS; x++)
   {
      if (xIS_SET(qobj->flags, x))
      {
         sprintf(sbuf, "%d ", x+1);
         strcat(buf, sbuf);
      }
   }
   for (x = 0; x < MAX_BITS; x++)
   {
      if (xIS_SET(qobj->flags2, x))
      {
         sprintf(sbuf, "%d ", x+MAX_BITS+1);
         strcat(buf, sbuf);
      }
   }
   return buf;
}
   
void do_qmob(CHAR_DATA *ch, char *argument)
{
   char arg1[MIL];
   char arg2[MIL];
   char arg3[MIL];
   char arg4[MIL];
   char arg5[MIL];
   char arg6[MIL];
   int cnt = 0;
   int race;
   QMOB_DATA *qmob;
   
   if (argument[0] == '\0')
   {
       send_to_char("Syntax:  qmob list [low diff] [hi diff]\n\r", ch);
       send_to_char("Syntax:  qmob add <boss #> <lowdiff> <hidiff> <race> <sex> <name>\n\r", ch);
       send_to_char("Syntax:  qmob delete <num>\n\r", ch);
       send_to_char("Syntax:  qmob edit <num> [boss/lodiff/hidiff/race/sex/name/flags/aflags] <value>\n\r", ch);
       ch_printf(ch, "Boss (0 - Reg, 1 - Captain, 2 - Boss) Difficulty (1-%d) Sex(0-2)\n\r", MAX_QDIFF);
       return;
   }
   argument = one_argument(argument, arg1);
   argument = one_argument(argument, arg2);
   argument = one_argument(argument, arg3);
   
   if (!str_cmp(arg1, "edit"))
   {
      if (atoi(arg2) < 1)
      {
         send_to_char("Need to choose the number listed in qmob list\n\r", ch);
         return;
      }
      for (qmob = first_qmob; qmob; qmob = qmob->next)
      {
         if (++cnt == atoi(arg2))
         {
            if (!str_cmp(arg3, "flags"))
            {
               xCLEAR_BITS(qmob->flags);
               for (;;)
               {
                  argument = one_argument(argument, arg4);  
                  if (arg4[0] == '\0')
                     break;
                  else
                     xSET_BIT(qmob->flags, atoi(arg4)-1);
               }
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "aflags"))
            {
               for (;;)
               {
                  argument = one_argument(argument, arg4);  
                  if (arg4[0] == '\0')
                     break;
                  else
                     xTOGGLE_BIT(qmob->flags, atoi(arg4)-1);
               }
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "boss"))
            {
               if (atoi(argument) < 0 || atoi(argument) > 2)
               {
                  send_to_char("Boss value is 0 - 2\n\r", ch);
                  return;
               }      
               qmob->boss = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "lodiff"))
            {
               if (atoi(argument) < 1 || atoi(argument) > MAX_QDIFF)
               {
                  ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
                  return;
               }    
               if (atoi(argument) > qmob->hidiff)
               {
                  send_to_char("Lowdiff has to be less than or equal to hidiff\n\r", ch);
                  return;
               }
               qmob->lowdiff = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "hidiff"))
            {
               if (atoi(argument) < 1 || atoi(argument) > MAX_QDIFF)
               {
                  ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
                  return;
               }    
               if (atoi(argument) < qmob->lowdiff)
               {
                  send_to_char("Hidiff has to be greater than or equal to lowdiff\n\r", ch);
                  return;
               }
               qmob->hidiff = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "race"))
            {
               race = get_npc_race(argument);
               if (race < 0)
               {
                  send_to_char("You must supply race via the name of the race.\n\r", ch);
                  return;
               }   
               qmob->race = race;
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "name"))
            {
               STRFREE(qmob->name);
               qmob->name = STRALLOC(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
            if (!str_cmp(arg3, "sex"))
            {
               if (atoi(argument) < 0 || atoi(argument) > 2)
               {
                  send_to_char("Range is 0 to 2.\n\r", ch);
                  return;
               }
               qmob->sex = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qmob_data();
               return;
            }
         }
      }
   }
   argument = one_argument(argument, arg4);
   argument = one_argument(argument, arg5);
   argument = one_argument(argument, arg6);
   if (!str_cmp(arg1, "delete"))
   {
      if (atoi(arg2) < 1)
      {
         send_to_char("Need to choose the number listed in qmob list\n\r", ch);
         return;
      }
      for (qmob = first_qmob; qmob; qmob = qmob->next)
      {
         if (++cnt == atoi(arg2))
         {
            STRFREE(qmob->name);
            UNLINK(qmob, first_qmob, last_qmob, next, prev);
            DISPOSE(qmob);
            fwrite_qmob_data();
            send_to_char("Done.\n\r", ch);
            return;
         }
      }
      send_to_char("That number does not exist, check qmob list again.\n\r", ch);
      return;
   }
   if (!str_cmp(arg1, "add"))
   {
      if (atoi(arg2) < 0 || atoi(arg2) > 2)
      {
         send_to_char("Boss value is 0 - 2\n\r", ch);
         return;
      }
      if (atoi(arg3) < 1 || atoi(arg3) > MAX_QDIFF)
      {
         ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg4) < 1 || atoi(arg4) > MAX_QDIFF)
      {
         ch_printf(ch, "Difficulty value is 1 - %dF\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg3) > atoi(arg4))
      {
         send_to_char("Lowdiff has to be less than or equal to hidiff\n\r", ch);
         return;
      }
      race = get_npc_race(arg5);
      if (race < 0)
      {
         send_to_char("You must supply race via the name of the race.\n\r", ch);
         return;
      }
      if (atoi(arg6) < 0 || atoi(arg6) > 2)
      {
         send_to_char("Sex ranges from 0 to 2.\n\r", ch);
         return;
      }
      CREATE(qmob, QMOB_DATA, 1);
      qmob->boss = atoi(arg2);
      qmob->lowdiff = atoi(arg3);
      qmob->hidiff = atoi(arg4);
      qmob->race = race;
      qmob->sex = atoi(arg6);
      qmob->name = STRALLOC(argument);
      LINK(qmob, first_qmob, last_qmob, next, prev);
      fwrite_qmob_data();
      send_to_char("Done.\n\r", ch);
      return;
   }     
   
   if (!str_cmp(arg1, "list"))
   {
      if (atoi(arg2) > MAX_QDIFF || atoi(arg3) > MAX_QDIFF)
      {
         ch_printf(ch, "Range is 0 to %d\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg2) < 1 || atoi(arg3) < 1)
      {
         send_to_char("&c&wNum   Name                             Boss  Lo  Hi  Sex  Race          Flags\n\r------------------------------------------------------------------------------------------\n\r", ch);
         for (qmob = first_qmob; qmob; qmob = qmob->next)
         {
            ch_printf(ch, "[%-3d] %-30s > %-4s  %-2d  %-2d  %-s   %-12s  %s\n\r", ++cnt, qmob->name, qmob->boss > 0 ? qmob->boss > 1 ? "&w&RBoss&c&w" : "&w&CCapt&c&w" : "&w&GRegu&c&w", qmob->lowdiff, qmob->hidiff, qmob->sex > 0 ? qmob->sex > 1 ? "&w&PFe&c&w" : "&w&CMa&c&w" : "&w&WNe&c&w", print_npc_race(qmob->race), print_qmob_flags(qmob));
         }
      }
      else
      {
         send_to_char("&c&wNum   Name                             Boss  Hi  Lo  Sex  Race          Flags\n\r------------------------------------------------------------------------------------------\n\r", ch);
         for (qmob = first_qmob; qmob; qmob = qmob->next)
         {
            cnt++;
            if (is_in_range(qmob->lowdiff, qmob->hidiff, atoi(arg2), atoi(arg3)))
            {
               ch_printf(ch, "[%-3d] %-30s > %-4s  %-2d  %-2d  %-s   %-12s  %s\n\r", cnt, qmob->name, qmob->boss > 0 ? qmob->boss > 1 ? "&w&RBoss&c&w" : "&w&CCapt&c&w" : "&w&GRegu&c&w", qmob->lowdiff, qmob->hidiff, qmob->sex > 0 ? qmob->sex > 1 ? "&w&PFe&c&w" : "&w&CMa&c&w" : "&w&WNe&c&w", print_npc_race(qmob->race), print_qmob_flags(qmob));
            }
         }
      }      
      return;
   }
   do_qmob(ch, "");
   return;
}

#if defined(KEY)
#undef KEY
#endif

#define KEY( literal, field, value )					\
				if ( !str_cmp( word, literal ) )	\
				{					\
				    field  = value;			\
				    fMatch = TRUE;			\
				    break;				\
				}
				
void fread_qobj_data(FILE *fp)
{
   bool fMatch;  
   char buf[MSL];   
   char *word;
   QOBJ_DATA *qobj;
   
   CREATE(qobj, QOBJ_DATA, 1);
   
   for (;;)
   {
      word = feof(fp) ? "End" : fread_word(fp);
      fMatch = FALSE;

      switch (UPPER(word[0]))
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol(fp);
            break;
            
         case 'B':
            KEY("Boss", qobj->boss, fread_number(fp));
            break;
            
         case 'F':
            KEY("Flags", qobj->flags, fread_bitvector(fp));            
            KEY("Flags2", qobj->flags2, fread_bitvector(fp));       
            break;
            
         case 'H':
            KEY("Hidiff", qobj->hidiff, fread_number(fp));
            break;
            
         case 'L':
            KEY("Lowdiff", qobj->lowdiff, fread_number(fp));
            break;
            
         case 'N':
            KEY("Name", qobj->name, fread_string(fp));
            break;
            
         case 'R':
            KEY("Race", qobj->race, fread_number(fp));
            break;
            
         case 'Q':
            KEY("QPS", qobj->qps, fread_number(fp));
            break;
            
         case 'T':
            KEY("Type", qobj->type, fread_number(fp));
            break;
            
         case 'G':
            KEY("Gold", qobj->gold, fread_number(fp));
            break;
            
         case 'S':
            if (!str_cmp(word, "Scroll"))
            {
               qobj->value[1] = skill_lookup(fread_word(fp));
               qobj->value[2] = skill_lookup(fread_word(fp));
               qobj->value[3] = skill_lookup(fread_word(fp));
               fMatch = TRUE;
            }
            break;
            
         case 'W':
            if (!str_cmp(word, "Weapon"))
            {
               qobj->value[4] = skill_lookup(fread_word(fp));
               fMatch = TRUE;
            }
            KEY("Weight", qobj->weight, fread_float(fp));
            break;
            
         case 'V':
            if (!str_cmp(word, "Value"))
            {
               char *ln;
               int x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14;
               ln = fread_line(fp);
               x1 = x2 = x3 = x4 = x5 = x6 = x7 = x8 = x9 = x10 = x11 = x12 = x13 = x14 = 0;
               sscanf(ln, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d", 
                  &x1, &x2, &x3, &x4, &x5, &x6, &x7, &x8, &x9, &x10, &x11, &x12, &x13, &x14);
               qobj->value[0] = x1;
               qobj->value[1] = x2;
               qobj->value[2] = x3;
               qobj->value[3] = x4;
               qobj->value[4] = x5;
               qobj->value[5] = x6;
               qobj->value[6] = x7;
               qobj->value[7] = x8;
               qobj->value[8] = x9;
               qobj->value[9] = x10;
               qobj->value[10] = x11;
               qobj->value[11] = x12;
               qobj->value[12] = x13;
               qobj->value[13] = x14;
               fMatch = TRUE;
            }
            break;
            
         case 'E':
            if (!str_cmp(word, "End"))
            {
               LINK(qobj, first_qobj, last_qobj, next, prev);
               return;       
            }
      }
      if (!fMatch)
      {
         sprintf(buf, "fread_qmob_data: no match: %s", word);
         bug(buf, 0);
      }
   }
}        
                   
void load_qobj_data()
{
   FILE *fp;
   char filename[MIL];
   
   sprintf(filename, "%s", QOBJ_FILE);
   if ((fp = fopen(filename, "r")) != NULL)
   {
      for (;;)
      {
         char letter;
         char *word;

         letter = fread_letter(fp);
         if (letter == '*')
         {
            fread_to_eol(fp);
            continue;
         }

         if (letter != '#')
         {
            bug("load_qobj_data: # not found.", 0);
            break;
         }

         word = fread_word(fp);
         if (!str_cmp(word, "OBJ"))
         {
            fread_qobj_data(fp);
            continue;
         }
         else if (!str_cmp(word, "END"))
         {
            break;
         }
         else
         {
            bug("load_qobj_data: bad section.", 0);
            continue;
         }
      }
   }
   else
   {
      bug("Cannot open the qobj data file", 0);
      return;
   }
   fclose(fp);
}   				

void fwrite_qobj_data()
{
   FILE *fp;
   char filename[MIL];
   QOBJ_DATA *qobj;
   sprintf(filename, "%s", QOBJ_FILE);
   if ((fp = fopen(filename, "w")) == NULL)
   {   
      bug("Cannot open: %s for writing", filename);
      return;
   }
   for (qobj = first_qobj; qobj; qobj = qobj->next)
   {
      fprintf(fp, "#OBJ\n\r");
      fprintf(fp, "Type         %d\n", qobj->type);
      fprintf(fp, "Gold         %d\n", qobj->gold);
      fprintf(fp, "Weight       %f\n", qobj->weight);
      fprintf(fp, "Boss         %d\n", qobj->boss);
      fprintf(fp, "Hidiff       %d\n", qobj->hidiff);
      fprintf(fp, "Lowdiff      %d\n", qobj->lowdiff);
      fprintf(fp, "Name         %s~\n", qobj->name);
      fprintf(fp, "QPS          %d\n", qobj->qps);
      fprintf(fp, "Race         %d\n", qobj->race);
      fprintf(fp, "Value        %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", qobj->value[0], qobj->value[1], qobj->value[2],
         qobj->value[3], qobj->value[4], qobj->value[5], qobj->value[6], qobj->value[7], qobj->value[8], qobj->value[9], 
         qobj->value[10], qobj->value[11], qobj->value[12], qobj->value[13]);
      if (qobj->type == 3 || qobj->type == 4) //Potion or Scroll
      {
         fprintf(fp, "Scroll       '%s' '%s' '%s'\n", IS_VALID_SN(qobj->value[1]) ? skill_table[qobj->value[1]]->name : "NONE",
                    IS_VALID_SN(qobj->value[2]) ? skill_table[qobj->value[2]]->name : "NONE",
                    IS_VALID_SN(qobj->value[3]) ? skill_table[qobj->value[3]]->name : "NONE");    
      }
      if (qobj->type == 1) //Weapon
      {
         fprintf(fp, "Weapon       '%s'\n", IS_VALID_SN(qobj->value[4]) ? skill_table[qobj->value[4]]->name : "NONE");
      }
      fprintf(fp, "Flags        %s\n", print_bitvector(&qobj->flags));
      fprintf(fp, "Flags2       %s\n", print_bitvector(&qobj->flags2));
      fprintf(fp, "End\n\n");
   }
   fprintf(fp, "#END\n");
   fclose(fp);
   return;
}

void fread_quest_data(FILE *fp)
{
   bool fMatch;  
   char buf[MSL];   
   char *word;
   QUEST_DATA *quest;
   char *ln;
   int x1, x2, x3, x4, x5, x6;
   AREA_DATA *area;
   
   CREATE(quest, QUEST_DATA, 1);
   
   for (;;)
   {
      word = feof(fp) ? "End" : fread_word(fp);
      fMatch = FALSE;

      switch (UPPER(word[0]))
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol(fp);
            break;
            
         case 'A':
            if (!str_cmp(word, "Area"))
            {
               int vnum = fread_number(fp);
               
               for (area = first_area; area; area = area->next)
               {
                  if (area->low_r_vnum == vnum)
                     quest->questarea = area;
               }
               fMatch = TRUE;
               if (!quest->questarea)
                  bug("fread_quest_data:  No area for vnum %d", vnum);
            }      
            break;
            
         case 'D':
            KEY("Difficulty", quest->difficulty, fread_number(fp));
            break;
            
         case 'K':
            KEY("Killed", quest->killed, fread_number(fp));
            break;
            
         case 'M':
            KEY("Map", quest->map, fread_number(fp));
            KEY("Mission", quest->mission, fread_number(fp));
            break;
            
         case 'P':
            if (!str_cmp(word, "Player"))
            {
               ln = fread_line(fp);
               x1 = x2 = x3 = x4 = x5 = x6 = 0;
               sscanf(ln, "%d %d %d %d %d %d", 
                  &x1, &x2, &x3, &x4, &x5, &x6);
               quest->player[0] = x1;
               quest->player[1] = x2;
               quest->player[2] = x3;
               quest->player[3] = x4;
               quest->player[4] = x5;
               quest->player[5] = x6;
               fMatch = TRUE;
            }
            break;
            
         case 'Q':
            if (!str_cmp(word, "Qp"))
            {
               ln = fread_line(fp);
               x1 = x2 = x3 = x4 = x5 = x6 = 0;
               sscanf(ln, "%d %d %d %d %d %d", 
                  &x1, &x2, &x3, &x4, &x5, &x6);
               quest->qp[0] = x1;
               quest->qp[1] = x2;
               quest->qp[2] = x3;
               quest->qp[3] = x4;
               quest->qp[4] = x5;
               quest->qp[5] = x6;
               fMatch = TRUE;
            }
            break;
            
         case 'T':
            KEY("Timeleft", quest->timeleft, fread_number(fp));
            KEY("Traveltime", quest->traveltime, fread_number(fp));
            KEY("Tillnew", quest->tillnew, fread_number(fp));
            KEY("Tokill", quest->tokill, fread_number(fp));
            break;
            
         case 'X':
            KEY("X", quest->x, fread_number(fp));
            break;
            
         case 'Y':
            KEY("Y", quest->y, fread_number(fp));
            break;
            
         case 'E':
            if (!str_cmp(word, "End"))
            {
               LINK(quest, first_quest, last_quest, next, prev);
               return;       
            }
      }
      if (!fMatch)
      {
         sprintf(buf, "fread_quest_data: no match: %s", word);
         bug(buf, 0);
      }
   }
}
extern bool fBootDb;
extern char strArea[MIL];
void fix_exits args((void));

void load_quest_contents()
{
   FILE *fp;
   char filename[MIL];
   CHAR_DATA *mob;
   OBJ_DATA *obj;
   OBJ_DATA *nobj;
   
   if ((fp = fopen(QUEST_LAREA, "r")) != NULL)
   {
      for (;;)
      {
         strcpy(strArea, fread_word(fp));
         if (strArea[0] == '$')
            break;
         fBootDb = TRUE;
         load_area_file(last_area, strArea);
         fBootDb = FALSE;
         remove(strArea);
      }
      fclose(fp);
      fix_exits();
      remove(QUEST_LAREA);
   }
   sprintf(filename, "%s", QUEST_OFILE);
   if ((fp = fopen(filename, "r")) != NULL)
   {
      for (;;)
      {
         char letter;
         char *word;
         
         letter = fread_letter(fp);
         if (letter == '*')
         {
            fread_to_eol(fp);
            continue;
         }

         if (letter != '#')
         {
            bug("load_quest_contents: # not found.", 0);
            break;
         }

         word = fread_word(fp);
         if (!strcmp(word, "GROUND"))
            fread_obj(NULL, fp, OS_GROUND);
         else if (!strcmp(word, "OBJECT"))
            fread_obj(NULL, fp, OS_CARRY);
         else if (!strcmp(word, "END"))  
         {
            break;
         }
         else
         {
            bug("Load_quest_content: objs: bad section.", 0);
            break;
         }
      }
      fclose(fp);
      remove(filename);
   }
   sprintf(filename, "%s", QUEST_MFILE);
   if ((fp = fopen(filename, "r")) != NULL)
   {
      for (;;)
      {
         char letter;
         char *word;
         
         letter = fread_letter(fp);
         if (letter == '*')
         {
            fread_to_eol(fp);
            continue;
         }

         if (letter != '#')
         {
            bug("load_quest_contents: # not found.", 0);
            break;
         }

         word = fread_word(fp);
         if (!strcmp(word, "MOBILE"))
         {
            mob = fread_mobile(fp);
            for (obj = mob->first_carrying; obj; obj = nobj)
            {
               nobj = obj->next_content;
               wear_obj(mob, obj, TRUE, -1);
            }
         }

         else if (!strcmp(word, "END"))
         {
            break;
         }
         else
         {
            bug("Load_quest_content: mobs: bad section.", 0);
            break;
         }
      }
      fclose(fp);
      remove(filename);
   }
}
void load_quest_data()
{
   FILE *fp;
   char filename[MIL];
   int first = 1;
   
   sprintf(filename, "%s", QUEST_FILE);
   if ((fp = fopen(filename, "r")) != NULL)
   {
      for (;;)
      {
         char letter;
         char *word;
         
         if (first == 1)
         {
            word = fread_word(fp);
            if (!str_cmp(word, "QuestVnum"))
            {
               top_quest_vnum = fread_number(fp);
               first = 0;
               continue;
            }      
            else
            {
               bug("load_quest_data:  First line didn't contain the top vnum.");
               fclose(fp);
               remove(filename);
               return;
            }
         }
         letter = fread_letter(fp);
         if (letter == '*')
         {
            fread_to_eol(fp);
            continue;
         }

         if (letter != '#')
         {
            bug("load_quest_data: # not found.", 0);
            break;
         }

         word = fread_word(fp);
         if (!str_cmp(word, "QUEST"))
         {
            fread_quest_data(fp);
            continue;
         }
         else if (!str_cmp(word, "END"))
         {
            break;
         }
         else
         {
            bug("load_quest_data: bad section.", 0);
            continue;
         }
      }
      fclose(fp);
      remove(filename);
   }
   else
      return;
}
void save_quest_contents()
{
   FILE *fp;
   char filename[MIL];
   AREA_DATA *area;
   CHAR_DATA *ch;
   OBJ_DATA *obj;          
   
   sprintf(filename, "%s", QUEST_MFILE);
   if ((fp = fopen(filename, "w")) == NULL)
   {   
      bug("Cannot open: %s for writing", filename);
      return;
   }
   for (area = first_area; area; area = area->next)
   {
      if (area->low_r_vnum >= START_QUEST_VNUM && area->hi_r_vnum <= END_QUEST_VNUM)
      {
         for (ch = first_char; ch; ch = ch->next)
         {
            if (ch->in_room && ch->in_room->vnum && (ch->in_room->vnum >= area->low_r_vnum && ch->in_room->vnum <= area->hi_r_vnum))
            {
               if (!IS_NPC(ch) || ch == supermob || xIS_SET(ch->act, ACT_PROTOTYPE) || xIS_SET(ch->act, ACT_PET)
               ||  xIS_SET(ch->act, ACT_MOUNTSAVE))
               {
                  continue;
               }
               else
               {
                  fwrite_mobile(fp, ch);
               }
            }
         }
      }
   }
   fprintf(fp, "#END\n");
   fclose(fp);
   sprintf(filename, "%s", QUEST_OFILE);
   if ((fp = fopen(filename, "w")) == NULL)
   {   
      bug("Cannot open: %s for writing", filename);
      return;
   }
   for (area = first_area; area; area = area->next)
   {
      if (area->low_r_vnum >= START_QUEST_VNUM && area->hi_r_vnum <= END_QUEST_VNUM)
      {
         for (obj = first_object; obj; obj = obj->next)
         {
            if (obj->item_type != ITEM_CORPSE_PC)
            {
               if (obj->in_room && obj->in_room->vnum && (obj->in_room->vnum >= area->low_r_vnum && obj->in_room->vnum <= area->hi_r_vnum))
               {
                  fwrite_obj(NULL, obj, fp, 0, OS_GROUND);
               }
            }
         }
      }
   }
   fprintf(fp, "#END\n");
   fclose(fp);
   sprintf(filename, "%s", QUEST_LAREA);
   if ((fp = fopen(filename, "w")) == NULL)
   {   
      bug("Cannot open: %s for writing", filename);
      return;
   }
   for (area = first_area; area; area = area->next)
   {
      if (area->low_r_vnum >= START_QUEST_VNUM && area->hi_r_vnum <= END_QUEST_VNUM)
      {
         fprintf(fp, "%s\n", area->filename);
         fold_area(area, area->filename, FALSE, 0);
      }
   }      
   fprintf(fp, "$\n");
   fclose(fp);
}
   	
void save_quest_data()
{
   QUEST_DATA *quest;
   FILE *fp;
   char filename[MIL];
   sprintf(filename, "%s", QUEST_FILE);
   
   if ((fp = fopen(filename, "w")) == NULL)
   {   
      bug("Cannot open: %s for writing", filename);
      return;
   }
   fprintf(fp, "QuestVnum   %d\n", top_quest_vnum);
   for (quest = first_quest; quest; quest = quest->next)
   {
      fprintf(fp, "#QUEST\n");
      fprintf(fp, "Player      %d %d %d %d %d %d\n", quest->player[0], quest->player[1], quest->player[2], quest->player[3],
         quest->player[4], quest->player[5]);
      fprintf(fp, "Qp          %d %d %d %d %d %d\n", quest->qp[0], quest->qp[1], quest->qp[2], quest->qp[3], quest->qp[4], 
         quest->qp[5]);
      fprintf(fp, "Timeleft    %d\n", quest->timeleft);
      fprintf(fp, "Traveltime  %d\n", quest->traveltime);
      fprintf(fp, "Tillnew     %d\n", quest->tillnew);
      fprintf(fp, "Mission     %d\n", quest->mission);
      fprintf(fp, "Tokill      %d\n", quest->tokill);
      fprintf(fp, "Killed      %d\n", quest->killed);
      fprintf(fp, "X           %d\n", quest->x);
      fprintf(fp, "Y           %d\n", quest->y);
      fprintf(fp, "Map         %d\n", quest->map);
      fprintf(fp, "Difficulty  %d\n", quest->difficulty);
      fprintf(fp, "Area        %d\n", quest->questarea->low_r_vnum);
      fprintf(fp, "End\n");
   }
   fprintf(fp, "#END\n");
   fclose(fp);
   save_quest_contents();
   return;
}

void do_qobj(CHAR_DATA *ch, char *argument)
{
   QOBJ_DATA *qobj;
   char arg1[MIL];
   char arg2[MIL];
   char arg3[MIL];
   char arg4[MIL];
   char arg5[MIL];
   char arg6[MIL];
   char arg7[MIL];
   char arg8[MIL];
   char arg9[MIL];
   char buf[MSL];
   int cnt = 0;
   int x;
   int race;
   
   if (argument[0] == '\0')
   {
       send_to_char("Syntax:  qobj list [low diff] [hi diff]\n\r", ch);
       send_to_char("Syntax:  qobj qps [low diff] [hi diff]\n\r", ch);
       send_to_char("Syntax:  qobj add <boss #> <lowdiff> <hidiff> <race> <name> <type> <weight> <gold> <values>\n\r", ch);
       send_to_char("Syntax:  qobj delete <num>\n\r", ch);
       send_to_char("Syntax:  qobj edit <num> [boss/lodiff/hidiff/race/values/name/flags/type/weight/gold/qps/aflags] <value>\n\r", ch);
       ch_printf(ch, "Boss (0 - Reg, 1 - Captain, 2 - Boss) Difficulty (1-%d) Race(0-1)\n\r", MAX_QDIFF);
       return;
   }
   argument = one_argument(argument, arg1);
   argument = one_argument(argument, arg2);
   argument = one_argument(argument, arg3);
   
   if (!str_cmp(arg1, "edit"))
   {
      if (atoi(arg2) < 1)
      {
         send_to_char("Need to choose the number listed in qobj list\n\r", ch);
         return;
      }
      for (qobj = first_qobj; qobj; qobj = qobj->next)
      {
         if (++cnt == atoi(arg2))
         {
            if (!str_cmp(arg3, "flags"))
            {
               xCLEAR_BITS(qobj->flags);
               xCLEAR_BITS(qobj->flags2);
               for (;;)
               {
                  argument = one_argument(argument, arg4);  
                  if (arg4[0] == '\0')
                     break;
                  else
                  {
                     if (atoi(arg4) > MAX_BITS)
                        xSET_BIT(qobj->flags2, atoi(arg4)-MAX_BITS-1);
                     else
                        xSET_BIT(qobj->flags, atoi(arg4)-1);
                  }
               }
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "aflags"))
            {
               for (;;)
               {
                  argument = one_argument(argument, arg4);  
                  if (arg4[0] == '\0')
                     break;
                  else
                  {
                     if (atoi(arg4) > MAX_BITS)
                        xTOGGLE_BIT(qobj->flags2, atoi(arg4)-MAX_BITS-1);
                     else
                        xTOGGLE_BIT(qobj->flags, atoi(arg4)-1);
                  }
               }
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "boss"))
            {
               if (atoi(argument) < 0 || atoi(argument) > 2)
               {
                  send_to_char("Boss value is 0 - 2\n\r", ch);
                  return;
               }      
               qobj->boss = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "lodiff"))
            {
               if (atoi(argument) < 1 || atoi(argument) > MAX_QDIFF)
               {
                  ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
                  return;
               }    
               if (atoi(argument) > qobj->hidiff)
               {
                  send_to_char("Lowdiff has to be less than or equal to hidiff\n\r", ch);
                  return;
               }
               qobj->lowdiff = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "hidiff"))
            {
               if (atoi(argument) < 1 || atoi(argument) > MAX_QDIFF)
               {
                  ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
                  return;
               }    
               if (atoi(argument) < qobj->lowdiff)
               {
                  send_to_char("Hidiff has to be greater than or equal to lowdiff\n\r", ch);
                  return;
               }
               qobj->hidiff = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "race"))
            {
               race = atoi(argument);
               if (race < 0 || race > 1)
               {
                  send_to_char("Race value is 0 or 1.\n\r", ch);
                  return;
               }
               qobj->race = race;
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "name"))
            {
               STRFREE(qobj->name);
               qobj->name = STRALLOC(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "type"))
            {
               qobj->type = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "qps"))
            {
               if (atoi(argument) < 0 || atoi(argument) > 9999999)
               {
                  send_to_char("The qps range is 0 to 9,999,999.\n\r", ch);
                  return;
               }
               qobj->qps = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "gold"))
            {
               if (atoi(argument) < 0 || atoi(argument) > 9999999)
               {
                  send_to_char("The gold range is 0 to 9,999,999.\n\r", ch);
                  return;
               }
               qobj->gold = atoi(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
            if (!str_cmp(arg3, "weight"))
            {
               if (atof(argument) < .01 || atof(argument) > 200)
               {
                  send_to_char("The weight range is .01 to 200.\n\r", ch);
                  return;
               }
               qobj->weight = adjust_weight(argument);
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
               
            if (!str_cmp(arg3, "value"))
            {
               for (x = 0; x <= MAX_QDIFF; x++)
               {
                  argument = one_argument(argument, arg3);
                  qobj->value[x] = atoi(arg3);
               }
               send_to_char("Done.\n\r", ch);
               fwrite_qobj_data();
               return;
            }
         }
      }
   }
   argument = one_argument(argument, arg4);
   argument = one_argument(argument, arg5);
   argument = one_argument(argument, arg6);
   argument = one_argument(argument, arg7);
   argument = one_argument(argument, arg8);
   argument = one_argument(argument, arg9);
   if (!str_cmp(arg1, "delete"))
   {
      if (atoi(arg2) < 1)
      {
         send_to_char("Need to choose the number listed in qobj list\n\r", ch);
         return;
      }
      for (qobj = first_qobj; qobj; qobj = qobj->next)
      {
         if (++cnt == atoi(arg2))
         {
            STRFREE(qobj->name);
            UNLINK(qobj, first_qobj, last_qobj, next, prev);
            DISPOSE(qobj);
            fwrite_qobj_data();
            send_to_char("Done.\n\r", ch);
            return;
         }
      }
      send_to_char("That number does not exist, check qobj list again.\n\r", ch);
      return;
   }
   if (!str_cmp(arg1, "add"))
   {
      if (atoi(arg2) < 0 || atoi(arg2) > 2)
      {
         send_to_char("Boss value is 0 - 2\n\r", ch);
         return;
      }
      if (atoi(arg3) < 1 || atoi(arg3) > MAX_QDIFF)
      {
         ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg4) < 1 || atoi(arg4) > MAX_QDIFF)
      {
         ch_printf(ch, "Difficulty value is 1 - %d\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg3) > atoi(arg4))
      {
         send_to_char("Lowdiff has to be less than or equal to hidiff\n\r", ch);
         return;
      }
      race = atoi(arg5);
      if (race < 0 || race > 1)
      {
         send_to_char("Race value is 0 - 1.\n\r", ch);
         return;
      }
      if (atof(arg8) < .01 || atof(arg8) > 200)
      {
         send_to_char("Weight value is .01 - 200.\n\r", ch);
         return;
      }
      if (atoi(arg9) < 0 || atoi(arg9) > 9999999)
      {
         send_to_char("Gold value is 0 - 9999999.\n\r", ch);
         return;
      }
      CREATE(qobj, QOBJ_DATA, 1);
      qobj->boss = atoi(arg2);
      qobj->lowdiff = atoi(arg3);
      qobj->hidiff = atoi(arg4);
      qobj->race = race;
      qobj->name = STRALLOC(arg6);
      qobj->type = atoi(arg7);
      qobj->weight = adjust_weight(arg8);
      qobj->gold = atoi(arg9);
      for (x = 0; x <= MAX_QDIFF; x++)
      {
         argument = one_argument(argument, arg3);
         qobj->value[x] = atoi(arg3);
      }
      
      LINK(qobj, first_qobj, last_qobj, next, prev);
      fwrite_qobj_data();
      send_to_char("Done.\n\r", ch);
      return;
   }     
   
   if (!str_cmp(arg1, "list"))
   {
      if (atoi(arg2) > MAX_QDIFF || atoi(arg3) > MAX_QDIFF)
      {
         ch_printf(ch, "Range is 0 to %d\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg2) < 1 || atoi(arg3) < 1)
      {
         send_to_char("&c&wNum   Name                     Boss  Lo  Hi  Race  Type  Gold     Lbs     Values                                      Flags\n\r---------------------------------------------------------------------------------------------------------------------------\n\r", ch);
         for (qobj = first_qobj; qobj; qobj = qobj->next)
         {
            sprintf(buf, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d", qobj->value[0], qobj->value[1], qobj->value[2],
               qobj->value[3], qobj->value[4], qobj->value[5], qobj->value[6], qobj->value[7], qobj->value[8], qobj->value[9], 
               qobj->value[10], qobj->value[11], qobj->value[12], qobj->value[13]); 
            ch_printf(ch, "[%-3d] %-22.22s > %-4s  %-2d  %-2d  %d     %-2d    %-7d  %-6.2f  %-42s  %s\n\r", ++cnt, qobj->name, 
               qobj->boss > 0 ? qobj->boss > 1 ? "&w&RBoss&c&w" : "&w&CCapt&c&w" : "&w&GRegu&c&w", qobj->lowdiff, qobj->hidiff, 
               qobj->race, qobj->type, qobj->gold, qobj->weight, buf, print_qobj_flags(qobj));
         }
      }
      else
      {
         send_to_char("&c&wNum   Name                     Boss  Lo  Hi  Race  Type  Gold     Lbs     Values                                      Flags\n\r---------------------------------------------------------------------------------------------------------------------------\n\r", ch);
         for (qobj = first_qobj; qobj; qobj = qobj->next)
         {
            cnt++;
            if (is_in_range(qobj->lowdiff, qobj->hidiff, atoi(arg2), atoi(arg3)))
            {
               sprintf(buf, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d", qobj->value[0], qobj->value[1], qobj->value[2],
               qobj->value[3], qobj->value[4], qobj->value[5], qobj->value[6], qobj->value[7], qobj->value[8], qobj->value[9], 
               qobj->value[10], qobj->value[11], qobj->value[12], qobj->value[13]); 
               ch_printf(ch, "[%-3d] %-22.22s > %-4s  %-2d  %-2d  %d     %-2d    %-7d  %-6.2f  %-42s  %s\n\r", cnt, qobj->name, 
                  qobj->boss > 0 ? qobj->boss > 1 ? "&w&RBoss&c&w" : "&w&CCapt&c&w" : "&w&GRegu&c&w", qobj->lowdiff, qobj->hidiff, 
                  qobj->race, qobj->type, qobj->gold, qobj->weight, buf, print_qobj_flags(qobj));
            }
         }
      }      
      return;
   }
   if (!str_cmp(arg1, "qps"))
   {
      if (atoi(arg2) > MAX_QDIFF || atoi(arg3) > MAX_QDIFF)
      {
         ch_printf(ch, "Range is 0 to %d\n\r", MAX_QDIFF);
         return;
      }
      if (atoi(arg2) < 1 || atoi(arg3) < 1)
      {
         send_to_char("&c&wNum   Name                     Boss  Lo  Hi  Race  Type  Gold     Lbs  QPS\n\r--------------------------------------------------------------------------------\n\r", ch);
         for (qobj = first_qobj; qobj; qobj = qobj->next)
         {
            ch_printf(ch, "[%-3d] %-22.22s > %-4s  %-2d  %-2d  %d     %-2d    %-7d  %-3d  %d\n\r", ++cnt, qobj->name, 
               qobj->boss > 0 ? qobj->boss > 1 ? "&w&RBoss&c&w" : "&w&CCapt&c&w" : "&w&GRegu&c&w", qobj->lowdiff, qobj->hidiff, 
               qobj->race, qobj->type, qobj->gold, qobj->weight, qobj->qps);
         }
      }
      else
      {
         send_to_char("&c&wNum   Name                     Boss  Lo  Hi  Race  Type  Gold     Lbs  QPS\n\r--------------------------------------------------------------------------------\n\r", ch);
         for (qobj = first_qobj; qobj; qobj = qobj->next)
         {
            cnt++;
            if (is_in_range(qobj->lowdiff, qobj->hidiff, atoi(arg2), atoi(arg3)))
            {
               ch_printf(ch, "[%-3d] %-22.22s > %-4s  %-2d  %-2d  %d     %-2d    %-7d  %-3d  %d\n\r", cnt, qobj->name, 
                  qobj->boss > 0 ? qobj->boss > 1 ? "&w&RBoss&c&w" : "&w&CCapt&c&w" : "&w&GRegu&c&w", qobj->lowdiff, qobj->hidiff, 
                  qobj->race, qobj->type, qobj->gold, qobj->weight, qobj->qps);
            }
         }
      }      
      return;
   }
   do_qobj(ch, "");
   return;
}
				
void fread_qmob_data(FILE *fp)
{
   bool fMatch;  
   char buf[MSL];   
   char *word;
   QMOB_DATA *qmob;
   
   CREATE(qmob, QMOB_DATA, 1);
   
   for (;;)
   {
      word = feof(fp) ? "End" : fread_word(fp);
      fMatch = FALSE;

      switch (UPPER(word[0]))
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol(fp);
            break;
            
         case 'B':
            KEY("Boss", qmob->boss, fread_number(fp));
            break;
            
         case 'F':
            KEY("Flags", qmob->flags, fread_bitvector(fp));            
            break;
            
         case 'H':
            KEY("Hidiff", qmob->hidiff, fread_number(fp));
            break;
            
         case 'L':
            KEY("Lowdiff", qmob->lowdiff, fread_number(fp));
            break;
            
         case 'N':
            KEY("Name", qmob->name, fread_string(fp));
            break;
            
         case 'R':
            KEY("Race", qmob->race, fread_number(fp));
            break;
            
         case 'S':
            KEY("Sex", qmob->sex, fread_number(fp));
            break;
            
         case 'E':
            if (!str_cmp(word, "End"))
            {
               LINK(qmob, first_qmob, last_qmob, next, prev);
               return;       
            }
      }
      if (!fMatch)
      {
         sprintf(buf, "fread_qmob_data: no match: %s", word);
         bug(buf, 0);
      }
   }
}        
                   
void load_qmob_data()
{
   FILE *fp;
   char filename[MIL];
   
   sprintf(filename, "%s", QMOB_FILE);
   if ((fp = fopen(filename, "r")) != NULL)
   {
      for (;;)
      {
         char letter;
         char *word;

         letter = fread_letter(fp);
         if (letter == '*')
         {
            fread_to_eol(fp);
            continue;
         }

         if (letter != '#')
         {
            bug("load_qmob_data: # not found.", 0);
            break;
         }

         word = fread_word(fp);
         if (!str_cmp(word, "MOB"))
         {
            fread_qmob_data(fp);
            continue;
         }
         else if (!str_cmp(word, "END"))
         {
            break;
         }
         else
         {
            bug("load_qmob_data: bad section.", 0);
            continue;
         }
      }
   }
   else
   {
      bug("Cannot open the qmob data file", 0);
      return;
   }
   fclose(fp);
}   

void set_quest_description(ROOM_INDEX_DATA *location)
{
   char namebuf[MSL];
   char descbuf[MSL];
   int x = number_range(1, 6);
   
   if (location->sector_type == 2) //Field
   {
      STRFREE(location->name);
      STRFREE(location->description);
      if (x == 1)
      {
         sprintf(namebuf, "A large grass field.");
         sprintf(descbuf, "In this evil cave this simple field of grass is about\n\r\as tranquil as it can get.  However, in such peace\n\ris when you need to be the most careful.\n\r");
      }   
      if (x == 2)
      {
         sprintf(namebuf, "A bloodstained field.");
         sprintf(descbuf, "The once green grass now has a lovely shade of red\n\rinstead of the alive green color it use to have.\n\rIf you stick around here for to long you just might\n\radd more red to the grass.\n\r");
      }
      if (x == 3)
      {
         sprintf(namebuf, "A trampled field.");
         sprintf(descbuf, "Looking closely at the grass it is easy to see some\n\rhidious beast has been through here recently and\n\rit did not look too be prancing through either by the\n\rmarkings in the grass.\n\r");
      }
      if (x == 4)
      {
         sprintf(namebuf, "A field of grass.");
         sprintf(descbuf, "Some green grass still grows here making this perhaps\n\rone of the only few spots unsoiled in this cave.\n\rIt is nice to look down and see life, but a lot of death\n\ris still waiting you ahead.\n\r");
      }
      if (x == 5)
      {
         sprintf(namebuf, "A flat clearing of grass.");
         sprintf(descbuf, "A few strains of grass still grow here.  It is kind of\n\rfunny how a little bit of grass can grow in a cave\n\rlike this, but it still managed to live on.  Perhaps\n\rsome light is creeping through somwhere.\n\r");
      }
      if (x == 6)
      {
         sprintf(namebuf, "A little grass.");
         sprintf(descbuf, "A little bit of grass mixes in here with the flattened\n\rred grass that seems to mark the death and pain in this\n\rhorrid place.  Unless you want to turn some more\n\rgreen grass red it might be a good idea to get moving.\n\r");
      }
      location->name = STRALLOC(namebuf);
      location->description = STRALLOC(descbuf);
   }
   if (location->sector_type == 13) //Underground
   {
      STRFREE(location->name);
      STRFREE(location->description);
      if (x == 1)
      {
         sprintf(namebuf, "Another path underground.");
         sprintf(descbuf, "As with any direction that you look, it appears this horrid\n\rdungeon has no end.  Just more and more underground\n\rpaths that lead most certainly to pain and doom.\n\rNow would be the the time to flee if want!\n\r");
      }   
      if (x == 2)
      {
         sprintf(namebuf, "A bloodied wall.");
         sprintf(descbuf, "Blood trickles all over the ground and the dugout walls.  All\n\raround you is the smell of rotting humanoid creatures\n\rand monsters only seen in nightmeres of children.\n\rNow would be a good time to hug your weapon.\n\r");
      }
      if (x == 3)
      {
         sprintf(namebuf, "A little light.");
         sprintf(descbuf, "A little bit of light seems to creep in from above.  Looking up\n\rtoward the light you can see the outside world, well\n\ratleast small parts of it.  This is probably how\n\rgrass can grow here and a bit of water can be found\n\r");
      }
      if (x == 4)
      {
         sprintf(namebuf, "Bodies litter the ground.");
         sprintf(descbuf, "The horrible stench of death runs as putrid as it gets in this little\n\ralcove.  Bodies are stacked up into the sky as\n\rperhaps an offering to some evil god or as a sign\n\rto all who would see it.\n\r");
      }
      if (x == 5)
      {
         sprintf(namebuf, "Shreeks echo through the halls.");
         sprintf(descbuf, "Shreeks of the living and the soon to be dead can be heard in all directions\n\rfrom this point in the dungeon.  The sounds are mostly\n\rthe creatures of the dungeons communicating\n\rwith eachother and the sounds of victory.\n\r");
      }
      if (x == 6)
      {
         sprintf(namebuf, "Some small scribles on the cavern walls");
         sprintf(descbuf, "It is really hard to read and understand, but it appears the creatures that\n\rinhabit this foul place have left behind some sort of\n\rhorrid looking history.  These creatures sure\n\rappear to enjoy killing as noted by the last picture of bodies\n\rspread out everywhere.\n\r");
      }
      location->name = STRALLOC(namebuf);
      location->description = STRALLOC(descbuf);
   }
   if (location->sector_type == 44) //Path
   {
      STRFREE(location->name);
      STRFREE(location->description);
      if (x == 1)
      {
         sprintf(namebuf, "A path into darkness.");
         sprintf(descbuf, "The path quickly starts to turn very dark here for\n\rreally no good reason.  Light almost seems to be eaten\n\rat this point.  Whatever is down this path does\n\rnot want to be seen by anyone.\n\r");
      }   
      if (x == 2)
      {
         sprintf(namebuf, "A path full of blood.");
         sprintf(descbuf, "Blood seems to pour out of the ground here.  All around\n\rblood just drips from every corner and wall.  It almost\n\reven looks like it is a slive in the way it is\n\rmoving.  Might be a good idea to start moving again.\n\r");
      }
      if (x == 3)
      {
         sprintf(namebuf, "A small path that winds into oblivion.");
         sprintf(descbuf, "This room just oozes with bad intentions.  Evil seems to\n\rpulsating from every direction and death is the only thing\n\rcertain in all of those directions.  Now would\n\rbe a good time to prey to whatever you beleive in.\n\r");
      }
      if (x == 4)
      {
         sprintf(namebuf, "A strange light from above.");
         sprintf(descbuf, "A small bit of light shines in from above.  The light offers\n\ra small amount of relaxation in a normally horid situation, but\n\rwhenever there is calm there is always a\n\rnasty storm to follow, better be prepared\n\r");
      }
      if (x == 5)
      {
         sprintf(namebuf, "A little bit of water sprinkles down the path.");
         sprintf(descbuf, "A small bit of water runs down the path here.  A small amount\n\rof grass can be seen growing in this area, but not enough to really\n\rhave any affect.  It is nice to stand around\n\rand look at the water and dream, but it is better to live.\n\r");
      }
      if (x == 6)
      {
         sprintf(namebuf, "The sounds of battle can be hard nearby.");
         sprintf(descbuf, "The grunting of the enemy echoes loudly here.  Just a short\n\rdistance the enemy is preparing to delivery you the bloody death that\n\rthe vacation guide mentioned before arriving here.\n\rMight be a good time to get ready for battle.\n\r");
      }
      location->name = STRALLOC(namebuf);
      location->description = STRALLOC(descbuf);
   }
   if (location->sector_type == 6) //Water
   {
      STRFREE(location->name);
      STRFREE(location->description);
      if (x == 1)
      {
         sprintf(namebuf, "A small pond in the darkness.");
         sprintf(descbuf, "A small pond of water in what is normally a dreadful dungeon\n\ris here for all to appreciate.  It might not be safe\n\rto drink from it but perhaps taking a quick second\n\rto wipe the death of your weapons might be a soothing time.\n\r");
      }   
      if (x == 2)
      {
         sprintf(namebuf, "A bloody red pool.");
         sprintf(descbuf, "The blood seems just to trickle down into the small pool of\n\rwater in this room.  The once clear and perhaps drinkable\n\rwater is now a blood red.  It is even quite possible\n\rthat it is simply just blood instead of water.\n\r");
      }
      if (x == 3)
      {
         sprintf(namebuf, "A small tranquil pool.");
         sprintf(descbuf, "The water here moves slowly and creates a very soothing\n\ratmosphere.  In any other situation it might be a good idea to sit,\n\rrest, and heal a little bit, but with the critters\n\rlooking for some fresh flesh it might be a good idea to keep moving\n\r");
      }
      if (x == 4)
      {
         sprintf(namebuf, "Some soothing blue water.");
         sprintf(descbuf, "The water here is a about a foot deep, which is good for\n\ran underground cave that shouldn't have any water at all.  The water\n\rlooks very clear and purge compared to most of this\n\rhorrible place.  It is a nice token of the hell to come.\n\r");
      }
      if (x == 5)
      {
         sprintf(namebuf, "A defiled pool of water.");
         sprintf(descbuf, "The pool of water in this rooms absolutely stinks foul of\n\rthings dead many days ago.  The evil creatures here have used the\n\rwater to dump their dead and the bones of their victims\n\rinstead of burrying or burning it.\n\r");
      }
      if (x == 6)
      {
         sprintf(namebuf, "A small stream runs through.");
         sprintf(descbuf, "A small stream of water slowly trickles through this room.\n\rIt is amazing to see something so pure and tranquil in this maze\n\rof doom, but that can only mean something horrid looking\n\rand smelling is waiting for you.\n\r");
      }
      location->name = STRALLOC(namebuf);
      location->description = STRALLOC(descbuf);
   }
}
   

int get_coord_dir(int x, int y)
{
   if (x == 0 && y == 1) //n
      return 0;
   if (x == 1 && y == 0) //e
      return 1;
   if (x == 0 && y == -1) //s
      return 2;
   if (x == -1 && y == 0) //w
      return 3;
   if (x == 1 && y == 1)  //ne
      return 6;
   if (x == -1 && y == 1) //nw
      return 7;
   if (x == 1 && y == -1)  //se
      return 8;
   if (x == -1 && y == -1)  //sw
      return 9;
      
   return 0;
}
   
char gridmap[201][201];
ROOM_INDEX_DATA *roomgrid[201][201];

char *const qmob_long_descr[18] = {
   "is here looking for trouble.", "has bad intentions for YOU!", "appears to be hungry for BLOOD!",
   "is looking for another victim!", "has a taste for DEATH today", "likes to kill innocent folks",
   "is here looking for a fight.", "is here looking for lunch", "is here go rip YOU a new one!",
   "is thinking about killing YOU!", "is here planning to stop YOU!", "is taking a liking to you DEAD!",
   "is here looking for skulls to CRACK!", "is here looking for souls to STEAL!", "is here and likes the SMELL OF DEATH!",
   "is here HUNTING YOU!", "is here looking to send you to your next life.", "is here to make you FEEL PAIN!"
};

char *const qobj_long_descr[12] = {
   "has been left behind for anyone to pickup.", "has been foolishly left here.", "has been left here for the next owner",
   "appears to be looking for a new owner", "is here for you to claim.", "is here for anyone to take",
   "is looking for a new owner.", "is here collecting dust.", "is here growing old.", "is here for the taking.",
   "lies here untouched.", "has been left behind for another."
};

void apply_npcquest_flags(EXT_BV *flags, NPCRACE_DATA *npcrace, int diff)
{
   int x = 1;
   
   for (x = 1; x <= diff; x++)
   {
      xSET_BITS(*flags, npcrace->flags[x-1]);
      xREMOVE_BITS(*flags, npcrace->nflags[x-1]);
   }
}

void adjust_qmob_flags(CHAR_DATA *mob, QMOB_DATA *qmob, NPCRACE_DATA *npcrace, int diff)
{
   int histat = 0;
   int lostat = 25;
   EXT_BV flags;
   
   xCLEAR_BITS(flags);
   if (mob->perm_str > histat)
      histat = mob->perm_str;
   if (mob->perm_dex > histat)
      histat = mob->perm_dex;
   if (mob->perm_int > histat)
      histat = mob->perm_int;
   if (mob->perm_lck > histat)
      histat = mob->perm_lck;
   if (mob->perm_wis > histat)
      histat = mob->perm_wis;
   if (mob->perm_con > histat)
      histat = mob->perm_con;
      
   if (mob->perm_str < lostat)
      lostat = mob->perm_str;
   if (mob->perm_dex < lostat)
      lostat = mob->perm_dex;
   if (mob->perm_int < lostat)
      lostat = mob->perm_int;
   if (mob->perm_lck < lostat)
      lostat = mob->perm_lck;
   if (mob->perm_wis < lostat)
      lostat = mob->perm_wis;
   if (mob->perm_con < lostat)
      lostat = mob->perm_con;
      
   if (qmob)
      flags = qmob->flags;
   else
      apply_npcquest_flags(&flags, npcrace, diff);
      
   if (xIS_SET(flags, QMOB_HP))
      mob->hit = mob->hit * 120/100;
   if (xIS_SET(flags, QMOB_LHP))
      mob->hit = mob->hit * 75/100;
   if (xIS_SET(flags, QMOB_AGI))
      mob->perm_agi += 10;
   if (xIS_SET(flags, QMOB_LAGI))
      mob->perm_agi -= 10;
   if (xIS_SET(flags, QMOB_STR))
      mob->perm_str = histat+2;
   if (xIS_SET(flags, QMOB_STR2) && !xIS_SET(flags, QMOB_STR))
      mob->perm_str = histat+4;
   if (xIS_SET(flags, QMOB_WIS))
      mob->perm_wis = histat+2;
   if (xIS_SET(flags, QMOB_WIS2) && !xIS_SET(flags, QMOB_WIS))
      mob->perm_wis = histat+4;
   if (xIS_SET(flags, QMOB_INT))
      mob->perm_int = histat+2;
   if (xIS_SET(flags, QMOB_INT2) && !xIS_SET(flags, QMOB_INT))
      mob->perm_int = histat+4;
   if (xIS_SET(flags, QMOB_DEX))
      mob->perm_dex = histat+2;
   if (xIS_SET(flags, QMOB_CON))
      mob->perm_con = histat+2;
   if (xIS_SET(flags, QMOB_LCK))
      mob->perm_lck = histat+2;
   if (xIS_SET(flags, QMOB_LSTR))
      mob->perm_str = lostat-2;
   if (xIS_SET(flags, QMOB_LSTR2) && !xIS_SET(flags, QMOB_LSTR))
      mob->perm_str = lostat-4;
   if (xIS_SET(flags, QMOB_LWIS))
      mob->perm_wis = lostat-2;
   if (xIS_SET(flags, QMOB_LWIS2) && !xIS_SET(flags, QMOB_LWIS))
      mob->perm_wis = lostat-4;
   if (xIS_SET(flags, QMOB_LINT))
      mob->perm_int = lostat-2;
   if (xIS_SET(flags, QMOB_LINT2) && !xIS_SET(flags, QMOB_LINT))
      mob->perm_int = lostat-4;
   if (xIS_SET(flags, QMOB_LDEX))
      mob->perm_dex = lostat-2;
   if (xIS_SET(flags, QMOB_LCON))
      mob->perm_con = lostat-2;
   if (xIS_SET(flags, QMOB_LLCK))
      mob->perm_lck = lostat-2;
     
   if (xIS_SET(flags, QMOB_BASH))
      mob->tohitbash = mob->armor+2;
   if (xIS_SET(flags, QMOB_SLASH))
      mob->tohitslash = mob->armor+2;
   if (xIS_SET(flags, QMOB_STAB))
      mob->tohitstab = mob->armor+2;
   if (xIS_SET(flags, QMOB_LBASH))
      mob->tohitbash = mob->armor-2;
   if (xIS_SET(flags, QMOB_LSLASH))
      mob->tohitslash = mob->armor-2;
   if (xIS_SET(flags, QMOB_LSTAB))
      mob->tohitstab = mob->armor-2;
   if (xIS_SET(flags, QMOB_ARMOR))
      mob->armor += 1;
   if (xIS_SET(flags, QMOB_ARMOR2) && !xIS_SET(flags, QMOB_ARMOR))
      mob->armor += 2;
   if (xIS_SET(flags, QMOB_LARMOR))
      mob->armor -= 1;
   if (xIS_SET(flags, QMOB_LARMOR2) && !xIS_SET(flags, QMOB_LARMOR))
      mob->armor -= 2;
   if (xIS_SET(flags, QMOB_DAM))
      mob->damplus = UMAX(mob->damplus+1, mob->damplus * 120/100);
   if (xIS_SET(flags, QMOB_DAM2) && !xIS_SET(flags, QMOB_DAM))
      mob->damplus = UMAX(mob->damplus+2, mob->damplus * 140/100);
   if (xIS_SET(flags, QMOB_LDAM))
      mob->damplus = UMIN(mob->damplus-1, mob->damplus * 85/100);
   if (xIS_SET(flags, QMOB_LDAM2) && !xIS_SET(flags, QMOB_LDAM))
      mob->damplus = UMIN(mob->damplus-2, mob->damplus * 70/100);
      
   if (xIS_SET(flags, QMOB_NOGOLD))
      mob->gold = 0;
   if (xIS_SET(flags, QMOB_GOLD1))
      mob->gold = mob->gold * 150/100;
   if (xIS_SET(flags, QMOB_GOLD2) && !xIS_SET(flags, QMOB_GOLD1))
      mob->gold = mob->gold * 250/100;
   if (xIS_SET(flags, QMOB_LGOLD1))
      mob->gold = mob->gold * 60/100;
   if (xIS_SET(flags, QMOB_LGOLD2) && !xIS_SET(flags, QMOB_LGOLD1))
      mob->gold = mob->gold * 35/100;
      
   if (xIS_SET(flags, QMOB_NOAGGRO))
      xREMOVE_BIT(mob->act, ACT_AGGRESSIVE);   
   if (xIS_SET(flags, QMOB_RUNNING))
      xSET_BIT(mob->act, ACT_RUNNING);
   if (xIS_SET(flags, QMOB_UNDEAD))
      xSET_BIT(mob->act, ACT_UNDEAD);
   if (xIS_SET(flags, QMOB_LIVINGDEAD))
      xSET_BIT(mob->act, ACT_LIVING_DEAD);
   if (xIS_SET(flags, QMOB_SENTINEL))
      xSET_BIT(mob->act, ACT_SENTINEL);   
      
   if (xIS_SET(flags, QMOB_DODGE))
      xSET_BIT(mob->defenses, DFND_DODGE);
   if (xIS_SET(flags, QMOB_PARRY))
      xSET_BIT(mob->defenses, DFND_PARRY);
   if (xIS_SET(flags, QMOB_LIGHT))
      xSET_BIT(mob->defenses, DFND_CURELIGHT);
   if (xIS_SET(flags, QMOB_SERIOUS))
      xSET_BIT(mob->defenses, DFND_CURESERIOUS);
   if (xIS_SET(flags, QMOB_CRITICAL))
      xSET_BIT(mob->defenses, DFND_CURECRITICAL);
   if (xIS_SET(flags, QMOB_HEAL))
      xSET_BIT(mob->defenses, DFND_HEAL);
   if (xIS_SET(flags, QMOB_SANCTUARY))
      xSET_BIT(mob->defenses, DFND_SANCTUARY);
   if (xIS_SET(flags, QMOB_FSHIELD))
      xSET_BIT(mob->defenses, DFND_FIRESHIELD);
   if (xIS_SET(flags, QMOB_SSHIELD))
      xSET_BIT(mob->defenses, DFND_SHOCKSHIELD);
   if (xIS_SET(flags, QMOB_ISHIELD))
      xSET_BIT(mob->defenses, DFND_ICESHIELD);
   if (xIS_SET(flags, QMOB_STONESKIN))
      xSET_BIT(mob->defenses, DFND_STONESKIN);
   if (xIS_SET(flags, QMOB_DISARM))
      xSET_BIT(mob->defenses, DFND_DISARM); 
   
   if (xIS_SET(flags, QMOB_TRIP))
      xSET_BIT(mob->attacks, ATCK_TRIP);
   if (xIS_SET(flags, QMOB_ABASH))
      xSET_BIT(mob->attacks, ATCK_BASH);
   if (xIS_SET(flags, QMOB_STUN))
      xSET_BIT(mob->attacks, ATCK_STUN);
   if (xIS_SET(flags, QMOB_GOUGE))
      xSET_BIT(mob->attacks, ATCK_GOUGE);
   if (xIS_SET(flags, QMOB_BACKSTAB))
      xSET_BIT(mob->attacks, ATCK_BACKSTAB);
   if (xIS_SET(flags, QMOB_BLINDNESS))
      xSET_BIT(mob->attacks, ATCK_BLINDNESS);
   if (xIS_SET(flags, QMOB_LBREATH))
      xSET_BIT(mob->attacks, ATCK_LIGHTNBREATH);
   if (xIS_SET(flags, QMOB_GBREATH))
      xSET_BIT(mob->attacks, ATCK_GASBREATH);
   if (xIS_SET(flags, QMOB_FIREBREATH))
      xSET_BIT(mob->attacks, ATCK_FIREBREATH);
   if (xIS_SET(flags, QMOB_FROSTBREATH))
      xSET_BIT(mob->attacks, ATCK_FROSTBREATH);
   if (xIS_SET(flags, QMOB_ACIDBREATH))
      xSET_BIT(mob->attacks, ATCK_ACIDBREATH);
   if (xIS_SET(flags, QMOB_CURSE))
      xSET_BIT(mob->attacks, ATCK_CURSE);
   if (xIS_SET(flags, QMOB_HARM))
      xSET_BIT(mob->attacks, ATCK_HARM);
   if (xIS_SET(flags, QMOB_FIREBALL))
      xSET_BIT(mob->attacks, ATCK_FIREBALL);
   if (xIS_SET(flags, QMOB_WEAKEN))
      xSET_BIT(mob->attacks, ATCK_WEAKEN);
   if (xIS_SET(flags, QMOB_POISON))
      xSET_BIT(mob->attacks, ATCK_POISON);
      
   if (xIS_SET(flags, QMOB_SFIRE))
      SET_BIT(mob->susceptible, RIS_FIRE);
   if (xIS_SET(flags, QMOB_SCOLD))
      SET_BIT(mob->susceptible, RIS_WATER);
   if (xIS_SET(flags, QMOB_SELECT))
      SET_BIT(mob->susceptible, RIS_ENERGY);
   if (xIS_SET(flags, QMOB_SENERGY))
      SET_BIT(mob->susceptible, RIS_EARTH);
   if (xIS_SET(flags, QMOB_SAIR))
      SET_BIT(mob->susceptible, RIS_AIR);
   if (xIS_SET(flags, QMOB_SBLUNT))
      SET_BIT(mob->susceptible, RIS_BLUNT);
   if (xIS_SET(flags, QMOB_SPIERCE))
      SET_BIT(mob->susceptible, RIS_PIERCE);
   if (xIS_SET(flags, QMOB_SSLASH))
      SET_BIT(mob->susceptible, RIS_SLASH);
   if (xIS_SET(flags, QMOB_SSLEEP))
      SET_BIT(mob->susceptible, RIS_SLEEP);
   if (xIS_SET(flags, QMOB_SCHARM))
      SET_BIT(mob->susceptible, RIS_CHARM);
   if (xIS_SET(flags, QMOB_SNONMAGIC))
      SET_BIT(mob->susceptible, RIS_NONMAGIC);
   if (xIS_SET(flags, QMOB_SMAGIC))
      SET_BIT(mob->susceptible, RIS_MAGIC);
   if (xIS_SET(flags, QMOB_SPARALYSIS))
      SET_BIT(mob->susceptible, RIS_PARALYSIS);
      
   if (xIS_SET(flags, QMOB_RFIRE))
      SET_BIT(mob->resistant, RIS_FIRE);
   if (xIS_SET(flags, QMOB_RCOLD))
      SET_BIT(mob->resistant, RIS_WATER);
   if (xIS_SET(flags, QMOB_RELECT))
      SET_BIT(mob->resistant, RIS_ENERGY);
   if (xIS_SET(flags, QMOB_RENERGY))
      SET_BIT(mob->resistant, RIS_EARTH);
   if (xIS_SET(flags, QMOB_RAIR))
      SET_BIT(mob->resistant, RIS_AIR);
   if (xIS_SET(flags, QMOB_RBLUNT))
      SET_BIT(mob->resistant, RIS_BLUNT);
   if (xIS_SET(flags, QMOB_RPIERCE))
      SET_BIT(mob->resistant, RIS_PIERCE);
   if (xIS_SET(flags, QMOB_RSLASH))
      SET_BIT(mob->resistant, RIS_SLASH);
   if (xIS_SET(flags, QMOB_RSLEEP))
      SET_BIT(mob->resistant, RIS_SLEEP);
   if (xIS_SET(flags, QMOB_RCHARM))
      SET_BIT(mob->resistant, RIS_CHARM);
   if (xIS_SET(flags, QMOB_RNONMAGIC))
      SET_BIT(mob->resistant, RIS_NONMAGIC);
   if (xIS_SET(flags, QMOB_RMAGIC))
      SET_BIT(mob->resistant, RIS_MAGIC);
   if (xIS_SET(flags, QMOB_RPARALYSIS))
      SET_BIT(mob->resistant, RIS_PARALYSIS);
      
   if (xIS_SET(flags, QMOB_IFIRE))
      SET_BIT(mob->immune, RIS_FIRE);
   if (xIS_SET(flags, QMOB_ICOLD))
      SET_BIT(mob->immune, RIS_WATER);
   if (xIS_SET(flags, QMOB_IELECT))
      SET_BIT(mob->immune, RIS_ENERGY);
   if (xIS_SET(flags, QMOB_IENERGY))
      SET_BIT(mob->immune, RIS_EARTH);
   if (xIS_SET(flags, QMOB_IAIR))
      SET_BIT(mob->immune, RIS_AIR);
   if (xIS_SET(flags, QMOB_IBLUNT))
      SET_BIT(mob->immune, RIS_BLUNT);
   if (xIS_SET(flags, QMOB_IPIERCE))
      SET_BIT(mob->immune, RIS_PIERCE);
   if (xIS_SET(flags, QMOB_ISLASH))
      SET_BIT(mob->immune, RIS_SLASH);
   if (xIS_SET(flags, QMOB_ISLEEP))
      SET_BIT(mob->immune, RIS_SLEEP);
   if (xIS_SET(flags, QMOB_ICHARM))
      SET_BIT(mob->immune, RIS_CHARM);
   if (xIS_SET(flags, QMOB_INONMAGIC))
      SET_BIT(mob->immune, RIS_NONMAGIC);
   if (xIS_SET(flags, QMOB_IMAGIC))
      SET_BIT(mob->immune, RIS_MAGIC);
   if (xIS_SET(flags, QMOB_IPARALYSIS))
      SET_BIT(mob->immune, RIS_PARALYSIS);
      
   if (xIS_SET(flags, QMOB_INVISIBLE))
      xSET_BIT(mob->affected_by, AFF_INVISIBLE);      
   if (xIS_SET(flags, QMOB_DETECTINVIS))
      xSET_BIT(mob->affected_by, AFF_DETECT_INVIS);
   if (xIS_SET(flags, QMOB_HIDE))
      xSET_BIT(mob->affected_by, AFF_HIDE);
   if (xIS_SET(flags, QMOB_TRUESIGHT))
      xSET_BIT(mob->affected_by, AFF_TRUESIGHT);
   if (xIS_SET(flags, QMOB_SNEAK))
      xSET_BIT(mob->affected_by, AFF_SNEAK);
   if (xIS_SET(flags, QMOB_DETECTHIDDEN))
      xSET_BIT(mob->affected_by, AFF_DETECT_HIDDEN);
      
   if (mob->perm_str < lostat)
      lostat = mob->perm_str;
   if (mob->perm_dex < lostat)
      lostat = mob->perm_dex;
   if (mob->perm_int < lostat)
      lostat = mob->perm_int;
   if (mob->perm_lck < lostat)
      lostat = mob->perm_lck;
   if (mob->perm_wis < lostat)
      lostat = mob->perm_wis;
   if (mob->perm_con < lostat)
      lostat = mob->perm_con;
      
   if (mob->perm_str < 10)
      mob->perm_str = 10;
   if (mob->perm_dex < 10)
      mob->perm_dex = 10;
   if (mob->perm_int < 10)
      mob->perm_int = 10;
   if (mob->perm_lck < 10)
      mob->perm_lck = 10;
   if (mob->perm_wis < 10)
      mob->perm_wis = 10;
   if (mob->perm_con < 10)
      mob->perm_con = 10;
      
   if (mob->perm_str > 25)
      mob->perm_str = 25;
   if (mob->perm_dex > 25)
      mob->perm_dex = 25;
   if (mob->perm_int > 25)
      mob->perm_int = 25;
   if (mob->perm_lck > 25)
      mob->perm_lck = 25;
   if (mob->perm_wis > 25)
      mob->perm_wis = 25;
   if (mob->perm_con > 25)
      mob->perm_con = 25;
      
   if (mob->perm_agi < 15)
      mob->perm_agi = 15;
   if (mob->perm_agi > 100)
      mob->perm_agi = 100;
      
   if (mob->pIndexData->damplus < 1)
      mob->pIndexData->damplus = 1;
   if (mob->armor < 1)
      mob->armor = 1;
   if (mob->armor > 25)
      mob->armor = 25;
   if (mob->tohitbash < 1)
      mob->tohitbash = 1;
   if (mob->tohitslash < 1)
      mob->tohitslash = 1;
   if (mob->tohitstab < 1)
      mob->tohitstab = 1;
   if (mob->tohitbash > 25)
      mob->tohitbash = 25;
   if (mob->tohitstab > 25)
      mob->tohitstab = 25;
   if (mob->tohitslash > 25)
      mob->tohitslash = 25;
      
   mob->max_hit = mob->hit;
   return;
}

char *add_npc_name(NPCRACE_DATA *npcrace, int diff)
{
   static char buf[MSL];
   
   if (npcrace->fulldescription[diff-1])
      sprintf(buf, "%s", npcrace->description[diff-1]);
   else
      sprintf(buf, "%s %s", npcrace->description[diff-1], npcrace->racename);
      
   return buf;
}

void adjust_questmob(CHAR_DATA *mob, int difficulty, QMOB_DATA *qmob, int vsize, AREA_DATA *area, NPCRACE_DATA *npcrace)
{
   int mult;
   int inc;
   int x;
   int lvl;
   int hp;
   int dam;
   char buf[MSL];
   OBJ_DATA *weapon;
   OBJ_DATA *weapon2 = NULL;
   OBJ_DATA *rleg;
   OBJ_DATA *lleg;
   OBJ_DATA *rarm;
   OBJ_DATA *larm;
   OBJ_DATA *neck;
   OBJ_DATA *chest;
   OBJ_DATA *head;
   SLAB_DATA *firstslab;
   SLAB_DATA *secondslab;
   SLAB_DATA *thirdslab = NULL;
   OBJ_DATA *firstslabobj = NULL;
   OBJ_DATA *secondslabobj = NULL;
   OBJ_DATA *thirdslabobj = NULL;
   int gold;
   int slab1;
   int slab2;
   int slab3;
   int per1;
   int per2;
   int per3;  
   int num;
   int race;
   int diff = ((difficulty-1)/10)+1;
   
   if (!qmob && !npcrace)
   {
      bug("adjust_questmob:  A null qmob and npcrace passed to adjust_questmob.");
      return;
   }
   if (qmob && npcrace)
   {
      bug("adjust_questmob:  Both qmob and npcrace are not null.");
      return;
   }
   
   weapon=rleg=lleg=rarm=larm=neck=chest=head=NULL;
   
   mult = 4750;
   inc = 750;
   
   lvl = difficulty;
   
   if (qmob)
   {
      if (qmob->boss == 1)
         lvl += 10;
      if (qmob->boss == 2)
         lvl += 20;
   }
   if (lvl > MAX_QDIFF_VALUE)
      lvl = MAX_QDIFF_VALUE;
   if (lvl < 5)
      lvl = 5;
      
   for (x = 11; x <= lvl; x = x+10)
   {
      inc += 250;
      if (x <= 101)
         mult += inc;

   }
   mult += 250;
   inc += 250 * (lvl-x+10) /10;
   if (lvl <= 100)
      mult += inc;     
        
   hp = lvl * mult / 2000;
   hp = number_range(hp * 90, hp * 110)/100;
      
   mob->hit = hp;
   mob->max_hit = mob->hit;
   mob->perm_agi = UMIN(100, 35+(lvl*4/10));
   if (lvl > 100)
      mob->perm_agi += 5;
   if (lvl > 110)
      mob->perm_agi += 5;
   if (lvl > 120)
      mob->perm_agi += 5;
      
   if (mob->perm_agi > 100)
      mob->perm_agi = 100;
   
   if (lvl <= 8)
   {
      if (lvl <= 3)
         mob->armor = 1;
      else if (lvl <= 6)
         mob->armor = 2;
      else
         mob->armor = 3;
   }
   else
   {
      mob->armor = 3+(lvl*100/666);
   }
   mob->tohitbash = UMAX(1, number_range(mob->armor-1, mob->armor+1));
   mob->tohitslash = UMAX(1, number_range(mob->armor-1, mob->armor+1));
   mob->tohitstab = UMAX(1, number_range(mob->armor-1, mob->armor+1));
   if (qmob && qmob->boss > 0)
      mob->tohitbash = mob->tohitslash = mob->tohitstab = mob->armor+1;
   dam = 1+lvl/5;
   if (lvl >= 48)
      dam+=(lvl-38)/10;
   if (lvl >= 97)
      dam+=1;
  
   mob->pIndexData->damnodice = 1;
   mob->pIndexData->damsizedice = 1+number_range(dam/2, dam/5);
   mob->pIndexData->damplus = dam - ((1 + (mob->pIndexData->damnodice*mob->pIndexData->damsizedice))/2);
   mob->barenumdie = mob->pIndexData->damnodice;
   mob->baresizedie = mob->pIndexData->damsizedice;
   mob->damplus = mob->pIndexData->damplus;
   mob->perm_str = 13+(lvl/12)+number_range(-2, 2);
   mob->perm_dex = 13+(lvl/12)+number_range(-2, 2);
   mob->perm_wis = 13+(lvl/12)+number_range(-2, 2);
   mob->perm_int = 13+(lvl/12)+number_range(-2, 2);
   mob->perm_lck = 13+(lvl/12)+number_range(-2, 2);
   mob->perm_wis = 13+(lvl/12)+number_range(-2, 2);
   if (lvl > 70)
   {
      dam = (lvl-70)/3;
      if (lvl > 100)
         dam += UMIN(20,(lvl-100));
      if (lvl > 120)
         dam += (lvl-120)*2;
      mob->damaddlow = dam * 75 / 100;
      mob->damaddhi = dam * 125 / 100;
      mob->pIndexData->damaddlow = mob->damaddlow;
      mob->pIndexData->damaddhi = mob->damaddhi;
   }
   if (qmob)
      mob->race = qmob->race;
   else
      mob->race = npcrace->racenum;
   if (lvl <= 10) //Target the body only....
      mob->perm_int = 6;
      
   if (mob->race >= 0 && mob->race < MAX_RACE)
   {  
      mob->gold = (lvl * lvl /4) + (lvl*10); 
      if ((number_range(1, 5) >= 4 && eqload < vsize/25) || (qmob && qmob->boss > 0))
      {
         mob->gold = (lvl * lvl /2.5) + (lvl*20); 
         if (qmob && qmob->boss <= 0)
            eqload++;
         if (lvl >= 101)
            mob->gold = 7000 + ((lvl-99)*2000);
         if (lvl >= 61 && number_range(1, 3) == 1)
         {
            weapon = create_object(get_obj_index(get_wilder_weapon(((lvl-1)/10+1),1)), 1);
            weapon2 = create_object(get_obj_index(get_wilder_weapon(((lvl-1)/10+1),1)), 1);
         }
         else
            weapon = create_object(get_obj_index(get_wilder_weapon(((lvl-1)/10+1),0)), 1);
            
         num = ((lvl-1)/10+1)+number_range(-3, 3);
         if (num < 1)
            num = 1;
            
         if (num <= 2)
         {
            rarm = create_object(get_obj_index(OBJ_FORGE_CHAIN_GAUNTLET), 1);
            larm = create_object(get_obj_index(OBJ_FORGE_CHAIN_GAUNTLET), 1);  
            neck = create_object(get_obj_index(OBJ_FORGE_AVENTAIL), 1);
            head = create_object(get_obj_index(OBJ_FORGE_CABASSET), 1);
            rleg = create_object(get_obj_index(OBJ_FORGE_CHAIN_GREAVE), 1);
            lleg = create_object(get_obj_index(OBJ_FORGE_CHAIN_GREAVE), 1);
         }
         else if (num <= 6)
         {
            rarm = create_object(get_obj_index(OBJ_FORGE_RING_GAUNTLET), 1);
            larm = create_object(get_obj_index(OBJ_FORGE_RING_GAUNTLET), 1);  
            neck = create_object(get_obj_index(OBJ_FORGE_COIF), 1);
            head = create_object(get_obj_index(OBJ_FORGE_CASQUE), 1);
            rleg = create_object(get_obj_index(OBJ_FORGE_RING_GREAVE), 1);
            lleg = create_object(get_obj_index(OBJ_FORGE_RING_GREAVE), 1);
         }
         else if (num <= 10)
         {
            rarm = create_object(get_obj_index(OBJ_FORGE_GAUNTLET), 1);   
            larm = create_object(get_obj_index(OBJ_FORGE_GAUNTLET), 1);   
            neck = create_object(get_obj_index(OBJ_FORGE_DOUBLE_COIF), 1);
            head = create_object(get_obj_index(OBJ_FORGE_ARMET), 1);
            rleg = create_object(get_obj_index(OBJ_FORGE_GREAVE), 1);
            lleg = create_object(get_obj_index(OBJ_FORGE_GREAVE), 1);
         }
         else if (num >= 10)
         {
            rarm = create_object(get_obj_index(OBJ_FORGE_VAMBRACE), 1);
            larm = create_object(get_obj_index(OBJ_FORGE_VAMBRACE), 1);
            neck = create_object(get_obj_index(OBJ_FORGE_DOUBLE_COIF), 1);
            head = create_object(get_obj_index(OBJ_FORGE_HEAUME), 1);
            rleg = create_object(get_obj_index(OBJ_FORGE_CUISS), 1);
            lleg = create_object(get_obj_index(OBJ_FORGE_CUISS), 1);
         }
         if (num <= 2)
            chest = create_object(get_obj_index(OBJ_FORGE_CHAIN_MAIL), 1);
         else if (num <= 5)
            chest = create_object(get_obj_index(OBJ_FORGE_CHAIN_HAUBERK), 1);
         else if (num <= 7)
            chest = create_object(get_obj_index(OBJ_FORGE_RING_MAIL), 1);
         else if (num <= 9)
            chest = create_object(get_obj_index(OBJ_FORGE_DOUBLE_RING_MAIL), 1);
         else if (num <= 11)
            chest = create_object(get_obj_index(OBJ_FORGE_BREASTPLATE), 1);
         else if (num >= 11)
            chest = create_object(get_obj_index(OBJ_FORGE_CUIRASS), 1);
            
         slab1 = get_slab_vnum(lvl, 1);
         slab2 = get_slab_vnum(lvl, 2);
         slab3 = get_slab_vnum(lvl, 3);
         per1 = get_slab_vnum(lvl, 4);
         per2 = get_slab_vnum(lvl, 5);
         per3 = get_slab_vnum(lvl, 6);
                           
         for (firstslab = first_slab; firstslab; firstslab = firstslab->next)
         {
            if (firstslab->vnum == slab1)
               break;
         }
         for (secondslab = first_slab; secondslab; secondslab = secondslab->next)
         {
            if (secondslab->vnum == slab2)
               break;
         }
         if (slab3 > 0)
         {
            for (thirdslab = first_slab; thirdslab; thirdslab = thirdslab->next)
            {
               if (thirdslab->vnum == slab3)
               break;
            }
         }
         if (!firstslab)
         {
            bug("Adjust_Wildermob: %d is not a valid Slab", slab1);
         }
         else if (!secondslab)
         {
            bug("Adjust_Wildermob: %d is not a valid Slab", slab2);
         }
         else if (slab3 > 0 && !thirdslab)
         {
            bug("Adjust_Wildermob: %d is not a valid Slab", slab3);
         }
         else
         {
            int times;
            int lastnum[7];
            
            for (times = 1; times <= 6; times++)
               lastnum[times] = 0;
            
            race = mob->race;
            if (mob->race < 0 || mob->race >= MAX_RACE)
               mob->race = 0; //Needs a valid race   
            times = number_range(1, 2);
            if (qmob && qmob->boss == 1)
               times = number_range(2, 3);
            if (qmob && qmob->boss == 2)
               times = number_range(2, 4);
            for (x = 1; x <= times; x++)
            {
               num = number_range(1, 6);
               
               if (lastnum[num] == 1)
               {
                  x--;
                  continue;
               }
               lastnum[num] = 1;
            }
            if (lastnum[1] == 0)  
               weapon = weapon2 = NULL;
            if (lastnum[2] == 0) 
               rarm = larm = NULL;
            if (lastnum[3] == 0) 
               neck = NULL;
            if (lastnum[4] == 0)  
               head = NULL;
            if (lastnum[5] == 0)  
               rleg = lleg = NULL;
            if (lastnum[6] == 0) 
               chest = NULL;
               
            firstslabobj = create_object(get_obj_index(firstslab->vnum), 1);
            secondslabobj = create_object(get_obj_index(secondslab->vnum), 1);
            if (slab3 > 0)
               thirdslabobj = create_object(get_obj_index(thirdslab->vnum), 1);
            
            if (weapon)
            {   
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, weapon, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, weapon, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, weapon, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, weapon, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, weapon, secondslabobj, secondslab);   
               }
            }	
            if (weapon2)
            {   
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, weapon2, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, weapon2, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, weapon2, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, weapon2, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, weapon2, secondslabobj, secondslab);   
               }
            }	
            if (neck)   
            {
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, neck, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, neck, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, neck, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, neck, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, neck, secondslabobj, secondslab);   
               }
            }
            if (head)   
            {
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, head, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, head, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, head, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, head, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, head, secondslabobj, secondslab);   
               }
            }
            if (rarm)   
            {
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, rarm, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, rarm, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, rarm, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, rarm, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, rarm, secondslabobj, secondslab);   
               }
            }
            if (larm)   
            {
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, larm, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, larm, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, larm, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, larm, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, larm, secondslabobj, secondslab);   
               }
            }
            if (rleg)   
            {
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, rleg, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, rleg, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, rleg, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, rleg, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, rleg, secondslabobj, secondslab);   
               }
            }
            if (lleg)   
            {
               if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, lleg, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, lleg, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, lleg, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, lleg, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, lleg, secondslabobj, secondslab);   
               }
            }
            if (chest)
            {
              if (per3 <= 0)
               {
                  if (number_range(1, 100) <= per1)
                     alter_forge_obj(mob, chest, firstslabobj, firstslab);	
                  else
                     alter_forge_obj(mob, chest, secondslabobj, secondslab);
               }
               else
               {
                  num = number_range(1, 100);
                  if (num <= per1)
                     alter_forge_obj(mob, chest, firstslabobj, firstslab);
                  else if (num > per3)
                     alter_forge_obj(mob, chest, thirdslabobj, thirdslab);
                  else
                     alter_forge_obj(mob, chest, secondslabobj, secondslab);   
               }
            }  
            mob->race = race;
         }       
         if (rleg)
         {
            obj_to_char(rleg, mob);
            equip_char(mob, rleg, WEAR_LEG_R);  
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, rleg);
         } 
         if (lleg)
         {
            obj_to_char(lleg, mob);
            equip_char(mob, lleg, WEAR_LEG_L);   
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, lleg); 
         }
         if (larm)
         {
            obj_to_char(larm, mob);
            equip_char(mob, larm, WEAR_ARM_L); 
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, larm);
         }
         if (rarm)
         {
            obj_to_char(rarm, mob);
            equip_char(mob, rarm, WEAR_ARM_R);   
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, rarm);
         }
         if (chest)
         {
            obj_to_char(chest, mob);
            equip_char(mob, chest, WEAR_BODY);  
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, chest);
         }
         if (head)
         {
            obj_to_char(head, mob);
            equip_char(mob, head, WEAR_HEAD);  
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, head);
         }
         if (neck)
         {
            obj_to_char(neck, mob);
            equip_char(mob, neck, WEAR_NECK);  
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, neck);
         }
         if (weapon)
         {
            obj_to_char(weapon, mob);
            equip_char(mob, weapon, WEAR_WIELD); 
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, weapon);
         }
         if (weapon2)
         {
            obj_to_char(weapon2, mob);
            equip_char(mob, weapon2, WEAR_DUAL_WIELD); 
            if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
               copy_static_area_obj(mob, weapon2);
         }
         if (firstslabobj)
            extract_obj(firstslabobj);
         if (secondslabobj)
            extract_obj(secondslabobj);
         if (thirdslabobj)
            extract_obj(thirdslabobj);
      }
   }
   if (qmob)
      mob->sex = qmob->sex;
   else
      mob->sex = npcrace->sex[diff-1];
   if (area->hi_r_vnum >= START_STATICQUEST_VNUM && mob->race <= 5 && (qmob && qmob->boss > 0))
   {
      STRFREE(mob->name);
      generate_randomname(mob->race, mob->sex, buf);
      if (buf[0] != '\0')
         mob->name = STRALLOC(buf);
      else
      {       
         if (qmob)
            sprintf(buf, "%s", qmob->name);
         else
            sprintf(buf, "%s", add_npc_name(npcrace, diff));
         mob->name = STRALLOC(buf);
      }
   }
   else
   {
      STRFREE(mob->name);
      if (qmob)
         sprintf(buf, "%s", qmob->name);
      else
         sprintf(buf, "%s", add_npc_name(npcrace, diff));
      mob->name = STRALLOC(buf);
   }
   STRFREE(mob->short_descr);
   STRFREE(mob->long_descr);
   mob->short_descr = STRALLOC(buf);
   sprintf(buf, "%s %s\n\r", mob->name, qmob_long_descr[number_range(0, 17)]);
   mob->long_descr = STRALLOC(buf);
   xREMOVE_BIT(mob->act, ACT_PROTOTYPE);
   xSET_BIT(mob->act, ACT_AGGRESSIVE);
   xSET_BIT(mob->affected_by, AFF_INFRARED);
   if (number_range(1, 100) <= 85)
      xSET_BIT(mob->act, ACT_NOWANDER);
   adjust_qmob_flags(mob, qmob, npcrace, diff);
   if (difficulty >= 101)
   {
      if (qmob && qmob->boss == 1)
      {
         mob->gold = (lvl * lvl /2.5) + (lvl*20);   
         if (lvl >= 101)
            mob->gold = 25000 + ((lvl-99)*2000);
         mob->hit = mob->hit *165/100;
         mob->pIndexData->damplus += 5;
         mob->max_hit = mob->hit;
         mob->damaddhi = mob->damaddhi * 125 / 100;
         mob->damaddlow = mob->damaddlow * 125 / 100;
         mob->tohitbash = UMIN(25, mob->tohitbash+1);
         mob->tohitslash = UMIN(25, mob->tohitslash+1);
         mob->tohitstab = UMIN(25, mob->tohitstab+1);
         mob->armor = UMIN(25, mob->armor+1);
         mob->gold *= 2;
      }
      if (qmob && qmob->boss == 2)
      {
         mob->gold = (lvl * lvl /2.5) + (lvl*20);   
         if (lvl >= 101)
            mob->gold = 35000 + ((lvl-99)*2000);
         mob->hit = mob->hit * 245/100;
         mob->pIndexData->damplus += 10;
         mob->damaddhi = mob->damaddhi * 150 / 100;
         mob->damaddlow = mob->damaddlow * 150 / 100;
         mob->max_hit = mob->hit;
         mob->tohitbash = UMIN(25, mob->tohitbash+2);
         mob->tohitslash = UMIN(25, mob->tohitslash+2);
         mob->tohitstab = UMIN(25, mob->tohitstab+2);
         mob->armor = UMIN(25, mob->armor+2);
         mob->gold *= 5;
      }
   }
   else
   {
      if (qmob && qmob->boss == 1)
      {
         mob->hit = mob->hit * 125/100;
         gold = (lvl * lvl /2.5) + (lvl*20);   
         if (lvl >= 101)
            gold = 30000 + ((lvl-99)*2000);
         if (gold > mob->gold)
            mob->gold = gold;
         if (lvl >= 101)
         {
            mob->gold *= 150/100;
            if (mob->gold < 20000)
               mob->gold = 20000;
         }
         else
            mob->gold *= 6;
      }
      if (qmob && qmob->boss == 2)
      {
         mob->hit = mob->hit * 155/100;
         gold = (lvl * lvl /2.5) + (lvl*20);  
         if (lvl >= 101)
            gold = 50000 + ((lvl-99)*2000);
         if (gold > mob->gold)
            mob->gold = gold;
         if (lvl >= 101)
         {
            mob->gold *= 200/100;
            if (mob->gold < 50000)
               mob->gold = 50000;
         }
         else
            mob->gold *= 15;
      }
   }
   if (area->hi_r_vnum >= START_STATICQUEST_VNUM)
      adjust_static_quest_mob(mob);
   return;
}

void link_paf_quest(int loc, int value, OBJ_DATA *obj)
{
   AFFECT_DATA *paf;
   CREATE(paf, AFFECT_DATA, 1);
   paf->type = -1;
   paf->duration = -1;
   paf->location = loc;
   paf->modifier = value;
   xCLEAR_BITS(paf->bitvector);
   paf->next = NULL;
   LINK(paf, obj->first_affect, obj->last_affect, next, prev);
   ++top_affect;
}
      
void adjust_qobj_flags(OBJ_DATA *obj, QOBJ_DATA *qobj)
{
   sh_int loc;
   int value;
   
   if (xIS_SET(qobj->flags, QOBJ_FINGER))
      SET_BIT(obj->wear_flags, ITEM_WEAR_FINGER);
   if (xIS_SET(qobj->flags, QOBJ_NECK))
      SET_BIT(obj->wear_flags, ITEM_WEAR_NECK);
   if (xIS_SET(qobj->flags, QOBJ_BODY))
      SET_BIT(obj->wear_flags, ITEM_WEAR_BODY);
   if (xIS_SET(qobj->flags, QOBJ_HEAD))
      SET_BIT(obj->wear_flags, ITEM_WEAR_HEAD);
   if (xIS_SET(qobj->flags, QOBJ_LEGS))
      SET_BIT(obj->wear_flags, ITEM_WEAR_LEGS);
   if (xIS_SET(qobj->flags, QOBJ_ARMS))
      SET_BIT(obj->wear_flags, ITEM_WEAR_ARMS);
   if (xIS_SET(qobj->flags, QOBJ_WSHIELD))
      SET_BIT(obj->wear_flags, ITEM_WEAR_SHIELD);
   if (xIS_SET(qobj->flags, QOBJ_ANECK))
      SET_BIT(obj->wear_flags, ITEM_WEAR_ABOUT_NECK);
   if (xIS_SET(qobj->flags, QOBJ_WAIST))
      SET_BIT(obj->wear_flags, ITEM_WEAR_WAIST);
   if (xIS_SET(qobj->flags2, QOBJ_BACK))
      SET_BIT(obj->wear_flags, ITEM_WEAR_BACK);
   if (xIS_SET(qobj->flags, QOBJ_WIELD))
      SET_BIT(obj->wear_flags, ITEM_WIELD);
   if (xIS_SET(qobj->flags, QOBJ_MAGIC))   
      xSET_BIT(obj->extra_flags, ITEM_MAGIC);
   if (xIS_SET(qobj->flags, QOBJ_NODROP))   
      xSET_BIT(obj->extra_flags, ITEM_NODROP);
   if (xIS_SET(qobj->flags, QOBJ_BLESS))   
      xSET_BIT(obj->extra_flags, ITEM_BLESS);
   if (xIS_SET(qobj->flags, QOBJ_INVENTORY))   
      xSET_BIT(obj->extra_flags, ITEM_INVENTORY);
   if (xIS_SET(qobj->flags, QOBJ_ORGANIC))   
      xSET_BIT(obj->extra_flags, ITEM_ORGANIC);
   if (xIS_SET(qobj->flags, QOBJ_METAL))   
      xSET_BIT(obj->extra_flags, ITEM_METAL);
   if (xIS_SET(qobj->flags, QOBJ_POISONED))   
      xSET_BIT(obj->extra_flags, ITEM_POISONED);
   if (xIS_SET(qobj->flags, QOBJ_DEATHROT))   
      xSET_BIT(obj->extra_flags, ITEM_DEATHROT);
   if (xIS_SET(qobj->flags, QOBJ_NOLOCATE))   
      xSET_BIT(obj->extra_flags, ITEM_NOLOCATE);
   if (xIS_SET(qobj->flags, QOBJ_GROUNDROT))   
      xSET_BIT(obj->extra_flags, ITEM_GROUNDROT);
   if (xIS_SET(qobj->flags, QOBJ_NOGIVE))   
      xSET_BIT(obj->extra_flags, ITEM_NOGIVE);
   if (xIS_SET(qobj->flags, QOBJ_NODISARM))   
      xSET_BIT(obj->extra_flags, ITEM_NODISARM);
   if (xIS_SET(qobj->flags, QOBJ_NOBREAK))   
      xSET_BIT(obj->extra_flags, ITEM_NOBREAK);
   if (xIS_SET(qobj->flags, QOBJ_ARTIFACT))   
      xSET_BIT(obj->extra_flags, ITEM_ARTIFACT);   
   if (xIS_SET(qobj->flags, QOBJ_TWOHANDED))   
      xSET_BIT(obj->extra_flags, ITEM_TWOHANDED);
   if (xIS_SET(qobj->flags, QOBJ_IMBUABLE))   
      xSET_BIT(obj->extra_flags, ITEM_IMBUABLE);
   if (xIS_SET(qobj->flags, QOBJ_GEM))   
      xSET_BIT(obj->extra_flags, ITEM_GEM);
   if (xIS_SET(qobj->flags, QOBJ_GEM_SETTING))   
      xSET_BIT(obj->extra_flags, ITEM_GEM_SETTING);
   if (xIS_SET(qobj->flags, QOBJ_SANCTIFIED))   
      xSET_BIT(obj->extra_flags, ITEM_SANCTIFIED);
   if (xIS_SET(qobj->flags, QOBJ_CLOAK))   
      xSET_BIT(obj->extra_flags, ITEM_CLOAK);
   if (xIS_SET(qobj->flags, QOBJ_UNIQUE))   
      xSET_BIT(obj->extra_flags, ITEM_UNIQUE);
   if (xIS_SET(qobj->flags, QOBJ_STR))
   {
      loc = APPLY_STR;
      value = 1;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_STR2))
   {
      loc = APPLY_STR;
      value = 2;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_STR3))
   {
      loc = APPLY_STR;
      value = 3;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_LSTR))
   {
      loc = APPLY_STR;
      value = -1;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_LSTR2))
   {
      loc = APPLY_STR;
      value = -2;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_DEX))
   {
      loc = APPLY_DEX;
      value = 1;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_DEX2))
   {
      loc = APPLY_DEX;
      value = 2;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_DEX3))
   {
      loc = APPLY_DEX;
      value = 3;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_LDEX))
   {
      loc = APPLY_DEX;
      value = -1;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_LDEX2))
   {
      loc = APPLY_DEX;
      value = -2;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_INT))
   {
      loc = APPLY_INT;
      value = 1;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_INT2))
   {
      loc = APPLY_INT;
      value = 2;      
      link_paf_quest(loc, value, obj);
   }
   if (xIS_SET(qobj->flags, QOBJ_INT3))
   {
      loc = APPLY_INT;
      value = 3;      
    

Showing the first 100 KB of 251.4 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571