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.31 by root, Mon Sep 11 23:33:27 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 * 912 object *op;
911 op;
912 913
913 if (freed.empty ()) 914 if (freed.empty ())
914 op = new object; 915 op = new object;
915 else 916 else
916 { 917 {
938void object::free (bool free_inventory) 939void object::free (bool free_inventory)
939{ 940{
940 if (QUERY_FLAG (this, FLAG_FREED)) 941 if (QUERY_FLAG (this, FLAG_FREED))
941 return; 942 return;
942 943
944 if (QUERY_FLAG (this, FLAG_FRIENDLY))
945 remove_friendly_object (this);
946
943 if (!QUERY_FLAG (this, FLAG_REMOVED)) 947 if (!QUERY_FLAG (this, FLAG_REMOVED))
944 remove_ob (this); 948 remove_ob (this);
945
946 if (QUERY_FLAG (this, FLAG_FRIENDLY))
947 remove_friendly_object (this);
948 949
949 SET_FLAG (this, FLAG_FREED); 950 SET_FLAG (this, FLAG_FREED);
950 951
951 if (more) 952 if (more)
952 { 953 {
958 { 959 {
959 /* Only if the space blocks everything do we not process - 960 /* Only if the space blocks everything do we not process -
960 * if some form of movement is allowed, let objects 961 * if some form of movement is allowed, let objects
961 * drop on that space. 962 * drop on that space.
962 */ 963 */
963 if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) 964 if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)
964 { 965 {
965 object *op = inv; 966 object *op = inv;
966 967
967 while (op) 968 while (op)
968 { 969 {
1224 * This function goes through all objects below and including top, and 1225 * This function goes through all objects below and including top, and
1225 * merges op to the first matching object. 1226 * merges op to the first matching object.
1226 * If top is NULL, it is calculated. 1227 * If top is NULL, it is calculated.
1227 * 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
1228 */ 1229 */
1229
1230object * 1230object *
1231merge_ob (object *op, object *top) 1231merge_ob (object *op, object *top)
1232{ 1232{
1233 if (!op->nrof) 1233 if (!op->nrof)
1234 return 0; 1234 return 0;
2722 * The returned string is shared. 2722 * The returned string is shared.
2723 */ 2723 */
2724const char * 2724const char *
2725get_ob_key_value (const object *op, const char *const key) 2725get_ob_key_value (const object *op, const char *const key)
2726{ 2726{
2727 key_value * 2727 key_value *link;
2728 link; 2728 shstr_cmp canonical_key (key);
2729 const char *
2730 canonical_key;
2731 2729
2732 canonical_key = shstr::find (key);
2733
2734 if (canonical_key == NULL) 2730 if (!canonical_key)
2735 { 2731 {
2736 /* 1. There being a field named key on any object 2732 /* 1. There being a field named key on any object
2737 * implies there'd be a shared string to find. 2733 * implies there'd be a shared string to find.
2738 * 2. Since there isn't, no object has this field. 2734 * 2. Since there isn't, no object has this field.
2739 * 3. Therefore, *this* object doesn't have this field. 2735 * 3. Therefore, *this* object doesn't have this field.
2740 */ 2736 */
2741 return NULL; 2737 return 0;
2742 } 2738 }
2743 2739
2744 /* This is copied from get_ob_key_link() above - 2740 /* This is copied from get_ob_key_link() above -
2745 * only 4 lines, and saves the function call overhead. 2741 * only 4 lines, and saves the function call overhead.
2746 */ 2742 */
2747 for (link = op->key_values; link != NULL; link = link->next) 2743 for (link = op->key_values; link; link = link->next)
2748 {
2749 if (link->key == canonical_key) 2744 if (link->key == canonical_key)
2750 {
2751 return link->value; 2745 return link->value;
2752 } 2746
2753 }
2754 return NULL; 2747 return 0;
2755} 2748}
2756 2749
2757 2750
2758/* 2751/*
2759 * Updates the canonical_key in op to value. 2752 * Updates the canonical_key in op to value.
2845 shstr key_ (key); 2838 shstr key_ (key);
2846 2839
2847 return set_ob_key_value_s (op, key_, value, add_key); 2840 return set_ob_key_value_s (op, key_, value, add_key);
2848} 2841}
2849 2842
2843object::depth_iterator::depth_iterator (object *container)
2844: iterator_base (container)
2845{
2846 while (item->inv)
2847 item = item->inv;
2848}
2849
2850void 2850void
2851object::deep_iterator::next () 2851object::depth_iterator::next ()
2852{ 2852{
2853 if (item->inv)
2854 item = item->inv;
2855 else if (item->below) 2853 if (item->below)
2854 {
2856 item = item->below; 2855 item = item->below;
2856
2857 while (item->inv)
2858 item = item->inv;
2859 }
2857 else 2860 else
2858 item = item->env->below; 2861 item = item->env;
2859} 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