… | |
… | |
334 | |
334 | |
335 | // find player who can see this object |
335 | // find player who can see this object |
336 | object * |
336 | object * |
337 | object::visible_to () const |
337 | object::visible_to () const |
338 | { |
338 | { |
339 | if (!flag [FLAG_REMOVED]) |
339 | if (client_visible () && !flag [FLAG_REMOVED]) |
340 | { |
340 | { |
341 | // see if we are in a container of sorts |
341 | // see if we are in a container of sorts |
342 | if (env) |
342 | if (env) |
343 | { |
343 | { |
344 | // the player inventory itself is always visible |
344 | // the player inventory itself is always visible |
… | |
… | |
358 | else |
358 | else |
359 | { |
359 | { |
360 | // maybe there is a player standing on the same mapspace |
360 | // maybe there is a player standing on the same mapspace |
361 | // this will catch the case where "this" is a player |
361 | // this will catch the case where "this" is a player |
362 | if (object *pl = ms ().player ()) |
362 | if (object *pl = ms ().player ()) |
|
|
363 | if (!pl->container || this == pl->container) |
363 | return pl; |
364 | return pl; |
364 | } |
365 | } |
365 | } |
366 | } |
366 | |
367 | |
367 | return 0; |
368 | return 0; |
368 | } |
369 | } |
… | |
… | |
605 | } |
606 | } |
606 | |
607 | |
607 | object & |
608 | object & |
608 | object::operator =(const object &src) |
609 | object::operator =(const object &src) |
609 | { |
610 | { |
610 | bool is_freed = flag [FLAG_FREED]; |
611 | remove (); |
611 | bool is_removed = flag [FLAG_REMOVED]; |
|
|
612 | |
612 | |
613 | *(object_copy *)this = src; |
613 | *(object_copy *)this = src; |
614 | |
614 | |
615 | flag [FLAG_FREED] = is_freed; |
|
|
616 | flag [FLAG_REMOVED] = is_removed; |
615 | flag [FLAG_REMOVED] = true; |
617 | |
616 | |
618 | /* Copy over key_values, if any. */ |
617 | /* Copy over key_values, if any. */ |
619 | if (src.key_values) |
618 | if (src.key_values) |
620 | { |
619 | { |
621 | key_value *tail = 0; |
620 | key_value *tail = 0; |
… | |
… | |
685 | object * |
684 | object * |
686 | object::clone () |
685 | object::clone () |
687 | { |
686 | { |
688 | object *neu = create (); |
687 | object *neu = create (); |
689 | copy_to (neu); |
688 | copy_to (neu); |
|
|
689 | neu->map = map; // not copied by copy_to |
690 | return neu; |
690 | return neu; |
691 | } |
691 | } |
692 | |
692 | |
693 | /* |
693 | /* |
694 | * 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 |
… | |
… | |
745 | * UP_OBJ_FACE: only the objects face has changed. |
745 | * UP_OBJ_FACE: only the objects face has changed. |
746 | */ |
746 | */ |
747 | void |
747 | void |
748 | update_object (object *op, int action) |
748 | update_object (object *op, int action) |
749 | { |
749 | { |
750 | if (op == NULL) |
750 | if (!op) |
751 | { |
751 | { |
752 | /* this should never happen */ |
752 | /* this should never happen */ |
753 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
753 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
754 | return; |
754 | return; |
755 | } |
755 | } |
756 | |
756 | |
757 | if (op->env) |
757 | if (!op->is_on_map ()) |
758 | { |
758 | { |
759 | /* Animation is currently handled by client, so nothing |
759 | /* Animation is currently handled by client, so nothing |
760 | * to do in this case. |
760 | * to do in this case. |
761 | */ |
761 | */ |
762 | return; |
762 | return; |
763 | } |
763 | } |
764 | |
|
|
765 | /* If the map is saving, don't do anything as everything is |
|
|
766 | * going to get freed anyways. |
|
|
767 | */ |
|
|
768 | if (!op->map || op->map->in_memory == MAP_SAVING) |
|
|
769 | return; |
|
|
770 | |
764 | |
771 | /* make sure the object is within map boundaries */ |
765 | /* make sure the object is within map boundaries */ |
772 | 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) |
773 | { |
767 | { |
774 | LOG (llevError, "update_object() called for object out of map!\n"); |
768 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
964 | object *op = new object; |
958 | object *op = new object; |
965 | op->link (); |
959 | op->link (); |
966 | return op; |
960 | return op; |
967 | } |
961 | } |
968 | |
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 | |
969 | void |
978 | void |
970 | object::do_destroy () |
979 | object::do_destroy () |
971 | { |
980 | { |
972 | if (flag [FLAG_IS_LINKED]) |
981 | if (flag [FLAG_IS_LINKED]) |
973 | remove_button_link (this); |
982 | remove_button_link (this); |
… | |
… | |
983 | unlink (); |
992 | unlink (); |
984 | |
993 | |
985 | flag [FLAG_FREED] = 1; |
994 | flag [FLAG_FREED] = 1; |
986 | |
995 | |
987 | // hack to ensure that freed objects still have a valid map |
996 | // hack to ensure that freed objects still have a valid map |
988 | { |
|
|
989 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
990 | |
|
|
991 | if (!freed_map) |
|
|
992 | { |
|
|
993 | freed_map = new maptile; |
|
|
994 | |
|
|
995 | freed_map->path = "<freed objects map>"; |
|
|
996 | freed_map->name = "/internal/freed_objects_map"; |
|
|
997 | freed_map->width = 3; |
|
|
998 | freed_map->height = 3; |
|
|
999 | freed_map->nodrop = 1; |
|
|
1000 | |
|
|
1001 | freed_map->alloc (); |
|
|
1002 | freed_map->in_memory = MAP_ACTIVE; |
|
|
1003 | } |
|
|
1004 | |
|
|
1005 | map = freed_map; |
997 | map = &freed_map; |
1006 | x = 1; |
998 | x = 1; |
1007 | y = 1; |
999 | y = 1; |
1008 | } |
|
|
1009 | |
1000 | |
1010 | if (more) |
1001 | if (more) |
1011 | { |
1002 | { |
1012 | more->destroy (); |
1003 | more->destroy (); |
1013 | more = 0; |
1004 | more = 0; |
… | |
… | |
1030 | |
1021 | |
1031 | if (!is_head () && !head->destroyed ()) |
1022 | if (!is_head () && !head->destroyed ()) |
1032 | { |
1023 | { |
1033 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
1024 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
1034 | head->destroy (destroy_inventory); |
1025 | head->destroy (destroy_inventory); |
|
|
1026 | return; |
1035 | } |
1027 | } |
1036 | |
1028 | |
1037 | destroy_inv (!destroy_inventory); |
1029 | destroy_inv (!destroy_inventory); |
1038 | |
1030 | |
1039 | if (is_head ()) |
1031 | if (is_head ()) |
… | |
… | |
1061 | if (flag [FLAG_REMOVED]) |
1053 | if (flag [FLAG_REMOVED]) |
1062 | return; |
1054 | return; |
1063 | |
1055 | |
1064 | INVOKE_OBJECT (REMOVE, this); |
1056 | INVOKE_OBJECT (REMOVE, this); |
1065 | |
1057 | |
1066 | if (object *pl = visible_to ()) |
|
|
1067 | esrv_del_item (pl->contr, count); |
|
|
1068 | |
|
|
1069 | flag [FLAG_REMOVED] = true; |
1058 | flag [FLAG_REMOVED] = true; |
1070 | |
1059 | |
1071 | if (more) |
1060 | if (more) |
1072 | more->remove (); |
1061 | more->remove (); |
1073 | |
1062 | |
… | |
… | |
1075 | * In this case, the object to be removed is in someones |
1064 | * In this case, the object to be removed is in someones |
1076 | * inventory. |
1065 | * inventory. |
1077 | */ |
1066 | */ |
1078 | if (env) |
1067 | if (env) |
1079 | { |
1068 | { |
|
|
1069 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1070 | if (object *pl = visible_to ()) |
|
|
1071 | esrv_del_item (pl->contr, count); |
|
|
1072 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1073 | |
1080 | adjust_weight (env, -total_weight ()); |
1074 | adjust_weight (env, -total_weight ()); |
1081 | |
1075 | |
1082 | *(above ? &above->below : &env->inv) = below; |
1076 | *(above ? &above->below : &env->inv) = below; |
1083 | |
1077 | |
1084 | if (below) |
1078 | if (below) |
… | |
… | |
1102 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1096 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1103 | otmp->update_stats (); |
1097 | otmp->update_stats (); |
1104 | } |
1098 | } |
1105 | else if (map) |
1099 | else if (map) |
1106 | { |
1100 | { |
1107 | if (type == PLAYER) |
|
|
1108 | { |
|
|
1109 | // leaving a spot always closes any open container on the ground |
|
|
1110 | if (container && !container->env) |
|
|
1111 | // this causes spurious floorbox updates, but it ensures |
|
|
1112 | // that the CLOSE event is being sent. |
|
|
1113 | close_container (); |
|
|
1114 | |
|
|
1115 | --map->players; |
|
|
1116 | map->touch (); |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | map->dirty = true; |
1101 | map->dirty = true; |
1120 | mapspace &ms = this->ms (); |
1102 | mapspace &ms = this->ms (); |
|
|
1103 | |
|
|
1104 | if (object *pl = ms.player ()) |
|
|
1105 | { |
|
|
1106 | if (type == PLAYER) // this == pl(!) |
|
|
1107 | { |
|
|
1108 | // leaving a spot always closes any open container on the ground |
|
|
1109 | if (container && !container->env) |
|
|
1110 | // this causes spurious floorbox updates, but it ensures |
|
|
1111 | // that the CLOSE event is being sent. |
|
|
1112 | close_container (); |
|
|
1113 | |
|
|
1114 | --map->players; |
|
|
1115 | map->touch (); |
|
|
1116 | } |
|
|
1117 | else if (pl->container == this) |
|
|
1118 | { |
|
|
1119 | // removing a container should close it |
|
|
1120 | close_container (); |
|
|
1121 | } |
|
|
1122 | |
|
|
1123 | esrv_del_item (pl->contr, count); |
|
|
1124 | } |
1121 | |
1125 | |
1122 | /* link the object above us */ |
1126 | /* link the object above us */ |
1123 | if (above) |
1127 | if (above) |
1124 | above->below = below; |
1128 | above->below = below; |
1125 | else |
1129 | else |
… | |
… | |
2321 | * create clone from object to another |
2325 | * create clone from object to another |
2322 | */ |
2326 | */ |
2323 | object * |
2327 | object * |
2324 | object_create_clone (object *asrc) |
2328 | object_create_clone (object *asrc) |
2325 | { |
2329 | { |
2326 | object *dst = 0, *tmp, *src, *prev, *item; |
2330 | object *dst = 0; |
2327 | |
2331 | |
2328 | if (!asrc) |
2332 | if (!asrc) |
2329 | return 0; |
2333 | return 0; |
2330 | |
2334 | |
2331 | src = asrc->head_ (); |
2335 | object *src = asrc->head_ (); |
2332 | |
2336 | |
2333 | prev = 0; |
2337 | object *prev = 0; |
2334 | for (object *part = src; part; part = part->more) |
2338 | for (object *part = src; part; part = part->more) |
2335 | { |
2339 | { |
2336 | tmp = part->clone (); |
2340 | object *tmp = part->clone (); |
|
|
2341 | |
2337 | tmp->x -= src->x; |
2342 | tmp->x -= src->x; |
2338 | tmp->y -= src->y; |
2343 | tmp->y -= src->y; |
2339 | |
2344 | |
2340 | if (!part->head) |
2345 | if (!part->head) |
2341 | { |
2346 | { |
… | |
… | |
2351 | prev->more = tmp; |
2356 | prev->more = tmp; |
2352 | |
2357 | |
2353 | prev = tmp; |
2358 | prev = tmp; |
2354 | } |
2359 | } |
2355 | |
2360 | |
2356 | for (item = src->inv; item; item = item->below) |
2361 | for (object *item = src->inv; item; item = item->below) |
2357 | insert_ob_in_ob (object_create_clone (item), dst); |
2362 | insert_ob_in_ob (object_create_clone (item), dst); |
2358 | |
2363 | |
2359 | return dst; |
2364 | return dst; |
2360 | } |
2365 | } |
2361 | |
2366 | |
… | |
… | |
2615 | object::open_container (object *new_container) |
2620 | object::open_container (object *new_container) |
2616 | { |
2621 | { |
2617 | if (container == new_container) |
2622 | if (container == new_container) |
2618 | return; |
2623 | return; |
2619 | |
2624 | |
2620 | if (object *old_container = container) |
2625 | object *old_container = container; |
|
|
2626 | |
|
|
2627 | if (old_container) |
2621 | { |
2628 | { |
2622 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2629 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2623 | return; |
2630 | return; |
2624 | |
2631 | |
2625 | #if 0 |
2632 | #if 0 |
… | |
… | |
2627 | if (object *closer = old_container->inv) |
2634 | if (object *closer = old_container->inv) |
2628 | if (closer->type == CLOSE_CON) |
2635 | if (closer->type == CLOSE_CON) |
2629 | closer->destroy (); |
2636 | closer->destroy (); |
2630 | #endif |
2637 | #endif |
2631 | |
2638 | |
|
|
2639 | // make sure the container is available |
|
|
2640 | esrv_send_item (this, old_container); |
|
|
2641 | |
2632 | old_container->flag [FLAG_APPLIED] = false; |
2642 | old_container->flag [FLAG_APPLIED] = false; |
2633 | container = 0; |
2643 | container = 0; |
2634 | |
2644 | |
|
|
2645 | // client needs item update to make it work, client bug requires this to be separate |
2635 | esrv_update_item (UPD_FLAGS, this, old_container); |
2646 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2647 | |
2636 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2648 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2637 | play_sound (sound_find ("chest_close")); |
2649 | play_sound (sound_find ("chest_close")); |
2638 | } |
2650 | } |
2639 | |
2651 | |
2640 | if (new_container) |
2652 | if (new_container) |
… | |
… | |
2653 | } |
2665 | } |
2654 | #endif |
2666 | #endif |
2655 | |
2667 | |
2656 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2668 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2657 | |
2669 | |
|
|
2670 | // make sure the container is available, client bug requires this to be separate |
|
|
2671 | esrv_send_item (this, new_container); |
|
|
2672 | |
2658 | new_container->flag [FLAG_APPLIED] = true; |
2673 | new_container->flag [FLAG_APPLIED] = true; |
2659 | container = new_container; |
2674 | container = new_container; |
2660 | |
2675 | |
|
|
2676 | // client needs flag change |
2661 | esrv_update_item (UPD_FLAGS, this, new_container); |
2677 | esrv_update_item (UPD_FLAGS, this, new_container); |
2662 | esrv_send_inventory (this, new_container); |
2678 | esrv_send_inventory (this, new_container); |
2663 | play_sound (sound_find ("chest_open")); |
2679 | play_sound (sound_find ("chest_open")); |
2664 | } |
2680 | } |
|
|
2681 | // else if (!old_container->env && contr && contr->ns) |
|
|
2682 | // contr->ns->floorbox_reset (); |
2665 | } |
2683 | } |
2666 | |
2684 | |
2667 | object * |
2685 | object * |
2668 | object::force_find (const shstr name) |
2686 | object::force_find (const shstr name) |
2669 | { |
2687 | { |