… | |
… | |
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 | } |
… | |
… | |
391 | return; |
392 | return; |
392 | |
393 | |
393 | op->carrying += weight; |
394 | op->carrying += weight; |
394 | |
395 | |
395 | if (object *pl = op->visible_to ()) |
396 | if (object *pl = op->visible_to ()) |
|
|
397 | if (pl != op) // player is handled lazily |
396 | esrv_update_item (UPD_WEIGHT, pl, op); |
398 | esrv_update_item (UPD_WEIGHT, pl, op); |
397 | |
399 | |
398 | op = op->env; |
400 | op = op->env; |
399 | } |
401 | } |
400 | } |
402 | } |
401 | |
403 | |
… | |
… | |
422 | if (sum != carrying) |
424 | if (sum != carrying) |
423 | { |
425 | { |
424 | carrying = sum; |
426 | carrying = sum; |
425 | |
427 | |
426 | if (object *pl = visible_to ()) |
428 | if (object *pl = visible_to ()) |
|
|
429 | if (pl != this) // player is handled lazily |
427 | esrv_update_item (UPD_WEIGHT, pl, this); |
430 | esrv_update_item (UPD_WEIGHT, pl, this); |
428 | } |
431 | } |
429 | } |
432 | } |
430 | |
433 | |
431 | /* |
434 | /* |
432 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
435 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
… | |
… | |
600 | } |
603 | } |
601 | |
604 | |
602 | op->key_values = 0; |
605 | op->key_values = 0; |
603 | } |
606 | } |
604 | |
607 | |
605 | object & |
608 | /* |
606 | object::operator =(const object &src) |
609 | * copy_to first frees everything allocated by the dst object, |
|
|
610 | * and then copies the contents of itself into the second |
|
|
611 | * object, allocating what needs to be allocated. Basically, any |
|
|
612 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
|
|
613 | * if the first object is freed, the pointers in the new object |
|
|
614 | * will point at garbage. |
|
|
615 | */ |
|
|
616 | void |
|
|
617 | object::copy_to (object *dst) |
607 | { |
618 | { |
608 | bool is_freed = flag [FLAG_FREED]; |
619 | dst->remove (); |
609 | bool is_removed = flag [FLAG_REMOVED]; |
|
|
610 | |
|
|
611 | *(object_copy *)this = src; |
620 | *(object_copy *)dst = *this; |
612 | |
|
|
613 | flag [FLAG_FREED] = is_freed; |
|
|
614 | flag [FLAG_REMOVED] = is_removed; |
621 | dst->flag [FLAG_REMOVED] = true; |
615 | |
622 | |
616 | /* Copy over key_values, if any. */ |
623 | /* Copy over key_values, if any. */ |
617 | if (src.key_values) |
624 | if (key_values) |
618 | { |
625 | { |
619 | key_value *tail = 0; |
626 | key_value *tail = 0; |
620 | key_values = 0; |
627 | dst->key_values = 0; |
621 | |
628 | |
622 | for (key_value *i = src.key_values; i; i = i->next) |
629 | for (key_value *i = key_values; i; i = i->next) |
623 | { |
630 | { |
624 | key_value *new_link = new key_value; |
631 | key_value *new_link = new key_value; |
625 | |
632 | |
626 | new_link->next = 0; |
633 | new_link->next = 0; |
627 | new_link->key = i->key; |
634 | new_link->key = i->key; |
628 | new_link->value = i->value; |
635 | new_link->value = i->value; |
629 | |
636 | |
630 | /* Try and be clever here, too. */ |
637 | /* Try and be clever here, too. */ |
631 | if (!key_values) |
638 | if (!dst->key_values) |
632 | { |
639 | { |
633 | key_values = new_link; |
640 | dst->key_values = new_link; |
634 | tail = new_link; |
641 | tail = new_link; |
635 | } |
642 | } |
636 | else |
643 | else |
637 | { |
644 | { |
638 | tail->next = new_link; |
645 | tail->next = new_link; |
639 | tail = new_link; |
646 | tail = new_link; |
640 | } |
647 | } |
641 | } |
648 | } |
642 | } |
649 | } |
643 | } |
|
|
644 | |
|
|
645 | /* |
|
|
646 | * copy_to first frees everything allocated by the dst object, |
|
|
647 | * and then copies the contents of itself into the second |
|
|
648 | * object, allocating what needs to be allocated. Basically, any |
|
|
649 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
|
|
650 | * if the first object is freed, the pointers in the new object |
|
|
651 | * will point at garbage. |
|
|
652 | */ |
|
|
653 | void |
|
|
654 | object::copy_to (object *dst) |
|
|
655 | { |
|
|
656 | *dst = *this; |
|
|
657 | |
650 | |
658 | if (speed < 0) |
651 | if (speed < 0) |
659 | dst->speed_left -= rndm (); |
652 | dst->speed_left -= rndm (); |
660 | |
653 | |
661 | dst->set_speed (dst->speed); |
654 | dst->set_speed (dst->speed); |
… | |
… | |
683 | object * |
676 | object * |
684 | object::clone () |
677 | object::clone () |
685 | { |
678 | { |
686 | object *neu = create (); |
679 | object *neu = create (); |
687 | copy_to (neu); |
680 | copy_to (neu); |
|
|
681 | neu->map = map; // not copied by copy_to |
688 | return neu; |
682 | return neu; |
689 | } |
683 | } |
690 | |
684 | |
691 | /* |
685 | /* |
692 | * If an object with the IS_TURNABLE() flag needs to be turned due |
686 | * If an object with the IS_TURNABLE() flag needs to be turned due |
… | |
… | |
743 | * UP_OBJ_FACE: only the objects face has changed. |
737 | * UP_OBJ_FACE: only the objects face has changed. |
744 | */ |
738 | */ |
745 | void |
739 | void |
746 | update_object (object *op, int action) |
740 | update_object (object *op, int action) |
747 | { |
741 | { |
748 | if (op == NULL) |
742 | if (!op) |
749 | { |
743 | { |
750 | /* this should never happen */ |
744 | /* this should never happen */ |
751 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
745 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
752 | return; |
746 | return; |
753 | } |
747 | } |
754 | |
748 | |
755 | if (op->env) |
749 | if (!op->is_on_map ()) |
756 | { |
750 | { |
757 | /* Animation is currently handled by client, so nothing |
751 | /* Animation is currently handled by client, so nothing |
758 | * to do in this case. |
752 | * to do in this case. |
759 | */ |
753 | */ |
760 | return; |
754 | return; |
761 | } |
755 | } |
762 | |
|
|
763 | /* If the map is saving, don't do anything as everything is |
|
|
764 | * going to get freed anyways. |
|
|
765 | */ |
|
|
766 | if (!op->map || op->map->in_memory == MAP_SAVING) |
|
|
767 | return; |
|
|
768 | |
756 | |
769 | /* make sure the object is within map boundaries */ |
757 | /* make sure the object is within map boundaries */ |
770 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
758 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
771 | { |
759 | { |
772 | LOG (llevError, "update_object() called for object out of map!\n"); |
760 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
915 | object::destroy_inv (bool drop_to_ground) |
903 | object::destroy_inv (bool drop_to_ground) |
916 | { |
904 | { |
917 | // need to check first, because the checks below might segfault |
905 | // need to check first, because the checks below might segfault |
918 | // as we might be on an invalid mapspace and crossfire code |
906 | // as we might be on an invalid mapspace and crossfire code |
919 | // is too buggy to ensure that the inventory is empty. |
907 | // is too buggy to ensure that the inventory is empty. |
920 | // corollary: if you create arrows etc. with stuff in tis inventory, |
908 | // corollary: if you create arrows etc. with stuff in its inventory, |
921 | // cf will crash below with off-map x and y |
909 | // cf will crash below with off-map x and y |
922 | if (!inv) |
910 | if (!inv) |
923 | return; |
911 | return; |
924 | |
912 | |
925 | /* Only if the space blocks everything do we not process - |
913 | /* Only if the space blocks everything do we not process - |
… | |
… | |
932 | || map->nodrop |
920 | || map->nodrop |
933 | || ms ().move_block == MOVE_ALL) |
921 | || ms ().move_block == MOVE_ALL) |
934 | { |
922 | { |
935 | while (inv) |
923 | while (inv) |
936 | { |
924 | { |
937 | inv->destroy_inv (drop_to_ground); |
925 | inv->destroy_inv (false); |
938 | inv->destroy (); |
926 | inv->destroy (); |
939 | } |
927 | } |
940 | } |
928 | } |
941 | else |
929 | else |
942 | { /* Put objects in inventory onto this space */ |
930 | { /* Put objects in inventory onto this space */ |
… | |
… | |
948 | || op->flag [FLAG_NO_DROP] |
936 | || op->flag [FLAG_NO_DROP] |
949 | || op->type == RUNE |
937 | || op->type == RUNE |
950 | || op->type == TRAP |
938 | || op->type == TRAP |
951 | || op->flag [FLAG_IS_A_TEMPLATE] |
939 | || op->flag [FLAG_IS_A_TEMPLATE] |
952 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
940 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
953 | op->destroy (); |
941 | op->destroy (true); |
954 | else |
942 | else |
955 | map->insert (op, x, y); |
943 | map->insert (op, x, y); |
956 | } |
944 | } |
957 | } |
945 | } |
958 | } |
946 | } |
… | |
… | |
962 | object *op = new object; |
950 | object *op = new object; |
963 | op->link (); |
951 | op->link (); |
964 | return op; |
952 | return op; |
965 | } |
953 | } |
966 | |
954 | |
|
|
955 | static struct freed_map : maptile |
|
|
956 | { |
|
|
957 | freed_map () |
|
|
958 | { |
|
|
959 | path = "<freed objects map>"; |
|
|
960 | name = "/internal/freed_objects_map"; |
|
|
961 | width = 3; |
|
|
962 | height = 3; |
|
|
963 | nodrop = 1; |
|
|
964 | |
|
|
965 | alloc (); |
|
|
966 | in_memory = MAP_ACTIVE; |
|
|
967 | } |
|
|
968 | } freed_map; // freed objects are moved here to avoid crashes |
|
|
969 | |
967 | void |
970 | void |
968 | object::do_destroy () |
971 | object::do_destroy () |
969 | { |
972 | { |
970 | if (flag [FLAG_IS_LINKED]) |
973 | if (flag [FLAG_IS_LINKED]) |
971 | remove_button_link (this); |
974 | remove_button_link (this); |
… | |
… | |
975 | |
978 | |
976 | remove (); |
979 | remove (); |
977 | |
980 | |
978 | attachable::do_destroy (); |
981 | attachable::do_destroy (); |
979 | |
982 | |
980 | destroy_inv (true); |
|
|
981 | |
|
|
982 | deactivate (); |
983 | deactivate (); |
983 | unlink (); |
984 | unlink (); |
984 | |
985 | |
985 | flag [FLAG_FREED] = 1; |
986 | flag [FLAG_FREED] = 1; |
986 | |
987 | |
987 | // hack to ensure that freed objects still have a valid map |
988 | // 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; |
989 | map = &freed_map; |
1006 | x = 1; |
990 | x = 1; |
1007 | y = 1; |
991 | y = 1; |
1008 | } |
|
|
1009 | |
992 | |
1010 | if (more) |
993 | if (more) |
1011 | { |
994 | { |
1012 | more->destroy (); |
995 | more->destroy (); |
1013 | more = 0; |
996 | more = 0; |
… | |
… | |
1026 | object::destroy (bool destroy_inventory) |
1009 | object::destroy (bool destroy_inventory) |
1027 | { |
1010 | { |
1028 | if (destroyed ()) |
1011 | if (destroyed ()) |
1029 | return; |
1012 | return; |
1030 | |
1013 | |
|
|
1014 | if (!is_head () && !head->destroyed ()) |
|
|
1015 | { |
|
|
1016 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
|
|
1017 | head->destroy (destroy_inventory); |
|
|
1018 | return; |
|
|
1019 | } |
|
|
1020 | |
1031 | if (destroy_inventory) |
1021 | destroy_inv (!destroy_inventory); |
1032 | destroy_inv (false); |
|
|
1033 | |
1022 | |
1034 | if (is_head ()) |
1023 | if (is_head ()) |
1035 | if (sound_destroy) |
1024 | if (sound_destroy) |
1036 | play_sound (sound_destroy); |
1025 | play_sound (sound_destroy); |
1037 | else if (flag [FLAG_MONSTER]) |
1026 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1056 | if (flag [FLAG_REMOVED]) |
1045 | if (flag [FLAG_REMOVED]) |
1057 | return; |
1046 | return; |
1058 | |
1047 | |
1059 | INVOKE_OBJECT (REMOVE, this); |
1048 | INVOKE_OBJECT (REMOVE, this); |
1060 | |
1049 | |
1061 | if (object *pl = visible_to ()) |
|
|
1062 | esrv_del_item (pl->contr, count); |
|
|
1063 | |
|
|
1064 | flag [FLAG_REMOVED] = true; |
1050 | flag [FLAG_REMOVED] = true; |
1065 | |
1051 | |
1066 | if (more) |
1052 | if (more) |
1067 | more->remove (); |
1053 | more->remove (); |
1068 | |
1054 | |
… | |
… | |
1070 | * In this case, the object to be removed is in someones |
1056 | * In this case, the object to be removed is in someones |
1071 | * inventory. |
1057 | * inventory. |
1072 | */ |
1058 | */ |
1073 | if (env) |
1059 | if (env) |
1074 | { |
1060 | { |
|
|
1061 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1062 | if (object *pl = visible_to ()) |
|
|
1063 | esrv_del_item (pl->contr, count); |
|
|
1064 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1065 | |
1075 | adjust_weight (env, -total_weight ()); |
1066 | adjust_weight (env, -total_weight ()); |
1076 | |
1067 | |
1077 | *(above ? &above->below : &env->inv) = below; |
1068 | *(above ? &above->below : &env->inv) = below; |
1078 | |
1069 | |
1079 | if (below) |
1070 | if (below) |
… | |
… | |
1097 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1088 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1098 | otmp->update_stats (); |
1089 | otmp->update_stats (); |
1099 | } |
1090 | } |
1100 | else if (map) |
1091 | else if (map) |
1101 | { |
1092 | { |
1102 | if (type == PLAYER) |
|
|
1103 | { |
|
|
1104 | // leaving a spot always closes any open container on the ground |
|
|
1105 | if (container && !container->env) |
|
|
1106 | // this causes spurious floorbox updates, but it ensures |
|
|
1107 | // that the CLOSE event is being sent. |
|
|
1108 | close_container (); |
|
|
1109 | |
|
|
1110 | --map->players; |
|
|
1111 | map->touch (); |
|
|
1112 | } |
|
|
1113 | |
|
|
1114 | map->dirty = true; |
1093 | map->dirty = true; |
1115 | mapspace &ms = this->ms (); |
1094 | mapspace &ms = this->ms (); |
|
|
1095 | |
|
|
1096 | if (object *pl = ms.player ()) |
|
|
1097 | { |
|
|
1098 | if (type == PLAYER) // this == pl(!) |
|
|
1099 | { |
|
|
1100 | // leaving a spot always closes any open container on the ground |
|
|
1101 | if (container && !container->env) |
|
|
1102 | // this causes spurious floorbox updates, but it ensures |
|
|
1103 | // that the CLOSE event is being sent. |
|
|
1104 | close_container (); |
|
|
1105 | |
|
|
1106 | --map->players; |
|
|
1107 | map->touch (); |
|
|
1108 | } |
|
|
1109 | else if (pl->container == this) |
|
|
1110 | { |
|
|
1111 | // removing a container should close it |
|
|
1112 | close_container (); |
|
|
1113 | } |
|
|
1114 | |
|
|
1115 | esrv_del_item (pl->contr, count); |
|
|
1116 | } |
1116 | |
1117 | |
1117 | /* link the object above us */ |
1118 | /* link the object above us */ |
1118 | if (above) |
1119 | if (above) |
1119 | above->below = below; |
1120 | above->below = below; |
1120 | else |
1121 | else |
… | |
… | |
1150 | * removed (most likely destroyed), update the player view |
1151 | * removed (most likely destroyed), update the player view |
1151 | * appropriately. |
1152 | * appropriately. |
1152 | */ |
1153 | */ |
1153 | pl->close_container (); |
1154 | pl->close_container (); |
1154 | |
1155 | |
|
|
1156 | //TODO: the floorbox prev/next might need updating |
|
|
1157 | //esrv_del_item (pl->contr, count); |
|
|
1158 | //TODO: update floorbox to preserve ordering |
|
|
1159 | if (pl->contr->ns) |
1155 | pl->contr->ns->floorbox_update (); |
1160 | pl->contr->ns->floorbox_update (); |
1156 | } |
1161 | } |
1157 | |
1162 | |
1158 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1163 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1159 | { |
1164 | { |
1160 | /* No point updating the players look faces if he is the object |
1165 | /* No point updating the players look faces if he is the object |
… | |
… | |
1286 | object * |
1291 | object * |
1287 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1292 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1288 | { |
1293 | { |
1289 | assert (!op->flag [FLAG_FREED]); |
1294 | assert (!op->flag [FLAG_FREED]); |
1290 | |
1295 | |
1291 | object *top, *floor = NULL; |
|
|
1292 | |
|
|
1293 | op->remove (); |
1296 | op->remove (); |
1294 | |
1297 | |
1295 | /* Ideally, the caller figures this out. However, it complicates a lot |
1298 | /* Ideally, the caller figures this out. However, it complicates a lot |
1296 | * of areas of callers (eg, anything that uses find_free_spot would now |
1299 | * of areas of callers (eg, anything that uses find_free_spot would now |
1297 | * need extra work |
1300 | * need extra work |
1298 | */ |
1301 | */ |
1299 | if (!xy_normalise (m, op->x, op->y)) |
1302 | if (!xy_normalise (m, op->x, op->y)) |
1300 | { |
1303 | { |
1301 | op->destroy (); |
1304 | op->destroy (1); |
1302 | return 0; |
1305 | return 0; |
1303 | } |
1306 | } |
1304 | |
1307 | |
1305 | if (object *more = op->more) |
1308 | if (object *more = op->more) |
1306 | if (!insert_ob_in_map (more, m, originator, flag)) |
1309 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1315 | */ |
1318 | */ |
1316 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1319 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1317 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1320 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1318 | if (object::can_merge (op, tmp)) |
1321 | if (object::can_merge (op, tmp)) |
1319 | { |
1322 | { |
|
|
1323 | // TODO: we atcually want to update tmp, not op, |
|
|
1324 | // but some caller surely breaks when we return tmp |
|
|
1325 | // from here :/ |
1320 | op->nrof += tmp->nrof; |
1326 | op->nrof += tmp->nrof; |
1321 | tmp->destroy (1); |
1327 | tmp->destroy (1); |
1322 | } |
1328 | } |
1323 | |
1329 | |
1324 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1330 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1346 | /* since *below* originator, no need to update top */ |
1352 | /* since *below* originator, no need to update top */ |
1347 | originator->below = op; |
1353 | originator->below = op; |
1348 | } |
1354 | } |
1349 | else |
1355 | else |
1350 | { |
1356 | { |
|
|
1357 | object *top, *floor = NULL; |
|
|
1358 | |
1351 | top = ms.bot; |
1359 | top = ms.bot; |
1352 | |
1360 | |
1353 | /* If there are other objects, then */ |
1361 | /* If there are other objects, then */ |
1354 | if (top) |
1362 | if (top) |
1355 | { |
1363 | { |
… | |
… | |
1454 | } |
1462 | } |
1455 | |
1463 | |
1456 | op->map->dirty = true; |
1464 | op->map->dirty = true; |
1457 | |
1465 | |
1458 | if (object *pl = ms.player ()) |
1466 | if (object *pl = ms.player ()) |
|
|
1467 | //TODO: the floorbox prev/next might need updating |
|
|
1468 | //esrv_send_item (pl, op); |
|
|
1469 | //TODO: update floorbox to preserve ordering |
|
|
1470 | if (pl->contr->ns) |
1459 | pl->contr->ns->floorbox_update (); |
1471 | pl->contr->ns->floorbox_update (); |
1460 | |
1472 | |
1461 | /* If this object glows, it may affect lighting conditions that are |
1473 | /* If this object glows, it may affect lighting conditions that are |
1462 | * visible to others on this map. But update_all_los is really |
1474 | * visible to others on this map. But update_all_los is really |
1463 | * an inefficient way to do this, as it means los for all players |
1475 | * an inefficient way to do this, as it means los for all players |
1464 | * on the map will get recalculated. The players could very well |
1476 | * on the map will get recalculated. The players could very well |
… | |
… | |
2311 | * create clone from object to another |
2323 | * create clone from object to another |
2312 | */ |
2324 | */ |
2313 | object * |
2325 | object * |
2314 | object_create_clone (object *asrc) |
2326 | object_create_clone (object *asrc) |
2315 | { |
2327 | { |
2316 | object *dst = 0, *tmp, *src, *prev, *item; |
2328 | object *dst = 0; |
2317 | |
2329 | |
2318 | if (!asrc) |
2330 | if (!asrc) |
2319 | return 0; |
2331 | return 0; |
2320 | |
2332 | |
2321 | src = asrc->head_ (); |
2333 | object *src = asrc->head_ (); |
2322 | |
2334 | |
2323 | prev = 0; |
2335 | object *prev = 0; |
2324 | for (object *part = src; part; part = part->more) |
2336 | for (object *part = src; part; part = part->more) |
2325 | { |
2337 | { |
2326 | tmp = part->clone (); |
2338 | object *tmp = part->clone (); |
|
|
2339 | |
2327 | tmp->x -= src->x; |
2340 | tmp->x -= src->x; |
2328 | tmp->y -= src->y; |
2341 | tmp->y -= src->y; |
2329 | |
2342 | |
2330 | if (!part->head) |
2343 | if (!part->head) |
2331 | { |
2344 | { |
… | |
… | |
2341 | prev->more = tmp; |
2354 | prev->more = tmp; |
2342 | |
2355 | |
2343 | prev = tmp; |
2356 | prev = tmp; |
2344 | } |
2357 | } |
2345 | |
2358 | |
2346 | for (item = src->inv; item; item = item->below) |
2359 | for (object *item = src->inv; item; item = item->below) |
2347 | insert_ob_in_ob (object_create_clone (item), dst); |
2360 | insert_ob_in_ob (object_create_clone (item), dst); |
2348 | |
2361 | |
2349 | return dst; |
2362 | return dst; |
2350 | } |
2363 | } |
2351 | |
2364 | |
… | |
… | |
2565 | &name, |
2578 | &name, |
2566 | title ? "\",title:\"" : "", |
2579 | title ? "\",title:\"" : "", |
2567 | title ? (const char *)title : "", |
2580 | title ? (const char *)title : "", |
2568 | flag_desc (flagdesc, 512), type); |
2581 | flag_desc (flagdesc, 512), type); |
2569 | |
2582 | |
2570 | if (!this->flag[FLAG_REMOVED] && env) |
2583 | if (!flag[FLAG_REMOVED] && env) |
2571 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2584 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2572 | |
2585 | |
2573 | if (map) |
2586 | if (map) |
2574 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2587 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2575 | |
2588 | |
… | |
… | |
2605 | object::open_container (object *new_container) |
2618 | object::open_container (object *new_container) |
2606 | { |
2619 | { |
2607 | if (container == new_container) |
2620 | if (container == new_container) |
2608 | return; |
2621 | return; |
2609 | |
2622 | |
2610 | if (object *old_container = container) |
2623 | object *old_container = container; |
|
|
2624 | |
|
|
2625 | if (old_container) |
2611 | { |
2626 | { |
2612 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2627 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2613 | return; |
2628 | return; |
2614 | |
2629 | |
2615 | #if 0 |
2630 | #if 0 |
… | |
… | |
2617 | if (object *closer = old_container->inv) |
2632 | if (object *closer = old_container->inv) |
2618 | if (closer->type == CLOSE_CON) |
2633 | if (closer->type == CLOSE_CON) |
2619 | closer->destroy (); |
2634 | closer->destroy (); |
2620 | #endif |
2635 | #endif |
2621 | |
2636 | |
|
|
2637 | // make sure the container is available |
|
|
2638 | esrv_send_item (this, old_container); |
|
|
2639 | |
2622 | old_container->flag [FLAG_APPLIED] = 0; |
2640 | old_container->flag [FLAG_APPLIED] = false; |
2623 | container = 0; |
2641 | container = 0; |
2624 | |
2642 | |
|
|
2643 | // client needs item update to make it work, client bug requires this to be separate |
2625 | esrv_update_item (UPD_FLAGS, this, old_container); |
2644 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2645 | |
2626 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2646 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2627 | play_sound (sound_find ("chest_close")); |
2647 | play_sound (sound_find ("chest_close")); |
2628 | } |
2648 | } |
2629 | |
2649 | |
2630 | if (new_container) |
2650 | if (new_container) |
… | |
… | |
2643 | } |
2663 | } |
2644 | #endif |
2664 | #endif |
2645 | |
2665 | |
2646 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2666 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2647 | |
2667 | |
|
|
2668 | // make sure the container is available, client bug requires this to be separate |
|
|
2669 | esrv_send_item (this, new_container); |
|
|
2670 | |
2648 | new_container->flag [FLAG_APPLIED] = 1; |
2671 | new_container->flag [FLAG_APPLIED] = true; |
2649 | container = new_container; |
2672 | container = new_container; |
2650 | |
2673 | |
|
|
2674 | // client needs flag change |
2651 | esrv_update_item (UPD_FLAGS, this, new_container); |
2675 | esrv_update_item (UPD_FLAGS, this, new_container); |
2652 | esrv_send_inventory (this, new_container); |
2676 | esrv_send_inventory (this, new_container); |
2653 | play_sound (sound_find ("chest_open")); |
2677 | play_sound (sound_find ("chest_open")); |
2654 | } |
2678 | } |
|
|
2679 | // else if (!old_container->env && contr && contr->ns) |
|
|
2680 | // contr->ns->floorbox_reset (); |
2655 | } |
2681 | } |
2656 | |
2682 | |
2657 | object * |
2683 | object * |
2658 | object::force_find (const shstr name) |
2684 | object::force_find (const shstr name) |
2659 | { |
2685 | { |