Crossfire Server, Trunk  1.75.0
sign.cpp
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(object *op, object *applier, int aflags);
35 static method_ret sign_type_move_on(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 moved_on) {
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 (!moved_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  /* Do we need to see it, or does it talk to us? */
73  if (QUERY_FLAG(op, FLAG_BLIND)
74  && !QUERY_FLAG(op, FLAG_WIZ)
75  && !moved_on) {
77  "You are unable to read while blind.");
78  return;
79  }
80  msgType = get_readable_message_type(sign);
82  sign->msg);
83  if (op->contr) {
84  knowledge_read(op->contr, sign);
85  }
86 }
87 
95 static method_ret sign_type_apply(object *op, object *applier, int aflags) {
96  (void)aflags;
97  apply_sign(op, applier, 0);
98  return METHOD_OK;
99 }
100 
108 static method_ret sign_type_move_on(object *trap, object *victim, object *originator) {
109  if (victim->type == TRANSPORT) {
110  // Read sign or magic mouth out for everyone in transport
111  FOR_INV_PREPARE(victim, inv) {
112  sign_type_move_on(trap, inv, originator);
113  } FOR_INV_FINISH();
114  }
115  if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
116  return METHOD_OK;
117  if (victim->type != PLAYER && trap->stats.food > 0) {
118  common_post_ob_move_on(trap, victim, originator);
119  return METHOD_OK; /* monsters musn't apply magic_mouths with counters */
120  }
121  apply_sign(trap, victim, 1);
122  common_post_ob_move_on(trap, victim, originator);
123  return METHOD_OK;
124 }
readable_message_type::message_type
uint8_t message_type
Message type to be sent to the client.
Definition: book.h:37
PLAYER
@ PLAYER
Definition: object.h:112
global.h
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_apply
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.cpp:62
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
register_move_on
void register_move_on(int ob_type, move_on_func method)
Registers the move_on method for the given type.
Definition: ob_types.cpp:89
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:247
TRANSPORT
@ TRANSPORT
see doc/Developers/objects
Definition: object.h:113
SIGN
@ SIGN
Definition: object.h:216
draw_ext_info
vs only yadda is in because all tags get reset on the next draw_ext_info In the second since it is all in one draw_ext_info
Definition: media-tags.txt:61
knowledge_read
void knowledge_read(player *pl, object *book)
Player is reading a book, give knowledge if needed, warn player, and such.
Definition: knowledge.cpp:1056
object::contr
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
sign_type_apply
static method_ret sign_type_apply(object *op, object *applier, int aflags)
Attempts to apply a sign.
Definition: sign.cpp:95
common_pre_ob_move_on
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.cpp:35
FLAG_BLIND
#define FLAG_BLIND
If set, object cannot see (visually)
Definition: define.h:336
object::last_eat
int32_t last_eat
How long since we last ate.
Definition: object.h:366
object::type
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
FLAG_WIZPASS
#define FLAG_WIZPASS
The wizard can go through walls.
Definition: define.h:314
init_type_sign
void init_type_sign(void)
Initializer for the SIGN object type.
Definition: sign.cpp:40
FOR_INV_FINISH
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
Definition: define.h:671
living::food
int32_t food
How much food in stomach.
Definition: living.h:48
sproto.h
readable_message_type::message_subtype
uint8_t message_subtype
Message subtype to be sent to the client.
Definition: book.h:38
method_ret
char method_ret
Define some standard return values for callbacks which don't need to return any other results.
Definition: ob_methods.h:14
ob_types.h
sounds.h
FLAG_WIZ
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:231
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:265
object::msg
sstring msg
If this is a book/sign/magic mouth/etc.
Definition: object.h:330
readable_message_type
Struct to store the message_type and message_subtype for signs and books used by the player.
Definition: book.h:36
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:607
apply_sign
static void apply_sign(object *sign, object *op, int autoapply)
Handles applying a sign.
Definition: sign.cpp:51
get_readable_message_type
const readable_message_type * get_readable_message_type(object *readable)
Get the readable type for an object (hopefully book).
Definition: readable.cpp:2055
METHOD_ERROR
#define METHOD_ERROR
Definition: ob_methods.h:17
ob_methods.h
object::stats
living stats
Str, Con, Dex, etc.
Definition: object.h:378
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:411
common_post_ob_move_on
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.cpp:67
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:604
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
Definition: define.h:664
sign_type_move_on
static method_ret sign_type_move_on(object *trap, object *victim, object *originator)
Move on this Sign object.
Definition: sign.cpp:108