… | |
… | |
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 | |
… | |
… | |
623 | /* |
622 | /* |
624 | * Updates the speed of an object. If the speed changes from 0 to another |
623 | * Updates the speed of an object. If the speed changes from 0 to another |
625 | * value, or vice versa, then add/remove the object from the active list. |
624 | * value, or vice versa, then add/remove the object from the active list. |
626 | * This function needs to be called whenever the speed of an object changes. |
625 | * This function needs to be called whenever the speed of an object changes. |
627 | */ |
626 | */ |
628 | |
|
|
629 | void |
627 | void |
630 | update_ob_speed (object *op) |
628 | update_ob_speed (object *op) |
631 | { |
629 | { |
632 | extern int arch_init; |
630 | extern int arch_init; |
633 | |
631 | |
… | |
… | |
642 | abort (); |
640 | abort (); |
643 | #else |
641 | #else |
644 | op->speed = 0; |
642 | op->speed = 0; |
645 | #endif |
643 | #endif |
646 | } |
644 | } |
|
|
645 | |
647 | if (arch_init) |
646 | if (arch_init) |
648 | { |
|
|
649 | return; |
647 | return; |
650 | } |
648 | |
651 | if (FABS (op->speed) > MIN_ACTIVE_SPEED) |
649 | if (FABS (op->speed) > MIN_ACTIVE_SPEED) |
652 | { |
650 | { |
653 | /* If already on active list, don't do anything */ |
651 | /* If already on active list, don't do anything */ |
654 | if (op->active_next || op->active_prev || op == active_objects) |
652 | if (op->active_next || op->active_prev || op == active_objects) |
655 | return; |
653 | return; |
656 | |
654 | |
657 | /* process_events() expects us to insert the object at the beginning |
655 | /* process_events() expects us to insert the object at the beginning |
658 | * of the list. */ |
656 | * of the list. */ |
659 | op->active_next = active_objects; |
657 | op->active_next = active_objects; |
|
|
658 | |
660 | if (op->active_next != NULL) |
659 | if (op->active_next != NULL) |
661 | op->active_next->active_prev = op; |
660 | op->active_next->active_prev = op; |
|
|
661 | |
662 | active_objects = op; |
662 | active_objects = op; |
663 | } |
663 | } |
664 | else |
664 | else |
665 | { |
665 | { |
666 | /* If not on the active list, nothing needs to be done */ |
666 | /* If not on the active list, nothing needs to be done */ |
… | |
… | |
668 | return; |
668 | return; |
669 | |
669 | |
670 | if (op->active_prev == NULL) |
670 | if (op->active_prev == NULL) |
671 | { |
671 | { |
672 | active_objects = op->active_next; |
672 | active_objects = op->active_next; |
|
|
673 | |
673 | if (op->active_next != NULL) |
674 | if (op->active_next != NULL) |
674 | op->active_next->active_prev = NULL; |
675 | op->active_next->active_prev = NULL; |
675 | } |
676 | } |
676 | else |
677 | else |
677 | { |
678 | { |
678 | op->active_prev->active_next = op->active_next; |
679 | op->active_prev->active_next = op->active_next; |
|
|
680 | |
679 | if (op->active_next) |
681 | if (op->active_next) |
680 | op->active_next->active_prev = op->active_prev; |
682 | op->active_next->active_prev = op->active_prev; |
681 | } |
683 | } |
|
|
684 | |
682 | op->active_next = NULL; |
685 | op->active_next = NULL; |
683 | op->active_prev = NULL; |
686 | op->active_prev = NULL; |
684 | } |
687 | } |
685 | } |
688 | } |
686 | |
689 | |
… | |
… | |
847 | freed.push_back (*i);//D |
850 | freed.push_back (*i);//D |
848 | //delete *i; |
851 | //delete *i; |
849 | mortals.erase (i); |
852 | mortals.erase (i); |
850 | } |
853 | } |
851 | |
854 | |
852 | if (mortals.size())//D |
855 | if (mortals.size() && 0)//D |
853 | LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D |
856 | LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D |
854 | } |
857 | } |
855 | |
858 | |
856 | object::object () |
859 | object::object () |
857 | { |
860 | { |
… | |
… | |
901 | objects = next; |
904 | objects = next; |
902 | } |
905 | } |
903 | |
906 | |
904 | object *object::create () |
907 | object *object::create () |
905 | { |
908 | { |
906 | object * |
909 | object *op; |
907 | op; |
|
|
908 | |
910 | |
909 | if (freed.empty ()) |
911 | if (freed.empty ()) |
910 | op = new object; |
912 | op = new object; |
911 | else |
913 | else |
912 | { |
914 | { |
… | |
… | |
934 | void object::free (bool free_inventory) |
936 | void object::free (bool free_inventory) |
935 | { |
937 | { |
936 | if (QUERY_FLAG (this, FLAG_FREED)) |
938 | if (QUERY_FLAG (this, FLAG_FREED)) |
937 | return; |
939 | return; |
938 | |
940 | |
|
|
941 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
|
|
942 | remove_friendly_object (this); |
|
|
943 | |
939 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
944 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
940 | remove_ob (this); |
945 | remove_ob (this); |
941 | |
|
|
942 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
|
|
943 | remove_friendly_object (this); |
|
|
944 | |
946 | |
945 | SET_FLAG (this, FLAG_FREED); |
947 | SET_FLAG (this, FLAG_FREED); |
946 | |
948 | |
947 | if (more) |
949 | if (more) |
948 | { |
950 | { |
… | |
… | |
954 | { |
956 | { |
955 | /* Only if the space blocks everything do we not process - |
957 | /* Only if the space blocks everything do we not process - |
956 | * if some form of movement is allowed, let objects |
958 | * if some form of movement is allowed, let objects |
957 | * drop on that space. |
959 | * drop on that space. |
958 | */ |
960 | */ |
959 | 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) |
960 | { |
962 | { |
961 | object *op = inv; |
963 | object *op = inv; |
962 | |
964 | |
963 | while (op) |
965 | while (op) |
964 | { |
966 | { |
… | |
… | |
2718 | * The returned string is shared. |
2720 | * The returned string is shared. |
2719 | */ |
2721 | */ |
2720 | const char * |
2722 | const char * |
2721 | get_ob_key_value (const object *op, const char *const key) |
2723 | get_ob_key_value (const object *op, const char *const key) |
2722 | { |
2724 | { |
2723 | key_value * |
2725 | key_value *link; |
2724 | link; |
2726 | shstr_cmp canonical_key (key); |
2725 | const char * |
|
|
2726 | canonical_key; |
|
|
2727 | |
2727 | |
2728 | canonical_key = shstr::find (key); |
|
|
2729 | |
|
|
2730 | if (canonical_key == NULL) |
2728 | if (!canonical_key) |
2731 | { |
2729 | { |
2732 | /* 1. There being a field named key on any object |
2730 | /* 1. There being a field named key on any object |
2733 | * implies there'd be a shared string to find. |
2731 | * implies there'd be a shared string to find. |
2734 | * 2. Since there isn't, no object has this field. |
2732 | * 2. Since there isn't, no object has this field. |
2735 | * 3. Therefore, *this* object doesn't have this field. |
2733 | * 3. Therefore, *this* object doesn't have this field. |
2736 | */ |
2734 | */ |
2737 | return NULL; |
2735 | return 0; |
2738 | } |
2736 | } |
2739 | |
2737 | |
2740 | /* This is copied from get_ob_key_link() above - |
2738 | /* This is copied from get_ob_key_link() above - |
2741 | * only 4 lines, and saves the function call overhead. |
2739 | * only 4 lines, and saves the function call overhead. |
2742 | */ |
2740 | */ |
2743 | for (link = op->key_values; link != NULL; link = link->next) |
2741 | for (link = op->key_values; link; link = link->next) |
2744 | { |
|
|
2745 | if (link->key == canonical_key) |
2742 | if (link->key == canonical_key) |
2746 | { |
|
|
2747 | return link->value; |
2743 | return link->value; |
2748 | } |
2744 | |
2749 | } |
|
|
2750 | return NULL; |
2745 | return 0; |
2751 | } |
2746 | } |
2752 | |
2747 | |
2753 | |
2748 | |
2754 | /* |
2749 | /* |
2755 | * Updates the canonical_key in op to value. |
2750 | * Updates the canonical_key in op to value. |
… | |
… | |
2840 | { |
2835 | { |
2841 | shstr key_ (key); |
2836 | shstr key_ (key); |
2842 | |
2837 | |
2843 | return set_ob_key_value_s (op, key_, value, add_key); |
2838 | return set_ob_key_value_s (op, key_, value, add_key); |
2844 | } |
2839 | } |
|
|
2840 | |
|
|
2841 | object::depth_iterator::depth_iterator (object *container) |
|
|
2842 | : iterator_base (container) |
|
|
2843 | { |
|
|
2844 | while (item->inv) |
|
|
2845 | item = item->inv; |
|
|
2846 | } |
|
|
2847 | |
|
|
2848 | void |
|
|
2849 | object::depth_iterator::next () |
|
|
2850 | { |
|
|
2851 | if (item->below) |
|
|
2852 | { |
|
|
2853 | item = item->below; |
|
|
2854 | |
|
|
2855 | while (item->inv) |
|
|
2856 | item = item->inv; |
|
|
2857 | } |
|
|
2858 | else |
|
|
2859 | item = item->env; |
|
|
2860 | } |
|
|
2861 | |
|
|
2862 | // return a suitable string describing an objetc in enough detail to find it |
|
|
2863 | const char * |
|
|
2864 | object::debug_desc (char *info) const |
|
|
2865 | { |
|
|
2866 | char info2[256 * 3]; |
|
|
2867 | char *p = info; |
|
|
2868 | |
|
|
2869 | p += snprintf (p, 256, "%d=\"%s%s%s\"", |
|
|
2870 | count, |
|
|
2871 | &name, |
|
|
2872 | title ? " " : "", |
|
|
2873 | title ? (const char *)title : ""); |
|
|
2874 | |
|
|
2875 | if (env) |
|
|
2876 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
|
|
2877 | |
|
|
2878 | if (map) |
|
|
2879 | p += snprintf (p, 256, "(on %s@%d+%d)", map->path, x, y); |
|
|
2880 | |
|
|
2881 | return info; |
|
|
2882 | } |
|
|
2883 | |
|
|
2884 | const char * |
|
|
2885 | object::debug_desc () const |
|
|
2886 | { |
|
|
2887 | static char info[256 * 3]; |
|
|
2888 | return debug_desc (info); |
|
|
2889 | } |
|
|
2890 | |