… | |
… | |
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 | } |
… | |
… | |
745 | * UP_OBJ_FACE: only the objects face has changed. |
746 | * UP_OBJ_FACE: only the objects face has changed. |
746 | */ |
747 | */ |
747 | void |
748 | void |
748 | update_object (object *op, int action) |
749 | update_object (object *op, int action) |
749 | { |
750 | { |
750 | if (op == NULL) |
751 | if (!op) |
751 | { |
752 | { |
752 | /* this should never happen */ |
753 | /* this should never happen */ |
753 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
754 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
754 | return; |
755 | return; |
755 | } |
756 | } |
756 | |
757 | |
757 | if (op->env) |
758 | if (!op->is_on_map ()) |
758 | { |
759 | { |
759 | /* Animation is currently handled by client, so nothing |
760 | /* Animation is currently handled by client, so nothing |
760 | * to do in this case. |
761 | * to do in this case. |
761 | */ |
762 | */ |
762 | return; |
763 | return; |
763 | } |
764 | } |
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 | |
765 | |
771 | /* make sure the object is within map boundaries */ |
766 | /* 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) |
767 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
773 | { |
768 | { |
774 | LOG (llevError, "update_object() called for object out of map!\n"); |
769 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
964 | object *op = new object; |
959 | object *op = new object; |
965 | op->link (); |
960 | op->link (); |
966 | return op; |
961 | return op; |
967 | } |
962 | } |
968 | |
963 | |
|
|
964 | static struct freed_map : maptile |
|
|
965 | { |
|
|
966 | freed_map () |
|
|
967 | { |
|
|
968 | path = "<freed objects map>"; |
|
|
969 | name = "/internal/freed_objects_map"; |
|
|
970 | width = 3; |
|
|
971 | height = 3; |
|
|
972 | nodrop = 1; |
|
|
973 | |
|
|
974 | alloc (); |
|
|
975 | in_memory = MAP_ACTIVE; |
|
|
976 | } |
|
|
977 | } freed_map; // freed objects are moved here to avoid crashes |
|
|
978 | |
969 | void |
979 | void |
970 | object::do_destroy () |
980 | object::do_destroy () |
971 | { |
981 | { |
972 | if (flag [FLAG_IS_LINKED]) |
982 | if (flag [FLAG_IS_LINKED]) |
973 | remove_button_link (this); |
983 | remove_button_link (this); |
… | |
… | |
983 | unlink (); |
993 | unlink (); |
984 | |
994 | |
985 | flag [FLAG_FREED] = 1; |
995 | flag [FLAG_FREED] = 1; |
986 | |
996 | |
987 | // hack to ensure that freed objects still have a valid map |
997 | // 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; |
998 | map = &freed_map; |
1006 | x = 1; |
999 | x = 1; |
1007 | y = 1; |
1000 | y = 1; |
1008 | } |
|
|
1009 | |
1001 | |
1010 | if (more) |
1002 | if (more) |
1011 | { |
1003 | { |
1012 | more->destroy (); |
1004 | more->destroy (); |
1013 | more = 0; |
1005 | more = 0; |
… | |
… | |
1025 | void |
1017 | void |
1026 | object::destroy (bool destroy_inventory) |
1018 | object::destroy (bool destroy_inventory) |
1027 | { |
1019 | { |
1028 | if (destroyed ()) |
1020 | if (destroyed ()) |
1029 | return; |
1021 | return; |
|
|
1022 | |
|
|
1023 | if (!is_head () && !head->destroyed ()) |
|
|
1024 | { |
|
|
1025 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
|
|
1026 | head->destroy (destroy_inventory); |
|
|
1027 | return; |
|
|
1028 | } |
1030 | |
1029 | |
1031 | destroy_inv (!destroy_inventory); |
1030 | destroy_inv (!destroy_inventory); |
1032 | |
1031 | |
1033 | if (is_head ()) |
1032 | if (is_head ()) |
1034 | if (sound_destroy) |
1033 | if (sound_destroy) |
… | |
… | |
1055 | if (flag [FLAG_REMOVED]) |
1054 | if (flag [FLAG_REMOVED]) |
1056 | return; |
1055 | return; |
1057 | |
1056 | |
1058 | INVOKE_OBJECT (REMOVE, this); |
1057 | INVOKE_OBJECT (REMOVE, this); |
1059 | |
1058 | |
1060 | if (object *pl = visible_to ()) |
|
|
1061 | esrv_del_item (pl->contr, count); |
|
|
1062 | |
|
|
1063 | flag [FLAG_REMOVED] = true; |
1059 | flag [FLAG_REMOVED] = true; |
1064 | |
1060 | |
1065 | if (more) |
1061 | if (more) |
1066 | more->remove (); |
1062 | more->remove (); |
1067 | |
1063 | |
… | |
… | |
1069 | * In this case, the object to be removed is in someones |
1065 | * In this case, the object to be removed is in someones |
1070 | * inventory. |
1066 | * inventory. |
1071 | */ |
1067 | */ |
1072 | if (env) |
1068 | if (env) |
1073 | { |
1069 | { |
|
|
1070 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1071 | if (object *pl = visible_to ()) |
|
|
1072 | esrv_del_item (pl->contr, count); |
|
|
1073 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1074 | |
1074 | adjust_weight (env, -total_weight ()); |
1075 | adjust_weight (env, -total_weight ()); |
1075 | |
1076 | |
1076 | *(above ? &above->below : &env->inv) = below; |
1077 | *(above ? &above->below : &env->inv) = below; |
1077 | |
1078 | |
1078 | if (below) |
1079 | if (below) |
… | |
… | |
1096 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1097 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1097 | otmp->update_stats (); |
1098 | otmp->update_stats (); |
1098 | } |
1099 | } |
1099 | else if (map) |
1100 | else if (map) |
1100 | { |
1101 | { |
1101 | if (type == PLAYER) |
|
|
1102 | { |
|
|
1103 | // leaving a spot always closes any open container on the ground |
|
|
1104 | if (container && !container->env) |
|
|
1105 | // this causes spurious floorbox updates, but it ensures |
|
|
1106 | // that the CLOSE event is being sent. |
|
|
1107 | close_container (); |
|
|
1108 | |
|
|
1109 | --map->players; |
|
|
1110 | map->touch (); |
|
|
1111 | } |
|
|
1112 | |
|
|
1113 | map->dirty = true; |
1102 | map->dirty = true; |
1114 | mapspace &ms = this->ms (); |
1103 | mapspace &ms = this->ms (); |
|
|
1104 | |
|
|
1105 | if (object *pl = ms.player ()) |
|
|
1106 | { |
|
|
1107 | if (type == PLAYER) // this == pl(!) |
|
|
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 | else if (pl->container == this) |
|
|
1119 | { |
|
|
1120 | // removing a container should close it |
|
|
1121 | close_container (); |
|
|
1122 | } |
|
|
1123 | |
|
|
1124 | esrv_del_item (pl->contr, count); |
|
|
1125 | } |
1115 | |
1126 | |
1116 | /* link the object above us */ |
1127 | /* link the object above us */ |
1117 | if (above) |
1128 | if (above) |
1118 | above->below = below; |
1129 | above->below = below; |
1119 | else |
1130 | else |
… | |
… | |
1149 | * removed (most likely destroyed), update the player view |
1160 | * removed (most likely destroyed), update the player view |
1150 | * appropriately. |
1161 | * appropriately. |
1151 | */ |
1162 | */ |
1152 | pl->close_container (); |
1163 | pl->close_container (); |
1153 | |
1164 | |
|
|
1165 | //TODO: the floorbox prev/next might need updating |
1154 | esrv_del_item (pl, count); |
1166 | esrv_del_item (pl->contr, count); |
1155 | } |
1167 | } |
1156 | |
1168 | |
1157 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1169 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1158 | { |
1170 | { |
1159 | /* No point updating the players look faces if he is the object |
1171 | /* No point updating the players look faces if he is the object |
… | |
… | |
1285 | object * |
1297 | object * |
1286 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1298 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1287 | { |
1299 | { |
1288 | assert (!op->flag [FLAG_FREED]); |
1300 | assert (!op->flag [FLAG_FREED]); |
1289 | |
1301 | |
1290 | object *top, *floor = NULL; |
|
|
1291 | |
|
|
1292 | op->remove (); |
1302 | op->remove (); |
1293 | |
1303 | |
1294 | /* Ideally, the caller figures this out. However, it complicates a lot |
1304 | /* Ideally, the caller figures this out. However, it complicates a lot |
1295 | * of areas of callers (eg, anything that uses find_free_spot would now |
1305 | * of areas of callers (eg, anything that uses find_free_spot would now |
1296 | * need extra work |
1306 | * need extra work |
… | |
… | |
1314 | */ |
1324 | */ |
1315 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1325 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1316 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1326 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1317 | if (object::can_merge (op, tmp)) |
1327 | if (object::can_merge (op, tmp)) |
1318 | { |
1328 | { |
|
|
1329 | // TODO: we atcually want to update tmp, not op, |
|
|
1330 | // but some caller surely breaks when we return tmp |
|
|
1331 | // from here :/ |
1319 | op->nrof += tmp->nrof; |
1332 | op->nrof += tmp->nrof; |
1320 | tmp->destroy (1); |
1333 | tmp->destroy (1); |
1321 | } |
1334 | } |
1322 | |
1335 | |
1323 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1336 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1345 | /* since *below* originator, no need to update top */ |
1358 | /* since *below* originator, no need to update top */ |
1346 | originator->below = op; |
1359 | originator->below = op; |
1347 | } |
1360 | } |
1348 | else |
1361 | else |
1349 | { |
1362 | { |
|
|
1363 | object *top, *floor = NULL; |
|
|
1364 | |
1350 | top = ms.bot; |
1365 | top = ms.bot; |
1351 | |
1366 | |
1352 | /* If there are other objects, then */ |
1367 | /* If there are other objects, then */ |
1353 | if (top) |
1368 | if (top) |
1354 | { |
1369 | { |
… | |
… | |
1453 | } |
1468 | } |
1454 | |
1469 | |
1455 | op->map->dirty = true; |
1470 | op->map->dirty = true; |
1456 | |
1471 | |
1457 | if (object *pl = ms.player ()) |
1472 | if (object *pl = ms.player ()) |
|
|
1473 | //TODO: the floorbox prev/next might need updating |
1458 | esrv_send_item (pl, op); |
1474 | esrv_send_item (pl, op); |
1459 | |
1475 | |
1460 | /* If this object glows, it may affect lighting conditions that are |
1476 | /* If this object glows, it may affect lighting conditions that are |
1461 | * visible to others on this map. But update_all_los is really |
1477 | * visible to others on this map. But update_all_los is really |
1462 | * an inefficient way to do this, as it means los for all players |
1478 | * an inefficient way to do this, as it means los for all players |
… | |
… | |
2604 | object::open_container (object *new_container) |
2620 | object::open_container (object *new_container) |
2605 | { |
2621 | { |
2606 | if (container == new_container) |
2622 | if (container == new_container) |
2607 | return; |
2623 | return; |
2608 | |
2624 | |
2609 | if (object *old_container = container) |
2625 | object *old_container = container; |
|
|
2626 | |
|
|
2627 | if (old_container) |
2610 | { |
2628 | { |
2611 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2629 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2612 | return; |
2630 | return; |
2613 | |
2631 | |
2614 | #if 0 |
2632 | #if 0 |
… | |
… | |
2616 | if (object *closer = old_container->inv) |
2634 | if (object *closer = old_container->inv) |
2617 | if (closer->type == CLOSE_CON) |
2635 | if (closer->type == CLOSE_CON) |
2618 | closer->destroy (); |
2636 | closer->destroy (); |
2619 | #endif |
2637 | #endif |
2620 | |
2638 | |
|
|
2639 | // make sure the container is available |
|
|
2640 | esrv_send_item (this, old_container); |
|
|
2641 | |
2621 | old_container->flag [FLAG_APPLIED] = false; |
2642 | old_container->flag [FLAG_APPLIED] = false; |
2622 | container = 0; |
2643 | container = 0; |
2623 | |
2644 | |
|
|
2645 | // client needs item update to make it work, client bug requires this to be separate |
2624 | esrv_update_item (UPD_FLAGS, this, old_container); |
2646 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2647 | |
2625 | 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)); |
2626 | play_sound (sound_find ("chest_close")); |
2649 | play_sound (sound_find ("chest_close")); |
2627 | } |
2650 | } |
2628 | |
2651 | |
2629 | if (new_container) |
2652 | if (new_container) |
… | |
… | |
2642 | } |
2665 | } |
2643 | #endif |
2666 | #endif |
2644 | |
2667 | |
2645 | 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)); |
2646 | |
2669 | |
|
|
2670 | // make sure the container is available, client bug requires this to be separate |
|
|
2671 | esrv_send_item (this, new_container); |
|
|
2672 | |
2647 | new_container->flag [FLAG_APPLIED] = true; |
2673 | new_container->flag [FLAG_APPLIED] = true; |
2648 | container = new_container; |
2674 | container = new_container; |
2649 | |
2675 | |
|
|
2676 | // client needs flag change |
2650 | esrv_update_item (UPD_FLAGS, this, new_container); |
2677 | esrv_update_item (UPD_FLAGS, this, new_container); |
2651 | esrv_send_inventory (this, new_container); |
2678 | esrv_send_inventory (this, new_container); |
2652 | play_sound (sound_find ("chest_open")); |
2679 | play_sound (sound_find ("chest_open")); |
2653 | } |
2680 | } |
|
|
2681 | // else if (!old_container->env && contr && contr->ns) |
|
|
2682 | // contr->ns->floorbox_reset (); |
2654 | } |
2683 | } |
2655 | |
2684 | |
2656 | object * |
2685 | object * |
2657 | object::force_find (const shstr name) |
2686 | object::force_find (const shstr name) |
2658 | { |
2687 | { |