Crossfire Server, Trunk  R20739
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.");
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.");
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.");
82  return;
83  }
84  msgType = get_readable_message_type(sign);
86  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:427
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:599
#define METHOD_ERROR
Definition: ob_methods.h:17
uint8_t message_type
Definition: book.h:37
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:310
#define MSG_TYPE_APPLY
Definition: newclient.h:384
#define NDI_NAVY
Definition: newclient.h:223
char method_ret
Definition: ob_methods.h:14
Definition: object.h:211
void register_move_on(int ob_type, move_on_func method)
Definition: ob_types.c:89
#define METHOD_OK
Definition: ob_methods.h:15
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:596
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:62
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define FLAG_WIZ
Definition: define.h:231
int32_t last_eat
Definition: object.h:356
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:87
Definition: object.h:107
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:337
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:368
uint8_t type
Definition: object.h:338
const char * msg
Definition: object.h:322
void init_type_sign(void)
Definition: sign.c:40
const readable_message_type * get_readable_message_type(object *readable)
Definition: readable.c:2222
#define NDI_UNIQUE
Definition: newclient.h:245
uint8_t message_subtype
Definition: book.h:38
#define FLAG_WIZPASS
Definition: define.h:315
int32_t food
Definition: living.h:47