--- deliantra/server/include/object.h 2008/04/20 00:44:12 1.160 +++ deliantra/server/include/object.h 2008/04/21 23:35:24 1.166 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * @@ -206,7 +206,7 @@ sint8 ACC (RW, glow_radius); /* indicates the glow radius of the object */ sint32 ACC (RW, weight); /* Attributes of the object */ sint32 ACC (RW, weight_limit);/* Weight-limit of object */ - sint32 ACC (RW, carrying); /* How much weight this object contains */ + sint32 ACC (RW, carrying); /* How much weight this object contains, must be 0 if nrof == 0 */ sint64 ACC (RW, perm_exp); /* Permanent exp */ uint32 ACC (RW, weapontype); /* type of weapon */ uint32 ACC (RW, tooltype); /* type of tool or build facility */ @@ -314,7 +314,7 @@ // recursively destroy all objects in inventory, optionally dropping them to the ground instead MTH void destroy_inv (bool drop_to_ground = false); MTH object *insert (object *item); // insert into inventory - MTH void play_sound (faceidx sound) const; + MTH void play_sound (faceidx sound); void do_remove (); MTH void remove () @@ -379,21 +379,26 @@ MTH const char *debug_desc () const; // uses at least 3 round-robin buffers const char *flag_desc (char *desc, int len) const; - int number_of () const + MTH bool decrease (sint32 nr = 1); // returns true if anything is left + MTH object *split (sint32 nr = 1); // return 0 on failure + + MTH int number_of () const { return nrof ? nrof : 1; } - uint64 total_weight () const + MTH sint32 total_weight () const { - return weight * number_of (); + return (weight + carrying) * number_of (); } + MTH void update_weight (); + // return the dominant material of this item, always return something const materialtype_t *dominant_material () const; // return the volume of this object in cm³ - uint64 volume () const + MTH uint64 volume () const { return total_weight () * 1000 @@ -427,14 +432,21 @@ */ MTH bool has_random_items () const { return randomitems && !flag [FLAG_IS_A_TEMPLATE]; } - // returns the player that has this object in his inventory, or 0 - MTH object *in_player () const + // returns the outermost environment, never returns 0 + MTH object *outer_env () { - for (object *op = env; op; op = op->env) - if (op->type == PLAYER) + for (object *op = this; ; op = op->env) + if (!op->env) return op; + } - return 0; + // returns the player that has this object in his inventory, or 0 + // we assume the player is always the outer env + MTH object *in_player () + { + object *op = outer_env (); + + return op->type == PLAYER ? op : 0; } // "temporary" helper function @@ -448,6 +460,14 @@ return head_ () == this; } + MTH bool is_on_map () const + { + return !env && !flag [FLAG_REMOVED]; + } + + // returns the player that cna see this object, if any + MTH object *visible_to () const; + MTH std::string long_desc (object *who = 0); MTH std::string describe_monster (object *who = 0); MTH std::string describe_item (object *who = 0); @@ -594,7 +614,8 @@ INTERFACE_CLASS (archetype) struct archetype : object { - static archetype *empty; // the empty_archetype + static arch_ptr empty; // the empty_archetype + MTH static void gc (); archetype (const char *name); ~archetype ();