armour.c
skylib_mudos_v1/mudlib/obj/armour.c · 5.2 KB
From the archive skylib_mudos_v1.tar.gz
Download the archive « Back to the archive contents
/**
* This is the basic armour object.
*/
#include <move_failures.h>
#define AC_LIMIT 100 // This is used in pocket_armour as well.
#undef INFORM
inherit OBJECT_OBJ;
inherit "/std/basic/wearable";
inherit "/std/basic/holdable";
inherit "/std/armour_logic";
int no_limbs;
nosave int held_in;
void create() {
do_setup++;
object::create();
armour_logic::create();
wearable::create();
do_setup--;
add_alias("armour");
add_plural("armours");
if( !query_property("shop type") )
add_property("shop type", "armoury");
if( !do_setup )
TO->setup();
} /* create() */
/**
* This method returns 1 to tell us that it is armour.
* @return always returns 1
*/
int query_armour() { return 1; }
/** @ignore yes */
string long( string word, int dark ) {
return object::long( word, dark ) + wearable::long( word, dark );
} /* long() */
/** @ignore yes */
varargs int query_ac( string type, int amount, string zone ) {
int a_class;
#ifdef INFORM
string message;
#endif
a_class = armour_logic::query_ac( type, amount, zone );
#ifdef INFORM
message = query_short()+": striking "+zone+", basic value "+a_class;
#endif
if( a_class > AC_LIMIT )
a_class = AC_LIMIT;
a_class += ( a_class * query_enchant() ) / query_max_enchant();
a_class += query_enchant();
#ifdef INFORM
message += "; after enchant "+ a_class;
if( objectp( worn_by ) )
event( ENV( worn_by ), "inform", message, "combat");
#endif
do_damage( type, amount );
a_class = ( a_class * cond ) / max_cond;
// Damage may get through depending on how good the armour is.
switch( random( a_class ) ) {
case 0:
return 0;
case 1:
return a_class / 2;
case 2..3:
return a_class * 2 / 3;
default:
// They'll always take a small amount of damage.
if( a_class > amount )
return amount - ( amount / ( 5 + random( 10 ) ) );
return a_class - ( a_class / ( 5 + random( 10 ) ) );
}
} /* query_ac() */
/** @ignore yes */
void setup_armour( int number ) {
set_max_cond( number );
set_cond( number );
set_lowest_cond( number );
} /* setup_armour() */
int query_value() {
return modify_value( object::query_value() );
} /* query_value() */
int query_full_value() { return object::query_value(); }
int query_no_limbs() { return no_limbs; }
void set_no_limbs( int number ) { no_limbs = number; }
mixed set_holder( object thing, int number ) {
TO->remove_hide_invis("concealed");
if( !thing ) {
worn_by = 0;
held_in = 0;
} else {
worn_by = thing;
held_in = number;
}
return 1;
} /* set_holder() */
/**
* This function is called on an object and causes it to be worn
* if it can be by it's environment(), i.e the player carrying it.
*/
void player_wear() {
if( !environment() )
return;
if( no_limbs )
TO->hold_item( environment(), held_in );
else
wearable::player_wear();
} /* player_wear() */
/** @ignore yes */
int drop( mixed dest ) {
if( worn_by && !no_limbs && living( worn_by ) )
return 1;
return object::drop(dest);
} /* drop() */
/** @ignore yes */
varargs int move( mixed dest, string messin, string messout ) {
int flag;
if( no_limbs && worn_by && worn_by != dest )
if( !sizeof( (int *)worn_by->set_unhold( TO ) ) )
return MOVE_NO_UNHOLD;
flag = object::move( dest, messin, messout );
if( flag == MOVE_OK && worn_by )
set_worn_by( 0 );
return flag;
} /* move() */
/** @ignore yes */
void dest_me() {
set_worn_by( 0 );
object::dest_me();
} /* dest_me() */
/** @ignore yes */
mixed stats() {
return object::stats() + armour_logic::stats() + wearable::stats() +
({ ({ "max ac", AC_LIMIT }),
({ "no limbs", no_limbs }) });
} /* stat() */
/** @ignore yes */
mapping int_query_static_auto_load() {
return ([
"::" : object::int_query_static_auto_load(),
"ac" : ac,
"armour types" : armour_types,
"no limbs" : no_limbs,
]) + wearable::query_static_auto_load();
} /* query_static_auto_load() */
/** @ignore yes */
mapping query_static_auto_load() {
if( base_name(TO) != __FILE__[0..<3] )
return ([ ]);
return int_query_static_auto_load();
} /* query_static_auto_load() */
/** @ignore yes */
mapping query_dynamic_auto_load() {
mapping map;
map = ([ "::" : object::query_dynamic_auto_load(),
]) + wearable::query_dynamic_auto_load();
if( no_limbs )
map["worn"] = ( worn_by ? held_in + 1 : 0 );
return map;
} /* query_dynamic_auto_load() */
/** @ignore yes */
void init_static_arg( mapping map ) {
if( !mapp( map ) )
return;
if( map[ "::" ] )
object::init_static_arg( map[ "::" ] );
wearable::init_static_arg( map );
if( map[ "ac" ] )
ac = map[ "ac" ];
if( map["armour types"] )
armour_types = map["armour types"];
if( map["no limbs"] )
no_limbs = map["no limbs"];
} /* init_static_arg() */
/** @ignore yes */
void init_dynamic_arg( mapping map, mixed dummy ) {
if( map["::"] )
object::init_dynamic_arg( map["::"] );
wearable::init_dynamic_arg( map );
if( map["worn"] )
held_in = map["worn"] - 1;
} /* init_dynamic_arg() */