/*
 *  /d/Gondor/common/lib/gems.h
 * This file defines macros for the gems currency in Lorien, Gondor.
 * The standard gems heap-object is /d/Gondor/common/obj/gems.c
 * Gems are worth more than coins are, and the lowest gem-value is
 * not as low as 1 copper coin. Any change below the lowest gem-value
 * is therefore lost for the player.
 *
 * Elessar, Nov. 1995
 */
#ifndef GEM_DEFINITIONS
#define GEM_DEFINITIONS
#define STDGEM  ("/d/Gondor/common/obj/gems")
#define GEM_FUNS   ("/d/Gondor/common/lib/gemtrade.c")

#define GEM_OBS(ob)        ((int *)GEM_FUNS->what_gems(ob))

/* seems like a redefinition to me.. Do we need it? Mercade */
#define GEMS_IN(ob)           GEM_OBS(ob)

/*
 * GEMS_SPLIT returns an array with the minimum number of gems that is
 * needed to make the total sum of n coppers. The returned array is of
 * form ({ lowest_value_gem, ....., highest_value_gem })
 */
#define GEMS_SPLIT(cp)        ((int *)GEM_FUNS->split_values(cp))

/*
 * GEMS_MERGE returns the combined value of the gems in the carr. The
 * array should be ({ ic, sc, mc, lc })
 */
#define GEMS_MERGE(carr)      ((int)GEM_FUNS->merge_values(carr))

/*
 * TOTAL_GEMS returns the total value of all gems carried by (or in) who.
 */
#define TOTAL_GEMS(who)       ((int)GEM_FUNS->total_gems(who))

/*
 * GEMS_MAKE does what we've always wanted. It creates gems and returns
 * the objectpointer. Use GEMS_MAKE_IC and such to create gems of a
 * specific type.
 */
#define GEMS_MAKE(num, gtype) ((object)GEM_FUNS->make_gems(gtype, num))

/*
 * GEMS_MOVE moves a certain ammoint of gems from 'from' to 'to'. You
 * can move s particular type of gems with GEMS_MOVE_IC and such.
 *
 * Returns: -1 - gems (type) not found
 *           0 - gems moved
 *          >1 - an error generated by the move-function in /std/object
 */
#define GEMS_MOVE(num, gtype, from, to) \
    ((int)GEM_FUNS->move_gems(gtype, num, from, to))

/*
 * GEMS_ADD will add 'amount'  of gems to 'who' in the largest
 * denominations possible. If amount < 0 gems will be taken in the
 * smallest denominations possible.
 *
 * Returns:
 * amount >= 0: always 1
 * amount <  0: 1 - the gems was removed
 *              0 - not enough gems to remove 'amount' (nothing is taken)
 */
#define GEMS_ADD(who, amount) ((int)GEM_FUNS->add_gems(who, amount))

/*
 * GEMS_TEXT will return a string describing the gems in the array.
 * The array must be ({ ic, sc, mc, lc })
 */
#define GEMS_TEXT(arr) ((string)GEM_FUNS->gems_text(arr))

/*
 * GEMS_TEXT_SPLIT returns a string describing the value of the gems
 * in the smallest denomination.
 */
#define GEMS_TEXT_SPLIT(cp) (GEMS_TEXT(GEMS_SPLIT(cp)))

#include "/d/Gondor/common/lib/gems2.h"

/* No new definitions beyond this line. */
#endif GEM_DEFINITIONS
