… | |
… | |
670 | face = blank_face; |
670 | face = blank_face; |
671 | } |
671 | } |
672 | |
672 | |
673 | object::~object () |
673 | object::~object () |
674 | { |
674 | { |
|
|
675 | unlink (); |
|
|
676 | |
675 | free_key_values (this); |
677 | free_key_values (this); |
676 | } |
678 | } |
677 | |
679 | |
678 | static int object_count; |
680 | static int object_count; |
679 | |
681 | |
… | |
… | |
687 | objects.insert (this); |
689 | objects.insert (this); |
688 | } |
690 | } |
689 | |
691 | |
690 | void object::unlink () |
692 | void object::unlink () |
691 | { |
693 | { |
692 | assert (index);//D |
694 | if (!index) |
|
|
695 | return; |
|
|
696 | |
693 | objects.erase (this); |
697 | objects.erase (this); |
694 | refcnt_dec (); |
698 | refcnt_dec (); |
695 | } |
699 | } |
696 | |
700 | |
697 | void |
701 | void |
… | |
… | |
771 | * drop on that space. |
775 | * drop on that space. |
772 | */ |
776 | */ |
773 | if (!drop_to_ground |
777 | if (!drop_to_ground |
774 | || !map |
778 | || !map |
775 | || map->in_memory != MAP_IN_MEMORY |
779 | || map->in_memory != MAP_IN_MEMORY |
|
|
780 | || map->nodrop |
776 | || ms ().move_block == MOVE_ALL) |
781 | || ms ().move_block == MOVE_ALL) |
777 | { |
782 | { |
778 | while (inv) |
783 | while (inv) |
779 | { |
784 | { |
780 | inv->destroy_inv (drop_to_ground); |
785 | inv->destroy_inv (drop_to_ground); |
… | |
… | |
814 | |
819 | |
815 | if (flag [FLAG_IS_LINKED]) |
820 | if (flag [FLAG_IS_LINKED]) |
816 | remove_button_link (this); |
821 | remove_button_link (this); |
817 | |
822 | |
818 | if (flag [FLAG_FRIENDLY]) |
823 | if (flag [FLAG_FRIENDLY]) |
|
|
824 | { |
819 | remove_friendly_object (this); |
825 | remove_friendly_object (this); |
|
|
826 | |
|
|
827 | if (type == GOLEM |
|
|
828 | && owner |
|
|
829 | && owner->type == PLAYER |
|
|
830 | && owner->contr->ranges[range_golem] == this) |
|
|
831 | owner->contr->ranges[range_golem] = 0; |
|
|
832 | } |
820 | |
833 | |
821 | if (!flag [FLAG_REMOVED]) |
834 | if (!flag [FLAG_REMOVED]) |
822 | remove (); |
835 | remove (); |
823 | |
836 | |
824 | destroy_inv (true); |
837 | destroy_inv (true); |
… | |
… | |
896 | * This function removes the object op from the linked list of objects |
909 | * This function removes the object op from the linked list of objects |
897 | * which it is currently tied to. When this function is done, the |
910 | * which it is currently tied to. When this function is done, the |
898 | * object will have no environment. If the object previously had an |
911 | * object will have no environment. If the object previously had an |
899 | * environment, the x and y coordinates will be updated to |
912 | * environment, the x and y coordinates will be updated to |
900 | * the previous environment. |
913 | * the previous environment. |
901 | * Beware: This function is called from the editor as well! |
|
|
902 | */ |
914 | */ |
903 | void |
915 | void |
904 | object::remove_slow () |
916 | object::do_remove () |
905 | { |
917 | { |
906 | object *tmp, *last = 0; |
918 | object *tmp, *last = 0; |
907 | object *otmp; |
919 | object *otmp; |
908 | |
920 | |
909 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
921 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
… | |
… | |
952 | } |
964 | } |
953 | else if (map) |
965 | else if (map) |
954 | { |
966 | { |
955 | if (type == PLAYER) |
967 | if (type == PLAYER) |
956 | { |
968 | { |
|
|
969 | // leaving a spot always closes any open container on the ground |
|
|
970 | if (container && !container->env) |
|
|
971 | // this causes spurious floorbox updates, but it ensures |
|
|
972 | // that the CLOSE event is being sent. |
|
|
973 | close_container (); |
|
|
974 | |
957 | --map->players; |
975 | --map->players; |
958 | map->touch (); |
976 | map->touch (); |
959 | } |
977 | } |
960 | |
978 | |
961 | map->dirty = true; |
979 | map->dirty = true; |
… | |
… | |
1746 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
1764 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
1747 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
1765 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
1748 | { |
1766 | { |
1749 | |
1767 | |
1750 | float |
1768 | float |
1751 | diff = tmp->move_slow_penalty * FABS (op->speed); |
1769 | diff = tmp->move_slow_penalty * fabs (op->speed); |
1752 | |
1770 | |
1753 | if (op->type == PLAYER) |
1771 | if (op->type == PLAYER) |
1754 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
1772 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
1755 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
1773 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
1756 | diff /= 4.0; |
1774 | diff /= 4.0; |
… | |
… | |
1963 | } |
1981 | } |
1964 | |
1982 | |
1965 | if (!index) |
1983 | if (!index) |
1966 | return -1; |
1984 | return -1; |
1967 | |
1985 | |
1968 | return altern[RANDOM () % index]; |
1986 | return altern [rndm (index)]; |
1969 | } |
1987 | } |
1970 | |
1988 | |
1971 | /* |
1989 | /* |
1972 | * find_first_free_spot(archetype, maptile, x, y) works like |
1990 | * find_first_free_spot(archetype, maptile, x, y) works like |
1973 | * find_free_spot(), but it will search max number of squares. |
1991 | * find_free_spot(), but it will search max number of squares. |
… | |
… | |
1994 | { |
2012 | { |
1995 | arr += begin; |
2013 | arr += begin; |
1996 | end -= begin; |
2014 | end -= begin; |
1997 | |
2015 | |
1998 | while (--end) |
2016 | while (--end) |
1999 | swap (arr [end], arr [RANDOM () % (end + 1)]); |
2017 | swap (arr [end], arr [rndm (end + 1)]); |
2000 | } |
2018 | } |
2001 | |
2019 | |
2002 | /* new function to make monster searching more efficient, and effective! |
2020 | /* new function to make monster searching more efficient, and effective! |
2003 | * This basically returns a randomized array (in the passed pointer) of |
2021 | * This basically returns a randomized array (in the passed pointer) of |
2004 | * the spaces to find monsters. In this way, it won't always look for |
2022 | * the spaces to find monsters. In this way, it won't always look for |
… | |
… | |
2566 | { |
2584 | { |
2567 | char flagdesc[512]; |
2585 | char flagdesc[512]; |
2568 | char info2[256 * 4]; |
2586 | char info2[256 * 4]; |
2569 | char *p = info; |
2587 | char *p = info; |
2570 | |
2588 | |
2571 | p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2589 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2572 | count, uuid.seq, |
2590 | count, uuid.seq, |
2573 | &name, |
2591 | &name, |
2574 | title ? "\",title:\"" : "", |
2592 | title ? "\",title:\"" : "", |
2575 | title ? (const char *)title : "", |
2593 | title ? (const char *)title : "", |
2576 | flag_desc (flagdesc, 512), type); |
2594 | flag_desc (flagdesc, 512), type); |
… | |
… | |
2596 | { |
2614 | { |
2597 | static char info[256 * 4]; |
2615 | static char info[256 * 4]; |
2598 | return debug_desc (info); |
2616 | return debug_desc (info); |
2599 | } |
2617 | } |
2600 | |
2618 | |
|
|
2619 | struct region * |
|
|
2620 | object::region () const |
|
|
2621 | { |
|
|
2622 | return map ? map->region (x, y) |
|
|
2623 | : region::default_region (); |
|
|
2624 | } |
|
|
2625 | |
|
|
2626 | const materialtype_t * |
|
|
2627 | object::dominant_material () const |
|
|
2628 | { |
|
|
2629 | if (materialtype_t *mat = name_to_material (materialname)) |
|
|
2630 | return mat; |
|
|
2631 | |
|
|
2632 | // omfg this is slow, this has to be temporary :) |
|
|
2633 | shstr unknown ("unknown"); |
|
|
2634 | |
|
|
2635 | return name_to_material (unknown); |
|
|
2636 | } |
|
|
2637 | |
|
|
2638 | void |
|
|
2639 | object::open_container (object *new_container) |
|
|
2640 | { |
|
|
2641 | if (container == new_container) |
|
|
2642 | return; |
|
|
2643 | |
|
|
2644 | if (object *old_container = container) |
|
|
2645 | { |
|
|
2646 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
|
|
2647 | return; |
|
|
2648 | |
|
|
2649 | #if 0 |
|
|
2650 | // remove the "Close old_container" object. |
|
|
2651 | if (object *closer = old_container->inv) |
|
|
2652 | if (closer->type == CLOSE_CON) |
|
|
2653 | closer->destroy (); |
|
|
2654 | #endif |
|
|
2655 | |
|
|
2656 | old_container->flag [FLAG_APPLIED] = 0; |
|
|
2657 | container = 0; |
|
|
2658 | |
|
|
2659 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2660 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
|
|
2661 | } |
|
|
2662 | |
|
|
2663 | if (new_container) |
|
|
2664 | { |
|
|
2665 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
|
|
2666 | return; |
|
|
2667 | |
|
|
2668 | // TODO: this does not seem to serve any purpose anymore? |
|
|
2669 | #if 0 |
|
|
2670 | // insert the "Close Container" object. |
|
|
2671 | if (archetype *closer = new_container->other_arch) |
|
|
2672 | { |
|
|
2673 | object *closer = arch_to_object (new_container->other_arch); |
|
|
2674 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
|
|
2675 | new_container->insert (closer); |
|
|
2676 | } |
|
|
2677 | #endif |
|
|
2678 | |
|
|
2679 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
|
|
2680 | |
|
|
2681 | new_container->flag [FLAG_APPLIED] = 1; |
|
|
2682 | container = new_container; |
|
|
2683 | |
|
|
2684 | esrv_update_item (UPD_FLAGS, this, new_container); |
|
|
2685 | esrv_send_inventory (this, new_container); |
|
|
2686 | } |
|
|
2687 | } |
|
|
2688 | |
|
|
2689 | |