--- deliantra/server/include/object.h 2008/12/23 18:52:57 1.191 +++ deliantra/server/include/object.h 2009/05/05 04:51:56 1.200 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * @@ -138,6 +138,19 @@ signed char used:4; /* Calculated value based on items equipped */ }; +typedef struct oblnk +{ /* Used to link together several objects */ + object_ptr ob; + struct oblnk *next; +} objectlink; + +typedef struct oblinkpt +{ /* Used to link together several object links */ + struct oblnk *link; + struct oblinkpt *next; + shstr id; /* Used as connected value in buttons/gates */ +} oblinkpt; + INTERFACE_CLASS (object) // these are being copied struct object_copy : attachable @@ -280,6 +293,11 @@ shstr ACC (RW, custom_name); /* Custom name assigned by player */ }; +const char *query_weight (const object *op); +const char *query_short_name (const object *op); +const char *query_name (const object *op); +const char *query_base_name (const object *op, int plural); + struct object : zero_initialised, object_copy { // These variables are not changed by ->copy_to @@ -310,36 +328,36 @@ key_value *key_values; /* Fields not explictly known by the loader. */ // privates / perl - const shstr &kv_get (const shstr &key) const; - void kv_del (const shstr &key); - void kv_set (const shstr &key, const shstr &value); + shstr_tmp kv_get (shstr_tmp key) const; + void kv_del (shstr_tmp key); + void kv_set (shstr_tmp key, shstr_tmp value); // custom extra fields management struct key_value_access_proxy { object &ob; - shstr key; + shstr_tmp key; - key_value_access_proxy (object &ob, const shstr &key) + key_value_access_proxy (object &ob, shstr_tmp key) : ob (ob), key (key) { } - const key_value_access_proxy &operator =(const shstr &value) const + const key_value_access_proxy &operator =(shstr_tmp value) const { ob.kv_set (key, value); return *this; } - operator const shstr &() const { return ob.kv_get (key); } - operator const char *() const { return ob.kv_get (key); } + operator const shstr_tmp () const { return ob.kv_get (key); } + operator const char *() const { return ob.kv_get (key); } private: void operator =(int); }; // operator [] is too annoying to use - const key_value_access_proxy kv (const shstr &key) + const key_value_access_proxy kv (shstr_tmp key) { return key_value_access_proxy (*this, key); } @@ -367,7 +385,8 @@ // 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); + MTH void play_sound (faceidx sound) const; + MTH void say_msg (const char *msg) const; void do_remove (); MTH void remove () @@ -385,6 +404,14 @@ insert_at (this, this); } + // high-level move functions, return true if successful + int move (int dir, object *originator); + + int move (int dir) + { + return move (dir, this); + } + static bool can_merge_slow (object *op1, object *op2); // this is often used in time-critical code, so optimise @@ -397,6 +424,7 @@ MTH void set_owner (object *owner); MTH void set_speed (float speed); + MTH void set_glow_radius (sint8 rad); MTH bool change_weapon (object *ob); MTH bool change_skill (object *ob); @@ -406,8 +434,12 @@ open_container (0); } - MTH object *force_find (const shstr name); - MTH object *force_add (const shstr name, int duration = 0); + MTH object *force_find (shstr_tmp name); + MTH object *force_add (shstr_tmp name, int duration = 0); + + oblinkpt *find_link () const; + MTH void add_link (maptile *map, shstr_tmp id); + MTH void remove_link (); // overwrite the attachable should_invoke function with a version that also checks ev_want_type bool should_invoke (event_type event) @@ -453,7 +485,7 @@ // return the volume of this object in cm³ MTH uint64 volume () const { - return total_weight () + return (uint64)total_weight () * 1000 * (type == CONTAINER ? 1000 : 1) / dominant_material ()->density; @@ -500,19 +532,19 @@ } // returns the outermost environment, never returns 0 - MTH object *outer_env () + MTH object *outer_env () const { - object *op; + const object *op; for (op = this; op->env; op = op->env) ; - return op; + return const_cast(op); } // 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 () + MTH object *in_player () const { object *op = outer_env (); @@ -520,12 +552,12 @@ } // "temporary" helper function - MTH object *head_ () + MTH object *head_ () const { - return head ? head : this; + return head ? head : const_cast(this); } - MTH bool is_head () + MTH bool is_head () const { return head_ () == this; } @@ -550,6 +582,11 @@ return glow_radius || flag [FLAG_BLOCKSVIEW]; } + MTH bool has_carried_lights () const + { + return glow_radius; + } + // returns the player that cna see this object, if any MTH object *visible_to () const; @@ -558,6 +595,11 @@ MTH std::string describe_item (object *who = 0); MTH std::string describe (object *who = 0); + MTH const char *query_weight () { return ::query_weight (this); } + MTH const char *query_name () { return ::query_name (this); } + MTH const char *query_short_name () { return ::query_short_name (this); } + MTH const char *query_base_name (bool plural) { return ::query_base_name (this, plural); } + // If this object has no extra parts but should have them, // add them, effectively expanding heads into multipart // objects. This method only works on objects not inserted @@ -655,6 +697,19 @@ // when they are invisible. MTH void make_noise (); + /* animation */ + bool has_anim () { return animation_id; } + const animation &anim () const { return animations [animation_id]; } + faceidx get_anim_frame (int frame) const { return anim ().faces [frame]; } + void set_anim_frame (int frame) { face = get_anim_frame (frame); } + /* anim_frames () returns the number of animations allocated. The last + * usuable animation will be anim_frames () - 1 (for example, if an object + * has 8 animations, anim_frames () will return 8, but the values will + * range from 0 through 7. + */ + int anim_frames () const { return anim ().num_animations; } + int anim_facings () const { return anim ().facings; } + protected: void link (); void unlink (); @@ -686,21 +741,8 @@ return ob; } -typedef struct oblnk -{ /* Used to link together several objects */ - object_ptr ob; - struct oblnk *next; -} objectlink; - -typedef struct oblinkpt -{ /* Used to link together several object links */ - struct oblnk *link; - sint32 value; /* Used as connected value in buttons/gates */ - struct oblinkpt *next; -} oblinkpt; - -object *find_skill_by_name (object *who, const char *name); -object *find_skill_by_name (object *who, const shstr &sh); +object *find_skill_by_name_fuzzy (object *who, const char *name); +object *find_skill_by_name (object *who, shstr_cmp sh); object *find_skill_by_number (object *who, int skillno); /*