… | |
… | |
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. |
… | |
… | |
603 | } |
606 | } |
604 | |
607 | |
605 | object & |
608 | object & |
606 | object::operator =(const object &src) |
609 | object::operator =(const object &src) |
607 | { |
610 | { |
608 | bool is_freed = flag [FLAG_FREED]; |
611 | remove (); |
609 | bool is_removed = flag [FLAG_REMOVED]; |
|
|
610 | |
612 | |
611 | *(object_copy *)this = src; |
613 | *(object_copy *)this = src; |
612 | |
614 | |
613 | flag [FLAG_FREED] = is_freed; |
|
|
614 | flag [FLAG_REMOVED] = is_removed; |
615 | flag [FLAG_REMOVED] = true; |
615 | |
616 | |
616 | /* Copy over key_values, if any. */ |
617 | /* Copy over key_values, if any. */ |
617 | if (src.key_values) |
618 | if (src.key_values) |
618 | { |
619 | { |
619 | key_value *tail = 0; |
620 | key_value *tail = 0; |
… | |
… | |
683 | object * |
684 | object * |
684 | object::clone () |
685 | object::clone () |
685 | { |
686 | { |
686 | object *neu = create (); |
687 | object *neu = create (); |
687 | copy_to (neu); |
688 | copy_to (neu); |
|
|
689 | neu->map = map; // not copied by copy_to |
688 | return neu; |
690 | return neu; |
689 | } |
691 | } |
690 | |
692 | |
691 | /* |
693 | /* |
692 | * 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 |
… | |
… | |
743 | * UP_OBJ_FACE: only the objects face has changed. |
745 | * UP_OBJ_FACE: only the objects face has changed. |
744 | */ |
746 | */ |
745 | void |
747 | void |
746 | update_object (object *op, int action) |
748 | update_object (object *op, int action) |
747 | { |
749 | { |
748 | if (op == NULL) |
750 | if (!op) |
749 | { |
751 | { |
750 | /* this should never happen */ |
752 | /* this should never happen */ |
751 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
753 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
752 | return; |
754 | return; |
753 | } |
755 | } |
754 | |
756 | |
755 | if (op->env) |
757 | if (!op->is_on_map ()) |
756 | { |
758 | { |
757 | /* Animation is currently handled by client, so nothing |
759 | /* Animation is currently handled by client, so nothing |
758 | * to do in this case. |
760 | * to do in this case. |
759 | */ |
761 | */ |
760 | return; |
762 | return; |
761 | } |
763 | } |
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 | |
764 | |
769 | /* make sure the object is within map boundaries */ |
765 | /* 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) |
766 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
771 | { |
767 | { |
772 | LOG (llevError, "update_object() called for object out of map!\n"); |
768 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
915 | object::destroy_inv (bool drop_to_ground) |
911 | object::destroy_inv (bool drop_to_ground) |
916 | { |
912 | { |
917 | // need to check first, because the checks below might segfault |
913 | // need to check first, because the checks below might segfault |
918 | // as we might be on an invalid mapspace and crossfire code |
914 | // as we might be on an invalid mapspace and crossfire code |
919 | // is too buggy to ensure that the inventory is empty. |
915 | // is too buggy to ensure that the inventory is empty. |
920 | // corollary: if you create arrows etc. with stuff in tis inventory, |
916 | // corollary: if you create arrows etc. with stuff in its inventory, |
921 | // cf will crash below with off-map x and y |
917 | // cf will crash below with off-map x and y |
922 | if (!inv) |
918 | if (!inv) |
923 | return; |
919 | return; |
924 | |
920 | |
925 | /* Only if the space blocks everything do we not process - |
921 | /* Only if the space blocks everything do we not process - |
… | |
… | |
932 | || map->nodrop |
928 | || map->nodrop |
933 | || ms ().move_block == MOVE_ALL) |
929 | || ms ().move_block == MOVE_ALL) |
934 | { |
930 | { |
935 | while (inv) |
931 | while (inv) |
936 | { |
932 | { |
937 | inv->destroy_inv (drop_to_ground); |
933 | inv->destroy_inv (false); |
938 | inv->destroy (); |
934 | inv->destroy (); |
939 | } |
935 | } |
940 | } |
936 | } |
941 | else |
937 | else |
942 | { /* Put objects in inventory onto this space */ |
938 | { /* Put objects in inventory onto this space */ |
… | |
… | |
948 | || op->flag [FLAG_NO_DROP] |
944 | || op->flag [FLAG_NO_DROP] |
949 | || op->type == RUNE |
945 | || op->type == RUNE |
950 | || op->type == TRAP |
946 | || op->type == TRAP |
951 | || op->flag [FLAG_IS_A_TEMPLATE] |
947 | || op->flag [FLAG_IS_A_TEMPLATE] |
952 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
948 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
953 | op->destroy (); |
949 | op->destroy (true); |
954 | else |
950 | else |
955 | map->insert (op, x, y); |
951 | map->insert (op, x, y); |
956 | } |
952 | } |
957 | } |
953 | } |
958 | } |
954 | } |
… | |
… | |
962 | object *op = new object; |
958 | object *op = new object; |
963 | op->link (); |
959 | op->link (); |
964 | return op; |
960 | return op; |
965 | } |
961 | } |
966 | |
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 | |
967 | void |
978 | void |
968 | object::do_destroy () |
979 | object::do_destroy () |
969 | { |
980 | { |
970 | if (flag [FLAG_IS_LINKED]) |
981 | if (flag [FLAG_IS_LINKED]) |
971 | remove_button_link (this); |
982 | remove_button_link (this); |
… | |
… | |
975 | |
986 | |
976 | remove (); |
987 | remove (); |
977 | |
988 | |
978 | attachable::do_destroy (); |
989 | attachable::do_destroy (); |
979 | |
990 | |
980 | destroy_inv (true); |
|
|
981 | |
|
|
982 | deactivate (); |
991 | deactivate (); |
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; |
… | |
… | |
1026 | object::destroy (bool destroy_inventory) |
1017 | object::destroy (bool destroy_inventory) |
1027 | { |
1018 | { |
1028 | if (destroyed ()) |
1019 | if (destroyed ()) |
1029 | return; |
1020 | return; |
1030 | |
1021 | |
|
|
1022 | if (!is_head () && !head->destroyed ()) |
|
|
1023 | { |
|
|
1024 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
|
|
1025 | head->destroy (destroy_inventory); |
|
|
1026 | return; |
|
|
1027 | } |
|
|
1028 | |
1031 | if (destroy_inventory) |
1029 | destroy_inv (!destroy_inventory); |
1032 | destroy_inv (false); |
|
|
1033 | |
1030 | |
1034 | if (is_head ()) |
1031 | if (is_head ()) |
1035 | if (sound_destroy) |
1032 | if (sound_destroy) |
1036 | play_sound (sound_destroy); |
1033 | play_sound (sound_destroy); |
1037 | else if (flag [FLAG_MONSTER]) |
1034 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1056 | if (flag [FLAG_REMOVED]) |
1053 | if (flag [FLAG_REMOVED]) |
1057 | return; |
1054 | return; |
1058 | |
1055 | |
1059 | INVOKE_OBJECT (REMOVE, this); |
1056 | INVOKE_OBJECT (REMOVE, this); |
1060 | |
1057 | |
1061 | if (object *pl = visible_to ()) |
|
|
1062 | esrv_del_item (pl->contr, count); |
|
|
1063 | |
|
|
1064 | flag [FLAG_REMOVED] = true; |
1058 | flag [FLAG_REMOVED] = true; |
1065 | |
1059 | |
1066 | if (more) |
1060 | if (more) |
1067 | more->remove (); |
1061 | more->remove (); |
1068 | |
1062 | |
… | |
… | |
1070 | * In this case, the object to be removed is in someones |
1064 | * In this case, the object to be removed is in someones |
1071 | * inventory. |
1065 | * inventory. |
1072 | */ |
1066 | */ |
1073 | if (env) |
1067 | if (env) |
1074 | { |
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 | |
1075 | adjust_weight (env, -total_weight ()); |
1074 | adjust_weight (env, -total_weight ()); |
1076 | |
1075 | |
1077 | *(above ? &above->below : &env->inv) = below; |
1076 | *(above ? &above->below : &env->inv) = below; |
1078 | |
1077 | |
1079 | if (below) |
1078 | if (below) |
… | |
… | |
1097 | 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)) |
1098 | otmp->update_stats (); |
1097 | otmp->update_stats (); |
1099 | } |
1098 | } |
1100 | else if (map) |
1099 | else if (map) |
1101 | { |
1100 | { |
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; |
1101 | map->dirty = true; |
1115 | 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 | } |
1116 | |
1125 | |
1117 | /* link the object above us */ |
1126 | /* link the object above us */ |
1118 | if (above) |
1127 | if (above) |
1119 | above->below = below; |
1128 | above->below = below; |
1120 | else |
1129 | else |
… | |
… | |
1150 | * removed (most likely destroyed), update the player view |
1159 | * removed (most likely destroyed), update the player view |
1151 | * appropriately. |
1160 | * appropriately. |
1152 | */ |
1161 | */ |
1153 | pl->close_container (); |
1162 | pl->close_container (); |
1154 | |
1163 | |
1155 | pl->contr->ns->floorbox_update (); |
1164 | //TODO: the floorbox prev/next might need updating |
|
|
1165 | esrv_del_item (pl->contr, count); |
1156 | } |
1166 | } |
1157 | |
1167 | |
1158 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1168 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1159 | { |
1169 | { |
1160 | /* No point updating the players look faces if he is the object |
1170 | /* No point updating the players look faces if he is the object |
… | |
… | |
1286 | object * |
1296 | object * |
1287 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1297 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1288 | { |
1298 | { |
1289 | assert (!op->flag [FLAG_FREED]); |
1299 | assert (!op->flag [FLAG_FREED]); |
1290 | |
1300 | |
1291 | object *top, *floor = NULL; |
|
|
1292 | |
|
|
1293 | op->remove (); |
1301 | op->remove (); |
1294 | |
1302 | |
1295 | /* Ideally, the caller figures this out. However, it complicates a lot |
1303 | /* 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 |
1304 | * of areas of callers (eg, anything that uses find_free_spot would now |
1297 | * need extra work |
1305 | * need extra work |
1298 | */ |
1306 | */ |
1299 | if (!xy_normalise (m, op->x, op->y)) |
1307 | if (!xy_normalise (m, op->x, op->y)) |
1300 | { |
1308 | { |
1301 | op->destroy (); |
1309 | op->destroy (1); |
1302 | return 0; |
1310 | return 0; |
1303 | } |
1311 | } |
1304 | |
1312 | |
1305 | if (object *more = op->more) |
1313 | if (object *more = op->more) |
1306 | if (!insert_ob_in_map (more, m, originator, flag)) |
1314 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1315 | */ |
1323 | */ |
1316 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1324 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1317 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1325 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1318 | if (object::can_merge (op, tmp)) |
1326 | if (object::can_merge (op, tmp)) |
1319 | { |
1327 | { |
|
|
1328 | // TODO: we atcually want to update tmp, not op, |
|
|
1329 | // but some caller surely breaks when we return tmp |
|
|
1330 | // from here :/ |
1320 | op->nrof += tmp->nrof; |
1331 | op->nrof += tmp->nrof; |
1321 | tmp->destroy (1); |
1332 | tmp->destroy (1); |
1322 | } |
1333 | } |
1323 | |
1334 | |
1324 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1335 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1346 | /* since *below* originator, no need to update top */ |
1357 | /* since *below* originator, no need to update top */ |
1347 | originator->below = op; |
1358 | originator->below = op; |
1348 | } |
1359 | } |
1349 | else |
1360 | else |
1350 | { |
1361 | { |
|
|
1362 | object *top, *floor = NULL; |
|
|
1363 | |
1351 | top = ms.bot; |
1364 | top = ms.bot; |
1352 | |
1365 | |
1353 | /* If there are other objects, then */ |
1366 | /* If there are other objects, then */ |
1354 | if (top) |
1367 | if (top) |
1355 | { |
1368 | { |
… | |
… | |
1454 | } |
1467 | } |
1455 | |
1468 | |
1456 | op->map->dirty = true; |
1469 | op->map->dirty = true; |
1457 | |
1470 | |
1458 | if (object *pl = ms.player ()) |
1471 | if (object *pl = ms.player ()) |
1459 | pl->contr->ns->floorbox_update (); |
1472 | //TODO: the floorbox prev/next might need updating |
|
|
1473 | esrv_send_item (pl, op); |
1460 | |
1474 | |
1461 | /* If this object glows, it may affect lighting conditions that are |
1475 | /* If this object glows, it may affect lighting conditions that are |
1462 | * visible to others on this map. But update_all_los is really |
1476 | * 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 |
1477 | * 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 |
1478 | * on the map will get recalculated. The players could very well |
… | |
… | |
2311 | * create clone from object to another |
2325 | * create clone from object to another |
2312 | */ |
2326 | */ |
2313 | object * |
2327 | object * |
2314 | object_create_clone (object *asrc) |
2328 | object_create_clone (object *asrc) |
2315 | { |
2329 | { |
2316 | object *dst = 0, *tmp, *src, *prev, *item; |
2330 | object *dst = 0; |
2317 | |
2331 | |
2318 | if (!asrc) |
2332 | if (!asrc) |
2319 | return 0; |
2333 | return 0; |
2320 | |
2334 | |
2321 | src = asrc->head_ (); |
2335 | object *src = asrc->head_ (); |
2322 | |
2336 | |
2323 | prev = 0; |
2337 | object *prev = 0; |
2324 | for (object *part = src; part; part = part->more) |
2338 | for (object *part = src; part; part = part->more) |
2325 | { |
2339 | { |
2326 | tmp = part->clone (); |
2340 | object *tmp = part->clone (); |
|
|
2341 | |
2327 | tmp->x -= src->x; |
2342 | tmp->x -= src->x; |
2328 | tmp->y -= src->y; |
2343 | tmp->y -= src->y; |
2329 | |
2344 | |
2330 | if (!part->head) |
2345 | if (!part->head) |
2331 | { |
2346 | { |
… | |
… | |
2341 | prev->more = tmp; |
2356 | prev->more = tmp; |
2342 | |
2357 | |
2343 | prev = tmp; |
2358 | prev = tmp; |
2344 | } |
2359 | } |
2345 | |
2360 | |
2346 | for (item = src->inv; item; item = item->below) |
2361 | for (object *item = src->inv; item; item = item->below) |
2347 | insert_ob_in_ob (object_create_clone (item), dst); |
2362 | insert_ob_in_ob (object_create_clone (item), dst); |
2348 | |
2363 | |
2349 | return dst; |
2364 | return dst; |
2350 | } |
2365 | } |
2351 | |
2366 | |
… | |
… | |
2565 | &name, |
2580 | &name, |
2566 | title ? "\",title:\"" : "", |
2581 | title ? "\",title:\"" : "", |
2567 | title ? (const char *)title : "", |
2582 | title ? (const char *)title : "", |
2568 | flag_desc (flagdesc, 512), type); |
2583 | flag_desc (flagdesc, 512), type); |
2569 | |
2584 | |
2570 | if (!this->flag[FLAG_REMOVED] && env) |
2585 | if (!flag[FLAG_REMOVED] && env) |
2571 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2586 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2572 | |
2587 | |
2573 | if (map) |
2588 | if (map) |
2574 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2589 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2575 | |
2590 | |
… | |
… | |
2605 | object::open_container (object *new_container) |
2620 | object::open_container (object *new_container) |
2606 | { |
2621 | { |
2607 | if (container == new_container) |
2622 | if (container == new_container) |
2608 | return; |
2623 | return; |
2609 | |
2624 | |
2610 | if (object *old_container = container) |
2625 | object *old_container = container; |
|
|
2626 | |
|
|
2627 | if (old_container) |
2611 | { |
2628 | { |
2612 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2629 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2613 | return; |
2630 | return; |
2614 | |
2631 | |
2615 | #if 0 |
2632 | #if 0 |
… | |
… | |
2617 | if (object *closer = old_container->inv) |
2634 | if (object *closer = old_container->inv) |
2618 | if (closer->type == CLOSE_CON) |
2635 | if (closer->type == CLOSE_CON) |
2619 | closer->destroy (); |
2636 | closer->destroy (); |
2620 | #endif |
2637 | #endif |
2621 | |
2638 | |
|
|
2639 | // make sure the container is available |
|
|
2640 | esrv_send_item (this, old_container); |
|
|
2641 | |
2622 | old_container->flag [FLAG_APPLIED] = 0; |
2642 | old_container->flag [FLAG_APPLIED] = false; |
2623 | container = 0; |
2643 | container = 0; |
2624 | |
2644 | |
|
|
2645 | // client needs item update to make it work, client bug requires this to be separate |
2625 | esrv_update_item (UPD_FLAGS, this, old_container); |
2646 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2647 | |
2626 | 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)); |
2627 | play_sound (sound_find ("chest_close")); |
2649 | play_sound (sound_find ("chest_close")); |
2628 | } |
2650 | } |
2629 | |
2651 | |
2630 | if (new_container) |
2652 | if (new_container) |
… | |
… | |
2643 | } |
2665 | } |
2644 | #endif |
2666 | #endif |
2645 | |
2667 | |
2646 | 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)); |
2647 | |
2669 | |
|
|
2670 | // make sure the container is available, client bug requires this to be separate |
|
|
2671 | esrv_send_item (this, new_container); |
|
|
2672 | |
2648 | new_container->flag [FLAG_APPLIED] = 1; |
2673 | new_container->flag [FLAG_APPLIED] = true; |
2649 | container = new_container; |
2674 | container = new_container; |
2650 | |
2675 | |
|
|
2676 | // client needs flag change |
2651 | esrv_update_item (UPD_FLAGS, this, new_container); |
2677 | esrv_update_item (UPD_FLAGS, this, new_container); |
2652 | esrv_send_inventory (this, new_container); |
2678 | esrv_send_inventory (this, new_container); |
2653 | play_sound (sound_find ("chest_open")); |
2679 | play_sound (sound_find ("chest_open")); |
2654 | } |
2680 | } |
|
|
2681 | // else if (!old_container->env && contr && contr->ns) |
|
|
2682 | // contr->ns->floorbox_reset (); |
2655 | } |
2683 | } |
2656 | |
2684 | |
2657 | object * |
2685 | object * |
2658 | object::force_find (const shstr name) |
2686 | object::force_find (const shstr name) |
2659 | { |
2687 | { |