[Package Index | Mudlib Index | Effect Index]

File /obj/food.c


This is the main inheritable for food objects. It allows you to create food and drink. Virtual files may also be coded if given the *.food extention. There are many examples of these virtual food files in the /obj/food directory. Food does the following things.

- It can be eaten or drunk.
- Food can be changed from solid to liquid with set_liquid(), and changed from liquid to solid with reset_liquid().
- The weight of each bite can be set with set_weight_per_bite().
- Effects can be added to the player when they are splashed with the food, get food rubbed on them, or get food applied to them with add_external_effect.
- Splashing, applying, and rubbing can be pk-checked with set_external_pk_check()
- Splashing can be activated with set_splashable()
- Splashing can be deactivated with unset_splashable()
- Applying can be activated with set_applicable()
- Applying can be deactivated with unset_applicable()
- Effects can be added to the player when they consume the food with add_eat_effect().
- Functions can be added to be carried out when the food is consumed with add_eat_func(). This function can be stored on another object if the set_eat_object() is used.
- An eat message can be set with set_eat_mess().
- Food can be cut up into pieces with sharp weapons.
- The description of the new 'pieces' can be set using set_piece_description(), set_piece_short(), set_piece_plural(), and set_piece_substance().
- Non-liquid food decays and will eventually crumble to dust.
- The decay speed can be set with set_decay_speed().
- Food can be 'pickled' to prevent decay using do_cure().

Inherits

This class inherits the following classes /obj/cont_medium.c

Includes

This class includes the following files /include/bits_controller.h, /include/units.h, /include/tokenise.h, /include/volumes.h, /include/weapon.h, /include/move_failures.h, /include/achievements.h, /include/drinks.h and /include/parser.h

Class Index

Method index

Public Functions

These are functions that everyone can access.

add_eat_effect
varargs int add_eat_effect(mixed word,
int number)

This adds an eat effect to the food. This will be added to the player or NPC when the food is eaten.

The effect is added with a number as the argument. The number is based on the amount which is eaten (in weight units), and usually represents the strength of the effect. If the object is continuous, the weight is calculated from the amount and weight_unit array...


eff_num = ( amount * number * weight_unit[0] ) / weight_unit[1]

...where the number is passed into the add_eat_effect() function. If the effect already exists, then the number is added onto the existing number.

Parameters:
word - The file name of the effect to add
number - The number to set to the effect to

Returns:
The current value of the effect in the mapping

See also:
/obj/cont_medium->set_weight_unit() and remove_eat_effect()


add_eat_function
varargs void add_eat_function(mixed ob,
string func,
mixed * args ...)

This sets up a function to be called when the object is eaten.

The function will be called with the object being eaten, the person eating the object and any extra arguments specified by add_eat_function().

Note that eat functions are saved over logout, so adding this_object() as the object to call the function on may not work as you might expect. Instead, use base_name( this_object() ) and all will be well.

Parameters:
ob - The object to call the function on (see caveat below)
func - The function to call on the object
args - (optional) Any extra args to be passed to the function

Example:
void create_food() {
  object food;
  food = clone_object("/obj/food/apple.food");
  food->add_eat_function( base_name( this_object() ), "eat_apple", 5 );
} /* create_food() */

void eat_apple( object food, object eater, int val ) {
  /* Do something wonderful! */
} /* eat_apple() */

add_external_effect
int add_external_effect(mixed word,
int number)

This adds an external effect to the food. This will be added to the player or NPC when the liquid is splashed, applied, or rubbed on them.

The effect is added with a number as the argument. The number is based on the amount which is splashed (in weight units), and usually represents the strength of the effect. If the object is continuous, the weight is calculated from the amount and weight_unit array...


eff_num = ( amount * number * weight_unit[0] ) / weight_unit[1]

...where the number is passed into the add_external_effect() function. If the effect already exists, then the number is added onto the existing number.

Parameters:
word - The file name of the effect to add.
number - The number to set to the effect to.

Returns:
The current value of the effect in the mapping

See also:
/obj/cont_medium->set_weight_unit(), set_splashable(), unset_splashable(), set_applicable(), unset_applicable.c, remove_external_effect() and set_external_pk_check()


check_for_container
int check_for_container()

This checks the outside of us for a container and then destroys ourselves if it is not a container.
check_sharp
int check_sharp(object weapon)

This checks to see if a weapon is sharp. This is used later to determine whether an object can be cut up with the weapon or not.

Parameters:
weapon - The weapon to check to see if it is sharp

Returns:
Return 1 if it is sharp, or 0 otherwise


consume
varargs void consume(object consumer,
int amount,
string type)

This consumes some of the food.

Parameters:
consumer - The person doing the consumption
amount - The amount being consumed
type - Use "splash" or "apply" or "external" to use external effects, anything else for eat effects.


do_apply
int do_apply(object * things)

This handles applying things

Returns:
Return 1 if it succeeded, or return 0 if it failed.

See also:
set_applicable() and consume(*).c


do_cure
int do_cure()

This is called by the pickling stick. It stops the food object decaying.

Returns:
returns 1 for suceess and 0 for failure

See also:
set_decay_speed()


do_cut
varargs int do_cut(int num_pieces)

This cuts the food up into bits. This is the command called with add_command() and does the actual cutting up into bits. If the num_pieces parameter is undefined, the food is cut in half. If the food is continuous, the cutting is handled by the state_change handler (all continuous objects must be cut this way).

Parameters:
num_pieces - The number of pieces to cut the food into.

Returns:
1 if it succeeded, 0 if not.

See also:
set_piece_description(), query_in_pieces(), query_piece_short(), query_piece_plural() and query_piece_substance()


do_drink
int do_drink()

This gives the appropriate message for drinking things.

Returns:
Return 1 if it succeeded, or return 0 if it failed.

See also:
do_eat(), consume(*).c and set_liquid()


do_drop
int do_drop(mixed * ind,
string dirm,
string * indm,
mixed * args,
string pat)
do_dry
int do_dry()

This method dries the food. Dried food no longer decays.

Returns:
returns 1 for suceess and 0 for failure

See also:
set_decay_speed()


do_eat
varargs int do_eat(int no_mess,
object ob)

This is the eat command call. This is setup with add_command() and does the actual eating.

Parameters:
no_mess - don't use success messages
ob - The object to eat. Is either this_object() or a proxy object based on this_object()

Returns:
Return 1 on success, 2 on success + last bit eaten and return 0 on failure.

See also:
/global/new_parse->add_command(), /global/new_parse->add_succeeded_mess() and set_eat_mess()


do_mince
int do_mince()
do_quaff
int do_quaff()

This gives the appropriate message for quaffing things. Its rather like drinking but a lot of it gets splashed on you.

Returns:
Return 1 if it succeeded, or return 0 if it failed.

See also:
do_eat(), consume(*).c and set_liquid()


do_splash
int do_splash(object * things)
mince_up
varargs object mince_up(int messages)

This minces the food item, using the state changer.

Parameters:
messages - 1 if succeeded/failed messages should be added to this_player() (only used internally)

Returns:
The transformed object

See also:
do_cut()


query_applicable
int query_applicable(object applier,
object appliee)

This queries applicability of the food. (rubbing on someone) Note that the food can only be applied when set_applicable() has been called

Parameters:
applier - Who applies it
appliee - Who it is applied to

Returns:
1 if it can be applied, 0 if it can't

See also:
set_applicable(), unset_applicable() and set_external_pk_check()


query_bite_weight
int query_bite_weight()

Returns the weight -- in the default metric weight units -- of a single bite. This is used along with the total weight of the object to calculate how many bites of the food can be taken. Note that this may be 0, in which case the object is single-bite. It takes drying into account, so returns the weight taken from the current metric weight if a single bite is taken.
query_bites_gone
float query_bites_gone()

This returns the number of bites that have been taken out of the food object.

Returns:
The number of bites which have been taken from the object

See also:
set_bites_gone() and set_weight_per_bite()


query_cured
int query_cured()

This returns the cured state of the bit.

Returns:
1 if it is cured, 0 if not


query_decay_divisor
float query_decay_divisor()

This tells us the current divisor used to determine decay. This can be modified with set_decay_speed.

Returns:
float the divisor

See also:
set_decay_speed(), query_decay_speed(), set_decay_level() and query_decay_level()


query_decay_level
int query_decay_level()

This returns the level of the decay.

Returns:
The level of decay

See also:
set_decay_speed()


query_decay_speed
int query_decay_speed()

This returns the decay speed. If this is 0 then the object is not decaying. This is the length of time it takes for the whole object to decay.

Returns:
The decay speed

See also:
set_decay_speed()


query_decays
int query_decays()

This query tells us whether the food decays. All objects which decay should have this function on them.

Returns:
Return 1 if the object decays

See also:
set_decay_speed()


query_dried
int query_dried()

This returns the dried state of the bit.

Returns:
1 if it is dried, 0 if not


query_eat_effects
mapping query_eat_effects()

The eat effects of the food. The mapping contains a set of strings (the effect) and a number associated with the effect.

Returns:
A mapping containing the eat effects

See also:
add_eat_effect()


query_eat_functions
class eat_function * query_eat_functions()

This returns the set of functions to be called when this object is eaten. Each class consists of the object to call a function on, the function to call, and any extra arguments that should be passed to the function.

Returns:
The set of eat functions on this object


query_eat_mess
mixed query_eat_mess()

This returns the eat message of the object.

Returns:
The eat message

See also:
set_eat_object(), set_eat_func() and set_eat_mess()


query_edible
int query_edible()

This tells us if the food is edible (i.e. can be consumed using "eat" instead of "drink"). If it is edible then it is not a liquid.

Returns:
Return 1 if the food is edible and non-liquid, and return 0 if it is inedible or a liquid. If the person trying to eat it is a troll, return 1 if it's a mineral and not otherwise.

See also:
set_liquid() and query_liquid()


query_external_effects
mapping query_external_effects()

The external (splash, apply, rub) effects of the food. The mapping contains a set of strings (the effect) and a number associated with the effect.

Returns:
A mapping containing the external effects

See also:
set_applicable() and set_splashable()


query_food_object
int query_food_object()

This method returns 1 if the item is a food object.

Returns:
1 when it is a food object


query_fraction_cut
int query_fraction_cut()

This returns the fraction of the piece.

Returns:
The fraction cut.


query_in_pieces
int query_in_pieces()

If the food has been cut up (using the 'cut' command) then this will return true.

Returns:
Return 1 if it is in pieces, and return 0 otherwise

See also:
do_cut()


query_liquid
int query_liquid()

This function returns one if the food is a liquid.

Returns:
Return 1 if the food is a liquid, and return 0 if it is not.


query_long_decay_level
string query_long_decay_level()

This method returns the decay level for the object as a string, it is used in the long() function.
query_long_eat_level
string query_long_eat_level()

This method returns how much of the item has been nibbled on.

Returns:
a string used in long().


query_metric_weight
int query_metric_weight()
query_original_weight
int query_original_weight()

This function returns the weight of the original item, not counting bites taken or cut into pieces.

Returns:
The original weight


query_piece_description
string query_piece_description()

This returns the long description of the food object when it is cut up into pieces.

Returns:
A string of text which is the piece description

See also:
set_piece_description() and query_in_pieces()


query_piece_plural
string query_piece_plural()
query_piece_short
string query_piece_short()
query_piece_substance
string query_piece_substance()
query_preserved
int query_preserved()

This tells us how the item is preserved.

Returns:
0 for not preserved, 1 for dried, 2 for cured


query_rotten
int query_rotten()

This tells us if the food has started to rot

Returns:
Return 1 if the food has started to rot, 0 otherwise.

See also:
set_decay_speed(), query_decay_speed(), set_decay_level(), query_decay_level() and query_decay_divisor()


query_short_rotten_adjective
string query_short_rotten_adjective()

This method returns the current rotten adjective that's used in the short description for decaying objects.

Returns:
a string like slightly rotten, mostly rotten, etc.


query_splashable
int query_splashable(object splasher,
object splashee)

This queries splashability of the food. Note that the food can only be splashed when liquid and when set_splashable() has been called

Parameters:
splasher - Who splashes
splashee - Who is splashed

Returns:
1 if it can splash, 0 if it can't

See also:
set_splashable(), unset_splashable(), set_liquid() and set_external_pk_check()


query_substance
varargs string query_substance(int plural,
int dark)
query_true_liquid
int query_true_liquid()

This function returns one if the food is a liquid. It's like query_liquid(), but doesn't exist in vessels.

Returns:
Return 1 if the food is a liquid, and return 0 if it is not.


query_weight_gone
int query_weight_gone()

This returns the weight that has been consumed, in the default metric weight units. This does NOT take drying into account, so it is the weight of the original (undried) object that is returned.
query_weight_per_bite
float query_weight_per_bite()

This sets the weight of each bite of the food object. This is used along with the total weight of the object to calculate how many bites of the food can be taken. This is REDUNDANT. Please use query_bite_weight instead.

Returns:
The weight of each bite.

See also:
/std/basic/misc->set_weight(), query_bite_weight(), set_weight_per_bite() and weight.c


remove_eat_effect
void remove_eat_effect(string word)

This removes the eat effect of the given name.

Parameters:
word - The name of the effect to delete

See also:
add_eat_effect()


remove_eat_function
void remove_eat_function(mixed ob,
string func)

This removes an eat function from the set of eat functions.

Parameters:
ob - The object to look for removal
func - The function to look for removal


remove_external_effect
void remove_external_effect(string word)

This removes the external effect of the given name.

Parameters:
word - The name of the effect to delete

See also:
add_external_effect()


reset_liquid
void reset_liquid()

This changes the food object into a solid. Solids are not 'continuous' and the decay speed will be set back to the default.

See also:
set_liquid() and set_decay_speed()


set_applicable
void set_applicable()

This sets it so the food can be applied. Note this is the default case.

See also:
unset_applicable()


set_bites_gone
void set_bites_gone(mixed number)

This sets the number of bites gone. This helps determine the total weight of the object.

Parameters:
number - The number of bites gone

See also:
set_weight_per_bite()


set_decay_level
void set_decay_level(int level)

This sets the decay level. It lets you make a food object seem as though it is already decaying.

Parameters:
level - The new decay level

See also:
query_decay_level() and set_decay_speed()


set_decay_speed
void set_decay_speed(int decay)

This sets the speed at which a food object decays. The speed is set in seconds and is the total amount of time before the food decays.

If the decay speed is set to 0, then the object will never decay.

Parameters:
speed - The speed at which the object will decay

See also:
set_decay_level() and query_decay_speed()

Example:
/* This will make the object decay totally in 30 minutes */
set_decay_speed( 1800 );

/* This will stop the object from ever decaying */
set_decay_speed( 0 );

set_eat_effects
void set_eat_effects(mapping map)

This sets all the eat effects. This function should NOT be used. Please use add_eat_effect.

Parameters:
map - The eat effects mapping.


set_eat_mess
void set_eat_mess(mixed word)

The eat mess should be treated exactly the same as a add_succeeded_mess(), as it is processed later as add_succeeded_mess( eat_mess, ({ }) ); It may also be a pointer to a function pointer which returns a valid string or array. Note that if the function is not owned by this ob, there is a risk that the owner of the function will be destructed before the function is evaluated.

Parameters:
word - The function, string or array to be used as the add_succeeded_mess() when eating the food.

See also:
/global/new_parse->add_succeeded_mess()


set_external_effects
void set_external_effects(mapping map)

This sets all the external effects. This function should NOT be used. Please use add_external_effect.

Parameters:
map - The external effects mapping


set_external_pk_check
void set_external_pk_check()

This makes the external effects pk checked.

See also:
add_external_effect(), set_applicable(), set_splashable() and unset_external_pk_check()


set_false_liquid
void set_false_liquid()

This function sets whether the food is liquid but not a *true* liquid. This calls set_liquid() as well to ensure consistency.
set_fraction_cut
void set_fraction_cut(int num)

This sets how many pieces the food has been cut into. 1 is intact, 2 is cut in half, etc. This can be used to make original food look like it has been cut.

Parameters:
num - How many pieces the thing has been cut into


set_inedible
void set_inedible(int i)

This makes the food inedible. Useful for things that rots but can't be eaten.

Parameters:
i - If the food is inedible or not


set_liquid
void set_liquid()

This changes the food object into a liquid. Liquids are automatically a 'continuous' medium, which means it will combine with other liquids of the same type.

This will automatically set the decay speed to 0. Liquids do not decay.

See also:
reset_liquid(), set_decay_speed() and /obj/cont_medium->set_continuous()


set_piece_description
void set_piece_description(string word)

This sets the long description of the food when it is has 'cut' into pieces.

Parameters:
word - The long description to use when cut into pieces.

See also:
query_in_pieces(), set_piece_short(), set_piece_plural() and set_piece_substance()

Example:
set_piece_description( "The brown, soft, moist piece of cake looks totally "
         "wonderful.\n" );

set_piece_plural
void set_piece_plural(string plural)

This plural description used for the pieces. It is only really of use if the piece short pluralises in an unusual manner. If it is not set the piece plural is set to what the pice short has been set to with an "s" stuck on the end, for example, slice to slices.

Parameters:
word - The plural used for the 'pieces' when cut into pieces.

See also:
query_in_pieces(), set_piece_description(), set_piece_short() and set_piece_substance()

Example:
set_piece_plural( "slices" );

set_piece_short
void set_piece_short(string short)

This is the description used in the short for the pieces. When the object is cut up this is used as the short description. For example, it can change 'piece of cake' to 'slice of cake', 'piece of chocolate' to 'square of chocolate', and so on. If the piece short has not been set it is set to the default which is simply "piece".

Parameters:
word - The short to use for the 'piece' when cut into pieces.

See also:
query_in_pieces(), set_piece_description(), set_piece_plural() and set_piece_substance()

Example:
set_piece_short( "slice" );

set_piece_substance
void set_piece_substance(string substance)

This sets a new description for what there are pieces of. For example, if you want the short of the food before it is cut up to be 'bar of chocolate', without the piece substance being set, when it is cut up it will become 'a piece of bar of chocolate'. If you set this in enables you to change that unwieldly description to 'a piece of chocolate'.

Parameters:
word - The description of what the 'piece' is of.

See also:
query_in_pieces(), set_piece_description(), set_piece_short() and set_piece_plural()

Example:
set_piece_substance( "chocolate" );

set_splashable
void set_splashable()

This sets it so the food can be splashed. Note that the food can only be splashed when liquid in any case. Note this is NOT the default case.

See also:
unset_splashable(), set_applicable(), unset_applicable() and add_external_effect()


set_weight_gone
void set_weight_gone(int number)

This sets the amount of weight that has already been consumed. This helps to determine the total weight of the object.
set_weight_per_bite
varargs void set_weight_per_bite(mixed number,
int unit)

This sets weight of each bite of the food object. This is used along with the total weight of the object to calculate how many bites of the food can be taken.

Parameters:
number - The weight each bite should be.
unit - (optional) The unit in which the weight is expressed. If not given, this is assumed to be UNIT_NINTHPOUND.

See also:
/std/basic/misc->set_weight() and weight.c


setup_eat_piece_messages
varargs void setup_eat_piece_messages(mixed piece,
mixed amt,
mixed last,
mixed first)

This sets up the eat messages for pieces and stuff. The amount message will replace the $amt$ string in the message with the amount_string(). Any of these messages may be a function pointer that returns an appropriate string or array. Note that if the function is not owned by this ob, there is a risk that the owner of the function will be destructed before the function is evaluated.

Parameters:
Piece - the eat piece message. This can be either a string or an array, it is passed to add_succeeded_mess()
amt - The amount messages
last - The message to print out when the last bit gets eaten
first - The message to print when the first bite is taken


slice_up
varargs object * slice_up(int num_pieces,
int messages)

This cuts the food item up into pieces, and returns the bits.

Parameters:
num_pieces - How many pieces to create, defaults to 2
messages - 1 if succeeded/failed messages should be added to this_player() (only used internally)

Returns:
The bits in a nice array

See also:
do_cut()


test_mess_fp
void test_mess_fp(mixed fp)

This tests the value of a set mess for validity of fp and generates a debug output if relevant. Hopefully the cre developing the food ob concerned will see the mess.

Parameters:
fp - the mess value being set


unset_applicable
void unset_applicable()

This sets it so the food cannot be applied.

See also:
set_applicable()


unset_external_pk_check
void unset_external_pk_check()

This makes the external effects not pk checked.

See also:
add_external_effect(), set_applicable(), set_splashable() and set_external_pk_check()


unset_splashable
void unset_splashable()

This sets it so the food cannot be splashed. Note that the food can only be splashed when liquid in any case.

See also:
set_splashable()


Classes

These are nice data types for dealing with... Data!