… | |
… | |
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 | |
37 | int nrofallocobjects = 0; |
36 | int nrofallocobjects = 0; |
38 | |
37 | |
39 | object *objects; /* Pointer to the list of used objects */ |
38 | object *objects; /* Pointer to the list of used objects */ |
… | |
… | |
417 | */ |
416 | */ |
418 | |
417 | |
419 | object * |
418 | object * |
420 | find_object_name (const char *str) |
419 | find_object_name (const char *str) |
421 | { |
420 | { |
422 | const char *name = shstr::find (str); |
421 | shstr_cmp str_ (str); |
423 | object *op; |
422 | object *op; |
424 | |
423 | |
425 | for (op = objects; op != NULL; op = op->next) |
424 | for (op = objects; op != NULL; op = op->next) |
426 | if (&op->name == name) |
425 | if (op->name == str_) |
427 | break; |
426 | break; |
428 | |
427 | |
429 | return op; |
428 | return op; |
430 | } |
429 | } |
431 | |
430 | |
… | |
… | |
851 | freed.push_back (*i);//D |
850 | freed.push_back (*i);//D |
852 | //delete *i; |
851 | //delete *i; |
853 | mortals.erase (i); |
852 | mortals.erase (i); |
854 | } |
853 | } |
855 | |
854 | |
856 | if (mortals.size())//D |
855 | if (mortals.size() && 0)//D |
857 | LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D |
856 | LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D |
858 | } |
857 | } |
859 | |
858 | |
860 | object::object () |
859 | object::object () |
861 | { |
860 | { |
… | |
… | |
905 | objects = next; |
904 | objects = next; |
906 | } |
905 | } |
907 | |
906 | |
908 | object *object::create () |
907 | object *object::create () |
909 | { |
908 | { |
910 | object * |
909 | object *op; |
911 | op; |
|
|
912 | |
910 | |
913 | if (freed.empty ()) |
911 | if (freed.empty ()) |
914 | op = new object; |
912 | op = new object; |
915 | else |
913 | else |
916 | { |
914 | { |
… | |
… | |
938 | void object::free (bool free_inventory) |
936 | void object::free (bool free_inventory) |
939 | { |
937 | { |
940 | if (QUERY_FLAG (this, FLAG_FREED)) |
938 | if (QUERY_FLAG (this, FLAG_FREED)) |
941 | return; |
939 | return; |
942 | |
940 | |
|
|
941 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
|
|
942 | remove_friendly_object (this); |
|
|
943 | |
943 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
944 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
944 | remove_ob (this); |
945 | remove_ob (this); |
945 | |
|
|
946 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
|
|
947 | remove_friendly_object (this); |
|
|
948 | |
946 | |
949 | SET_FLAG (this, FLAG_FREED); |
947 | SET_FLAG (this, FLAG_FREED); |
950 | |
948 | |
951 | if (more) |
949 | if (more) |
952 | { |
950 | { |
… | |
… | |
958 | { |
956 | { |
959 | /* Only if the space blocks everything do we not process - |
957 | /* Only if the space blocks everything do we not process - |
960 | * if some form of movement is allowed, let objects |
958 | * if some form of movement is allowed, let objects |
961 | * drop on that space. |
959 | * drop on that space. |
962 | */ |
960 | */ |
963 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) |
961 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
964 | { |
962 | { |
965 | object *op = inv; |
963 | object *op = inv; |
966 | |
964 | |
967 | while (op) |
965 | while (op) |
968 | { |
966 | { |
… | |
… | |
2722 | * The returned string is shared. |
2720 | * The returned string is shared. |
2723 | */ |
2721 | */ |
2724 | const char * |
2722 | const char * |
2725 | get_ob_key_value (const object *op, const char *const key) |
2723 | get_ob_key_value (const object *op, const char *const key) |
2726 | { |
2724 | { |
2727 | key_value * |
2725 | key_value *link; |
2728 | link; |
2726 | shstr_cmp canonical_key (key); |
2729 | const char * |
|
|
2730 | canonical_key; |
|
|
2731 | |
2727 | |
2732 | canonical_key = shstr::find (key); |
|
|
2733 | |
|
|
2734 | if (canonical_key == NULL) |
2728 | if (!canonical_key) |
2735 | { |
2729 | { |
2736 | /* 1. There being a field named key on any object |
2730 | /* 1. There being a field named key on any object |
2737 | * implies there'd be a shared string to find. |
2731 | * implies there'd be a shared string to find. |
2738 | * 2. Since there isn't, no object has this field. |
2732 | * 2. Since there isn't, no object has this field. |
2739 | * 3. Therefore, *this* object doesn't have this field. |
2733 | * 3. Therefore, *this* object doesn't have this field. |
2740 | */ |
2734 | */ |
2741 | return NULL; |
2735 | return 0; |
2742 | } |
2736 | } |
2743 | |
2737 | |
2744 | /* This is copied from get_ob_key_link() above - |
2738 | /* This is copied from get_ob_key_link() above - |
2745 | * only 4 lines, and saves the function call overhead. |
2739 | * only 4 lines, and saves the function call overhead. |
2746 | */ |
2740 | */ |
2747 | for (link = op->key_values; link != NULL; link = link->next) |
2741 | for (link = op->key_values; link; link = link->next) |
2748 | { |
|
|
2749 | if (link->key == canonical_key) |
2742 | if (link->key == canonical_key) |
2750 | { |
|
|
2751 | return link->value; |
2743 | return link->value; |
2752 | } |
2744 | |
2753 | } |
|
|
2754 | return NULL; |
2745 | return 0; |
2755 | } |
2746 | } |
2756 | |
2747 | |
2757 | |
2748 | |
2758 | /* |
2749 | /* |
2759 | * Updates the canonical_key in op to value. |
2750 | * Updates the canonical_key in op to value. |
… | |
… | |
2845 | shstr key_ (key); |
2836 | shstr key_ (key); |
2846 | |
2837 | |
2847 | return set_ob_key_value_s (op, key_, value, add_key); |
2838 | return set_ob_key_value_s (op, key_, value, add_key); |
2848 | } |
2839 | } |
2849 | |
2840 | |
|
|
2841 | object::depth_iterator::depth_iterator (object *container) |
|
|
2842 | : iterator_base (container) |
|
|
2843 | { |
|
|
2844 | while (item->inv) |
|
|
2845 | item = item->inv; |
|
|
2846 | } |
|
|
2847 | |
2850 | void |
2848 | void |
2851 | object::deep_iterator::next () |
2849 | object::depth_iterator::next () |
2852 | { |
2850 | { |
2853 | if (item->inv) |
|
|
2854 | item = item->inv; |
|
|
2855 | else if (item->below) |
2851 | if (item->below) |
|
|
2852 | { |
2856 | item = item->below; |
2853 | item = item->below; |
|
|
2854 | |
|
|
2855 | while (item->inv) |
|
|
2856 | item = item->inv; |
|
|
2857 | } |
2857 | else |
2858 | else |
2858 | item = item->env->below; |
2859 | item = item->env; |
2859 | } |
2860 | } |
|
|
2861 | |