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.32 by root, Mon Sep 11 23:53:30 2006 UTC vs.
Revision 1.38 by root, Wed Sep 13 01:09:24 2006 UTC

29#include <stdio.h> 29#include <stdio.h>
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/uio.h> 31#include <sys/uio.h>
32#include <object.h> 32#include <object.h>
33#include <funcpoint.h> 33#include <funcpoint.h>
34#include <skills.h>
35#include <loader.h> 34#include <loader.h>
36 35
37int nrofallocobjects = 0; 36int nrofallocobjects = 0;
38 37
39object *objects; /* Pointer to the list of used objects */ 38object *objects; /* Pointer to the list of used objects */
255 { 254 {
256 if (inv->inv) 255 if (inv->inv)
257 sum_weight (inv); 256 sum_weight (inv);
258 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); 257 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1);
259 } 258 }
259
260 if (op->type == CONTAINER && op->stats.Str) 260 if (op->type == CONTAINER && op->stats.Str)
261 sum = (sum * (100 - op->stats.Str)) / 100; 261 sum = (sum * (100 - op->stats.Str)) / 100;
262
262 if (op->carrying != sum) 263 if (op->carrying != sum)
263 op->carrying = sum; 264 op->carrying = sum;
265
264 return sum; 266 return sum;
265} 267}
266 268
267/** 269/**
268 * Return the outermost environment object for a given object. 270 * Return the outermost environment object for a given object.
417 */ 419 */
418 420
419object * 421object *
420find_object_name (const char *str) 422find_object_name (const char *str)
421{ 423{
422 const char *name = shstr::find (str); 424 shstr_cmp str_ (str);
423 object *op; 425 object *op;
424 426
425 for (op = objects; op != NULL; op = op->next) 427 for (op = objects; op != NULL; op = op->next)
426 if (&op->name == name) 428 if (op->name == str_)
427 break; 429 break;
428 430
429 return op; 431 return op;
430} 432}
431 433
837 if (op->more != NULL) 839 if (op->more != NULL)
838 update_object (op->more, action); 840 update_object (op->more, action);
839} 841}
840 842
841static unordered_vector<object *> mortals; 843static unordered_vector<object *> mortals;
842static std::vector<object *> freed; 844static std::vector<object *, slice_allocator <object *> > freed;
843 845
844void object::free_mortals () 846void object::free_mortals ()
845{ 847{
846 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) 848 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();)
847 if ((*i)->refcnt) 849 if ((*i)->refcnt)
851 freed.push_back (*i);//D 853 freed.push_back (*i);//D
852 //delete *i; 854 //delete *i;
853 mortals.erase (i); 855 mortals.erase (i);
854 } 856 }
855 857
856 if (mortals.size())//D 858 if (mortals.size() && 0)//D
857 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D 859 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D
858} 860}
859 861
860object::object () 862object::object ()
861{ 863{
886 888
887void object::unlink () 889void object::unlink ()
888{ 890{
889 count = 0; 891 count = 0;
890 892
893 if (this == objects)
894 objects = next;
895
891 /* Remove this object from the list of used objects */ 896 /* Remove this object from the list of used objects */
892 if (prev) 897 if (prev)
893 { 898 {
894 prev->next = next; 899 prev->next = next;
895 prev = 0; 900 prev = 0;
898 if (next) 903 if (next)
899 { 904 {
900 next->prev = prev; 905 next->prev = prev;
901 next = 0; 906 next = 0;
902 } 907 }
903
904 if (this == objects)
905 objects = next;
906} 908}
907 909
908object *object::create () 910object *object::create ()
909{ 911{
910 object *op; 912 object *op;
1223 * This function goes through all objects below and including top, and 1225 * This function goes through all objects below and including top, and
1224 * merges op to the first matching object. 1226 * merges op to the first matching object.
1225 * If top is NULL, it is calculated. 1227 * If top is NULL, it is calculated.
1226 * 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
1227 */ 1229 */
1228
1229object * 1230object *
1230merge_ob (object *op, object *top) 1231merge_ob (object *op, object *top)
1231{ 1232{
1232 if (!op->nrof) 1233 if (!op->nrof)
1233 return 0; 1234 return 0;
2721 * The returned string is shared. 2722 * The returned string is shared.
2722 */ 2723 */
2723const char * 2724const char *
2724get_ob_key_value (const object *op, const char *const key) 2725get_ob_key_value (const object *op, const char *const key)
2725{ 2726{
2726 key_value * 2727 key_value *link;
2727 link; 2728 shstr_cmp canonical_key (key);
2728 const char *
2729 canonical_key;
2730 2729
2731 canonical_key = shstr::find (key);
2732
2733 if (canonical_key == NULL) 2730 if (!canonical_key)
2734 { 2731 {
2735 /* 1. There being a field named key on any object 2732 /* 1. There being a field named key on any object
2736 * implies there'd be a shared string to find. 2733 * implies there'd be a shared string to find.
2737 * 2. Since there isn't, no object has this field. 2734 * 2. Since there isn't, no object has this field.
2738 * 3. Therefore, *this* object doesn't have this field. 2735 * 3. Therefore, *this* object doesn't have this field.
2739 */ 2736 */
2740 return NULL; 2737 return 0;
2741 } 2738 }
2742 2739
2743 /* This is copied from get_ob_key_link() above - 2740 /* This is copied from get_ob_key_link() above -
2744 * only 4 lines, and saves the function call overhead. 2741 * only 4 lines, and saves the function call overhead.
2745 */ 2742 */
2746 for (link = op->key_values; link != NULL; link = link->next) 2743 for (link = op->key_values; link; link = link->next)
2747 {
2748 if (link->key == canonical_key) 2744 if (link->key == canonical_key)
2749 {
2750 return link->value; 2745 return link->value;
2751 } 2746
2752 }
2753 return NULL; 2747 return 0;
2754} 2748}
2755 2749
2756 2750
2757/* 2751/*
2758 * Updates the canonical_key in op to value. 2752 * Updates the canonical_key in op to value.
2844 shstr key_ (key); 2838 shstr key_ (key);
2845 2839
2846 return set_ob_key_value_s (op, key_, value, add_key); 2840 return set_ob_key_value_s (op, key_, value, add_key);
2847} 2841}
2848 2842
2843object::depth_iterator::depth_iterator (object *container)
2844: iterator_base (container)
2845{
2846 while (item->inv)
2847 item = item->inv;
2848}
2849
2849void 2850void
2850object::deep_iterator::next () 2851object::depth_iterator::next ()
2851{ 2852{
2852 if (item->inv)
2853 item = item->inv;
2854 else if (item->below) 2853 if (item->below)
2854 {
2855 item = item->below; 2855 item = item->below;
2856
2857 while (item->inv)
2858 item = item->inv;
2859 }
2856 else 2860 else
2857 item = item->env->below; 2861 item = item->env;
2858} 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