/* 22-APR-94 Bannor - Added clean_up() in an effort to reduce the number
* of excess objects floating around.
*/
#pragma save_binary
#include "move_failures.h"
#include "money.h"
inherit "/std/basic/light";
inherit "/std/basic/move";
/* this will also handle monetary value... */
static int weight;
int value;
create()
{
}
void adjust_weight( int w )
{
if( environment() )
environment()->add_weight( w );
weight += w;
}
void set_weight( int w )
{
if( environment() )
environment()->add_weight( w - weight );
weight = w;
}
int query_weight()
{
return weight;
}
varargs int adjust_money( mixed amt, string type )
{
if( pointerp( amt ) )
{
value += (int)MONEY_HAND->query_total_value( amt );
if( value < 0 )
value = 0;
return value;
}
amt = (int)MONEY_HAND->query_total_value( ({ type, amt }) );
value += amt;
if( value < 0 )
value = 0;
return value;
}
int adjust_value( int i )
{
value += i;
if( value < 0 )
value = 0;
return value;
}
mixed * query_money_array()
{
return( mixed * )MONEY_HAND->create_money_array( value );
}
int query_money( string type )
{
int i;
mixed * m_a;
m_a = (mixed *)MONEY_HAND->create_money_array( value );
if( (i = member_array( type, m_a )) == -1 )
return 0;
return m_a[ i + 1 ];
}
void set_value( int i )
{
value = i;
}
int query_value()
{
return value;
}
move( mixed dest, mixed messout, mixed messin )
{
int i;
object from;
from = environment();
if( !dest->add_weight( weight ) )
return MOVE_TOO_HEAVY;
i = ::move( dest, messout, messin );
if( i == MOVE_OK )
{
if( from )
{
from->add_weight( -weight );
from->adjust_light( -query_light() );
}
if( from = environment() )
from->adjust_light( query_light() );
}
else
dest->add_weight( -weight );
return i;
}
void dest_me()
{
if( environment() )
environment()->add_weight( -weight );
::dest_me();
}
/* well, clean_up didn't work to well here, so i'll try
it in other places. Bannor. */
void xclean_up()
{
mixed * arr;
int i;
string junk1, junk2;
if( living( this_object() ) )
return;
if( sscanf( file_name( this_object() ), "%s#%s", junk1, junk2 ) != 2 )
return;
arr = deep_inventory( this_object() );
for( i = 0; i < sizeof( arr ); i++ )
if( interactive( arr[ i ] ) )
return;
arr->dest_me();
dest_me();
} /* clean_up() */
mixed * query_init_data()
{
return light ::query_init_data() +
move ::query_init_data() +
({ "weight", weight, "set_weight/p/",
"value", value, "set_value/p/" });
}