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.87 by root, Tue Dec 26 08:54:59 2006 UTC vs.
Revision 1.94 by root, Wed Dec 27 05:22:35 2006 UTC

778 778
779 prev = 0; 779 prev = 0;
780 next = 0; 780 next = 0;
781} 781}
782 782
783object *object::create ()
784{
785 object *op = new object;
786 op->link ();
787 return op;
788}
789
790void
791object::do_destroy ()
792{
793 attachable::do_destroy ();
794
795 if (flag [FLAG_IS_LINKED])
796 remove_button_link (this);
797
798 if (flag [FLAG_FRIENDLY])
799 remove_friendly_object (this);
800
801 if (!flag [FLAG_REMOVED])
802 remove ();
803
804 if (flag [FLAG_FREED])
805 return;
806
807 flag [FLAG_FREED] = 1;
808
809 // hack to ensure that freed objects still have a valid map
810 {
811 static maptile *freed_map; // freed objects are moved here to avoid crashes
812
813 if (!freed_map)
814 {
815 freed_map = new maptile;
816
817 freed_map->name = "/internal/freed_objects_map";
818 freed_map->width = 3;
819 freed_map->height = 3;
820
821 freed_map->allocate ();
822 }
823
824 map = freed_map;
825 x = 1;
826 y = 1;
827 }
828
829 more = 0;
830 head = 0;
831 inv = 0;
832
833 // clear those pointers that likely might have circular references to us
834 owner = 0;
835 enemy = 0;
836 attacked_by = 0;
837
838 // only relevant for players(?), but make sure of it anyways
839 contr = 0;
840
841 /* Remove object from the active list */
842 set_speed (0);
843
844 unlink ();
845}
846
847/* 783/*
848 * Remove and free all objects in the inventory of the given object. 784 * Remove and free all objects in the inventory of the given object.
849 * object.c ? 785 * object.c ?
850 */ 786 */
851void 787void
852object::destroy_inv (bool drop_to_ground) 788object::destroy_inv (bool drop_to_ground)
853{ 789{
790 // need to check first, because the checks below might segfault
791 // as we might be on an invalid mapspace and crossfire code
792 // is too buggy to ensure that the inventory is empty.
793 // corollary: if you create arrows etc. with stuff in tis inventory,
794 // cf will crash below with off-map x and y
854 if (!inv) 795 if (!inv)
855 return; 796 return;
856 797
857 /* Only if the space blocks everything do we not process - 798 /* Only if the space blocks everything do we not process -
858 * if some form of movement is allowed, let objects 799 * if some form of movement is allowed, let objects
859 * drop on that space. 800 * drop on that space.
860 */ 801 */
861 if (!drop_to_ground || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) 802 if (!drop_to_ground
803 || !map
804 || map->in_memory != MAP_IN_MEMORY
805 || map->at (x, y).move_block == MOVE_ALL)
862 { 806 {
863 while (inv) 807 while (inv)
864 { 808 {
865 inv->destroy_inv (drop_to_ground); 809 inv->destroy_inv (drop_to_ground);
866 inv->destroy (); 810 inv->destroy ();
877 || op->type == RUNE 821 || op->type == RUNE
878 || op->type == TRAP 822 || op->type == TRAP
879 || op->flag [FLAG_IS_A_TEMPLATE]) 823 || op->flag [FLAG_IS_A_TEMPLATE])
880 op->destroy (); 824 op->destroy ();
881 else 825 else
882 { 826 map->insert (op, x, y);
883 op->remove ();
884 op->x = x;
885 op->y = y;
886 insert_ob_in_map (op, map, 0, 0); /* Insert in same map as the envir */
887 }
888 } 827 }
889 } 828 }
829}
830
831object *object::create ()
832{
833 object *op = new object;
834 op->link ();
835 return op;
836}
837
838void
839object::do_destroy ()
840{
841 if (flag [FLAG_IS_LINKED])
842 remove_button_link (this);
843
844 if (flag [FLAG_FRIENDLY])
845 remove_friendly_object (this);
846
847 if (!flag [FLAG_REMOVED])
848 remove ();
849
850 if (flag [FLAG_FREED])
851 return;
852
853 set_speed (0);
854
855 flag [FLAG_FREED] = 1;
856
857 attachable::do_destroy ();
858
859 destroy_inv (true);
860 unlink ();
861
862 // hack to ensure that freed objects still have a valid map
863 {
864 static maptile *freed_map; // freed objects are moved here to avoid crashes
865
866 if (!freed_map)
867 {
868 freed_map = new maptile;
869
870 freed_map->name = "/internal/freed_objects_map";
871 freed_map->width = 3;
872 freed_map->height = 3;
873
874 freed_map->allocate ();
875 }
876
877 map = freed_map;
878 x = 1;
879 y = 1;
880 }
881
882 head = 0;
883
884 if (more)
885 {
886 more->destroy ();
887 more = 0;
888 }
889
890 // clear those pointers that likely might have circular references to us
891 owner = 0;
892 enemy = 0;
893 attacked_by = 0;
894
895 // only relevant for players(?), but make sure of it anyways
896 contr = 0;
890} 897}
891 898
892void 899void
893object::destroy (bool destroy_inventory) 900object::destroy (bool destroy_inventory)
894{ 901{
895 if (destroyed ()) 902 if (destroyed ())
896 return; 903 return;
897 904
898 if (more)
899 {
900 //TODO: non-head objects must not have inventory
901 more->destroy (destroy_inventory);
902 more = 0;
903 }
904
905 if (destroy_inventory) 905 if (destroy_inventory)
906 destroy_inv (true); 906 destroy_inv (false);
907 907
908 attachable::destroy (); 908 attachable::destroy ();
909} 909}
910 910
911/* 911/*
1024 if (map->in_memory == MAP_SAVING) 1024 if (map->in_memory == MAP_SAVING)
1025 return; 1025 return;
1026 1026
1027 int check_walk_off = !flag [FLAG_NO_APPLY]; 1027 int check_walk_off = !flag [FLAG_NO_APPLY];
1028 1028
1029 for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) 1029 for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above)
1030 { 1030 {
1031 /* No point updating the players look faces if he is the object 1031 /* No point updating the players look faces if he is the object
1032 * being removed. 1032 * being removed.
1033 */ 1033 */
1034 1034
1120 * job preparing multi-part monsters 1120 * job preparing multi-part monsters
1121 */ 1121 */
1122object * 1122object *
1123insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y) 1123insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y)
1124{ 1124{
1125 object *tmp;
1126
1127 if (op->head)
1128 op = op->head;
1129
1130 for (tmp = op; tmp; tmp = tmp->more) 1125 for (object *tmp = op->head_ (); tmp; tmp = tmp->more)
1131 { 1126 {
1132 tmp->x = x + tmp->arch->clone.x; 1127 tmp->x = x + tmp->arch->clone.x;
1133 tmp->y = y + tmp->arch->clone.y; 1128 tmp->y = y + tmp->arch->clone.y;
1134 } 1129 }
1135 1130
1449 tmp1->x = op->x; 1444 tmp1->x = op->x;
1450 tmp1->y = op->y; 1445 tmp1->y = op->y;
1451 insert_ob_in_map (tmp1, op->map, op, 0); 1446 insert_ob_in_map (tmp1, op->map, op, 0);
1452} 1447}
1453 1448
1449object *
1450object::insert_at (object *where, object *originator, int flags)
1451{
1452 where->map->insert (this, where->x, where->y, originator, flags);
1453}
1454
1454/* 1455/*
1455 * get_split_ob(ob,nr) splits up ob into two parts. The part which 1456 * get_split_ob(ob,nr) splits up ob into two parts. The part which
1456 * is returned contains nr objects, and the remaining parts contains 1457 * is returned contains nr objects, and the remaining parts contains
1457 * the rest (or is removed and freed if that number is 0). 1458 * the rest (or is removed and freed if that number is 0).
1458 * On failure, NULL is returned, and the reason put into the 1459 * On failure, NULL is returned, and the reason put into the
1459 * global static errmsg array. 1460 * global static errmsg array.
1460 */ 1461 */
1461
1462object * 1462object *
1463get_split_ob (object *orig_ob, uint32 nr) 1463get_split_ob (object *orig_ob, uint32 nr)
1464{ 1464{
1465 object *newob; 1465 object *newob;
1466 int is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0); 1466 int is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0);
1730 * 1730 *
1731 * MSW 2001-07-08: Check all objects on space, not just those below 1731 * MSW 2001-07-08: Check all objects on space, not just those below
1732 * object being inserted. insert_ob_in_map may not put new objects 1732 * object being inserted. insert_ob_in_map may not put new objects
1733 * on top. 1733 * on top.
1734 */ 1734 */
1735
1736int 1735int
1737check_move_on (object *op, object *originator) 1736check_move_on (object *op, object *originator)
1738{ 1737{
1739 object *tmp; 1738 object *tmp;
1740 maptile *m = op->map; 1739 maptile *m = op->map;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines