ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.33 by root, Tue Sep 12 00:53:56 2006 UTC vs.
Revision 1.37 by root, Tue Sep 12 20:55:40 2006 UTC

254 { 254 {
255 if (inv->inv) 255 if (inv->inv)
256 sum_weight (inv); 256 sum_weight (inv);
257 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); 257 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1);
258 } 258 }
259
259 if (op->type == CONTAINER && op->stats.Str) 260 if (op->type == CONTAINER && op->stats.Str)
260 sum = (sum * (100 - op->stats.Str)) / 100; 261 sum = (sum * (100 - op->stats.Str)) / 100;
262
261 if (op->carrying != sum) 263 if (op->carrying != sum)
262 op->carrying = sum; 264 op->carrying = sum;
265
263 return sum; 266 return sum;
264} 267}
265 268
266/** 269/**
267 * Return the outermost environment object for a given object. 270 * Return the outermost environment object for a given object.
416 */ 419 */
417 420
418object * 421object *
419find_object_name (const char *str) 422find_object_name (const char *str)
420{ 423{
421 const char *name = shstr::find (str); 424 shstr_cmp str_ (str);
422 object *op; 425 object *op;
423 426
424 for (op = objects; op != NULL; op = op->next) 427 for (op = objects; op != NULL; op = op->next)
425 if (&op->name == name) 428 if (op->name == str_)
426 break; 429 break;
427 430
428 return op; 431 return op;
429} 432}
430 433
836 if (op->more != NULL) 839 if (op->more != NULL)
837 update_object (op->more, action); 840 update_object (op->more, action);
838} 841}
839 842
840static unordered_vector<object *> mortals; 843static unordered_vector<object *> mortals;
841static std::vector<object *> freed; 844static std::vector<object *, slice_allocator <object *> > freed;
842 845
843void object::free_mortals () 846void object::free_mortals ()
844{ 847{
845 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) 848 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();)
846 if ((*i)->refcnt) 849 if ((*i)->refcnt)
850 freed.push_back (*i);//D 853 freed.push_back (*i);//D
851 //delete *i; 854 //delete *i;
852 mortals.erase (i); 855 mortals.erase (i);
853 } 856 }
854 857
855 if (mortals.size())//D 858 if (mortals.size() && 0)//D
856 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D 859 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D
857} 860}
858 861
859object::object () 862object::object ()
860{ 863{
1222 * This function goes through all objects below and including top, and 1225 * This function goes through all objects below and including top, and
1223 * merges op to the first matching object. 1226 * merges op to the first matching object.
1224 * If top is NULL, it is calculated. 1227 * If top is NULL, it is calculated.
1225 * Returns pointer to object if it succeded in the merge, otherwise NULL 1228 * Returns pointer to object if it succeded in the merge, otherwise NULL
1226 */ 1229 */
1227
1228object * 1230object *
1229merge_ob (object *op, object *top) 1231merge_ob (object *op, object *top)
1230{ 1232{
1231 if (!op->nrof) 1233 if (!op->nrof)
1232 return 0; 1234 return 0;
2720 * The returned string is shared. 2722 * The returned string is shared.
2721 */ 2723 */
2722const char * 2724const char *
2723get_ob_key_value (const object *op, const char *const key) 2725get_ob_key_value (const object *op, const char *const key)
2724{ 2726{
2725 key_value * 2727 key_value *link;
2726 link; 2728 shstr_cmp canonical_key (key);
2727 const char *
2728 canonical_key;
2729 2729
2730 canonical_key = shstr::find (key);
2731
2732 if (canonical_key == NULL) 2730 if (!canonical_key)
2733 { 2731 {
2734 /* 1. There being a field named key on any object 2732 /* 1. There being a field named key on any object
2735 * implies there'd be a shared string to find. 2733 * implies there'd be a shared string to find.
2736 * 2. Since there isn't, no object has this field. 2734 * 2. Since there isn't, no object has this field.
2737 * 3. Therefore, *this* object doesn't have this field. 2735 * 3. Therefore, *this* object doesn't have this field.
2738 */ 2736 */
2739 return NULL; 2737 return 0;
2740 } 2738 }
2741 2739
2742 /* This is copied from get_ob_key_link() above - 2740 /* This is copied from get_ob_key_link() above -
2743 * only 4 lines, and saves the function call overhead. 2741 * only 4 lines, and saves the function call overhead.
2744 */ 2742 */
2745 for (link = op->key_values; link != NULL; link = link->next) 2743 for (link = op->key_values; link; link = link->next)
2746 {
2747 if (link->key == canonical_key) 2744 if (link->key == canonical_key)
2748 {
2749 return link->value; 2745 return link->value;
2750 } 2746
2751 }
2752 return NULL; 2747 return 0;
2753} 2748}
2754 2749
2755 2750
2756/* 2751/*
2757 * Updates the canonical_key in op to value. 2752 * Updates the canonical_key in op to value.
2843 shstr key_ (key); 2838 shstr key_ (key);
2844 2839
2845 return set_ob_key_value_s (op, key_, value, add_key); 2840 return set_ob_key_value_s (op, key_, value, add_key);
2846} 2841}
2847 2842
2843object::depth_iterator::depth_iterator (object *container)
2844: iterator_base (container)
2845{
2846 while (item->inv)
2847 item = item->inv;
2848}
2849
2848void 2850void
2849object::deep_iterator::next () 2851object::depth_iterator::next ()
2850{ 2852{
2851 if (item->inv)
2852 item = item->inv;
2853 else if (item->below) 2853 if (item->below)
2854 {
2854 item = item->below; 2855 item = item->below;
2856
2857 while (item->inv)
2858 item = item->inv;
2859 }
2855 else 2860 else
2856 item = item->env->below; 2861 item = item->env;
2857} 2862}
2863
2864// return a suitable string describing an objetc in enough detail to find it
2865const char *
2866object::debug_desc (char *info) const
2867{
2868 char info2[256 * 3];
2869 char *p = info;
2870
2871 p += snprintf (p, 256, "%d=\"%s%s%s\"",
2872 count,
2873 &name,
2874 title ? " " : "",
2875 title ? (const char *)title : "");
2876
2877 if (env)
2878 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2879
2880 if (map)
2881 p += snprintf (p, 256, "(on %s@%d+%d)", map->path, x, y);
2882
2883 return info;
2884}
2885
2886const char *
2887object::debug_desc () const
2888{
2889 static char info[256 * 3];
2890 return debug_desc (info);
2891}
2892

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines