Crossfire Server, Branch 1.12  R12190
deep_swamp.c
Go to the documentation of this file.
00001 /*
00002     CrossFire, A Multiplayer game for X-windows
00003 
00004     Copyright (C) 2007 Mark Wedel & Crossfire Development Team
00005     Copyright (C) 1992 Frank Tore Johansen
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 
00021     The authors can be reached via e-mail at crossfire-devel@real-time.com
00022 */
00023 
00027 #include <global.h>
00028 #include <ob_methods.h>
00029 #include <ob_types.h>
00030 #include <sounds.h>
00031 #include <sproto.h>
00032 
00033 static method_ret deep_swamp_type_process(ob_methods *context, object *op);
00034 static method_ret deep_swamp_type_move_on(ob_methods *context, object *trap, object *victim, object *originator);
00035 
00039 void init_type_deep_swamp(void) {
00040     register_move_on(DEEP_SWAMP, deep_swamp_type_move_on);
00041     register_process(DEEP_SWAMP, deep_swamp_type_process);
00042 }
00043 
00050 static method_ret deep_swamp_type_process(ob_methods *context, object *op) {
00051     object *above = op->above;
00052     object *nabove;
00053     int got_player = 0;
00054 
00055     while (above) {
00056         nabove = above->above;
00057         if (above->type == PLAYER
00058         && !(above->move_type&MOVE_FLYING)
00059         && above->stats.hp >= 0
00060         && !QUERY_FLAG(above, FLAG_WIZ)) {
00061             object *woodsman = find_obj_by_type_subtype(above, SKILL, SK_WOODSMAN);
00062             got_player = 1;
00063             if (op->stats.food < 1) {
00064                 LOG(llevDebug, "move_deep_swamp(): player is here, but state is %d\n", op->stats.food);
00065                 op->stats.food = 1;
00066             }
00067             if (op->stats.food < 10) {
00068                 if (rndm(0, 2) == 0) {
00069                     draw_ext_info_format(NDI_UNIQUE, 0, above, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SWAMP,
00070                         "You are down to your waist in the wet %s.",
00071                         "You are down to your waist in the wet %s.",
00072                         op->name);
00073                         op->stats.food = woodsman ? op->stats.food+1 : 10;
00074                         above->speed_left -= op->move_slow_penalty;
00075                 }
00076             } else if (op->stats.food < 20) {
00077                 if (rndm(0, 2) == 0) {
00078                     draw_ext_info_format(NDI_UNIQUE|NDI_RED, 0, above, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SWAMP,
00079                         "You are down to your NECK in the dangerous %s.",
00080                         "You are down to your NECK in the dangerous %s.",
00081                         op->name);
00082                     op->stats.food = woodsman ? op->stats.food+1 : 20;
00083                     snprintf(above->contr->killer, sizeof(above->contr->killer), "drowning in a %s", op->name);
00084                     above->stats.hp--;
00085                     above->speed_left -= op->move_slow_penalty;
00086                 }
00087             } else if (rndm(0, 4) == 0) {
00088                 op->stats.food = 0;
00089                 draw_ext_info_format(NDI_UNIQUE|NDI_ALL, 1, NULL, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
00090                     "%s disappeared into a %s.", "%s disappeared into a %s.",
00091                     above->name, op->name);
00092                 snprintf(above->contr->killer, sizeof(above->contr->killer), "drowning in a %s", op->name);
00093                 above->stats.hp = -1;
00094                 kill_player(above); /* player dies in the swamp */
00095             }
00096         } else if (!QUERY_FLAG(above, FLAG_ALIVE)
00097         && !(above->move_type&MOVE_FLYING)
00098         && !(QUERY_FLAG(above, FLAG_IS_FLOOR))
00099         && !(QUERY_FLAG(above, FLAG_OVERLAY_FLOOR))
00100         && !(QUERY_FLAG(above, FLAG_NO_PICK))) {
00101             if (rndm(0, 2) == 0)
00102                 decrease_ob(above);
00103         }
00104         above = nabove;
00105     }
00106     if (!got_player)
00107         op->stats.food = 1;
00108     return METHOD_OK;
00109 }
00110 
00119 static method_ret deep_swamp_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) {
00120     if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
00121         return METHOD_OK;
00122     if (victim->type == PLAYER
00123     && victim->stats.hp >= 0
00124     && !(victim->move_type&MOVE_FLYING)) {
00125         draw_ext_info_format(NDI_UNIQUE, 0, victim, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SWAMP,
00126             "You are down to your knees in the %s.",
00127             "You are down to your knees in the %s.", trap->name);
00128         trap->stats.food = 1;
00129         victim->speed_left -= trap->move_slow_penalty;
00130     }
00131     common_post_ob_move_on(trap, victim, originator);
00132     return METHOD_OK;
00133 }