… | |
… | |
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 |
… | |
… | |
1238 | |
1231 | |
1239 | object *top, *floor = NULL; |
1232 | object *top, *floor = NULL; |
1240 | |
1233 | |
1241 | op->remove (); |
1234 | op->remove (); |
1242 | |
1235 | |
1243 | #if 0 |
|
|
1244 | if (!m->active != !op->active) |
|
|
1245 | if (m->active) |
|
|
1246 | op->activate_recursive (); |
|
|
1247 | else |
|
|
1248 | op->deactivate_recursive (); |
|
|
1249 | #endif |
|
|
1250 | |
|
|
1251 | if (out_of_map (m, op->x, op->y)) |
1236 | if (out_of_map (m, op->x, op->y)) |
1252 | { |
1237 | { |
1253 | 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 ()); |
1254 | #ifdef MANY_CORES |
1239 | #ifdef MANY_CORES |
1255 | /* 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 |
… | |
… | |
1421 | op->map->touch (); |
1406 | op->map->touch (); |
1422 | } |
1407 | } |
1423 | |
1408 | |
1424 | op->map->dirty = true; |
1409 | op->map->dirty = true; |
1425 | |
1410 | |
1426 | /* If we have a floor, we know the player, if any, will be above |
|
|
1427 | * it, so save a few ticks and start from there. |
|
|
1428 | */ |
|
|
1429 | if (!(flag & INS_MAP_LOAD)) |
1411 | if (!(flag & INS_MAP_LOAD)) |
1430 | if (object *pl = ms.player ()) |
1412 | if (object *pl = ms.player ()) |
1431 | pl->contr->ns->floorbox_update (); |
1413 | pl->contr->ns->floorbox_update (); |
1432 | |
1414 | |
1433 | /* If this object glows, it may affect lighting conditions that are |
1415 | /* If this object glows, it may affect lighting conditions that are |
… | |
… | |
1674 | * be != op, if items are merged. -Tero |
1656 | * be != op, if items are merged. -Tero |
1675 | */ |
1657 | */ |
1676 | object * |
1658 | object * |
1677 | object::insert (object *op) |
1659 | object::insert (object *op) |
1678 | { |
1660 | { |
1679 | object *tmp, *otmp; |
|
|
1680 | |
|
|
1681 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1661 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1682 | op->remove (); |
1662 | op->remove (); |
1683 | |
1663 | |
1684 | if (op->more) |
1664 | if (op->more) |
1685 | { |
1665 | { |
… | |
… | |
1687 | return op; |
1667 | return op; |
1688 | } |
1668 | } |
1689 | |
1669 | |
1690 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1670 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1691 | CLEAR_FLAG (op, FLAG_REMOVED); |
1671 | CLEAR_FLAG (op, FLAG_REMOVED); |
|
|
1672 | |
1692 | if (op->nrof) |
1673 | if (op->nrof) |
1693 | { |
1674 | { |
1694 | for (tmp = inv; tmp != NULL; tmp = tmp->below) |
1675 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1695 | if (object::can_merge (tmp, op)) |
1676 | if (object::can_merge (tmp, op)) |
1696 | { |
1677 | { |
1697 | /* return the original object and remove inserted object |
1678 | /* return the original object and remove inserted object |
1698 | (client needs the original object) */ |
1679 | (client needs the original object) */ |
1699 | tmp->nrof += op->nrof; |
1680 | tmp->nrof += op->nrof; |
… | |
… | |
1718 | add_weight (this, op->weight * op->nrof); |
1699 | add_weight (this, op->weight * op->nrof); |
1719 | } |
1700 | } |
1720 | else |
1701 | else |
1721 | add_weight (this, (op->weight + op->carrying)); |
1702 | add_weight (this, (op->weight + op->carrying)); |
1722 | |
1703 | |
1723 | otmp = this->in_player (); |
1704 | if (object *otmp = this->in_player ()) |
1724 | if (otmp && otmp->contr) |
|
|
1725 | if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1705 | if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1726 | otmp->update_stats (); |
1706 | otmp->update_stats (); |
1727 | |
1707 | |
|
|
1708 | op->owner = 0; // its his/hers now. period. |
1728 | op->map = 0; |
1709 | op->map = 0; |
1729 | op->env = this; |
1710 | op->env = this; |
1730 | op->above = 0; |
1711 | op->above = 0; |
1731 | op->below = 0; |
1712 | op->below = 0; |
1732 | op->x = 0, op->y = 0; |
1713 | op->x = op->y = 0; |
1733 | |
1714 | |
1734 | /* 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 */ |
1735 | if ((op->glow_radius != 0) && map) |
1716 | if (op->glow_radius && map) |
1736 | { |
1717 | { |
1737 | #ifdef DEBUG_LIGHTS |
1718 | #ifdef DEBUG_LIGHTS |
1738 | 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); |
1739 | #endif /* DEBUG_LIGHTS */ |
1720 | #endif /* DEBUG_LIGHTS */ |
1740 | if (map->darkness) |
1721 | if (map->darkness) |
… | |
… | |
2611 | &name, |
2592 | &name, |
2612 | title ? "\",title:\"" : "", |
2593 | title ? "\",title:\"" : "", |
2613 | title ? (const char *)title : "", |
2594 | title ? (const char *)title : "", |
2614 | flag_desc (flagdesc, 512), type); |
2595 | flag_desc (flagdesc, 512), type); |
2615 | |
2596 | |
2616 | if (env) |
2597 | if (!this->flag[FLAG_REMOVED] && env) |
2617 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2598 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2618 | |
2599 | |
2619 | if (map) |
2600 | if (map) |
2620 | 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); |
2621 | |
2602 | |
… | |
… | |
2668 | old_container->flag [FLAG_APPLIED] = 0; |
2649 | old_container->flag [FLAG_APPLIED] = 0; |
2669 | container = 0; |
2650 | container = 0; |
2670 | |
2651 | |
2671 | esrv_update_item (UPD_FLAGS, this, old_container); |
2652 | esrv_update_item (UPD_FLAGS, this, old_container); |
2672 | 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")); |
2673 | } |
2655 | } |
2674 | |
2656 | |
2675 | if (new_container) |
2657 | if (new_container) |
2676 | { |
2658 | { |
2677 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
2659 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
… | |
… | |
2693 | new_container->flag [FLAG_APPLIED] = 1; |
2675 | new_container->flag [FLAG_APPLIED] = 1; |
2694 | container = new_container; |
2676 | container = new_container; |
2695 | |
2677 | |
2696 | esrv_update_item (UPD_FLAGS, this, new_container); |
2678 | esrv_update_item (UPD_FLAGS, this, new_container); |
2697 | esrv_send_inventory (this, new_container); |
2679 | esrv_send_inventory (this, new_container); |
|
|
2680 | play_sound (sound_find ("chest_open")); |
2698 | } |
2681 | } |
2699 | } |
2682 | } |
2700 | |
2683 | |
2701 | object * |
2684 | object * |
2702 | object::force_find (const shstr name) |
2685 | object::force_find (const shstr name) |
… | |
… | |
2728 | force->flag [FLAG_APPLIED] = true; |
2711 | force->flag [FLAG_APPLIED] = true; |
2729 | |
2712 | |
2730 | insert (force); |
2713 | insert (force); |
2731 | } |
2714 | } |
2732 | |
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 | |