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