/
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@betterbox.net       *
\***********************************************************************/

/***********************************************************************\
*                            VERSION HISTORY                            *
* v0.1a--original development                                           *
\***********************************************************************/

#ifdef macintosh
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "merc.h"
#include "recycle.h"
#include "tables.h"
#include "lookup.h"
#include "general.h"

void gnrl_level( CHAR_DATA *ch, char * argument )
{
    CHAR_DATA *victim;
    char buf[MAX_STRING_LENGTH];
    int cost;

    if ( argument[0] == '\0' )
    {
	send_to_char( "Syntax: level <character>.\n\r", ch );
	return;
    }

    if ( ( victim = get_char_world( ch, argument ) ) == NULL )
    {
	send_to_char( "I can't seem to find that person.\n\r", ch );
	return;
    }

    if ( IS_NPC( victim ) )
    {
	send_to_char( "Not on MOBs!\n\r", ch );
	return;
    }

/*
    if ( !is_same_clan( ch, victim ) )
    {
	send_to_char( "Only for your own clan members, please.\n\r", ch );
	return;
    }
*/

    if ( IS_HERO( victim ) )
    {
	send_to_char( "It'll be hard to make that person any higher without an IMM's help!\n\r", ch );
	return;
    }

    cost = ( ( victim->level - 1 ) * 10 * ( IS_OMNI( victim ) ? 10 : 1 ) );

    if ( ch->pcdata->prestige < cost )
    {
	sprintf( buf, "Sorry, you need at least %d prestige points to do that.\n\r",
		cost );
	send_to_char( buf, ch );
	return;
    }

    ch->pcdata->prestige -= cost;

    send_to_char( "{c>>{b)){B!!{RYou just gained a level{B!!{b(({c<<{x\n\r", victim );
    send_to_char( "Ok.\n\r", ch );
    advance_level( victim );
    victim->level++;
    victim->exp   = exp_per_level(victim,victim->pcdata->points)
                  * UMAX( 1, victim->level ); 
    save_char_obj( ch );
    save_char_obj( victim );
}



void gnrl_advance( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];

    if ( ch->pcdata->gnrl_rank >= MAX_GENERAL_RANK )
    {
	send_to_char( "Sorry, but you can't go any higher than you already are!\n\r", ch );
	return;
    }

    /*
     * Make them pay for it in prestige, then actually advance them one
     * rank.
     */

    if ( argument[0] == '\0' )
    {
	sprintf( buf,
		 "To advance from rank {W%d{x to rank {W%d{x, you will need:\n\r"
		 "{%c%ld{x platinum\n\r"
		 "{%c%d{x prestige\n\r"
		 "{%c%d{x quest points\n\r",
		GENERAL_RANK( ch ), GENERAL_RANK( ch ) - 1,
		( ch->platinum >= ( 100000 * ch->pcdata->gnrl_rank )
		  ? 'G' : 'R' ),
		(long) ( 100000 * ch->pcdata->gnrl_rank ),
		( ch->pcdata->prestige >= ( 1500 * ch->pcdata->gnrl_rank )
		  ? 'G' : 'R' ),
		( 1500 * ch->pcdata->gnrl_rank ),
		( ch->questpoints >= ( 100 * ch->pcdata->gnrl_rank )
		  ? 'G' : 'R' ),
		( 100 * ch->pcdata->gnrl_rank ) );
		send_to_char( buf, ch );
	if ( ch->platinum >= ( 100000 * ch->pcdata->gnrl_rank )
	  && ch->pcdata->prestige >= ( 1500 * ch->pcdata->gnrl_rank )
	  && ch->questpoints >= ( 100 * ch->pcdata->gnrl_rank ) )
	{
	    sprintf( buf, "You are ready to advance.  Type {Badvance %d{x to do so.\n\r",
			GENERAL_RANK( ch ) - 1 );
	    send_to_char( buf, ch );
	}
	return;
    }

    sprintf( buf, "%d", GENERAL_RANK( ch ) - 1 );

    if ( str_cmp( argument, buf ) )
    {
	sprintf( buf, "Syntax:  {Badvance{x.\n\r"
		"If you have all needed resources, type: {Badvance %d{x.\n\r",
		GENERAL_RANK( ch ) - 1 );
	send_to_char( buf, ch );
	return;
    }

    if ( ch->platinum >= ( 100000 * ch->pcdata->gnrl_rank )
      && ch->pcdata->prestige >= ( 1500 * ch->pcdata->gnrl_rank )
      && ch->questpoints >= ( 100 * ch->pcdata->gnrl_rank ) )
    {
	ch->platinum -= ( 100000 * ch->pcdata->gnrl_rank );
	ch->pcdata->prestige -= ( 1500 * ch->pcdata->gnrl_rank );
	ch->questpoints -= ( 100 * ch->pcdata->gnrl_rank );
	send_to_char( "{BWelcome to your new rank.{x\n\r"
		        " -May you use it wisely- \n\r", ch );
	sprintf( buf, "%s has ascended to the %d%s rank.\n\r",
		ch->name, GENERAL_RANK( ch ) - 1,
		( ( ( GENERAL_RANK( ch ) - 1 ) % 10 ) == 3 ? "rd" :
		  ( ( ( GENERAL_RANK( ch ) - 1 ) % 10 ) == 2 ? "nd" :
		    ( ( ( GENERAL_RANK( ch ) - 1 ) % 10 ) == 1 ? "st" :
		      "th" ) ) ) );
	send_to_all_chars( buf );
	ch->pcdata->gnrl_rank++;
	save_char_obj( ch );
	return;
    }

    send_to_char( "You lack the resources needed to advance.  Type {Badvance{x to\n\r"
		"see what you're missing.\n\r", ch );
    return;
}



void gnrl_cash( CHAR_DATA *ch, char *argument )
{
    send_to_char( "Unimplemented.\n\r", ch );
    return;
}



void gnrl_restore( CHAR_DATA *ch, char *argument )
{
    CHAR_DATA *victim;
    char buf[MAX_STRING_LENGTH];

    if ( argument[0] == '\0' )
    {
	send_to_char( "Syntax: restore <character>.\n\r", ch );
	sprintf( buf, "Restore costs %d prestige points per person for"
		 " %d%s-rank Generals.\n\r",
		( ( ( MAX_GENERAL_RANK * 10 ) + 10 )
		     - ( ch->pcdata->gnrl_rank * 10 ) ),
		GENERAL_RANK( ch ),
		( ( ( GENERAL_RANK( ch ) ) % 10 ) == 3 ? "rd" :
		  ( ( ( GENERAL_RANK( ch ) ) % 10 ) == 2 ? "nd" :
		    ( ( ( GENERAL_RANK( ch ) ) % 10 ) == 1 ? "st" :
		      "th" ) ) ) );
	send_to_char( buf, ch );
	return;
    }

    if ( ( victim = get_char_world( ch, argument ) ) == NULL )
    {
	send_to_char( "I can't seem to find that person.\n\r", ch );
	return;
    }

    if ( IS_NPC( victim ) )
    {
	send_to_char( "Not on MOBs!\n\r", ch );
	return;
    }

    if ( ch == victim )
    {
	send_to_char( "Use your points on your members, not yourself!\n\r", ch );
	return;
    }

/*
    if ( !is_same_clan( ch, victim ) )
    {
	send_to_char( "Only for your own clan members, please.\n\r", ch );
	return;
    }
*/

    if ( ch->pcdata->prestige < 100 )
    {
	sprintf( buf, "Sorry, you need at least %d prestige points to do that.\n\r",
		   ( ( ( MAX_GENERAL_RANK * 10 ) + 10 )
		     - ( ch->pcdata->gnrl_rank * 10 ) ) );
	send_to_char( buf, ch );
	return;
    }

    ch->pcdata->prestige -= ( ( ( MAX_GENERAL_RANK * 10 ) + 10 )
		     - ( ch->pcdata->gnrl_rank * 10 ) );

    sprintf( buf, "{c>>{b)){B!!{R%d%s-rank General %s%s{R%s has"
		" just restored you{B!!{b(({c<<{x\n\r",
		GENERAL_RANK( ch ),
		( ( ( GENERAL_RANK( ch ) ) % 10 ) == 3 ? "rd" :
		  ( ( ( GENERAL_RANK( ch ) ) % 10 ) == 2 ? "nd" :
		    ( ( ( GENERAL_RANK( ch ) ) % 10 ) == 1 ? "st" :
		      "th" ) ) ),
		ch->name,
		ch->pcdata->title,
		( ( ch->pcdata->title[0] == ',' ) ? "," : "" ) );
    send_to_char( buf, victim );
    send_to_char( "Ok.\n\r", ch );
    RESTORE_CHAR( victim );
    save_char_obj( ch );
    save_char_obj( victim );
}



void gnrl_spellup( CHAR_DATA *ch, char *argument )
{
    send_to_char( "Unimplemented.\n\r", ch );
    return;
}



void gnrl_transfer( CHAR_DATA *ch, char *argument )
{
    send_to_char( "Unimplemented.\n\r", ch );
    return;
}



void gnrl_qp( CHAR_DATA *ch, char *argument )
{
    send_to_char( "Unimplemented.\n\r", ch );
    return;
}



void do_worship( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *victim;

    if ( argument[0] == '\0' )
    {
	send_to_char( "Syntax: worship <char>.\n\r", ch );
	return;
    }

    if ( IS_NPC( ch ) )
    {
	send_to_char( "Sorry, only PCs can worship Generals.\n\r", ch );
	return;
    }

    if ( ch->pcdata->prestige == 0 )
    {
	send_to_char( "But you have no prestige points to give!\n\r", ch );
	return;
    }

    if ( ( victim = get_char_world( ch, argument ) ) == NULL )
    {
	send_to_char( "That person isn't here.\n\r", ch );
	return;
    }

    if ( IS_NPC( victim ) )
    {
	send_to_char( "You can only worship players.\n\r", ch );
	return;
    }

/*
    if ( !is_same_clan( ch, victim ) )
    {
	send_to_char( "You can only worship your OWN clan General!\n\r", ch );
	return;
    }
*/

    if ( !IS_GENERAL( victim ) )
    {
	send_to_char( "That person's not even a General!\n\r", ch );
	return;
    }

    if ( ch == victim )
    {
	if ( IS_MXP( ch ) )
	    send_to_char( "Now <I><B>that's</B></I> being vain.\n\r", ch );
	else
	    send_to_char( "Now THAT's being vain.\n\r", ch );
	return;
    }

    send_to_char( "Your body coils into itself, then {rlaunches{x a giant "
		"{Gglowing{x\n\r{Gsphere of power{x into the sky, where it "
		"blazes a trail towards\n\ryour General.\n\r", ch );
    sprintf( buf, "%s sends a {Gglowing sphere{x to you through the air.\n\r"
		"Catching it, you discover %ld prestige points inside.\n\r",
		ch->name, ch->pcdata->prestige );
    send_to_char( buf, victim );

    victim->pcdata->prestige += ch->pcdata->prestige;
    ch->pcdata->prestige = 0;
}