Crossfire Server, Branch 1.12  R12190
trapdoor.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 trapdoor_type_move_on(ob_methods *context, object *trap, object *victim, object *originator);
00034 
00038 void init_type_trapdoor(void) {
00039     register_move_on(TRAPDOOR, trapdoor_type_move_on);
00040 }
00049 static method_ret trapdoor_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) {
00050     int max, sound_was_played;
00051     object *ab, *ab_next;
00052     if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
00053         return METHOD_OK;
00054     if (!trap->value) {
00055         int tot;
00056 
00057         for (ab = trap->above, tot = 0; ab != NULL; ab = ab->above)
00058             if ((ab->move_type && trap->move_on) || ab->move_type == 0)
00059                 tot += (ab->nrof ? ab->nrof : 1)*ab->weight+ab->carrying;
00060 
00061         if (!(trap->value = (tot > trap->weight) ? 1 : 0)) {
00062             common_post_ob_move_on(trap, victim, originator);
00063             return METHOD_OK;
00064         }
00065         SET_ANIMATION(trap, trap->value);
00066         update_object(trap, UP_OBJ_FACE);
00067     }
00068 
00069     for (ab = trap->above, max = 100, sound_was_played = 0; --max && ab; ab = ab_next) {
00070         /* need to set this up, since if we do transfer the object,
00071          * ab->above would be bogus
00072          */
00073         ab_next = ab->above;
00074 
00075         if ((ab->move_type && trap->move_on) || ab->move_type == 0) {
00076             if (!sound_was_played) {
00077                 play_sound_map(SOUND_TYPE_GROUND, trap, 0, "fall hole");
00078                 sound_was_played = 1;
00079             }
00080             draw_ext_info(NDI_UNIQUE, 0, ab, MSG_TYPE_APPLY, MSG_TYPE_APPLY_TRAP,
00081                   "You fall into a trapdoor!", NULL);
00082             transfer_ob(ab, (int)EXIT_X(trap), (int)EXIT_Y(trap), 0, ab);
00083         }
00084     }
00085     common_post_ob_move_on(trap, victim, originator);
00086     return METHOD_OK;
00087 }