rm6/
rm6/clans/
rm6/councils/
rm6/deity/
rm6/doc/mudprogs/
rm6/exchange/
rm6/gods/
rm6/homes/
rm6/nations/
rm6/player/
rm6/player/a/
rm6/src/RCS/
rm6/src/dmalloc/
rm6/src/dmalloc/bin/
rm6/src/dmalloc/include/
rm6/src/dmalloc/lib/
rm6/src/scripts/
rm6/src/utils/
/****************************************************************************
 * ResortMUD Version 5.0 was mainly programmed by Ntanel, Garinan, Josh,    *
 * Badastaz, Digifuzz, Senir, Kratas, Scion, Shogar and Tagith.             *
 * ------------------------------------------------------------------------ *
 * Copyright (C) 1996 - 2001 Haslage Net Electronics: MudWorld of Lorain,   *
 * Ohio.    ALL RIGHTS RESERVED    See /doc/RMLicense.txt for more details. *
 ****************************************************************************/

/****************************************************************************
 * [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.     *
 * ------------------------------------------------------------------------ *
 *			   Smaug banking support module                           *
 ****************************************************************************/
/***************************************************************************  
 *                          SMAUG Banking Support Code                     *
 ***************************************************************************
 *                                                                         *
 * This code may be used freely, as long as credit is given in the help    *
 * file. Thanks.                                                           *
 *								                           *
 *                                        -= Minas Ravenblood =-           *
 *                                 Implementor of The Apocalypse Theatre   *
 *                                      (email: krisco7@hotmail.com)       *
 *									                     *
 ***************************************************************************/

/* Modifications to original source by Samson */

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"

/* You can add this or just put it in the do_bank code. I don't really know
   why I made a seperate function for this, but I did. If you do add it,
   don't forget to declare it - Minas */
/* Finds banker mobs in a room. Installed by Samson on unknown date */
/* NOTE: Smaug 1.02a Users - Your compiler probably died on this
   function - if so, remove the x in front of IS_SET and recompile */

/* Local functions for new money system -Garinan */
int       goldamount               args( (int tmpvalue) );
int       silvamount               args( (int tmpvalue) );

CHAR_DATA *find_banker( CHAR_DATA *ch )
{
  CHAR_DATA *banker;
  
  for ( banker = ch->in_room->first_person; banker; banker = banker->next_in_room )
    if ( IS_NPC( banker ) && xIS_SET( banker->act, ACT_BANKER ) )
      break;

  return banker;
}

/* SMAUG Bank Support
 * Coded by Minas Ravenblood for The Apocalypse Theatre
 * (email: krisco7@hotmail.com)
 */
/* Installed by Samson on unknown date */
/* Deposit, withdraw, balance and transfer commands */
void do_deposit( CHAR_DATA *ch, char *argument )
{
  CHAR_DATA *banker;
  char arg1[MAX_INPUT_LENGTH];
  char arg2[MAX_INPUT_LENGTH];
  char buf [MAX_STRING_LENGTH];
  bool isgold = FALSE;
  bool issilver = FALSE;
  bool iscopper = FALSE;
  int amount;
  int newamount;
  
  if ( !( banker = find_banker( ch ) ) )
  {
    send_to_char( "&WYou're not in a bank!&w\n\r", ch );
    return;
  }
  
  if ( IS_NPC( ch ) )
  {
    sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
    do_say( banker, buf );
    return;
  }
  
  if ( argument[0] == '\0' )
  {
    do_say( banker, "If you need help, see HELP BANK." );
    return;
  }
  
  argument = one_argument( argument, arg1 );
  argument = one_argument( argument, arg2 );
          
  if ( arg1 == '\0' )
  {
    sprintf( buf, "%s How much do you wish to deposit?", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( str_cmp( arg1, "all" ) && !is_number( arg1 ) )
  {
    sprintf( buf, "%s How much do you wish to deposit?", ch->name );
    do_tell( banker, buf );
    return;
  }

  /* New Money System -Garinan */
  if ( arg2 == '\0' )
  {
    sprintf( buf, "%s You must specify gold, silver, or copper.", ch->name );
    do_tell( banker, buf );
    return;
  }
  
  if ( !str_cmp(arg2, "gold") )
	isgold = TRUE;
  else if ( !str_cmp(arg2, "silver") )
	issilver = TRUE;
  else if ( !str_cmp(arg2, "copper") )
	iscopper = TRUE;
  else
  {
    sprintf( buf, "%s I don't trade in that currency.", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( !str_cmp( arg1, "all" ) )
    isgold ? (amount = ch->gold) : issilver ? (amount = ch->silver) : (amount = ch->copper);
  else
    amount = atoi( arg1 );
  
  if ( ( amount > ch->gold && isgold ) || ( amount > ch->silver && issilver ) || ( amount > ch->copper && iscopper ) )
  {
      sprintf( buf, "%s Sorry, but you don't have that much %s to deposit.", ch->name, isgold ? "gold" : issilver ? "silver" : 
		"copper" );
      do_tell( banker, buf );
      return;
  }
    
  if ( amount <= 0 )
  {
      sprintf( buf, "%s Oh, I see.. I didn't know i was doing business with a comedian.", ch->name );
      do_tell( banker, buf );
      return;
  }

  if( !IS_IMMORTAL( ch ) )
  {
      if( ch->pcdata->balance == 5000000 )
      {
          do_tell( banker, "You can't deposit more than 5,000,000 coins!" );
          return;
      }

      if( ch->pcdata->balance + amount > 5000000 )
          amount = 5000000 - ch->pcdata->balance;
  }
  if (isgold)
  {
      ch->gold		-= amount;
      newamount = get_value(amount,0,0);
  }
  else if (issilver)
  {
      ch->silver	-= amount;
      newamount = get_value(0,amount,0);
  }
  else if (iscopper)
  {
      ch->copper	-= amount;
      newamount = get_value(0,0,amount);
  }
  else
  {
	bug("Invalid money type in banks. Error code: Er21301 Please report this code to Garinan.");
	return;
  }
/* This is ugly, but i'm tired -Garinan */
  if (( ch->pcdata->balance + newamount) <= 0 || (ch->pcdata->balance + newamount) > 200000000)
  {
    sprintf( buf, "%s Your account has reached its limit.", ch->name );
    do_tell( banker, buf );
    newamount = 0;
    ch->pcdata->balance = 200000000;
  }
  ch->pcdata->balance	+= newamount;
  sprintf( buf, "You deposit %d %s coin%s.\n\r", amount, isgold ? "gold" : issilver ? "silver" : "copper" ,(amount != 1) ? 
		"s" : "" );
  set_char_color( AT_WHITE, ch );
  send_to_char( buf, ch );
  sprintf( buf, "$n deposits %d %s coin%s.\n\r", amount, isgold ? "gold" : issilver ? "silver" : "copper" ,(amount != 1) ?  
		"s" : "" );
  act( AT_WHITE, buf, ch, NULL, NULL, TO_ROOM );
  return;
}

void do_withdraw( CHAR_DATA *ch, char *argument )
{
  CHAR_DATA *banker;
  char arg1[MAX_INPUT_LENGTH];
  char arg2[MAX_INPUT_LENGTH];
  char buf [MAX_STRING_LENGTH];
  bool isgold = FALSE;
  bool issilver = FALSE;
  bool iscopper = FALSE;
  int amount;
  int thebalance;
  int newamount;
  
  if ( !( banker = find_banker( ch ) ) )
  {
    send_to_char( "&WYou're not in a bank!&w\n\r", ch );
    return;
  }
  
  if ( IS_NPC( ch ) )
  {
    sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
    do_say( banker, buf );
    return;
  }
  
  if ( argument[0] == '\0' )
  {
    do_say( banker, "If you need help, see HELP BANK." );
    return;
  }
  
  argument = one_argument( argument, arg1 );
  argument = one_argument( argument, arg2 );
    
  if ( arg1 == '\0' )
  {
    sprintf( buf, "%s How much do you wish to withdraw?", ch->name );
    do_tell( banker, buf );
    return;
  }
  if ( str_cmp( arg1, "all" ) && !is_number( arg1 ) )
  { 
    sprintf( buf, "%s How much do you wish to withdraw?", ch->name );
    do_tell( banker, buf );
    return;
  }

  if ( arg2 == '\0' || (str_cmp(arg2, "gold") && str_cmp(arg2, "silver") && str_cmp(arg2, "copper") ) )
  {
    sprintf( buf, "%s You must specify gold, silver, or copper.", ch->name );
    do_tell( banker, buf );
    return;
  }

  if ( !str_cmp(arg2, "gold") )
  {
        isgold = TRUE;
	thebalance = goldamount(ch->pcdata->balance);
  }
  else if ( !str_cmp(arg2, "silver") )
  {
        issilver = TRUE;
	thebalance = silvamount(ch->pcdata->balance);
  }
  else if ( !str_cmp(arg2, "copper") )
  {
        iscopper = TRUE;
	thebalance = ch->pcdata->balance;
  }
  else
  {
    bug( "Invalid money type in banks. Error code: Er21302 Please report this code to Garinan." );
    return;
  }
    
  if ( !str_cmp( arg1, "all" ) )
    amount = ch->pcdata->balance;    
  else
    amount = atoi( arg1 );
  
  if ( amount > thebalance )
  {
    sprintf( buf, "%s But you do not have that much %s in your account!", ch->name, isgold ? "gold" : issilver ? "silver" : 
		"copper" );
    do_tell( banker, buf );
    return;
  }
    
  if ( amount <= 0 )
  {
    sprintf( buf, "%s Oh I see.. I didn't know i was doing business with a comedian.", ch->name );
    do_tell( banker, buf );
    return;
  }
  if (iscopper)
  {  
      ch->pcdata->balance	-= amount;
      ch->copper 		+= amount;
  }
  else if (isgold)
  {
      newamount = get_value(amount,0,0);
      ch->pcdata->balance	-= newamount;
      ch->gold                  += amount;
  }
  else if (issilver)
  {
      newamount = get_value(0,amount,0);
      ch->pcdata->balance	-= newamount;
      ch->silver                += amount;
  }
  else  
  {
    bug( "Invalid money type in banks. Error code: Er21303 Please report this code to Garinan." );
    return;
  }
  sprintf( buf, "You withdraw %d %s coin%s.\n\r", amount, isgold ? "gold" : issilver ? "silver" : "copper", (amount != 1) ? 
		"s" : "" );
  set_char_color( AT_WHITE, ch );
  send_to_char( buf, ch );
  sprintf( buf, "$n withdraws %d %s coin%s.\n\r", amount, isgold ? "gold" : issilver ? "silver" : "copper", (amount != 1) ? 
		"s" : "" );
  act( AT_WHITE, buf, ch, NULL, NULL, TO_ROOM );
  return;
}

void do_balance( CHAR_DATA *ch, char *argument )
{
  CHAR_DATA *banker;
  char buf [MAX_STRING_LENGTH];
  int silvies;
  int goldies;
    
    if ( !( banker = find_banker( ch ) ) )
    {
      send_to_char( "&WYou're not in a bank!&w\n\r", ch );
      return;
    }
    
    if ( IS_NPC( ch ) )
    {
      sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
      do_say( banker, buf );
      return;
    }

    goldies = goldamount(ch->pcdata->balance);
    silvies = silvamount(ch->pcdata->balance);

    set_char_color( AT_WHITE, ch );
    send_to_char( "Your account value is:\n\r", ch);
    sprintf( buf, "&YGold: %d.\n\r&WSilver: %d.\n\r&RCopper: %d.\n\r\n\r", goldies, silvies, ch->pcdata->balance);
    send_to_char( buf, ch );
    return;
}

void do_transfer( CHAR_DATA *ch, char *argument )
{
  CHAR_DATA *banker;
  CHAR_DATA *victim;
  char arg1[MAX_INPUT_LENGTH];
  char arg2[MAX_INPUT_LENGTH];
  char arg3[MAX_INPUT_LENGTH];
  bool isgold = FALSE;
  bool issilver = FALSE;
  bool iscopper = FALSE;

  char buf [MAX_STRING_LENGTH];
  int amount;
  int thebalance;
  int newamount;
  
  if ( !( banker = find_banker( ch ) ) )
  {
    send_to_char( "&WYou're not in a bank!&w\n\r", ch );
    return;
  }
  
  if ( IS_NPC( ch ) )
  {
    sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
    do_say( banker, buf );
    return;
  }
  
  if ( argument[0] == '\0' )
  {
    do_say( banker, "If you need help, see HELP BANK." );
    return;
  }
  
  
  argument = one_argument( argument, arg1 );
  argument = one_argument( argument, arg2 );
  argument = one_argument( argument, arg3 );
    
  if ( arg1 == '\0' || arg2 == '\0' || arg3 == '\0')
  {
    sprintf( buf, "%s How much do you wish to send to who?", ch->name );
    do_tell( banker, buf );
    return;
  }
  if ( str_cmp( arg1, "all" ) && !is_number( arg1 ) )
  {
    sprintf( buf, "%s How much do you wish to send to who?", ch->name );
    do_tell( banker, buf );
    return;
  }
  if (!str_cmp(arg2, "gold") )
  {
      isgold = TRUE;
      thebalance = goldamount(ch->pcdata->balance);
  }
  else if (!str_cmp(arg2, "silver") )
  {
      issilver = TRUE;
      thebalance = silvamount(ch->pcdata->balance);
  }
  else if (!str_cmp(arg2, "copper") )
  {
      iscopper = TRUE;
      thebalance = ch->pcdata->balance;
  }
  else
  {
    sprintf( buf, "%s I don't trade in that currency.", ch->name );
    do_tell( banker, buf );
    return;
  }      
  
  if ( !( victim = get_char_world( ch, arg3 ) ) )
  {
    sprintf( buf, "%s %s could not be located.", ch->name, capitalize(arg2) );
    do_tell( banker, buf );
    return;
  }
    
  if ( IS_NPC( victim ) )
  {
    sprintf( buf, "%s We do not do business with mobiles...", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( !str_cmp( arg1, "all" ) )
    amount = ch->pcdata->balance;
  else
    amount = atoi( arg1 );
  
  if ( amount > thebalance )
  {
    sprintf( buf, "%s You are very generous, but you don't have that much gold!", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( amount <= 0 )
  {
    sprintf( buf, "%s Oh I see.. I didn't know I was doing business with a comedian.", ch->name );
    do_tell( banker, buf );
    return;
  }
  if (isgold)
      newamount = get_value(amount,0,0);
  else if (issilver)
      newamount = get_value(amount,0,0);
  else if (iscopper)
      newamount = amount;
  else
  {
    bug( "Invalid money type in banks. Error code: Er21303 Please report this code to Garinan." );
    return;
  }

  ch->pcdata->balance     -= newamount;
  victim->pcdata->balance += newamount;
  sprintf( buf, "You transfer %d %s coin%s to %s's bank account.\n\r",
           amount, isgold ? "gold" : issilver ? "silver" : "copper", (amount != 1) ? "s" : "", victim->name );
  set_char_color( AT_WHITE, ch );
  send_to_char( buf, ch );
  sprintf( buf, "%s just transferred %d %s coin%s to your bank account.\n\r",
           ch->name, amount, isgold ? "gold" : issilver ? "silver" : "copper", (amount != 1) ? "s" : "" );
  set_char_color( AT_WHITE, victim );
  send_to_char( buf, victim );
  return;
}

/* End of new bank support */

/* A couple functions required for banking with new money -Garinan */

int goldamount (int tmpvalue)
{
    int goldies;

    goldies = tmpvalue/10000;
    return goldies;
}

int silvamount (int tmpvalue)
{
    int silvies;

    silvies = tmpvalue/100;
    return silvies;
}