Crossfire Server, Branches 1.12  R18729
sign.c
Go to the documentation of this file.
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 crossfire-devel@real-time.com
22 */
23 
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 
40 void init_type_sign(void) {
43 }
44 
51 static void apply_sign(object *sign, object *op, int autoapply) {
52  const readable_message_type *msgType;
53 
54  if (sign->msg == NULL) {
56  "Nothing is written on it.", NULL);
57  return;
58  }
59 
60  if (sign->stats.food) {
61  if (sign->last_eat >= sign->stats.food) {
62  if (!sign->move_on)
64  "You cannot read it anymore.", NULL);
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) {
81  "You are unable to read while blind.", NULL);
82  return;
83  }
84  msgType = get_readable_message_type(sign);
86  sign->msg, sign->msg);
87 }
88 
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 
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 }
MoveType move_on
Definition: object.h:280
uint8 message_subtype
Definition: book.h:61
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:519
#define METHOD_ERROR
Definition: ob_methods.h:44
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
#define PLAYER
Definition: define.h:113
#define NDI_NAVY
Definition: newclient.h:197
uint8 message_type
Definition: book.h:60
char method_ret
Definition: ob_methods.h:41
void register_move_on(int ob_type, move_on_func method)
Definition: ob_types.c:106
#define METHOD_OK
Definition: ob_methods.h:42
static void apply_sign(object *sign, object *op, int autoapply)
Definition: sign.c:51
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:79
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define MSG_TYPE_APPLY
Definition: newclient.h:330
#define FLAG_WIZ
Definition: define.h:527
sint32 last_eat
Definition: object.h:207
#define SIGN
Definition: define.h:280
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:88
static method_ret sign_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: sign.c:97
#define FLAG_BLIND
Definition: define.h:633
static method_ret sign_type_move_on(ob_methods *context, object *trap, object *victim, object *originator)
Definition: sign.c:110
living stats
Definition: object.h:219
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:516
const char * msg
Definition: object.h:175
void init_type_sign(void)
Definition: sign.c:40
const readable_message_type * get_readable_message_type(object *readable)
Definition: readable.c:2181
#define NDI_UNIQUE
Definition: newclient.h:219
#define FLAG_WIZPASS
Definition: define.h:611
uint8 type
Definition: object.h:189
sint32 food
Definition: living.h:89