char *take_best_coins( MONEY_TYPE * money, int cost ) { /* best fits a money to a base cost, returns a buf with change val as first arg, then the coin string in keyword format to take */ int still_needs = cost; int unit_level, cnt, can_take_this, change; char takecatbuf[MSL], debug_moneybuf[MSL], takebuf[MSL]; static char returnbuf[MSL]; MONEY_TYPE *transaction = new MONEY_TYPE; MONEY_TYPE *debug_money; unit_level = 0; /* start at smallest currency unit */ change = 0; for ( cnt = 0; cnt < MAX_CURRENCY; cnt++ ) transaction->cash_unit[cnt] = money->cash_unit[cnt]; takebuf[0] = '\0'; for ( ; still_needs > 0; ) { /* * take smallest unit, see what happens */ can_take_this = transaction->cash_unit[unit_level] * currency_table[unit_level].exchange_val; if ( can_take_this >= still_needs ) { short how_many; how_many = ( still_needs / currency_table[unit_level].exchange_val ) + ( ( still_needs % currency_table[unit_level].exchange_val != 0 ) ? 1 : 0 ); change = change + ( how_many * currency_table[unit_level].exchange_val ) - still_needs; still_needs = 0; snprintf( takecatbuf, MSL, " %d %s", how_many, currency_table[unit_level].keyword ); strncat( takebuf, takecatbuf, MSL - 1 ); break; } else { snprintf( takecatbuf, MSL, " %d %s", transaction->cash_unit[unit_level], currency_table[unit_level].keyword ); strncat( takebuf, takecatbuf, MSL - 1 ); transaction->cash_unit[unit_level] = 0; still_needs -= can_take_this; unit_level++; } } change = change + ( 0 - still_needs ); debug_money = round_money( cost, TRUE ); snprintf( debug_moneybuf, MSL, "%s", money_string( debug_money ) ); snprintf( log_buf, (2 * MIL), "Buy: cost: %d ( %s )\r\n, money has %s\r\n, wants to take %s\r\n, change %d.", cost, debug_moneybuf, money_string( money ), takebuf, change ); monitor_chan( log_buf, MONITOR_DEBUG ); delete transaction; delete debug_money; snprintf( returnbuf, MSL, "%d %s", change, takebuf ); return returnbuf; }
char *cost_to_money( int cost ) { static char outbuf[MSL]; MONEY_TYPE *money; money = round_money( cost, TRUE ); snprintf( outbuf, MSL, "%s", money_string( money ) ); delete money; return outbuf; }
/* * 'Split' originally by Gnort, God of Chaos. */ void do_split( CHAR_DATA * ch, char * argument ) { CHAR_DATA * gch; char buf[ MAX_STRING_LENGTH ]; char arg[ MAX_INPUT_LENGTH ]; int members; int amount = 0; int share = 0; int extra = 0; MONEY_DATA amt; char arg2[ MAX_STRING_LENGTH ]; argument = one_argument( argument, arg ); argument = one_argument( argument, arg2 ); if ( arg[ 0 ] == '\0' ) { send_to_char( AT_YELLOW, "Split how much?\n\r", ch ); return; } /* split 5 copper,gold,silver */ amount = is_number( arg ) ? atoi( arg ) : 0; amt.gold = amt.silver = amt.copper = 0; if ( !str_cmp( arg2, "gold" ) ) { amt.gold = amount; } else if ( !str_cmp( arg2, "silver" ) ) { amt.silver = amount; } else if ( !str_cmp( arg2, "copper" ) ) { amt.copper = amount; } else { send_to_char( AT_WHITE, "&WSyntax: &Rsplit <amount> <currency type>\n\r", ch ); return; } if ( ( amt.gold < 0 ) || ( amt.silver < 0 ) || ( amt.copper < 0 ) ) { send_to_char( AT_YELLOW, "Your group wouldn't like that.\n\r", ch ); return; } if ( ( amt.gold == 0 ) && ( amt.silver == 0 ) && ( amt.copper == 0 ) ) { send_to_char( AT_YELLOW, "You hand out zero coins, but no one notices.\n\r", ch ); return; } if ( ( ch->money.gold < amt.gold ) || ( ch->money.silver < amt.silver ) || ( ch->money.copper < amt.copper ) ) { sprintf( buf, "You don't have that many %s coins.\n\r", arg2 ); send_to_char( AT_YELLOW, buf, ch ); return; } members = 0; for ( gch = ch->in_room->people; gch; gch = gch->next_in_room ) { if ( gch->deleted ) { continue; } if ( is_same_group( gch, ch ) ) { members++; } } if ( members < 2 ) { return; } share = amount / members; extra = amount % members; if ( share == 0 ) { send_to_char( AT_YELLOW, "Don't even bother, cheapskate.\n\r", ch ); return; } if ( !str_cmp( arg2, "gold" ) ) { ch->money.gold -= amount; ch->money.gold += share + extra; } else if ( !str_cmp( arg2, "silver" ) ) { ch->money.silver -= amount; ch->money.silver += share + extra; } else if ( !str_cmp( arg2, "copper" ) ) { ch->money.copper -= amount; ch->money.silver += share + extra; } sprintf( buf, "You split %s Your share is %d %s coins.\n\r", money_string( &amt ), share + extra, arg2 ); send_to_char( AT_YELLOW, buf, ch ); sprintf( buf, "$n splits %s Your share is %d %s coins.", money_string( &amt ), share, arg2 ); for ( gch = ch->in_room->people; gch; gch = gch->next_in_room ) { if ( gch->deleted ) { continue; } if ( gch != ch && is_same_group( gch, ch ) ) { act( C_DEFAULT, buf, ch, NULL, gch, TO_VICT ); gch->money.gold += ( !str_cmp( arg2, "gold" ) ) ? share : 0; gch->money.silver += ( !str_cmp( arg2, "silver" ) ) ? share : 0; gch->money.copper += ( !str_cmp( arg2, "copper" ) ) ? share : 0; } } return; }
bool get_money_obj( CHAR_DATA * ch, char *argument, OBJ_DATA * obj ) { MONEY_TYPE *transfer = new MONEY_TYPE; short looper; char m_number[MSL]; char m_name[MSL]; char outbuf[MSL]; if ( !str_cmp( "all", argument ) ) { for ( looper = 0; looper < MAX_CURRENCY; looper++ ) { transfer->cash_unit[looper] = obj->money->cash_unit[looper]; obj->money->cash_unit[looper] = 0; } } else { for ( looper = 0; looper < MAX_CURRENCY; looper++ ) { transfer->cash_unit[looper] = 0; } for ( ;; ) { short mn; argument = one_argument( argument, m_number ); if ( m_number[0] == '\0' ) break; argument = one_argument( argument, m_name ); if ( m_name[0] == '\0' ) break; if ( ( ( mn = money_lookup( m_name ) ) < 0 ) || ( !is_number( m_number ) ) ) { snprintf( outbuf, MSL, "%s %s isn't a valid money type!\r\n", m_number, m_name ); send_to_char( outbuf, ch ); join_money( transfer, obj->money ); return FALSE; } if ( obj->money->cash_unit[mn] < atoi( m_number ) ) { /* snprintf( outbuf, MSL, "There isn't that much %s in %s!\r\n", m_name, obj->short_descr ); send_to_char( outbuf, ch ); */ join_money( transfer, obj->money ); return FALSE; } obj->money->cash_unit[mn] -= atoi( m_number ); transfer->cash_unit[mn] += atoi( m_number ); } } if ( money_value( transfer ) <= 0 ) { delete transfer; return FALSE; } if ( ( ch->carry_weight + money_weight( transfer ) ) > can_carry_w( ch ) ) { snprintf( outbuf, MSL, "%s", "You cannot carry that much weight!\r\n" ); send_to_char( outbuf, ch ); join_money( transfer, obj->money ); return FALSE; } ch->carry_weight += money_weight( transfer ); if ( check_charm_aff(ch, CHARM_AFF_GOLD) ) for ( looper = 0; looper < MAX_CURRENCY; looper++ ) transfer->cash_unit[looper] *= ((100 + get_charm_bonus(ch, CHARM_AFF_GOLD)) / 100); snprintf( outbuf, MSL, "You take %s from %s.\r\n", money_string( transfer ), obj->short_descr ); send_to_char( outbuf, ch ); join_money( transfer, ch->money ); return TRUE; }
bool get_money_room( CHAR_DATA * ch, char *argument ) { MONEY_TYPE *transfer = new MONEY_TYPE; short looper; char m_number[MSL]; char m_name[MSL]; char outbuf[MSL]; if ( !str_cmp( "all", argument ) ) { for ( looper = 0; looper < MAX_CURRENCY; looper++ ) { transfer->cash_unit[looper] = ch->in_room->treasure->cash_unit[looper]; ch->in_room->treasure->cash_unit[looper] = 0; } } else { for ( looper = 0; looper < MAX_CURRENCY; looper++ ) { transfer->cash_unit[looper] = 0; } for ( ;; ) { short mn; argument = one_argument( argument, m_number ); if ( m_number[0] == '\0' ) break; argument = one_argument( argument, m_name ); if ( m_name[0] == '\0' ) break; if ( ( ( mn = money_lookup( m_name ) ) < 0 ) || ( !is_number( m_number ) ) ) { snprintf( outbuf, MSL, "%s %s isn't a valid money type!\r\n", m_number, m_name ); send_to_char( outbuf, ch ); join_money( transfer, ch->in_room->treasure ); return FALSE; } if ( ch->in_room->treasure->cash_unit[mn] < atoi( m_number ) ) { /* snprintf( outbuf, MSL, "There isn't that much %s here!\r\n", m_name ); send_to_char( outbuf, ch ); */ join_money( transfer, ch->in_room->treasure ); return FALSE; } ch->in_room->treasure->cash_unit[mn] -= atoi( m_number ); transfer->cash_unit[mn] += atoi( m_number ); } } if ( ( ch->carry_weight + money_weight( transfer ) ) > can_carry_w( ch ) ) { snprintf( outbuf, MSL, "%s", "You cannot carry that much weight!\r\n" ); send_to_char( outbuf, ch ); join_money( transfer, ch->in_room->treasure ); return FALSE; } ch->carry_weight += money_weight( transfer ); if ( money_value( transfer ) <= 0 ) return FALSE; snprintf( outbuf, MSL, "You pick up %s.\r\n", money_string( transfer ) ); send_to_char( outbuf, ch ); join_money( transfer, ch->money ); return TRUE; }