Crossfire Server, Branch 1.12  R12190
sign.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 void apply_sign(object *sign, object *op, int autoapply);
00034 static method_ret sign_type_apply(ob_methods *context, object *op, object *applier, int aflags);
00035 static method_ret sign_type_move_on(ob_methods *context, object *trap, object *victim, object *originator);
00036 
00040 void init_type_sign(void) {
00041     register_move_on(SIGN, sign_type_move_on);
00042     register_apply(SIGN, sign_type_apply);
00043 }
00044 
00051 static void apply_sign(object *sign, object *op, int autoapply) {
00052     const readable_message_type *msgType;
00053 
00054     if (sign->msg == NULL) {
00055         draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
00056             "Nothing is written on it.", NULL);
00057         return;
00058     }
00059 
00060     if (sign->stats.food) {
00061         if (sign->last_eat >= sign->stats.food) {
00062             if (!sign->move_on)
00063                 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
00064                     "You cannot read it anymore.", NULL);
00065             return;
00066         }
00067 
00068         if (!QUERY_FLAG(op, FLAG_WIZPASS))
00069             sign->last_eat++;
00070     }
00071 
00072     /* Sign or magic mouth?  Do we need to see it, or does it talk to us?
00073      * No way to know for sure.  The presumption is basically that if
00074      * move_on is zero, it needs to be manually applied (doesn't talk
00075      * to us).
00076      */
00077     if (QUERY_FLAG(op, FLAG_BLIND)
00078     && !QUERY_FLAG(op, FLAG_WIZ)
00079     && !sign->move_on) {
00080         draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00081             "You are unable to read while blind.", NULL);
00082         return;
00083     }
00084     msgType = get_readable_message_type(sign);
00085     draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype,
00086         sign->msg, sign->msg);
00087 }
00088 
00097 static method_ret sign_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
00098     apply_sign(op, applier, 0);
00099     return METHOD_OK;
00100 }
00101 
00110 static method_ret sign_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) {
00111     if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
00112         return METHOD_OK;
00113     if (victim->type != PLAYER && trap->stats.food > 0) {
00114         common_post_ob_move_on(trap, victim, originator);
00115         return METHOD_OK; /* monsters musn't apply magic_mouths with counters */
00116     }
00117     apply_sign(trap, victim, 1);
00118     common_post_ob_move_on(trap, victim, originator);
00119     return METHOD_OK;
00120 }