This ability is used for objects that can be "measured", such as fuel, potions and money. A measurable object has a unit of measure and quantity (for example 5 copper coins).
A measurable object may be coalescent. This means that when such an object is moved, it checks whether there is another measurable object with the same unit in its environment. If there is, then the two objects merge to form a single object (a good example of this is money).
You can specify what happens when a measurable object becomes empty.
#include <ability.h> inherit MEASURABLE;
void set_quantity(int q)
q
, which must
be a non-negative integer (negative integers will
be changed to 0
).
int query_quantity()
emptyp()
instead.
void add_quantity(int q)
q
.
Here q
can be negative, but the
final quantity will not be allowed to be negative.
If the object becomes empty, then a special action
may be triggered.
void set_unit(string u)
u
.
string query_unit()
int emptyp()
1
if the object is empty, and 0
otherwise.
void set_emptyf(function f)
set_quantity()
or
add_quantity()
. If f
is
0
then no function will be called.
void set_empty_destruct()
set_emptyf((:destruct, this_object():))
,
i.e., the object will be destroyed with destruct()
.
function query_emptyf()
set_quantity()
or
add_quantity()
. If no such function
is defined, return 0
.
void set_coalescent(int m)
m
is 0
then the object is
set to not coalescent, otherwise it is set to
coalescent.
int query_coalescent()
1
if the object is coalescent,
and 0
otherwise.
void merge(mixed ob)
ob
.
The merge happens if both object are coalescent and
have the same unit. Return value is ob
if
the merge happened, and 0
otherwise.
If ob
is a list of objects then this object
is merged with the first object in the list that is
coalescent and has the same unit. Return value is the object
that this object was merged with, and 0
otherwise.
Note that this object is emptied if the merge happens, which may trigger a special action.