void charges (int hours, double *charge, double *average_cost) { int temp_hours = hours; double money = 7.99, average = 0.0; if (hours > 10) { temp_hours -= 10; money = money + (temp_hours * 1.99); } average = money / hours; money = round_money (money); average = round_money (average); *charge = money; *average_cost = average; }
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; }
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; }
int exchange_money( CHAR_DATA * ch, char *argument ) { MONEY_TYPE *transfer = new MONEY_TYPE; char m_number[MSL]; char m_name[MSL]; char outbuf[MSL]; int base_val; float taxed = 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->money ); return -1; } if ( ch->money->cash_unit[mn] < atoi( m_number ) ) { snprintf( outbuf, MSL, "You don't have %s %s!\r\n", m_number, m_name ); send_to_char( outbuf, ch ); join_money( transfer, ch->money ); return -1; } ch->money->cash_unit[mn] -= atoi( m_number ); transfer->cash_unit[mn] += atoi( m_number ); } ch->carry_weight -= money_weight( transfer ); base_val = money_value( transfer ); taxed = EXCHANGE_COST * base_val; base_val -= (int)taxed; delete transfer; transfer = round_money( base_val, TRUE ); ch->carry_weight += money_weight( transfer ); join_money( transfer, ch->money ); return (int)taxed; }
void crusade_reward( CHAR_DATA *ch ) { char buf[MSL]; int reward = 0; ch->pcdata->records->crusade++; reward = quest_object->value[0]; snprintf( buf, MSL, "You receive %d quest points!\r\n", reward ); send_to_char( buf, ch ); ch->pcdata->quest_points += reward; ch->pcdata->records->qp_tot += reward; if ( ch->pcdata->quest_points > ch->pcdata->records->qp ) { send_to_char("@@yYou've broken your quest point record!@@N\r\n", ch); ch->pcdata->records->qp = ch->pcdata->quest_points; } reward = quest_object->value[1]; snprintf( buf, MSL, "You receive %d practices!\r\n", reward ); send_to_char( buf, ch ); ch->pcdata->practice += reward; reward = (exp_mob_base(quest_mob->level) * sysdata.killperlev); reward = number_range(static_cast<int>(reward * 0.02), static_cast<int>(reward * 0.04)); snprintf( buf, MSL, "You receive %d experience points!\r\n", reward ); send_to_char( buf, ch ); ch->exp += reward; reward = quest_object->value[2]; snprintf( buf, MSL, "You receive %s!\r\n", cost_to_money( reward ) ); send_to_char( buf, ch ); join_money( round_money( reward, TRUE ), ch->money ); return; }