Crossfire Server, Trunk  R20513
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 }
Sound-related defines.
MoveType move_on
Move types affected moving on to this space.
Definition: object.h:427
Typedefs for ob_methods.
Definition: ob_methods.h:45
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:599
#define METHOD_ERROR
Definition: ob_methods.h:17
uint8_t message_type
Message type to be sent to the client.
Definition: book.h:37
Global type definitions and header inclusions.
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:384
#define NDI_NAVY
Definition: newclient.h:223
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
See Sign & Magic Mouth.
Definition: object.h:211
void register_move_on(int ob_type, move_on_func method)
Registers the move_on method for the given type.
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)
Handles applying a sign.
Definition: sign.c:51
Struct to store the message_type and message_subtype for signs and books used by the player...
Definition: book.h:36
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.c:62
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:231
int32_t last_eat
How long since we last ate.
Definition: object.h:356
Object type variables.
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:87
See Player.
Definition: object.h:107
static method_ret sign_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Attempts to apply a sign.
Definition: sign.c:97
#define FLAG_BLIND
If set, object cannot see (visually)
Definition: define.h:337
static method_ret sign_type_move_on(ob_methods *context, object *trap, object *victim, object *originator)
Move on this Sign object.
Definition: sign.c:110
living stats
Str, Con, Dex, etc.
Definition: object.h:368
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
const char * msg
If this is a book/sign/magic mouth/etc.
Definition: object.h:322
void init_type_sign(void)
Initializer for the SIGN object type.
Definition: sign.c:40
const readable_message_type * get_readable_message_type(object *readable)
Get the readable type for an object (hopefully book).
Definition: readable.c:2200
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
uint8_t message_subtype
Message subtype to be sent to the client.
Definition: book.h:38
#define FLAG_WIZPASS
The wizard can go through walls.
Definition: define.h:315
Object type functions and variables.
int32_t food
How much food in stomach.
Definition: living.h:47