[an error occurred while processing this directive]
[<a href="index.shtml">Package Index</a></code> | <a href="index_std.shtml">Mudlib Index</a></code> | <a href="index_eff.shtml">Effect Index</a></code>]<br><h2>File /std/shops/inherit/clone_on_demand.c</h2>
This is a inheritable that provides an efficient way of storing
lots of items. Only one copy of the item is effectively in storage
and everytime one is removed, an exact copy is duplicated and
put back in the store. Objects are added to the store via
add_object(). The actual storage container object
can be returned by query_cont() and this container should be
searched when you want to find what objects the store contains.
<p>
Any object can inherit this, and methods
should be put in place in the inheriting file that end up calling
create_real_object() which will sort out duplicating the item
and returning an object pointer to the one you can deal with.<p><b>See also:</b><br>add_object
.c<p>Written by Pinkfish Aquilo<h3>Example</h3>
<pre>inherit "clone_on_demand";
int do_buy( objects *obs );

void setup(){
  set_name("shop");
  set_short("widget shop");
  add_object( "sprocket" );
}

object create_object( string arg ){
  if( arg == "sprocket" )
    return clone_object( "/path/of/sprocket" );
}

void init(){
  add_command("buy", "<indirect:object:" +
                     base_name( query_cont() ) + ">");
}

int do_buy( object *obs ){
  object ob;
  foreach(ob in obs){
    widget = create_real_object(ob);
    widget->move( this_player() );
  }
  add_succeeded_mess( "$N buy$s $I.\n", obs );
  return 1;
}
</pre>
<h2>Includes</h2>
This class includes the following files <a href="include.armoury.h.shtml">/include/armoury.h</a><h2>Method index</h2>
<dl><ul>
<li><a href="#add_object">add_object</a>(string, int, string)<br/>
This method is used to add an item to the storage.
<li><a href="#create_real_object">create_real_object</a>(object)<br/>
The main point of entry.
<li><a href="#query_cont">query_cont</a>()<br/>
This method returns the container which is used to keep one copy of
each items in storage.
<li><a href="#query_items_left">query_items_left</a>(string *)<br/>
This function can be used to check the quantity left of an array
of items.
<li><a href="#query_num_items_left">query_num_items_left</a>(object)<br/>
Returns how more times object ob can be duplicated
<li><a href="#query_number_left">query_number_left</a>(string)<br/>
This function returns the quantity of particular object available
to be cloned on demand.
<li><a href="#query_object_domain">query_object_domain</a>()<br/>
This method returns the domain the objects will be created from.
<li><a href="#set_object_domain">set_object_domain</a>(string)<br/>
This method sets the domain the objects will be created from.
</ul><h2>Public Functions</h2>
These are functions that everyone can access.<p>
.<ul><a name="add_object">
add_object</a><pre>
varargs int add_object(string name,
                       int max_per_reset,
                       string display_as)
</pre></br>
This method is used to add an item to the storage.
When this method is called, create_object() is called
(with the object name as an arg) in the inheriting file.
If no object is returned by that function,
the name is cloned with clone_object(), and failing that
request_item() is called in the armoury against the name.

This method makes add_weapon() and add_armour() obsolete.

<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the object to add.
<br/>max_per_reset - the maximum number of items to be available at any one time
<br/>display_as - the name that this item is displayed as in shops
<li><b>Returns:</b>
<br/>1 if the item was added successfully to the store, 0 if it was not.

<li><b>Example:</b>
<br/><pre>add_object( "frog", 1 + random( 3 ) );
// This will try and create an object called frog, in the order mentioned
// above</pre><br/><pre>
add_object( "/obj/food/apple.food", 0 );
// Add unlimited numbers of apples.</pre></dl>

<ul><a name="query_cont">
query_cont</a><pre>
object query_cont()
</pre></br>
This method returns the container which is used to keep one copy of
each items in storage.
<br/><ul>
<li><b>Returns:</b>
<br/>the object container

</dl>

<ul><a name="query_items_left">
query_items_left</a><pre>
int * query_items_left(string * names)
</pre></br>
This function can be used to check the quantity left of an array
of items.  It returns a parallel array of integers.  In other words
the array it returns contains the numbers of stock in array positions
corresponding to the array positions of the objects it was passed.
<br/><ul>
<li><b>Parameters:</b>
<br/>names - an array of the short names of the items you wish to query
<li><b>Returns:</b>
<br/>an array of integers, each one returning like query_number_left
would for the object in that position of the object array.
<li><b>See also:</b>
<br/>query_number_left
.c<li><b>Example:</b>
<br/><pre>query_items_left( ({ "banana" , "melon" }) )
would return ({ 12 , 6 }) if there were 12 bananas and 6 melons left.</pre></dl>

<ul><a name="query_num_items_left">
query_num_items_left</a><pre>
int query_num_items_left(object ob)
</pre></br>
Returns how more times object ob can be duplicated
<br/><ul>
<li><b>Parameters:</b>
<br/>ob - the object to test
<li><b>Returns:</b>
<br/>how many more times

</dl>

<ul><a name="query_number_left">
query_number_left</a><pre>
int query_number_left(string name)
</pre></br>
This function returns the quantity of particular object available
to be cloned on demand. In matching which object is the one in
question it uses the short name of the object, which is passed as
an argument to the function.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - is the short name of the object you wish to query.
<li><b>Returns:</b>
<br/>the number left, returns INFINITE_LEFT if the shop has an infinite
number, returns -1 if the item isn't stocked.

</dl>

<ul><a name="query_object_domain">
query_object_domain</a><pre>
string query_object_domain()
</pre></br>
This method returns the domain the objects will be created from.
<br/><ul>
<li><b>Returns:</b>
<br/>the domain the objects are created from

</dl>

<ul><a name="set_object_domain">
set_object_domain</a><pre>
void set_object_domain(string domain)
</pre></br>
This method sets the domain the objects will be created from.
The default objects will always be matched as well.  So setting
this will allow objects from the default of the specified armoury
domain.
<br/><ul>
<li><b>Parameters:</b>
<br/>domain - the domain to try and create from
<li><b>Example:</b>
<br/><pre>set_object_domain("cwc");
</pre></dl>


<h2>Protected Functions</h2>
These are functions that only objects inheriting the class can access.<p>
<ul><a name="create_real_object">
create_real_object</a><pre>
object create_real_object(object thing)
</pre></br>
The main point of entry. 'thing' should be an object already placed
in the clone_on_demand store container via 'add_object'. This
method then duplicates that object, replaces the original copy in
the container with this new one, and returns the original which can
be delt with as normal.
<br/><ul>
<li><b>Parameters:</b>
<br/>thing - an object in the store
<li><b>Returns:</b>
<br/>the original object
<li><b>See also:</b>
<br/>add_object
.c</dl>


[an error occurred while processing this directive]

