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