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.120 by root, Sun Jan 21 21:28:27 2007 UTC vs.
Revision 1.131 by root, Sat Feb 10 15:20:23 2007 UTC

670 face = blank_face; 670 face = blank_face;
671} 671}
672 672
673object::~object () 673object::~object ()
674{ 674{
675 if (index)
676 unlink (); 675 unlink ();
677 676
678 free_key_values (this); 677 free_key_values (this);
679} 678}
680 679
681static int object_count; 680static int object_count;
690 objects.insert (this); 689 objects.insert (this);
691} 690}
692 691
693void object::unlink () 692void object::unlink ()
694{ 693{
695 assert (index);//D 694 if (!index)
695 return;
696
696 objects.erase (this); 697 objects.erase (this);
697 refcnt_dec (); 698 refcnt_dec ();
698} 699}
699 700
700void 701void
774 * drop on that space. 775 * drop on that space.
775 */ 776 */
776 if (!drop_to_ground 777 if (!drop_to_ground
777 || !map 778 || !map
778 || map->in_memory != MAP_IN_MEMORY 779 || map->in_memory != MAP_IN_MEMORY
780 || map->nodrop
779 || ms ().move_block == MOVE_ALL) 781 || ms ().move_block == MOVE_ALL)
780 { 782 {
781 while (inv) 783 while (inv)
782 { 784 {
783 inv->destroy_inv (drop_to_ground); 785 inv->destroy_inv (drop_to_ground);
817 819
818 if (flag [FLAG_IS_LINKED]) 820 if (flag [FLAG_IS_LINKED])
819 remove_button_link (this); 821 remove_button_link (this);
820 822
821 if (flag [FLAG_FRIENDLY]) 823 if (flag [FLAG_FRIENDLY])
824 {
822 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 }
823 833
824 if (!flag [FLAG_REMOVED]) 834 if (!flag [FLAG_REMOVED])
825 remove (); 835 remove ();
826 836
827 destroy_inv (true); 837 destroy_inv (true);
899 * 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
900 * 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
901 * object will have no environment. If the object previously had an 911 * object will have no environment. If the object previously had an
902 * environment, the x and y coordinates will be updated to 912 * environment, the x and y coordinates will be updated to
903 * the previous environment. 913 * the previous environment.
904 * Beware: This function is called from the editor as well!
905 */ 914 */
906void 915void
907object::remove_slow () 916object::do_remove ()
908{ 917{
909 object *tmp, *last = 0; 918 object *tmp, *last = 0;
910 object *otmp; 919 object *otmp;
911 920
912 if (QUERY_FLAG (this, FLAG_REMOVED)) 921 if (QUERY_FLAG (this, FLAG_REMOVED))
955 } 964 }
956 else if (map) 965 else if (map)
957 { 966 {
958 if (type == PLAYER) 967 if (type == PLAYER)
959 { 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
960 --map->players; 975 --map->players;
961 map->touch (); 976 map->touch ();
962 } 977 }
963 978
964 map->dirty = true; 979 map->dirty = true;
1966 } 1981 }
1967 1982
1968 if (!index) 1983 if (!index)
1969 return -1; 1984 return -1;
1970 1985
1971 return altern[RANDOM () % index]; 1986 return altern [rndm (index)];
1972} 1987}
1973 1988
1974/* 1989/*
1975 * find_first_free_spot(archetype, maptile, x, y) works like 1990 * find_first_free_spot(archetype, maptile, x, y) works like
1976 * find_free_spot(), but it will search max number of squares. 1991 * find_free_spot(), but it will search max number of squares.
1997{ 2012{
1998 arr += begin; 2013 arr += begin;
1999 end -= begin; 2014 end -= begin;
2000 2015
2001 while (--end) 2016 while (--end)
2002 swap (arr [end], arr [RANDOM () % (end + 1)]); 2017 swap (arr [end], arr [rndm (end + 1)]);
2003} 2018}
2004 2019
2005/* new function to make monster searching more efficient, and effective! 2020/* new function to make monster searching more efficient, and effective!
2006 * This basically returns a randomized array (in the passed pointer) of 2021 * This basically returns a randomized array (in the passed pointer) of
2007 * 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
2569{ 2584{
2570 char flagdesc[512]; 2585 char flagdesc[512];
2571 char info2[256 * 4]; 2586 char info2[256 * 4];
2572 char *p = info; 2587 char *p = info;
2573 2588
2574 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}",
2575 count, uuid.seq, 2590 count, uuid.seq,
2576 &name, 2591 &name,
2577 title ? "\",title:\"" : "", 2592 title ? "\",title:\"" : "",
2578 title ? (const char *)title : "", 2593 title ? (const char *)title : "",
2579 flag_desc (flagdesc, 512), type); 2594 flag_desc (flagdesc, 512), type);
2599{ 2614{
2600 static char info[256 * 4]; 2615 static char info[256 * 4];
2601 return debug_desc (info); 2616 return debug_desc (info);
2602} 2617}
2603 2618
2619struct region *
2620object::region () const
2621{
2622 return map ? map->region (x, y)
2623 : region::default_region ();
2624}
2625
2626const materialtype_t *
2627object::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
2638void
2639object::open_container (object *new_container)
2640{
2641 if (container == new_container)
2642 return;
2643
2644 if (contr && contr->ns)
2645 contr->ns->floorbox_reset ();
2646
2647 if (object *old_container = container)
2648 {
2649 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2650 return;
2651
2652#if 0
2653 // remove the "Close old_container" object.
2654 if (object *closer = old_container->inv)
2655 if (closer->type == CLOSE_CON)
2656 closer->destroy ();
2657#endif
2658
2659 old_container->flag [FLAG_APPLIED] = 0;
2660 container = 0;
2661
2662 esrv_update_item (UPD_FLAGS, this, old_container);
2663 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2664 }
2665
2666 if (new_container)
2667 {
2668 if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this)))
2669 return;
2670
2671 // TODO: this does not seem to serve any purpose anymore?
2672#if 0
2673 // insert the "Close Container" object.
2674 if (archetype *closer = new_container->other_arch)
2675 {
2676 object *closer = arch_to_object (new_container->other_arch);
2677 closer->flag [FLAG_NO_MAP_SAVE] = 1;
2678 new_container->insert (closer);
2679 }
2680#endif
2681
2682 new_container->flag [FLAG_APPLIED] = 1;
2683 container = new_container;
2684
2685 esrv_update_item (UPD_FLAGS, this, new_container);
2686 esrv_send_inventory (this, new_container);
2687 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2688 }
2689}
2690
2691

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines