--- deliantra/server/common/object.C 2007/08/08 04:52:59 1.174 +++ deliantra/server/common/object.C 2007/08/20 19:13:10 1.183 @@ -431,22 +431,15 @@ /* * Sets the owner and sets the skill and exp pointers to owner's current * skill and experience objects. + * ACTUALLY NO! investigate! TODO */ void object::set_owner (object *owner) { - if (!owner) - return; - - /* next line added to allow objects which own objects */ - /* Add a check for ownercounts in here, as I got into an endless loop - * with the fireball owning a poison cloud which then owned the - * fireball. I believe that was caused by one of the objects getting - * freed and then another object replacing it. Since the ownercounts - * didn't match, this check is valid and I believe that cause is valid. - */ - while (owner->owner) - owner = owner->owner; + // allow objects which own objects + if (owner) + while (owner->owner) + owner = owner->owner; this->owner = owner; } @@ -1091,18 +1084,23 @@ int check_walk_off = !flag [FLAG_NO_APPLY]; - for (tmp = ms.bot; tmp; tmp = tmp->above) + if (object *pl = ms.player ()) { - /* No point updating the players look faces if he is the object - * being removed. - */ - - if (tmp->type == PLAYER && tmp->container == this) + if (pl->container == this) /* If a container that the player is currently using somehow gets * removed (most likely destroyed), update the player view * appropriately. */ - tmp->close_container (); + pl->close_container (); + + pl->contr->ns->floorbox_update (); + } + + for (tmp = ms.bot; tmp; tmp = tmp->above) + { + /* No point updating the players look faces if he is the object + * being removed. + */ /* See if object moving off should effect something */ if (check_walk_off @@ -1235,14 +1233,6 @@ op->remove (); -#if 0 - if (!m->active != !op->active) - if (m->active) - op->activate_recursive (); - else - op->deactivate_recursive (); -#endif - if (out_of_map (m, op->x, op->y)) { LOG (llevError, "Trying to insert object outside the map.\n%s\n", op->debug_desc ()); @@ -1418,13 +1408,9 @@ op->map->dirty = true; - /* If we have a floor, we know the player, if any, will be above - * it, so save a few ticks and start from there. - */ if (!(flag & INS_MAP_LOAD)) if (object *pl = ms.player ()) - if (pl->contr->ns) - pl->contr->ns->floorbox_update (); + pl->contr->ns->floorbox_update (); /* If this object glows, it may affect lighting conditions that are * visible to others on this map. But update_all_los is really @@ -1672,8 +1658,6 @@ object * object::insert (object *op) { - object *tmp, *otmp; - if (!QUERY_FLAG (op, FLAG_REMOVED)) op->remove (); @@ -1685,9 +1669,10 @@ CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); CLEAR_FLAG (op, FLAG_REMOVED); + if (op->nrof) { - for (tmp = inv; tmp != NULL; tmp = tmp->below) + for (object *tmp = inv; tmp; tmp = tmp->below) if (object::can_merge (tmp, op)) { /* return the original object and remove inserted object @@ -1716,19 +1701,19 @@ else add_weight (this, (op->weight + op->carrying)); - otmp = this->in_player (); - if (otmp && otmp->contr) - if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) + if (object *otmp = this->in_player ()) + if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) otmp->update_stats (); - op->map = 0; - op->env = this; + op->owner = 0; // its his/hers now. period. + op->map = 0; + op->env = this; op->above = 0; op->below = 0; - op->x = 0, op->y = 0; + op->x = op->y = 0; /* reset the light list and los of the players on the map */ - if ((op->glow_radius != 0) && map) + if (op->glow_radius && map) { #ifdef DEBUG_LIGHTS LOG (llevDebug, " insert_ob_in_ob(): got %s to insert in map/op\n", op->name); @@ -2342,7 +2327,6 @@ * * Add a check so we can't pick up invisible objects (0.93.8) */ - int can_pick (const object *who, const object *item) { @@ -2610,7 +2594,7 @@ title ? (const char *)title : "", flag_desc (flagdesc, 512), type); - if (env) + if (!this->flag[FLAG_REMOVED] && env) p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); if (map) @@ -2667,6 +2651,7 @@ esrv_update_item (UPD_FLAGS, this, old_container); new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); + play_sound (sound_find ("chest_close")); } if (new_container) @@ -2692,6 +2677,7 @@ esrv_update_item (UPD_FLAGS, this, new_container); esrv_send_inventory (this, new_container); + play_sound (sound_find ("chest_open")); } } @@ -2727,3 +2713,21 @@ insert (force); } +void +object::play_sound (faceidx sound) const +{ + if (!sound) + return; + + if (flag [FLAG_REMOVED]) + return; + + if (env) + { + if (object *pl = in_player ()) + pl->contr->play_sound (sound); + } + else + map->play_sound (sound, x, y); +} +