… | |
… | |
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"); |
… | |
… | |
917 | object::destroy_inv (bool drop_to_ground) |
912 | object::destroy_inv (bool drop_to_ground) |
918 | { |
913 | { |
919 | // need to check first, because the checks below might segfault |
914 | // need to check first, because the checks below might segfault |
920 | // as we might be on an invalid mapspace and crossfire code |
915 | // as we might be on an invalid mapspace and crossfire code |
921 | // is too buggy to ensure that the inventory is empty. |
916 | // is too buggy to ensure that the inventory is empty. |
922 | // corollary: if you create arrows etc. with stuff in tis inventory, |
917 | // corollary: if you create arrows etc. with stuff in its inventory, |
923 | // cf will crash below with off-map x and y |
918 | // cf will crash below with off-map x and y |
924 | if (!inv) |
919 | if (!inv) |
925 | return; |
920 | return; |
926 | |
921 | |
927 | /* Only if the space blocks everything do we not process - |
922 | /* Only if the space blocks everything do we not process - |
… | |
… | |
934 | || map->nodrop |
929 | || map->nodrop |
935 | || ms ().move_block == MOVE_ALL) |
930 | || ms ().move_block == MOVE_ALL) |
936 | { |
931 | { |
937 | while (inv) |
932 | while (inv) |
938 | { |
933 | { |
939 | inv->destroy_inv (drop_to_ground); |
934 | inv->destroy_inv (false); |
940 | inv->destroy (); |
935 | inv->destroy (); |
941 | } |
936 | } |
942 | } |
937 | } |
943 | else |
938 | else |
944 | { /* Put objects in inventory onto this space */ |
939 | { /* Put objects in inventory onto this space */ |
… | |
… | |
950 | || op->flag [FLAG_NO_DROP] |
945 | || op->flag [FLAG_NO_DROP] |
951 | || op->type == RUNE |
946 | || op->type == RUNE |
952 | || op->type == TRAP |
947 | || op->type == TRAP |
953 | || op->flag [FLAG_IS_A_TEMPLATE] |
948 | || op->flag [FLAG_IS_A_TEMPLATE] |
954 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
949 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
955 | op->destroy (); |
950 | op->destroy (true); |
956 | else |
951 | else |
957 | map->insert (op, x, y); |
952 | map->insert (op, x, y); |
958 | } |
953 | } |
959 | } |
954 | } |
960 | } |
955 | } |
… | |
… | |
976 | remove_friendly_object (this); |
971 | remove_friendly_object (this); |
977 | |
972 | |
978 | remove (); |
973 | remove (); |
979 | |
974 | |
980 | attachable::do_destroy (); |
975 | attachable::do_destroy (); |
981 | |
|
|
982 | destroy_inv (true); |
|
|
983 | |
976 | |
984 | deactivate (); |
977 | deactivate (); |
985 | unlink (); |
978 | unlink (); |
986 | |
979 | |
987 | flag [FLAG_FREED] = 1; |
980 | flag [FLAG_FREED] = 1; |
… | |
… | |
1028 | object::destroy (bool destroy_inventory) |
1021 | object::destroy (bool destroy_inventory) |
1029 | { |
1022 | { |
1030 | if (destroyed ()) |
1023 | if (destroyed ()) |
1031 | return; |
1024 | return; |
1032 | |
1025 | |
|
|
1026 | if (!is_head () && !head->destroyed ()) |
|
|
1027 | { |
|
|
1028 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
|
|
1029 | head->destroy (destroy_inventory); |
|
|
1030 | } |
|
|
1031 | |
1033 | if (destroy_inventory) |
1032 | destroy_inv (!destroy_inventory); |
1034 | destroy_inv (false); |
|
|
1035 | |
1033 | |
1036 | if (is_head ()) |
1034 | if (is_head ()) |
1037 | if (sound_destroy) |
1035 | if (sound_destroy) |
1038 | play_sound (sound_destroy); |
1036 | play_sound (sound_destroy); |
1039 | else if (flag [FLAG_MONSTER]) |
1037 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1058 | if (flag [FLAG_REMOVED]) |
1056 | if (flag [FLAG_REMOVED]) |
1059 | return; |
1057 | return; |
1060 | |
1058 | |
1061 | INVOKE_OBJECT (REMOVE, this); |
1059 | INVOKE_OBJECT (REMOVE, this); |
1062 | |
1060 | |
1063 | if (object *pl = visible_to ()) |
|
|
1064 | esrv_del_item (pl->contr, count); |
|
|
1065 | |
|
|
1066 | flag [FLAG_REMOVED] = true; |
1061 | flag [FLAG_REMOVED] = true; |
1067 | |
1062 | |
1068 | if (more) |
1063 | if (more) |
1069 | more->remove (); |
1064 | more->remove (); |
1070 | |
1065 | |
… | |
… | |
1072 | * In this case, the object to be removed is in someones |
1067 | * In this case, the object to be removed is in someones |
1073 | * inventory. |
1068 | * inventory. |
1074 | */ |
1069 | */ |
1075 | if (env) |
1070 | if (env) |
1076 | { |
1071 | { |
|
|
1072 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1073 | if (object *pl = visible_to ()) |
|
|
1074 | esrv_del_item (pl->contr, count); |
|
|
1075 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1076 | |
1077 | adjust_weight (env, -total_weight ()); |
1077 | adjust_weight (env, -total_weight ()); |
1078 | |
1078 | |
1079 | *(above ? &above->below : &env->inv) = below; |
1079 | *(above ? &above->below : &env->inv) = below; |
1080 | |
1080 | |
1081 | if (below) |
1081 | if (below) |
… | |
… | |
1099 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1099 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1100 | otmp->update_stats (); |
1100 | otmp->update_stats (); |
1101 | } |
1101 | } |
1102 | else if (map) |
1102 | else if (map) |
1103 | { |
1103 | { |
1104 | if (type == PLAYER) |
|
|
1105 | { |
|
|
1106 | // leaving a spot always closes any open container on the ground |
|
|
1107 | if (container && !container->env) |
|
|
1108 | // this causes spurious floorbox updates, but it ensures |
|
|
1109 | // that the CLOSE event is being sent. |
|
|
1110 | close_container (); |
|
|
1111 | |
|
|
1112 | --map->players; |
|
|
1113 | map->touch (); |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | map->dirty = true; |
1104 | map->dirty = true; |
1117 | mapspace &ms = this->ms (); |
1105 | mapspace &ms = this->ms (); |
|
|
1106 | |
|
|
1107 | if (object *pl = ms.player ()) |
|
|
1108 | { |
|
|
1109 | if (type == PLAYER) // this == pl(!) |
|
|
1110 | { |
|
|
1111 | // leaving a spot always closes any open container on the ground |
|
|
1112 | if (container && !container->env) |
|
|
1113 | // this causes spurious floorbox updates, but it ensures |
|
|
1114 | // that the CLOSE event is being sent. |
|
|
1115 | close_container (); |
|
|
1116 | |
|
|
1117 | --map->players; |
|
|
1118 | map->touch (); |
|
|
1119 | } |
|
|
1120 | else if (pl->container == this) |
|
|
1121 | { |
|
|
1122 | // removing a container should close it |
|
|
1123 | close_container (); |
|
|
1124 | } |
|
|
1125 | |
|
|
1126 | esrv_del_item (pl->contr, count); |
|
|
1127 | } |
1118 | |
1128 | |
1119 | /* link the object above us */ |
1129 | /* link the object above us */ |
1120 | if (above) |
1130 | if (above) |
1121 | above->below = below; |
1131 | above->below = below; |
1122 | else |
1132 | else |
… | |
… | |
1152 | * removed (most likely destroyed), update the player view |
1162 | * removed (most likely destroyed), update the player view |
1153 | * appropriately. |
1163 | * appropriately. |
1154 | */ |
1164 | */ |
1155 | pl->close_container (); |
1165 | pl->close_container (); |
1156 | |
1166 | |
1157 | pl->contr->ns->floorbox_update (); |
1167 | //TODO: the floorbox prev/next might need updating |
|
|
1168 | esrv_del_item (pl->contr, count); |
1158 | } |
1169 | } |
1159 | |
1170 | |
1160 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1171 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1161 | { |
1172 | { |
1162 | /* No point updating the players look faces if he is the object |
1173 | /* No point updating the players look faces if he is the object |
… | |
… | |
1288 | object * |
1299 | object * |
1289 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1300 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1290 | { |
1301 | { |
1291 | assert (!op->flag [FLAG_FREED]); |
1302 | assert (!op->flag [FLAG_FREED]); |
1292 | |
1303 | |
1293 | object *top, *floor = NULL; |
|
|
1294 | |
|
|
1295 | op->remove (); |
1304 | op->remove (); |
1296 | |
1305 | |
1297 | /* Ideally, the caller figures this out. However, it complicates a lot |
1306 | /* Ideally, the caller figures this out. However, it complicates a lot |
1298 | * of areas of callers (eg, anything that uses find_free_spot would now |
1307 | * of areas of callers (eg, anything that uses find_free_spot would now |
1299 | * need extra work |
1308 | * need extra work |
1300 | */ |
1309 | */ |
1301 | if (!xy_normalise (m, op->x, op->y)) |
1310 | if (!xy_normalise (m, op->x, op->y)) |
1302 | { |
1311 | { |
1303 | op->destroy (); |
1312 | op->destroy (1); |
1304 | return 0; |
1313 | return 0; |
1305 | } |
1314 | } |
1306 | |
1315 | |
1307 | if (object *more = op->more) |
1316 | if (object *more = op->more) |
1308 | if (!insert_ob_in_map (more, m, originator, flag)) |
1317 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1317 | */ |
1326 | */ |
1318 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1327 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1319 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1328 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1320 | if (object::can_merge (op, tmp)) |
1329 | if (object::can_merge (op, tmp)) |
1321 | { |
1330 | { |
|
|
1331 | // TODO: we atcually want to update tmp, not op, |
|
|
1332 | // but some caller surely breaks when we return tmp |
|
|
1333 | // from here :/ |
1322 | op->nrof += tmp->nrof; |
1334 | op->nrof += tmp->nrof; |
1323 | tmp->destroy (1); |
1335 | tmp->destroy (1); |
1324 | } |
1336 | } |
1325 | |
1337 | |
1326 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1338 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1348 | /* since *below* originator, no need to update top */ |
1360 | /* since *below* originator, no need to update top */ |
1349 | originator->below = op; |
1361 | originator->below = op; |
1350 | } |
1362 | } |
1351 | else |
1363 | else |
1352 | { |
1364 | { |
|
|
1365 | object *top, *floor = NULL; |
|
|
1366 | |
1353 | top = ms.bot; |
1367 | top = ms.bot; |
1354 | |
1368 | |
1355 | /* If there are other objects, then */ |
1369 | /* If there are other objects, then */ |
1356 | if (top) |
1370 | if (top) |
1357 | { |
1371 | { |
… | |
… | |
1456 | } |
1470 | } |
1457 | |
1471 | |
1458 | op->map->dirty = true; |
1472 | op->map->dirty = true; |
1459 | |
1473 | |
1460 | if (object *pl = ms.player ()) |
1474 | if (object *pl = ms.player ()) |
1461 | pl->contr->ns->floorbox_update (); |
1475 | //TODO: the floorbox prev/next might need updating |
|
|
1476 | esrv_send_item (pl, op); |
1462 | |
1477 | |
1463 | /* If this object glows, it may affect lighting conditions that are |
1478 | /* If this object glows, it may affect lighting conditions that are |
1464 | * visible to others on this map. But update_all_los is really |
1479 | * visible to others on this map. But update_all_los is really |
1465 | * an inefficient way to do this, as it means los for all players |
1480 | * an inefficient way to do this, as it means los for all players |
1466 | * on the map will get recalculated. The players could very well |
1481 | * on the map will get recalculated. The players could very well |
… | |
… | |
2567 | &name, |
2582 | &name, |
2568 | title ? "\",title:\"" : "", |
2583 | title ? "\",title:\"" : "", |
2569 | title ? (const char *)title : "", |
2584 | title ? (const char *)title : "", |
2570 | flag_desc (flagdesc, 512), type); |
2585 | flag_desc (flagdesc, 512), type); |
2571 | |
2586 | |
2572 | if (!this->flag[FLAG_REMOVED] && env) |
2587 | if (!flag[FLAG_REMOVED] && env) |
2573 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2588 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2574 | |
2589 | |
2575 | if (map) |
2590 | if (map) |
2576 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2591 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2577 | |
2592 | |
… | |
… | |
2607 | object::open_container (object *new_container) |
2622 | object::open_container (object *new_container) |
2608 | { |
2623 | { |
2609 | if (container == new_container) |
2624 | if (container == new_container) |
2610 | return; |
2625 | return; |
2611 | |
2626 | |
2612 | if (object *old_container = container) |
2627 | object *old_container = container; |
|
|
2628 | |
|
|
2629 | if (old_container) |
2613 | { |
2630 | { |
2614 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2631 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2615 | return; |
2632 | return; |
2616 | |
2633 | |
2617 | #if 0 |
2634 | #if 0 |
… | |
… | |
2619 | if (object *closer = old_container->inv) |
2636 | if (object *closer = old_container->inv) |
2620 | if (closer->type == CLOSE_CON) |
2637 | if (closer->type == CLOSE_CON) |
2621 | closer->destroy (); |
2638 | closer->destroy (); |
2622 | #endif |
2639 | #endif |
2623 | |
2640 | |
|
|
2641 | // make sure the container is available |
|
|
2642 | esrv_send_item (this, old_container); |
|
|
2643 | |
2624 | old_container->flag [FLAG_APPLIED] = false; |
2644 | old_container->flag [FLAG_APPLIED] = false; |
2625 | container = 0; |
2645 | container = 0; |
2626 | |
2646 | |
|
|
2647 | // client needs item update to make it work, client bug requires this to be separate |
2627 | esrv_update_item (UPD_FLAGS, this, old_container); |
2648 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2649 | |
2628 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2650 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2629 | play_sound (sound_find ("chest_close")); |
2651 | play_sound (sound_find ("chest_close")); |
2630 | } |
2652 | } |
2631 | |
2653 | |
2632 | if (new_container) |
2654 | if (new_container) |
… | |
… | |
2645 | } |
2667 | } |
2646 | #endif |
2668 | #endif |
2647 | |
2669 | |
2648 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2670 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2649 | |
2671 | |
|
|
2672 | // make sure the container is available, client bug requires this to be separate |
|
|
2673 | esrv_send_item (this, new_container); |
|
|
2674 | |
2650 | new_container->flag [FLAG_APPLIED] = true; |
2675 | new_container->flag [FLAG_APPLIED] = true; |
2651 | container = new_container; |
2676 | container = new_container; |
2652 | |
2677 | |
|
|
2678 | // client needs flag change |
2653 | esrv_update_item (UPD_FLAGS, this, new_container); |
2679 | esrv_update_item (UPD_FLAGS, this, new_container); |
2654 | esrv_send_inventory (this, new_container); |
2680 | esrv_send_inventory (this, new_container); |
2655 | play_sound (sound_find ("chest_open")); |
2681 | play_sound (sound_find ("chest_open")); |
2656 | } |
2682 | } |
|
|
2683 | // else if (!old_container->env && contr && contr->ns) |
|
|
2684 | // contr->ns->floorbox_reset (); |
2657 | } |
2685 | } |
2658 | |
2686 | |
2659 | object * |
2687 | object * |
2660 | object::force_find (const shstr name) |
2688 | object::force_find (const shstr name) |
2661 | { |
2689 | { |