… | |
… | |
429 | } |
429 | } |
430 | |
430 | |
431 | /* |
431 | /* |
432 | * Sets the owner and sets the skill and exp pointers to owner's current |
432 | * Sets the owner and sets the skill and exp pointers to owner's current |
433 | * skill and experience objects. |
433 | * skill and experience objects. |
|
|
434 | * ACTUALLY NO! investigate! TODO |
434 | */ |
435 | */ |
435 | void |
436 | void |
436 | object::set_owner (object *owner) |
437 | object::set_owner (object *owner) |
437 | { |
438 | { |
|
|
439 | // allow objects which own objects |
438 | if (!owner) |
440 | if (owner) |
439 | return; |
|
|
440 | |
|
|
441 | /* next line added to allow objects which own objects */ |
|
|
442 | /* Add a check for ownercounts in here, as I got into an endless loop |
|
|
443 | * with the fireball owning a poison cloud which then owned the |
|
|
444 | * fireball. I believe that was caused by one of the objects getting |
|
|
445 | * freed and then another object replacing it. Since the ownercounts |
|
|
446 | * didn't match, this check is valid and I believe that cause is valid. |
|
|
447 | */ |
|
|
448 | while (owner->owner) |
441 | while (owner->owner) |
449 | owner = owner->owner; |
442 | owner = owner->owner; |
450 | |
443 | |
451 | this->owner = owner; |
444 | this->owner = owner; |
452 | } |
445 | } |
453 | |
446 | |
454 | int |
447 | int |
… | |
… | |
1089 | if (map->in_memory == MAP_SAVING) |
1082 | if (map->in_memory == MAP_SAVING) |
1090 | return; |
1083 | return; |
1091 | |
1084 | |
1092 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1085 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1093 | |
1086 | |
|
|
1087 | if (object *pl = ms.player ()) |
|
|
1088 | { |
|
|
1089 | if (pl->container == this) |
|
|
1090 | /* If a container that the player is currently using somehow gets |
|
|
1091 | * removed (most likely destroyed), update the player view |
|
|
1092 | * appropriately. |
|
|
1093 | */ |
|
|
1094 | pl->close_container (); |
|
|
1095 | |
|
|
1096 | pl->contr->ns->floorbox_update (); |
|
|
1097 | } |
|
|
1098 | |
1094 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1099 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1095 | { |
1100 | { |
1096 | /* No point updating the players look faces if he is the object |
1101 | /* No point updating the players look faces if he is the object |
1097 | * being removed. |
1102 | * being removed. |
1098 | */ |
1103 | */ |
1099 | |
|
|
1100 | if (tmp->type == PLAYER && tmp->container == this) |
|
|
1101 | /* If a container that the player is currently using somehow gets |
|
|
1102 | * removed (most likely destroyed), update the player view |
|
|
1103 | * appropriately. |
|
|
1104 | */ |
|
|
1105 | tmp->close_container (); |
|
|
1106 | |
1104 | |
1107 | /* See if object moving off should effect something */ |
1105 | /* See if object moving off should effect something */ |
1108 | if (check_walk_off |
1106 | if (check_walk_off |
1109 | && ((move_type & tmp->move_off) |
1107 | && ((move_type & tmp->move_off) |
1110 | && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1108 | && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
… | |
… | |
1233 | |
1231 | |
1234 | object *top, *floor = NULL; |
1232 | object *top, *floor = NULL; |
1235 | |
1233 | |
1236 | op->remove (); |
1234 | op->remove (); |
1237 | |
1235 | |
1238 | #if 0 |
|
|
1239 | if (!m->active != !op->active) |
|
|
1240 | if (m->active) |
|
|
1241 | op->activate_recursive (); |
|
|
1242 | else |
|
|
1243 | op->deactivate_recursive (); |
|
|
1244 | #endif |
|
|
1245 | |
|
|
1246 | if (out_of_map (m, op->x, op->y)) |
1236 | if (out_of_map (m, op->x, op->y)) |
1247 | { |
1237 | { |
1248 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", op->debug_desc ()); |
1238 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", op->debug_desc ()); |
1249 | #ifdef MANY_CORES |
1239 | #ifdef MANY_CORES |
1250 | /* Better to catch this here, as otherwise the next use of this object |
1240 | /* Better to catch this here, as otherwise the next use of this object |
… | |
… | |
1416 | op->map->touch (); |
1406 | op->map->touch (); |
1417 | } |
1407 | } |
1418 | |
1408 | |
1419 | op->map->dirty = true; |
1409 | op->map->dirty = true; |
1420 | |
1410 | |
1421 | /* If we have a floor, we know the player, if any, will be above |
|
|
1422 | * it, so save a few ticks and start from there. |
|
|
1423 | */ |
|
|
1424 | if (!(flag & INS_MAP_LOAD)) |
1411 | if (!(flag & INS_MAP_LOAD)) |
1425 | if (object *pl = ms.player ()) |
1412 | if (object *pl = ms.player ()) |
1426 | if (pl->contr->ns) |
|
|
1427 | pl->contr->ns->floorbox_update (); |
1413 | pl->contr->ns->floorbox_update (); |
1428 | |
1414 | |
1429 | /* If this object glows, it may affect lighting conditions that are |
1415 | /* If this object glows, it may affect lighting conditions that are |
1430 | * visible to others on this map. But update_all_los is really |
1416 | * visible to others on this map. But update_all_los is really |
1431 | * an inefficient way to do this, as it means los for all players |
1417 | * an inefficient way to do this, as it means los for all players |
1432 | * on the map will get recalculated. The players could very well |
1418 | * on the map will get recalculated. The players could very well |
… | |
… | |
1670 | * be != op, if items are merged. -Tero |
1656 | * be != op, if items are merged. -Tero |
1671 | */ |
1657 | */ |
1672 | object * |
1658 | object * |
1673 | object::insert (object *op) |
1659 | object::insert (object *op) |
1674 | { |
1660 | { |
1675 | object *tmp, *otmp; |
|
|
1676 | |
|
|
1677 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1661 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1678 | op->remove (); |
1662 | op->remove (); |
1679 | |
1663 | |
1680 | if (op->more) |
1664 | if (op->more) |
1681 | { |
1665 | { |
… | |
… | |
1683 | return op; |
1667 | return op; |
1684 | } |
1668 | } |
1685 | |
1669 | |
1686 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1670 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1687 | CLEAR_FLAG (op, FLAG_REMOVED); |
1671 | CLEAR_FLAG (op, FLAG_REMOVED); |
|
|
1672 | |
1688 | if (op->nrof) |
1673 | if (op->nrof) |
1689 | { |
1674 | { |
1690 | for (tmp = inv; tmp != NULL; tmp = tmp->below) |
1675 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1691 | if (object::can_merge (tmp, op)) |
1676 | if (object::can_merge (tmp, op)) |
1692 | { |
1677 | { |
1693 | /* return the original object and remove inserted object |
1678 | /* return the original object and remove inserted object |
1694 | (client needs the original object) */ |
1679 | (client needs the original object) */ |
1695 | tmp->nrof += op->nrof; |
1680 | tmp->nrof += op->nrof; |
… | |
… | |
1714 | add_weight (this, op->weight * op->nrof); |
1699 | add_weight (this, op->weight * op->nrof); |
1715 | } |
1700 | } |
1716 | else |
1701 | else |
1717 | add_weight (this, (op->weight + op->carrying)); |
1702 | add_weight (this, (op->weight + op->carrying)); |
1718 | |
1703 | |
1719 | otmp = this->in_player (); |
1704 | if (object *otmp = this->in_player ()) |
1720 | if (otmp && otmp->contr) |
|
|
1721 | if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1705 | if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1722 | otmp->update_stats (); |
1706 | otmp->update_stats (); |
1723 | |
1707 | |
|
|
1708 | op->owner = 0; // its his/hers now. period. |
1724 | op->map = 0; |
1709 | op->map = 0; |
1725 | op->env = this; |
1710 | op->env = this; |
1726 | op->above = 0; |
1711 | op->above = 0; |
1727 | op->below = 0; |
1712 | op->below = 0; |
1728 | op->x = 0, op->y = 0; |
1713 | op->x = op->y = 0; |
1729 | |
1714 | |
1730 | /* reset the light list and los of the players on the map */ |
1715 | /* reset the light list and los of the players on the map */ |
1731 | if ((op->glow_radius != 0) && map) |
1716 | if (op->glow_radius && map) |
1732 | { |
1717 | { |
1733 | #ifdef DEBUG_LIGHTS |
1718 | #ifdef DEBUG_LIGHTS |
1734 | LOG (llevDebug, " insert_ob_in_ob(): got %s to insert in map/op\n", op->name); |
1719 | LOG (llevDebug, " insert_ob_in_ob(): got %s to insert in map/op\n", op->name); |
1735 | #endif /* DEBUG_LIGHTS */ |
1720 | #endif /* DEBUG_LIGHTS */ |
1736 | if (map->darkness) |
1721 | if (map->darkness) |
… | |
… | |
2340 | * Cf 0.91.3 - don't let WIZ's pick up anything - will likely cause |
2325 | * Cf 0.91.3 - don't let WIZ's pick up anything - will likely cause |
2341 | * core dumps if they do. |
2326 | * core dumps if they do. |
2342 | * |
2327 | * |
2343 | * Add a check so we can't pick up invisible objects (0.93.8) |
2328 | * Add a check so we can't pick up invisible objects (0.93.8) |
2344 | */ |
2329 | */ |
2345 | |
|
|
2346 | int |
2330 | int |
2347 | can_pick (const object *who, const object *item) |
2331 | can_pick (const object *who, const object *item) |
2348 | { |
2332 | { |
2349 | return /*QUERY_FLAG(who,FLAG_WIZ)|| */ |
2333 | return /*QUERY_FLAG(who,FLAG_WIZ)|| */ |
2350 | (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && |
2334 | (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && |
… | |
… | |
2608 | &name, |
2592 | &name, |
2609 | title ? "\",title:\"" : "", |
2593 | title ? "\",title:\"" : "", |
2610 | title ? (const char *)title : "", |
2594 | title ? (const char *)title : "", |
2611 | flag_desc (flagdesc, 512), type); |
2595 | flag_desc (flagdesc, 512), type); |
2612 | |
2596 | |
2613 | if (env) |
2597 | if (!this->flag[FLAG_REMOVED] && env) |
2614 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2598 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2615 | |
2599 | |
2616 | if (map) |
2600 | if (map) |
2617 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2601 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2618 | |
2602 | |
… | |
… | |
2665 | old_container->flag [FLAG_APPLIED] = 0; |
2649 | old_container->flag [FLAG_APPLIED] = 0; |
2666 | container = 0; |
2650 | container = 0; |
2667 | |
2651 | |
2668 | esrv_update_item (UPD_FLAGS, this, old_container); |
2652 | esrv_update_item (UPD_FLAGS, this, old_container); |
2669 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2653 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
|
|
2654 | play_sound (sound_find ("chest_close")); |
2670 | } |
2655 | } |
2671 | |
2656 | |
2672 | if (new_container) |
2657 | if (new_container) |
2673 | { |
2658 | { |
2674 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
2659 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
… | |
… | |
2690 | new_container->flag [FLAG_APPLIED] = 1; |
2675 | new_container->flag [FLAG_APPLIED] = 1; |
2691 | container = new_container; |
2676 | container = new_container; |
2692 | |
2677 | |
2693 | esrv_update_item (UPD_FLAGS, this, new_container); |
2678 | esrv_update_item (UPD_FLAGS, this, new_container); |
2694 | esrv_send_inventory (this, new_container); |
2679 | esrv_send_inventory (this, new_container); |
|
|
2680 | play_sound (sound_find ("chest_open")); |
2695 | } |
2681 | } |
2696 | } |
2682 | } |
2697 | |
2683 | |
2698 | object * |
2684 | object * |
2699 | object::force_find (const shstr name) |
2685 | object::force_find (const shstr name) |
… | |
… | |
2725 | force->flag [FLAG_APPLIED] = true; |
2711 | force->flag [FLAG_APPLIED] = true; |
2726 | |
2712 | |
2727 | insert (force); |
2713 | insert (force); |
2728 | } |
2714 | } |
2729 | |
2715 | |
|
|
2716 | void |
|
|
2717 | object::play_sound (faceidx sound) const |
|
|
2718 | { |
|
|
2719 | if (!sound) |
|
|
2720 | return; |
|
|
2721 | |
|
|
2722 | if (flag [FLAG_REMOVED]) |
|
|
2723 | return; |
|
|
2724 | |
|
|
2725 | if (env) |
|
|
2726 | { |
|
|
2727 | if (object *pl = in_player ()) |
|
|
2728 | pl->contr->play_sound (sound); |
|
|
2729 | } |
|
|
2730 | else |
|
|
2731 | map->play_sound (sound, x, y); |
|
|
2732 | } |
|
|
2733 | |