/
Cool3/bin/
/***********************************************************************\
*                                 GENERAL                               *
*       GENERAL is by Jouster@COOLmud.  He can be reached at            *
* dan@betterbox.net.  This file falls under the GPL and the licenses    *
* of Diku, Merc, ROM, RoT, and any licenses that may apply to any       *
* portions of any file that this program may modify.                    *
*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*
*       If you don't mind, I'd appreciate an email if you use this      *
* file in your code.  Thanks.                                           *
*                                               dan@coolmud.com		*
\***********************************************************************/

/***********************************************************************\
*                            VERSION HISTORY                            *
* v0.1a--original development                                           *
* v0.1--Initial Implementation						*
* v0.2--Updated and revised to act as a fourth tier			*
\***********************************************************************/

#ifdef macintosh
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "general.h"


/*
 * Generals' Command Table
 */
const	struct	gnrl_cmd_type	gnrl_cmd_table	[] =
{
    { "advance",	gnrl_advance,	G1,	LOG_ALWAYS },
    { "cash",		gnrl_cash,	G2,	LOG_NORMAL },
    { "level",		gnrl_level,	G8,	LOG_ALWAYS },
    { "restore",	gnrl_restore,	G1,	LOG_NORMAL },
    { "spellup",	gnrl_spellup,	G3,	LOG_NORMAL },
    { "transfer",	gnrl_transfer,	G4,	LOG_NORMAL },
    { "questpoint",	gnrl_qp,	G6,	LOG_NORMAL },


    /*
     * End of list.
     */
    { "",		0,		0,  LOG_NORMAL }
};


/*
 * Da Function.  Only called if ch is a general to begin with.
 */

void interp_general( CHAR_DATA *ch, char *argument )
{
    /*
     * Thanks for the code on memchecks, Garry Turkington
     * <gary@reddwarf.qub.ac.uk>
     */
    extern int nAllocString;
    extern int nAllocPerm;
    int string_count = nAllocString;
    int perm_count = nAllocPerm;
    char command[MAX_INPUT_LENGTH];
    char logline[MAX_INPUT_LENGTH];
    int cmd;
    bool found;

    if ( IS_NPC( ch ) )
	return;

    /*
     * Kill leading spaces.
     */
    while ( isspace(*argument) )
	argument++;
    if ( argument[0] == '\0' )
	return;

    /*
     * Copy logline for Gary and split the word.
     */
    strcpy( logline, argument );
    argument = one_argument( argument, command );

    /*
     * Look for da command in da table.
     */
    found = FALSE;
    for ( cmd = 0; gnrl_cmd_table[cmd].name[0] != '\0'; cmd++ )
	if ( command[0] == gnrl_cmd_table[ cmd ].name[0] &&
	     !str_prefix( command, gnrl_cmd_table[ cmd ].name ) )
	    if ( gnrl_cmd_table[cmd].rank <= ch->pcdata->gnrl_rank )
	    {
		found = TRUE;
		break;
	    }

    /*
     * Straight copy from interp.c, then modified, since we don't want to
     * repeat any log statements.
     */
    if ( gnrl_cmd_table[cmd].log == LOG_ALWAYS
    &&	 !IS_SET(ch->act, PLR_LOG)
    &&	 ch->level != MAX_LEVEL
    &&	 !fLogAll
    &&	 gnrl_cmd_table[cmd].log != LOG_NEVER )
    {
	sprintf( log_buf, "Log %s: %s", ch->name, logline );
	wiznet(log_buf,ch,NULL,WIZ_SECURE,0,get_trust(ch));
	log_string( log_buf );
    }

    if ( !found )
    {
	send_to_char( "Huh?\n\r", ch );
	return;
    }

    /*
     * Dispatch the command.
     */
    (*gnrl_cmd_table[cmd].do_fun) ( ch, argument );

    if (string_count != nAllocString)
    {
	sprintf(log_buf,	"%s in strings :: %s : %s.\n\r"
				"%d to %d, a%s of %d",
				( string_count < nAllocString ? "Increase" :
					"Decrease" ),
				ch->name, logline,
				string_count, nAllocString,
				( string_count < nAllocString ? "n increase" :
					" decrease" ),
				abs( ( nAllocString - string_count) ) );
	wiznet(log_buf, NULL, NULL, WIZ_MEMCHECK,0,0);
    }

    if (perm_count != nAllocPerm)
    {
	sprintf(log_buf,	"%s in perms :: %s : %s.\n\r"
				"%d to %d, a%s of %d",
				( perm_count < nAllocPerm ? "Increase" :
					"Decrease" ),
				ch->name, logline,
				perm_count, nAllocPerm,
				( perm_count < nAllocPerm ? "n increase" :
					" decrease" ),
				abs( ( nAllocPerm - perm_count) ) );
	wiznet(log_buf, NULL, NULL, WIZ_MEMCHECK,0,0);
    }

    tail_chain( );
    return;
}