Atrinik Server 2.5
types/treasure.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 
00036 void apply_treasure(object *op, object *tmp)
00037 {
00038     object *treas;
00039     tag_t tmp_tag = tmp->count, op_tag = op->count;
00040 
00041     /* Nice side effect of new treasure creation method is that the
00042      * treasure for the chest is done when the chest is created, and put
00043      * into the chest's inventory. So that when the chest burns up, the
00044      * items still exist. Also prevents people from moving chests to more
00045      * difficult maps to get better treasure. */
00046     treas = tmp->inv;
00047 
00048     if (tmp->map)
00049     {
00050         play_sound_map(tmp->map, CMD_SOUND_EFFECT, "open_container.ogg", tmp->x, tmp->y, 0, 0);
00051     }
00052 
00053     /* msg like "the chest crumbles to dust" */
00054     if (tmp->msg)
00055     {
00056         new_draw_info(0, COLOR_WHITE, op, tmp->msg);
00057     }
00058 
00059     if (treas == NULL)
00060     {
00061         new_draw_info(0, COLOR_WHITE, op, "The chest was empty.");
00062         decrease_ob(tmp);
00063         return;
00064     }
00065     do
00066     {
00067         remove_ob(treas);
00068         check_walk_off(treas, NULL, MOVE_APPLY_VANISHED);
00069         new_draw_info_format(0, COLOR_WHITE, op, "You find %s in the chest.", query_name(treas, NULL));
00070         treas->x = op->x,treas->y = op->y;
00071 
00072         /* Monsters can be trapped in treasure chests */
00073         if (treas->type == MONSTER)
00074         {
00075             int i = find_free_spot(treas->arch, NULL, op->map, treas->x, treas->y, 0, 9);
00076 
00077             if (i != -1)
00078             {
00079                 treas->x += freearr_x[i];
00080                 treas->y += freearr_y[i];
00081             }
00082 
00083             fix_monster(treas);
00084         }
00085 
00086         treas = insert_ob_in_map(treas, op->map, op, 0);
00087 
00088         if (treas && treas->type == RUNE && treas->level && IS_LIVE(op))
00089         {
00090             spring_trap(treas, op);
00091         }
00092 
00093         if (was_destroyed(op, op_tag) || was_destroyed(tmp, tmp_tag))
00094         {
00095             break;
00096         }
00097     }
00098     while ((treas = tmp->inv) != NULL);
00099 
00100     if (!was_destroyed(tmp, tmp_tag) && tmp->inv == NULL)
00101     {
00102         decrease_ob(tmp);
00103     }
00104 }