[Package Index | Mudlib Index | Effect Index]

File /obj/handlers/state_change.c

This handler is meant to simulate the changing of an object's "state", such as melting, grinding, etc. In reality, rather than changing the source object, the transform() method clones a completely new object, based on the internal lookup table; it is the caller's responsibility to dest the source object and put the new one in its place.

The handler's lookup table is stored in a series of files: any files in /obj/state_change ending in .dat will be added to the table when the handler is loaded. See /include/state_change.h for field definitions. The data files are loaded by the data handler, and can contain fancy things like expressions and function pointers.

See also:
/include/state_change.h and /obj/handlers/data.c

Written by Jeremy

Includes

This class includes the following files /include/playtesters.h and /include/state_change.h

Method index

Public Functions

These are functions that everyone can access.

query_table
mapping query_table()

This method returns the entire lookup table. It is mainly for debugging.

Returns:
the state_change lookup table


query_table_entry
int query_table_entry(string method,
                      string medium)

This function determines if there is an entry for a specific medium alias for a specific transformation or not.

Parameters:
method - The transformation method to check
medium - The medium alias to search for

Returns:
1 if an entry exists, 0 if it doesn't


transform
varargs object transform(object ob,
                         string transformation,
                         object player)

This method is generally called by the object doing the state change (e.g., a food grinder). It looks up the specified source object in the table and clones the "transformed" object as specified.

The table is indexed by the source object as follows: if the source object has a property "state name", the value of this is used. If not, the object's medium alias (if any, regardless of whether the object is continuous) is used. Failing these, the object's short description is used. The first one resulting in a valid string is concatenated with the transformation string (with a ":" between) and the result is used as the index. If the lookup fails, 0 is returned.

Note that the resulting object is only cloned. It is the responsibility of the caller to dest the source and put the result in its place.

Parameters:
ob - the source object
transformation - a string specifying the transformation (e.g., "grind")
The - player to whom this state change will be attributed to! [optional]

Returns:
the result of the transformation