/* -----------------------------------------------------------------------
The following snippet was written by Gary McNickle (dharvest) for
Rom 2.4 specific MUDs and is released into the public domain. My thanks to
the originators of Diku, and Rom, as well as to all those others who have
released code for this mud base.  Goes to show that the freeware idea can
actually work. ;)  In any case, all I ask is that you credit this code
properly, and perhaps drop me a line letting me know it's being used.

from: gary@dharvest.com
website: http://www.dharvest.com
or http://www.dharvest.com/resource.html (rom related)

Send any comments, flames, bug-reports, suggestions, requests, etc... 
to the above email address.
----------------------------------------------------------------------- */

  To Install:

*** in merc.h ***

  1: add this to your "global variables" section
extern          int                     num_quotes;     /* do_quotes */
  
  2: define a "QUOTE_DIR" like so...
#define QUOTE_DIR       "../data/quotes/"       /* dir for quote files */

  3: add this to your prototypes section. (for whichever file you put 
     the "do_quotes" command into. (act_comm.c would be a good file)
void do_quotes          args( ( CHAR_DATA *ch ) );

*** in db.c ***

  1: somewhere in your "globals" section, add this:
int                     num_quotes; /* for do_quotes */

  2: in your local prototypes section, add:
void    load_quotes     args( (void) );

  3: in "boot_db", after "load_songs()"  add:
void    load_quotes     args( (void) );

  4: add the "load_quotes" function at the bottom of this file after
     "boot_db"

*** in whatever file you like. act_comm.c would be good. ***

  1: add the "do_quotes" function found at the bottom of this file.

*** misc ***

  1: create the QUOTE_DIR
  2: write some quotes up! file names should be "quote.1" "quote.2" etc.
  

****  That's it to installing, recompile and enjoy.  ****
*/


/** Function: load_quotes
  * Descr   : Determines how many (if any) quote files are located within
  *           QUOTE_DIR, for later use by "do_quotes".
  * Returns : (void)
  * Syntax  : (none)
  * Written : v1.0 12/97
  * Author  : Gary McNickle <gary@dharvest.com>
  */
void load_quotes( void )
{
  int n=0;
  FILE *fp;
  char buf[100];

  sprintf(buf, "%squote.1", QUOTE_DIR);

  while ( (fp = fopen(buf, "r")) != NULL )
  {
    fclose(fp);
    n++;
    sprintf(buf, "%squote.%d", QUOTE_DIR, n);
  }
  n--;

  num_quotes = n;
  sprintf(buf, "%d Quote files found in %s.", num_quotes, QUOTE_DIR);
  log_string(buf);
  return;
} /* end load_quotes */


/** Function: do_quotes
  * Descr   : Outputs an ascii file "quote.#" to the player. The number (#)
  *           is determined at random, based on how many quote files are
  *           stored in the QUOTE_DIR directory.
  * Returns : (void)
  * Syntax  : (none)
  * Written : v1.0 12/97
  * Author  : Gary McNickle <gary@dharvest.com>    
  */
void do_quotes(CHAR_DATA *ch)
{
  int i;
  char buf[MAX_STRING_LENGTH];  
  FILE *fp;

  if ( num_quotes <= 0 ) 
  {
    /* replace msg with your default logout message. */
    send_to_char("All good things come to and end.", ch);
    return;
  }

  i = number_range( 1, num_quotes);
  sprintf(buf, "%squote.%d", QUOTE_DIR, i);

  if ( (fp = fopen(buf, "r")) == NULL )
  {
    log_string("No quote files found.");

    /* use your default "logout msg" here instead. */
    send_to_char("All good things must end...", ch);
    return;
  } 

  send_to_char("\n\r", ch);
  while ( !feof(fp) )
  {
    /* be sure fgets read some more data, we dont want to send the last 
       line twice. */
    if ( fgets(buf, MAX_STRING_LENGTH, fp) != NULL )
      send_to_char(buf, ch);    
  }  

  send_to_char("\n\r", ch);
  fclose(fp);
     
} /* end do_quotes */

