… | |
… | |
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. |
… | |
… | |
743 | * UP_OBJ_FACE: only the objects face has changed. |
746 | * UP_OBJ_FACE: only the objects face has changed. |
744 | */ |
747 | */ |
745 | void |
748 | void |
746 | update_object (object *op, int action) |
749 | update_object (object *op, int action) |
747 | { |
750 | { |
748 | if (op == NULL) |
751 | if (!op) |
749 | { |
752 | { |
750 | /* this should never happen */ |
753 | /* this should never happen */ |
751 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
754 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
752 | return; |
755 | return; |
753 | } |
756 | } |
754 | |
757 | |
755 | if (op->env) |
758 | if (!op->is_on_map ()) |
756 | { |
759 | { |
757 | /* Animation is currently handled by client, so nothing |
760 | /* Animation is currently handled by client, so nothing |
758 | * to do in this case. |
761 | * to do in this case. |
759 | */ |
762 | */ |
760 | return; |
763 | return; |
761 | } |
764 | } |
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 | |
765 | |
769 | /* make sure the object is within map boundaries */ |
766 | /* 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) |
767 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
771 | { |
768 | { |
772 | LOG (llevError, "update_object() called for object out of map!\n"); |
769 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
915 | object::destroy_inv (bool drop_to_ground) |
912 | object::destroy_inv (bool drop_to_ground) |
916 | { |
913 | { |
917 | // need to check first, because the checks below might segfault |
914 | // need to check first, because the checks below might segfault |
918 | // as we might be on an invalid mapspace and crossfire code |
915 | // as we might be on an invalid mapspace and crossfire code |
919 | // is too buggy to ensure that the inventory is empty. |
916 | // is too buggy to ensure that the inventory is empty. |
920 | // corollary: if you create arrows etc. with stuff in tis inventory, |
917 | // corollary: if you create arrows etc. with stuff in its inventory, |
921 | // cf will crash below with off-map x and y |
918 | // cf will crash below with off-map x and y |
922 | if (!inv) |
919 | if (!inv) |
923 | return; |
920 | return; |
924 | |
921 | |
925 | /* Only if the space blocks everything do we not process - |
922 | /* Only if the space blocks everything do we not process - |
… | |
… | |
932 | || map->nodrop |
929 | || map->nodrop |
933 | || ms ().move_block == MOVE_ALL) |
930 | || ms ().move_block == MOVE_ALL) |
934 | { |
931 | { |
935 | while (inv) |
932 | while (inv) |
936 | { |
933 | { |
937 | inv->destroy_inv (drop_to_ground); |
934 | inv->destroy_inv (false); |
938 | inv->destroy (); |
935 | inv->destroy (); |
939 | } |
936 | } |
940 | } |
937 | } |
941 | else |
938 | else |
942 | { /* Put objects in inventory onto this space */ |
939 | { /* Put objects in inventory onto this space */ |
… | |
… | |
948 | || op->flag [FLAG_NO_DROP] |
945 | || op->flag [FLAG_NO_DROP] |
949 | || op->type == RUNE |
946 | || op->type == RUNE |
950 | || op->type == TRAP |
947 | || op->type == TRAP |
951 | || op->flag [FLAG_IS_A_TEMPLATE] |
948 | || op->flag [FLAG_IS_A_TEMPLATE] |
952 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
949 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
953 | op->destroy (); |
950 | op->destroy (true); |
954 | else |
951 | else |
955 | map->insert (op, x, y); |
952 | map->insert (op, x, y); |
956 | } |
953 | } |
957 | } |
954 | } |
958 | } |
955 | } |
… | |
… | |
974 | remove_friendly_object (this); |
971 | remove_friendly_object (this); |
975 | |
972 | |
976 | remove (); |
973 | remove (); |
977 | |
974 | |
978 | attachable::do_destroy (); |
975 | attachable::do_destroy (); |
979 | |
|
|
980 | destroy_inv (true); |
|
|
981 | |
976 | |
982 | deactivate (); |
977 | deactivate (); |
983 | unlink (); |
978 | unlink (); |
984 | |
979 | |
985 | flag [FLAG_FREED] = 1; |
980 | flag [FLAG_FREED] = 1; |
… | |
… | |
1026 | object::destroy (bool destroy_inventory) |
1021 | object::destroy (bool destroy_inventory) |
1027 | { |
1022 | { |
1028 | if (destroyed ()) |
1023 | if (destroyed ()) |
1029 | return; |
1024 | return; |
1030 | |
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 | |
1031 | if (destroy_inventory) |
1032 | destroy_inv (!destroy_inventory); |
1032 | destroy_inv (false); |
|
|
1033 | |
1033 | |
1034 | if (is_head ()) |
1034 | if (is_head ()) |
1035 | if (sound_destroy) |
1035 | if (sound_destroy) |
1036 | play_sound (sound_destroy); |
1036 | play_sound (sound_destroy); |
1037 | else if (flag [FLAG_MONSTER]) |
1037 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1056 | if (flag [FLAG_REMOVED]) |
1056 | if (flag [FLAG_REMOVED]) |
1057 | return; |
1057 | return; |
1058 | |
1058 | |
1059 | INVOKE_OBJECT (REMOVE, this); |
1059 | INVOKE_OBJECT (REMOVE, this); |
1060 | |
1060 | |
1061 | if (object *pl = visible_to ()) |
|
|
1062 | esrv_del_item (pl->contr, count); |
|
|
1063 | |
|
|
1064 | flag [FLAG_REMOVED] = true; |
1061 | flag [FLAG_REMOVED] = true; |
1065 | |
1062 | |
1066 | if (more) |
1063 | if (more) |
1067 | more->remove (); |
1064 | more->remove (); |
1068 | |
1065 | |
… | |
… | |
1070 | * In this case, the object to be removed is in someones |
1067 | * In this case, the object to be removed is in someones |
1071 | * inventory. |
1068 | * inventory. |
1072 | */ |
1069 | */ |
1073 | if (env) |
1070 | if (env) |
1074 | { |
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 | |
1075 | adjust_weight (env, -total_weight ()); |
1077 | adjust_weight (env, -total_weight ()); |
1076 | |
1078 | |
1077 | *(above ? &above->below : &env->inv) = below; |
1079 | *(above ? &above->below : &env->inv) = below; |
1078 | |
1080 | |
1079 | if (below) |
1081 | if (below) |
… | |
… | |
1097 | 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)) |
1098 | otmp->update_stats (); |
1100 | otmp->update_stats (); |
1099 | } |
1101 | } |
1100 | else if (map) |
1102 | else if (map) |
1101 | { |
1103 | { |
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; |
1104 | map->dirty = true; |
1115 | 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 | } |
1116 | |
1128 | |
1117 | /* link the object above us */ |
1129 | /* link the object above us */ |
1118 | if (above) |
1130 | if (above) |
1119 | above->below = below; |
1131 | above->below = below; |
1120 | else |
1132 | else |
… | |
… | |
1150 | * removed (most likely destroyed), update the player view |
1162 | * removed (most likely destroyed), update the player view |
1151 | * appropriately. |
1163 | * appropriately. |
1152 | */ |
1164 | */ |
1153 | pl->close_container (); |
1165 | pl->close_container (); |
1154 | |
1166 | |
1155 | pl->contr->ns->floorbox_update (); |
1167 | //TODO: the floorbox prev/next might need updating |
|
|
1168 | esrv_del_item (pl->contr, count); |
1156 | } |
1169 | } |
1157 | |
1170 | |
1158 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1171 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1159 | { |
1172 | { |
1160 | /* 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 |
… | |
… | |
1286 | object * |
1299 | object * |
1287 | 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) |
1288 | { |
1301 | { |
1289 | assert (!op->flag [FLAG_FREED]); |
1302 | assert (!op->flag [FLAG_FREED]); |
1290 | |
1303 | |
1291 | object *top, *floor = NULL; |
|
|
1292 | |
|
|
1293 | op->remove (); |
1304 | op->remove (); |
1294 | |
1305 | |
1295 | /* Ideally, the caller figures this out. However, it complicates a lot |
1306 | /* 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 |
1307 | * of areas of callers (eg, anything that uses find_free_spot would now |
1297 | * need extra work |
1308 | * need extra work |
1298 | */ |
1309 | */ |
1299 | if (!xy_normalise (m, op->x, op->y)) |
1310 | if (!xy_normalise (m, op->x, op->y)) |
1300 | { |
1311 | { |
1301 | op->destroy (); |
1312 | op->destroy (1); |
1302 | return 0; |
1313 | return 0; |
1303 | } |
1314 | } |
1304 | |
1315 | |
1305 | if (object *more = op->more) |
1316 | if (object *more = op->more) |
1306 | if (!insert_ob_in_map (more, m, originator, flag)) |
1317 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1315 | */ |
1326 | */ |
1316 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1327 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1317 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1328 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1318 | if (object::can_merge (op, tmp)) |
1329 | if (object::can_merge (op, tmp)) |
1319 | { |
1330 | { |
|
|
1331 | // TODO: we atcually want to update tmp, not op, |
|
|
1332 | // but some caller surely breaks when we return tmp |
|
|
1333 | // from here :/ |
1320 | op->nrof += tmp->nrof; |
1334 | op->nrof += tmp->nrof; |
1321 | tmp->destroy (1); |
1335 | tmp->destroy (1); |
1322 | } |
1336 | } |
1323 | |
1337 | |
1324 | 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 */ |
… | |
… | |
1346 | /* since *below* originator, no need to update top */ |
1360 | /* since *below* originator, no need to update top */ |
1347 | originator->below = op; |
1361 | originator->below = op; |
1348 | } |
1362 | } |
1349 | else |
1363 | else |
1350 | { |
1364 | { |
|
|
1365 | object *top, *floor = NULL; |
|
|
1366 | |
1351 | top = ms.bot; |
1367 | top = ms.bot; |
1352 | |
1368 | |
1353 | /* If there are other objects, then */ |
1369 | /* If there are other objects, then */ |
1354 | if (top) |
1370 | if (top) |
1355 | { |
1371 | { |
… | |
… | |
1454 | } |
1470 | } |
1455 | |
1471 | |
1456 | op->map->dirty = true; |
1472 | op->map->dirty = true; |
1457 | |
1473 | |
1458 | if (object *pl = ms.player ()) |
1474 | if (object *pl = ms.player ()) |
1459 | pl->contr->ns->floorbox_update (); |
1475 | //TODO: the floorbox prev/next might need updating |
|
|
1476 | esrv_send_item (pl, op); |
1460 | |
1477 | |
1461 | /* If this object glows, it may affect lighting conditions that are |
1478 | /* If this object glows, it may affect lighting conditions that are |
1462 | * 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 |
1463 | * 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 |
1464 | * on the map will get recalculated. The players could very well |
1481 | * on the map will get recalculated. The players could very well |
… | |
… | |
2565 | &name, |
2582 | &name, |
2566 | title ? "\",title:\"" : "", |
2583 | title ? "\",title:\"" : "", |
2567 | title ? (const char *)title : "", |
2584 | title ? (const char *)title : "", |
2568 | flag_desc (flagdesc, 512), type); |
2585 | flag_desc (flagdesc, 512), type); |
2569 | |
2586 | |
2570 | if (!this->flag[FLAG_REMOVED] && env) |
2587 | if (!flag[FLAG_REMOVED] && env) |
2571 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2588 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2572 | |
2589 | |
2573 | if (map) |
2590 | if (map) |
2574 | 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); |
2575 | |
2592 | |
… | |
… | |
2605 | object::open_container (object *new_container) |
2622 | object::open_container (object *new_container) |
2606 | { |
2623 | { |
2607 | if (container == new_container) |
2624 | if (container == new_container) |
2608 | return; |
2625 | return; |
2609 | |
2626 | |
2610 | if (object *old_container = container) |
2627 | object *old_container = container; |
|
|
2628 | |
|
|
2629 | if (old_container) |
2611 | { |
2630 | { |
2612 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2631 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2613 | return; |
2632 | return; |
2614 | |
2633 | |
2615 | #if 0 |
2634 | #if 0 |
… | |
… | |
2617 | if (object *closer = old_container->inv) |
2636 | if (object *closer = old_container->inv) |
2618 | if (closer->type == CLOSE_CON) |
2637 | if (closer->type == CLOSE_CON) |
2619 | closer->destroy (); |
2638 | closer->destroy (); |
2620 | #endif |
2639 | #endif |
2621 | |
2640 | |
|
|
2641 | // make sure the container is available |
|
|
2642 | esrv_send_item (this, old_container); |
|
|
2643 | |
2622 | old_container->flag [FLAG_APPLIED] = 0; |
2644 | old_container->flag [FLAG_APPLIED] = false; |
2623 | container = 0; |
2645 | container = 0; |
2624 | |
2646 | |
|
|
2647 | // client needs item update to make it work, client bug requires this to be separate |
2625 | esrv_update_item (UPD_FLAGS, this, old_container); |
2648 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2649 | |
2626 | 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)); |
2627 | play_sound (sound_find ("chest_close")); |
2651 | play_sound (sound_find ("chest_close")); |
2628 | } |
2652 | } |
2629 | |
2653 | |
2630 | if (new_container) |
2654 | if (new_container) |
… | |
… | |
2643 | } |
2667 | } |
2644 | #endif |
2668 | #endif |
2645 | |
2669 | |
2646 | 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)); |
2647 | |
2671 | |
|
|
2672 | // make sure the container is available, client bug requires this to be separate |
|
|
2673 | esrv_send_item (this, new_container); |
|
|
2674 | |
2648 | new_container->flag [FLAG_APPLIED] = 1; |
2675 | new_container->flag [FLAG_APPLIED] = true; |
2649 | container = new_container; |
2676 | container = new_container; |
2650 | |
2677 | |
|
|
2678 | // client needs flag change |
2651 | esrv_update_item (UPD_FLAGS, this, new_container); |
2679 | esrv_update_item (UPD_FLAGS, this, new_container); |
2652 | esrv_send_inventory (this, new_container); |
2680 | esrv_send_inventory (this, new_container); |
2653 | play_sound (sound_find ("chest_open")); |
2681 | play_sound (sound_find ("chest_open")); |
2654 | } |
2682 | } |
|
|
2683 | // else if (!old_container->env && contr && contr->ns) |
|
|
2684 | // contr->ns->floorbox_reset (); |
2655 | } |
2685 | } |
2656 | |
2686 | |
2657 | object * |
2687 | object * |
2658 | object::force_find (const shstr name) |
2688 | object::force_find (const shstr name) |
2659 | { |
2689 | { |