… | |
… | |
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; |
… | |
… | |
746 | * UP_OBJ_FACE: only the objects face has changed. |
744 | * UP_OBJ_FACE: only the objects face has changed. |
747 | */ |
745 | */ |
748 | void |
746 | void |
749 | update_object (object *op, int action) |
747 | update_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 | |
|
|
962 | static 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 | |
970 | void |
977 | void |
971 | object::do_destroy () |
978 | object::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 ()) |
… | |
… | |
2334 | * create clone from object to another |
2324 | * create clone from object to another |
2335 | */ |
2325 | */ |
2336 | object * |
2326 | object * |
2337 | object_create_clone (object *asrc) |
2327 | object_create_clone (object *asrc) |
2338 | { |
2328 | { |
2339 | object *dst = 0, *tmp, *src, *prev, *item; |
2329 | object *dst = 0; |
2340 | |
2330 | |
2341 | if (!asrc) |
2331 | if (!asrc) |
2342 | return 0; |
2332 | return 0; |
2343 | |
2333 | |
2344 | src = asrc->head_ (); |
2334 | object *src = asrc->head_ (); |
2345 | |
2335 | |
2346 | prev = 0; |
2336 | object *prev = 0; |
2347 | for (object *part = src; part; part = part->more) |
2337 | for (object *part = src; part; part = part->more) |
2348 | { |
2338 | { |
2349 | tmp = part->clone (); |
2339 | object *tmp = part->clone (); |
|
|
2340 | |
2350 | tmp->x -= src->x; |
2341 | tmp->x -= src->x; |
2351 | tmp->y -= src->y; |
2342 | tmp->y -= src->y; |
2352 | |
2343 | |
2353 | if (!part->head) |
2344 | if (!part->head) |
2354 | { |
2345 | { |
… | |
… | |
2364 | prev->more = tmp; |
2355 | prev->more = tmp; |
2365 | |
2356 | |
2366 | prev = tmp; |
2357 | prev = tmp; |
2367 | } |
2358 | } |
2368 | |
2359 | |
2369 | for (item = src->inv; item; item = item->below) |
2360 | for (object *item = src->inv; item; item = item->below) |
2370 | insert_ob_in_ob (object_create_clone (item), dst); |
2361 | insert_ob_in_ob (object_create_clone (item), dst); |
2371 | |
2362 | |
2372 | return dst; |
2363 | return dst; |
2373 | } |
2364 | } |
2374 | |
2365 | |