Abit/Qbit Questbits code - by Scion
-----------------------------------

This code is intended for use on Smaug FUSS 1.7. It should work fine on any version of Smaug though.
What this code does
-------------------

This code allows you to create quest bits to apply to mobs and players so that you can
keep track of who has complete what quest. This is best used for short simple quests that
don't require a lot of intermediate stages.

Installation Instructions
-------------------------

1. Place the bits.c and bits.h files in your src directory. Open your Makefile and add bits.c
to the appropriate section.

2. Open db.c and find function free_char()

Locate:
   TIMER *timer;
   MPROG_ACT_LIST *mpact, *mpact_next;

Below that, add:
   BIT_DATA *abit, *abit_next;

Locate:
   free_fight( ch );

Below that, add:
   for( abit = ch->first_abit; abit; abit = abit_next )
   {
      abit_next = abit->next;

      UNLINK( abit, ch->first_abit, ch->last_abit, next, prev );
      DISPOSE( abit );
   }

Locate:
   if( ch->pcdata )
   {
      IGNORE_DATA *temp, *next;

Change to:
   if( ch->pcdata )
   {
      IGNORE_DATA *temp, *next;
      BIT_DATA *qbit, *qbit_next;

Locate:
      if( ch->pcdata->tell_history )
      {
         int i;
         for( i = 0; i < 26; i++ )
         {
            if( ch->pcdata->tell_history[i] )
               STRFREE( ch->pcdata->tell_history[i] );
         }
         DISPOSE( ch->pcdata->tell_history );
      }

Below that, add:
      for( qbit = ch->pcdata->first_qbit; qbit; qbit = qbit_next )
      {
         qbit_next = qbit->next;

         UNLINK( qbit, ch->pcdata->first_qbit, ch->pcdata->last_qbit, next, prev );
         DISPOSE( qbit );
      }

In function boot_db, locate:

   log_string( "Loading tongues" );
   load_tongues(  );

Below that, add:
   /*
    * abit/qbit code
    */
   log_string( "Loading quest bit tables" );
   load_bits(  );

3. Open mud_prog.c

Locate:
      if( !str_cmp( chck, "isaffected" ) )
      {
         int value = get_aflag( rval );

         if( value < 0 || value > MAX_BITS )
         {
            progbug( "Unknown affect being checked", mob );
            return BERR;
         }
         return IS_AFFECTED( chkchar, value ) ? TRUE : FALSE;
      }

Below that, add:
      /*
       * abits and qbits 
       */
      if( !str_cmp( chck, "hasabit" ) )
      {
         int number;

         if( is_number( rval ) )
         {
            number = atoi( rval );

            if( get_abit( chkchar, number ) == NULL )
               return mprog_veval( 0, opr, 1, mob );
            else
               return mprog_veval( 1, opr, 1, mob );
         }
         progbug( "hasabit: bad abit number", mob );
         return BERR;
      }

      /*
       * abits and qbits 
       */
      if( !str_cmp( chck, "hasqbit" ) )
      {
         int number;

         if( is_number( rval ) )
         {
            number = atoi( rval );

            if( get_qbit( chkchar, number ) == NULL )
               return mprog_veval( 0, opr, 1, mob );
            else
               return mprog_veval( 1, opr, 1, mob );
         }
         progbug( "hasqbit: bad qbit number", mob );
         return BERR;
      }

4. Open save.c, function fwrite_char()

Locate:
   fprintf( fp, "%s", "End\n\n" );
   return;

Above that, add:
   if( ch->pcdata->first_qbit )
   {
      BIT_DATA *bit;

      for( bit = ch->pcdata->first_qbit; bit; bit = bit->next )
         fprintf( fp, "Qbit        %d %s~\n", bit->number, bit->desc );
   }

In function fread_char()

Locate:
            if( !str_cmp( word, "PTimer" ) )
            {
               add_timer( ch, TIMER_PKILLED, fread_number( fp ), NULL, 0 );
               fMatch = TRUE;
               break;
            }
            break;

Below that, add:
         case 'Q':
            if( !str_cmp( word, "Qbit" ) )
            {
               BIT_DATA *bit;
               BIT_DATA *desc;

               CREATE( bit, BIT_DATA, 1 );

               bit->number = fread_number( fp );
               if( !( desc = find_qbit( bit->number ) ) )
                  mudstrlcpy( bit->desc, fread_flagstring( fp ), MAX_STRING_LENGTH );
               else
               {
                  mudstrlcpy( bit->desc, desc->desc, MAX_STRING_LENGTH );
                  fread_flagstring( fp );
               }
               LINK( bit, ch->pcdata->first_qbit, ch->pcdata->last_qbit, next, prev );
               fMatch = TRUE;
               break;
            }
            break;

5. Open mud.h and find the DECLARE_DO_FUN statements.

Add the following statements:

DECLARE_DO_FUN( do_showabit );
DECLARE_DO_FUN( do_showqbit );
DECLARE_DO_FUN( do_setabit );
DECLARE_DO_FUN( do_setqbit );
DECLARE_DO_FUN( do_abit );
DECLARE_DO_FUN( do_qbit );
DECLARE_DO_FUN( do_mpaset );
DECLARE_DO_FUN( do_mpqset );

Locate:
 * Structure for extended bitvectors -- Thoric
 */
struct extended_bitvector
{
   unsigned int bits[XBI];
};

Below that, add:
#include "bits.h"

In struct_char_data, locate:
   ROOM_INDEX_DATA *in_room;
   ROOM_INDEX_DATA *was_in_room;
   PC_DATA *pcdata;

Below that, add:
   BIT_DATA *first_abit;  /* abit/qbit code */
   BIT_DATA *last_abit;

In struct pc_data, locate:
   COUNCIL_DATA *council;
   AREA_DATA *area;
   DEITY_DATA *deity;

Below that, add:
   BIT_DATA *first_qbit;  /* abit/qbit code */
   BIT_DATA *last_qbit;

6. Open comm.c, function cleanup_memory()

Locate:
   /*
    * Descriptors
    */
   fprintf( stdout, "%s", "Descriptors.\n" );
   for( desc = first_descriptor; desc; desc = desc_next )
   {
      desc_next = desc->next;
      UNLINK( desc, first_descriptor, last_descriptor, next, prev );
      free_desc( desc );
   }

Below that, add:
   /* Questbits */
   fprintf( stdout, "%s", "Questbits.\n" );
   free_questbits();

7. Compile and pray.

8. Once the MUD reboots, use cedit to create the following commands at the appropriate levels:

abit
qbit
showabit
showqbit
setabit
setqbit
mpaset
mpqset

9. Add the contents of the bits.help file to your help data.
