Atrinik Server 2.5
types/poison.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_poison(object *op, object *tmp)
00037 {
00038     if (op->type == PLAYER)
00039     {
00040         play_sound_player_only(CONTR(op), CMD_SOUND_EFFECT, "poison.ogg", 0, 0, 0, 0);
00041         new_draw_info(0, COLOR_WHITE, op, "Yech! That tasted poisonous!");
00042         strcpy(CONTR(op)->killer, "poisonous food");
00043     }
00044 
00045     if (tmp->stats.dam)
00046     {
00047         /* internal damage part will take care about our poison */
00048         hit_player(op, tmp->stats.dam, tmp, AT_POISON);
00049     }
00050 
00051     op->stats.food -= op->stats.food / 4;
00052     decrease_ob(tmp);
00053 }
00054 
00058 void poison_more(object *op)
00059 {
00060     if (op->env == NULL || !IS_LIVE(op->env) || op->env->stats.hp < 0)
00061     {
00062         remove_ob(op);
00063         check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
00064         return;
00065     }
00066 
00067     if (!op->stats.food)
00068     {
00069         /* need to remove the object before fix_player is called, else fix_player
00070          * will not do anything. */
00071         if (op->env->type == PLAYER)
00072         {
00073             CLEAR_FLAG(op, FLAG_APPLIED);
00074             fix_player(op->env);
00075             new_draw_info(0, COLOR_WHITE, op->env, "You feel much better now.");
00076         }
00077 
00078         remove_ob(op);
00079         check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
00080         return;
00081     }
00082 
00083     if (op->env->type == PLAYER)
00084     {
00085         op->env->stats.food--;
00086         new_draw_info(0, COLOR_WHITE, op->env, "You feel very sick...");
00087     }
00088 
00089     /* If we successfully do damage to the player, the poison effects
00090      * worsen... */
00091     if (hit_player(op->env, op->stats.dam, op, AT_INTERNAL))
00092     {
00093         int i;
00094 
00095         /* Pick some stats to 'deplete'. */
00096         for (i = 0; i < NUM_STATS; i++)
00097         {
00098             if (!(RANDOM() % 2) && get_attr_value(&op->stats, i) > -(MAX_STAT / 2))
00099             {
00100                 /* Now deplete the stat. Relatively small chance that the depletion
00101                  * will be worse than usual. */
00102                 change_attr_value(&op->stats, i, !(RANDOM() % 6) ? -2 : -1);
00103                 new_draw_info(0, COLOR_GRAY, op->env, lose_msg[i]);
00104             }
00105         }
00106 
00107         fix_player(op->env);
00108     }
00109 }