… | |
… | |
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 | } |
… | |
… | |
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 | destroy_inv (!destroy_inventory); |
1038 | destroy_inv (!destroy_inventory); |
1032 | |
1039 | |
1033 | if (is_head ()) |
1040 | if (is_head ()) |
1034 | if (sound_destroy) |
1041 | if (sound_destroy) |
1035 | play_sound (sound_destroy); |
1042 | play_sound (sound_destroy); |
… | |
… | |
1055 | if (flag [FLAG_REMOVED]) |
1062 | if (flag [FLAG_REMOVED]) |
1056 | return; |
1063 | return; |
1057 | |
1064 | |
1058 | INVOKE_OBJECT (REMOVE, this); |
1065 | INVOKE_OBJECT (REMOVE, this); |
1059 | |
1066 | |
1060 | if (object *pl = visible_to ()) |
|
|
1061 | esrv_del_item (pl->contr, count); |
|
|
1062 | |
|
|
1063 | flag [FLAG_REMOVED] = true; |
1067 | flag [FLAG_REMOVED] = true; |
1064 | |
1068 | |
1065 | if (more) |
1069 | if (more) |
1066 | more->remove (); |
1070 | more->remove (); |
1067 | |
1071 | |
… | |
… | |
1069 | * In this case, the object to be removed is in someones |
1073 | * In this case, the object to be removed is in someones |
1070 | * inventory. |
1074 | * inventory. |
1071 | */ |
1075 | */ |
1072 | if (env) |
1076 | if (env) |
1073 | { |
1077 | { |
|
|
1078 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1079 | if (object *pl = visible_to ()) |
|
|
1080 | esrv_del_item (pl->contr, count); |
|
|
1081 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1082 | |
1074 | adjust_weight (env, -total_weight ()); |
1083 | adjust_weight (env, -total_weight ()); |
1075 | |
1084 | |
1076 | *(above ? &above->below : &env->inv) = below; |
1085 | *(above ? &above->below : &env->inv) = below; |
1077 | |
1086 | |
1078 | if (below) |
1087 | if (below) |
… | |
… | |
1096 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1105 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1097 | otmp->update_stats (); |
1106 | otmp->update_stats (); |
1098 | } |
1107 | } |
1099 | else if (map) |
1108 | else if (map) |
1100 | { |
1109 | { |
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; |
1110 | map->dirty = true; |
1114 | mapspace &ms = this->ms (); |
1111 | mapspace &ms = this->ms (); |
|
|
1112 | |
|
|
1113 | if (object *pl = ms.player ()) |
|
|
1114 | { |
|
|
1115 | if (type == PLAYER) // this == pl(!) |
|
|
1116 | { |
|
|
1117 | // leaving a spot always closes any open container on the ground |
|
|
1118 | if (container && !container->env) |
|
|
1119 | // this causes spurious floorbox updates, but it ensures |
|
|
1120 | // that the CLOSE event is being sent. |
|
|
1121 | close_container (); |
|
|
1122 | |
|
|
1123 | --map->players; |
|
|
1124 | map->touch (); |
|
|
1125 | } |
|
|
1126 | else if (pl->container == this) |
|
|
1127 | { |
|
|
1128 | // removing a container should close it |
|
|
1129 | close_container (); |
|
|
1130 | } |
|
|
1131 | |
|
|
1132 | esrv_del_item (pl->contr, count); |
|
|
1133 | } |
1115 | |
1134 | |
1116 | /* link the object above us */ |
1135 | /* link the object above us */ |
1117 | if (above) |
1136 | if (above) |
1118 | above->below = below; |
1137 | above->below = below; |
1119 | else |
1138 | else |
… | |
… | |
1149 | * removed (most likely destroyed), update the player view |
1168 | * removed (most likely destroyed), update the player view |
1150 | * appropriately. |
1169 | * appropriately. |
1151 | */ |
1170 | */ |
1152 | pl->close_container (); |
1171 | pl->close_container (); |
1153 | |
1172 | |
|
|
1173 | //TODO: the floorbox prev/next might need updating |
1154 | esrv_del_item (pl, count); |
1174 | esrv_del_item (pl->contr, count); |
1155 | } |
1175 | } |
1156 | |
1176 | |
1157 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1177 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1158 | { |
1178 | { |
1159 | /* No point updating the players look faces if he is the object |
1179 | /* No point updating the players look faces if he is the object |
… | |
… | |
1285 | object * |
1305 | object * |
1286 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1306 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1287 | { |
1307 | { |
1288 | assert (!op->flag [FLAG_FREED]); |
1308 | assert (!op->flag [FLAG_FREED]); |
1289 | |
1309 | |
1290 | object *top, *floor = NULL; |
|
|
1291 | |
|
|
1292 | op->remove (); |
1310 | op->remove (); |
1293 | |
1311 | |
1294 | /* Ideally, the caller figures this out. However, it complicates a lot |
1312 | /* 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 |
1313 | * of areas of callers (eg, anything that uses find_free_spot would now |
1296 | * need extra work |
1314 | * need extra work |
… | |
… | |
1314 | */ |
1332 | */ |
1315 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1333 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1316 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1334 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1317 | if (object::can_merge (op, tmp)) |
1335 | if (object::can_merge (op, tmp)) |
1318 | { |
1336 | { |
|
|
1337 | // TODO: we atcually want to update tmp, not op, |
|
|
1338 | // but some caller surely breaks when we return tmp |
|
|
1339 | // from here :/ |
1319 | op->nrof += tmp->nrof; |
1340 | op->nrof += tmp->nrof; |
1320 | tmp->destroy (1); |
1341 | tmp->destroy (1); |
1321 | } |
1342 | } |
1322 | |
1343 | |
1323 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1344 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1345 | /* since *below* originator, no need to update top */ |
1366 | /* since *below* originator, no need to update top */ |
1346 | originator->below = op; |
1367 | originator->below = op; |
1347 | } |
1368 | } |
1348 | else |
1369 | else |
1349 | { |
1370 | { |
|
|
1371 | object *top, *floor = NULL; |
|
|
1372 | |
1350 | top = ms.bot; |
1373 | top = ms.bot; |
1351 | |
1374 | |
1352 | /* If there are other objects, then */ |
1375 | /* If there are other objects, then */ |
1353 | if (top) |
1376 | if (top) |
1354 | { |
1377 | { |
… | |
… | |
1453 | } |
1476 | } |
1454 | |
1477 | |
1455 | op->map->dirty = true; |
1478 | op->map->dirty = true; |
1456 | |
1479 | |
1457 | if (object *pl = ms.player ()) |
1480 | if (object *pl = ms.player ()) |
|
|
1481 | //TODO: the floorbox prev/next might need updating |
1458 | esrv_send_item (pl, op); |
1482 | esrv_send_item (pl, op); |
1459 | |
1483 | |
1460 | /* If this object glows, it may affect lighting conditions that are |
1484 | /* If this object glows, it may affect lighting conditions that are |
1461 | * visible to others on this map. But update_all_los is really |
1485 | * 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 |
1486 | * an inefficient way to do this, as it means los for all players |
… | |
… | |
2604 | object::open_container (object *new_container) |
2628 | object::open_container (object *new_container) |
2605 | { |
2629 | { |
2606 | if (container == new_container) |
2630 | if (container == new_container) |
2607 | return; |
2631 | return; |
2608 | |
2632 | |
2609 | if (object *old_container = container) |
2633 | object *old_container = container; |
|
|
2634 | |
|
|
2635 | if (old_container) |
2610 | { |
2636 | { |
2611 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2637 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2612 | return; |
2638 | return; |
2613 | |
2639 | |
2614 | #if 0 |
2640 | #if 0 |
… | |
… | |
2616 | if (object *closer = old_container->inv) |
2642 | if (object *closer = old_container->inv) |
2617 | if (closer->type == CLOSE_CON) |
2643 | if (closer->type == CLOSE_CON) |
2618 | closer->destroy (); |
2644 | closer->destroy (); |
2619 | #endif |
2645 | #endif |
2620 | |
2646 | |
|
|
2647 | // make sure the container is available |
|
|
2648 | esrv_send_item (this, old_container); |
|
|
2649 | |
2621 | old_container->flag [FLAG_APPLIED] = false; |
2650 | old_container->flag [FLAG_APPLIED] = false; |
2622 | container = 0; |
2651 | container = 0; |
2623 | |
2652 | |
|
|
2653 | // client needs item update to make it work, client bug requires this to be separate |
2624 | esrv_update_item (UPD_FLAGS, this, old_container); |
2654 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2655 | |
2625 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2656 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2626 | play_sound (sound_find ("chest_close")); |
2657 | play_sound (sound_find ("chest_close")); |
2627 | } |
2658 | } |
2628 | |
2659 | |
2629 | if (new_container) |
2660 | if (new_container) |
… | |
… | |
2642 | } |
2673 | } |
2643 | #endif |
2674 | #endif |
2644 | |
2675 | |
2645 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2676 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2646 | |
2677 | |
|
|
2678 | // make sure the container is available, client bug requires this to be separate |
|
|
2679 | esrv_send_item (this, new_container); |
|
|
2680 | |
2647 | new_container->flag [FLAG_APPLIED] = true; |
2681 | new_container->flag [FLAG_APPLIED] = true; |
2648 | container = new_container; |
2682 | container = new_container; |
2649 | |
2683 | |
|
|
2684 | // client needs flag change |
2650 | esrv_update_item (UPD_FLAGS, this, new_container); |
2685 | esrv_update_item (UPD_FLAGS, this, new_container); |
2651 | esrv_send_inventory (this, new_container); |
2686 | esrv_send_inventory (this, new_container); |
2652 | play_sound (sound_find ("chest_open")); |
2687 | play_sound (sound_find ("chest_open")); |
2653 | } |
2688 | } |
|
|
2689 | // else if (!old_container->env && contr && contr->ns) |
|
|
2690 | // contr->ns->floorbox_reset (); |
2654 | } |
2691 | } |
2655 | |
2692 | |
2656 | object * |
2693 | object * |
2657 | object::force_find (const shstr name) |
2694 | object::force_find (const shstr name) |
2658 | { |
2695 | { |