Debian Codegraph @

types/sign/sign.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at [email protected]
22 */
23
24 /** @file sign.c
25 * The implementation of the Sign class of objects.
26 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sounds.h>
31 #include <sproto.h>
32
33 static void apply_sign(object *sign, object *op, int autoapply);
34 static method_ret sign_type_apply(ob_methods *context, object *op, object *applier, int aflags);
35 static method_ret sign_type_move_on(ob_methods *context, object *trap, object *victim, object *originator);
36
37 /**
38 * Initializer for the SIGN object type.
39 */
40 void init_type_sign(void) {
41 register_move_on(SIGN, sign_type_move_on);
42 register_apply(SIGN, sign_type_apply);
43 }
44
45 /**
46 * Handles applying a sign.
47 * @param sign The sign applied
48 * @param op The object applying the sign
49 * @param autoapply Set this to 1 to automatically apply the sign
50 */
51 static void apply_sign(object *sign, object *op, int autoapply) {
52 const readable_message_type *msgType;
53
54 if (sign->msg == NULL) {
55 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
56 "Nothing is written on it.");
57 return;
58 }
59
60 if (sign->stats.food) {
61 if (sign->last_eat >= sign->stats.food) {
62 if (!sign->move_on)
63 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
64 "You cannot read it anymore.");
65 return;
66 }
67
68 if (!QUERY_FLAG(op, FLAG_WIZPASS))
69 sign->last_eat++;
70 }
71
72 /* Sign or magic mouth? Do we need to see it, or does it talk to us?
73 * No way to know for sure. The presumption is basically that if
74 * move_on is zero, it needs to be manually applied (doesn't talk
75 * to us).
76 */
77 if (QUERY_FLAG(op, FLAG_BLIND)
78 && !QUERY_FLAG(op, FLAG_WIZ)
79 && !sign->move_on) {
80 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
81 "You are unable to read while blind.");
82 return;
83 }
84 msgType = get_readable_message_type(sign);
85 draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype,
86 sign->msg);
87 }
88
89 /**
90 * Attempts to apply a sign.
91 * @param context The method context
92 * @param op The Sign to apply
93 * @param applier The object attempting to apply the Sign
94 * @param aflags Special flags (always apply/unapply)
95 * @return The return value is always METHOD_OK
96 */
97 static method_ret sign_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
98 apply_sign(op, applier, 0);
99 return METHOD_OK;
100 }
101
102 /**
103 * Move on this Sign object.
104 * @param context The method context
105 * @param trap The Sign we're moving on
106 * @param victim The object moving over this one
107 * @param originator The object that caused the move_on event
108 * @return METHOD_OK
109 */
110 static method_ret sign_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) {
111 if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
112 return METHOD_OK;
113 if (victim->type != PLAYER && trap->stats.food > 0) {
114 common_post_ob_move_on(trap, victim, originator);
115 return METHOD_OK; /* monsters musn't apply magic_mouths with counters */
116 }
117 apply_sign(trap, victim, 1);
118 common_post_ob_move_on(trap, victim, originator);
119 return METHOD_OK;
120 }