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.220 by root, Thu Apr 24 00:30:52 2008 UTC vs.
Revision 1.224 by root, Fri May 2 20:16:24 2008 UTC

606} 606}
607 607
608object & 608object &
609object::operator =(const object &src) 609object::operator =(const object &src)
610{ 610{
611 bool is_freed = flag [FLAG_FREED]; 611 remove ();
612 bool is_removed = flag [FLAG_REMOVED];
613 612
614 *(object_copy *)this = src; 613 *(object_copy *)this = src;
615 614
616 flag [FLAG_FREED] = is_freed;
617 flag [FLAG_REMOVED] = is_removed; 615 flag [FLAG_REMOVED] = true;
618 616
619 /* Copy over key_values, if any. */ 617 /* Copy over key_values, if any. */
620 if (src.key_values) 618 if (src.key_values)
621 { 619 {
622 key_value *tail = 0; 620 key_value *tail = 0;
746 * UP_OBJ_FACE: only the objects face has changed. 744 * UP_OBJ_FACE: only the objects face has changed.
747 */ 745 */
748void 746void
749update_object (object *op, int action) 747update_object (object *op, int action)
750{ 748{
751 if (op == NULL) 749 if (!op)
752 { 750 {
753 /* this should never happen */ 751 /* this should never happen */
754 LOG (llevDebug, "update_object() called for NULL object.\n"); 752 LOG (llevError | logBacktrace, "update_object() called for NULL object.\n");
755 return; 753 return;
756 } 754 }
757 755
758 if (op->env) 756 if (!op->is_on_map ())
759 { 757 {
760 /* Animation is currently handled by client, so nothing 758 /* Animation is currently handled by client, so nothing
761 * to do in this case. 759 * to do in this case.
762 */ 760 */
763 return; 761 return;
764 } 762 }
765
766 /* If the map is saving, don't do anything as everything is
767 * going to get freed anyways.
768 */
769 if (!op->map || op->map->in_memory == MAP_SAVING)
770 return;
771 763
772 /* make sure the object is within map boundaries */ 764 /* make sure the object is within map boundaries */
773 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) 765 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height)
774 { 766 {
775 LOG (llevError, "update_object() called for object out of map!\n"); 767 LOG (llevError, "update_object() called for object out of map!\n");
965 object *op = new object; 957 object *op = new object;
966 op->link (); 958 op->link ();
967 return op; 959 return op;
968} 960}
969 961
962static struct freed_map : maptile
963{
964 freed_map ()
965 {
966 path = "<freed objects map>";
967 name = "/internal/freed_objects_map";
968 width = 3;
969 height = 3;
970 nodrop = 1;
971
972 alloc ();
973 in_memory = MAP_ACTIVE;
974 }
975} freed_map; // freed objects are moved here to avoid crashes
976
970void 977void
971object::do_destroy () 978object::do_destroy ()
972{ 979{
973 if (flag [FLAG_IS_LINKED]) 980 if (flag [FLAG_IS_LINKED])
974 remove_button_link (this); 981 remove_button_link (this);
984 unlink (); 991 unlink ();
985 992
986 flag [FLAG_FREED] = 1; 993 flag [FLAG_FREED] = 1;
987 994
988 // hack to ensure that freed objects still have a valid map 995 // hack to ensure that freed objects still have a valid map
989 {
990 static maptile *freed_map; // freed objects are moved here to avoid crashes
991
992 if (!freed_map)
993 {
994 freed_map = new maptile;
995
996 freed_map->path = "<freed objects map>";
997 freed_map->name = "/internal/freed_objects_map";
998 freed_map->width = 3;
999 freed_map->height = 3;
1000 freed_map->nodrop = 1;
1001
1002 freed_map->alloc ();
1003 freed_map->in_memory = MAP_ACTIVE;
1004 }
1005
1006 map = freed_map; 996 map = &freed_map;
1007 x = 1; 997 x = 1;
1008 y = 1; 998 y = 1;
1009 }
1010 999
1011 if (more) 1000 if (more)
1012 { 1001 {
1013 more->destroy (); 1002 more->destroy ();
1014 more = 0; 1003 more = 0;
1031 1020
1032 if (!is_head () && !head->destroyed ()) 1021 if (!is_head () && !head->destroyed ())
1033 { 1022 {
1034 LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); 1023 LOG (llevError | logBacktrace, "tried to destroy the tail of an object");
1035 head->destroy (destroy_inventory); 1024 head->destroy (destroy_inventory);
1025 return;
1036 } 1026 }
1037 1027
1038 destroy_inv (!destroy_inventory); 1028 destroy_inv (!destroy_inventory);
1039 1029
1040 if (is_head ()) 1030 if (is_head ())
1073 * In this case, the object to be removed is in someones 1063 * In this case, the object to be removed is in someones
1074 * inventory. 1064 * inventory.
1075 */ 1065 */
1076 if (env) 1066 if (env)
1077 { 1067 {
1068 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed
1078 if (object *pl = visible_to ()) 1069 if (object *pl = visible_to ())
1079 esrv_del_item (pl->contr, count); 1070 esrv_del_item (pl->contr, count);
1071 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1080 1072
1081 adjust_weight (env, -total_weight ()); 1073 adjust_weight (env, -total_weight ());
1082 1074
1083 *(above ? &above->below : &env->inv) = below; 1075 *(above ? &above->below : &env->inv) = below;
1084 1076
2332 * create clone from object to another 2324 * create clone from object to another
2333 */ 2325 */
2334object * 2326object *
2335object_create_clone (object *asrc) 2327object_create_clone (object *asrc)
2336{ 2328{
2337 object *dst = 0, *tmp, *src, *prev, *item; 2329 object *dst = 0;
2338 2330
2339 if (!asrc) 2331 if (!asrc)
2340 return 0; 2332 return 0;
2341 2333
2342 src = asrc->head_ (); 2334 object *src = asrc->head_ ();
2343 2335
2344 prev = 0; 2336 object *prev = 0;
2345 for (object *part = src; part; part = part->more) 2337 for (object *part = src; part; part = part->more)
2346 { 2338 {
2347 tmp = part->clone (); 2339 object *tmp = part->clone ();
2340
2348 tmp->x -= src->x; 2341 tmp->x -= src->x;
2349 tmp->y -= src->y; 2342 tmp->y -= src->y;
2350 2343
2351 if (!part->head) 2344 if (!part->head)
2352 { 2345 {
2362 prev->more = tmp; 2355 prev->more = tmp;
2363 2356
2364 prev = tmp; 2357 prev = tmp;
2365 } 2358 }
2366 2359
2367 for (item = src->inv; item; item = item->below) 2360 for (object *item = src->inv; item; item = item->below)
2368 insert_ob_in_ob (object_create_clone (item), dst); 2361 insert_ob_in_ob (object_create_clone (item), dst);
2369 2362
2370 return dst; 2363 return dst;
2371} 2364}
2372 2365

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines