/*
 * /sys/money.h
 *
 * This file defines some macros that are usefull for handling money.
 */

#ifndef MONEY_DEFINITIONS
#define MONEY_DEFINITIONS

/*
 * Documentation for functions can be found in this file:
 */
#define MONEY_FN "/sys/global/money.c"

/*
 * MONEY_COINS return an array with the number of coins for each type.
 * The array is ({ cc, sc, gc, pc })
 */
#define MONEY_COINS(ob)        ((int *)MONEY_FN->what_coins(ob))

/*
 * MONEY_SPLIT returns an array with the minimum number of coins that is
 * needed to make the total sum of cp coppers. The returned array is of
 * form ({ cc, sc, gc, pc })
 */
#define MONEY_SPLIT(cp)        ((int *)MONEY_FN->split_values(cp))

/*
 * MONEY_MERGE returns the combined value of the coins in the carr. The
 * array should be ({ cc, sc, gc, pc })
 */
#define MONEY_MERGE(carr)      ((int)MONEY_FN->merge_values(carr))

/*
 * TOTAL_MONEY returns the total value of all coins carried by (or in) who.
 */
#define TOTAL_MONEY(who)       ((int)MONEY_FN->total_money(who))

/*
 * MONEY_MAKE does what we've always wanted. It creates money and returns
 * the objectpointer. Use MONEY_MAKE_CC and such to create money of a
 * specific type.
 */
#define MONEY_MAKE(num, ctype) ((object)MONEY_FN->make_coins(ctype, num))

/*
 * MONEY_MOVE moves a certain ammoint of coins from 'from' to 'to'. You
 * can move s particular type of coins with MONEY_MOVE_CC and such.
 *
 * Returns: -1 - money (type) not found
 *           0 - money moved
 *          >1 - an error generated by the move-function in /std/object
 */
#define MONEY_MOVE(num, ctype, from, to) \
    ((int)MONEY_FN->move_coins(ctype, num, from, to))

/*
 * MONEY_ADD will add 'amount'  of money to 'who' in the largest
 * denominations possible. If amount < 0 money will be taken in the
 * smallest denominations possible.
 *
 * Returns:
 * amount >= 0: always 1
 * amount <  0: 1 - the money was removed
 *              0 - not enough money to remove 'amount' (nothing is taken)
 */
#define MONEY_ADD(who, amount) ((int)MONEY_FN->add_money(who, amount))

/*
 * MONEY_TEXT zwraca string opisujacy monety podane w tablicy, w podanym
 * przypadku. Tablica musi miec ({ cc, sc, gc, pc }).
 */
#define MONEY_TEXT(arr, przyp) ((string)MONEY_FN->money_text(arr, przyp))

/*
 * MONEY_TEXT_SPLIT returns a string describing the value of the coins
 * in the smallest denomination.
 */
#define MONEY_TEXT_SPLIT(cc) (MONEY_TEXT(MONEY_SPLIT(cc)))

/* 
 * MONEY_UNIQUE_NAME(ct) returns the value for the HEAP_S_UNIQUE_ID property
 * added to coins of the coin type ct.
 */
#define MONEY_UNIQUE_NAME(ct)  ("_coin_" + (ct))

/* We include the file keeping the mud-specific coin types. */
#include "/config/sys/money2.h"

/* No new definitions beyond this line. */
#endif MONEY_DEFINITIONS
