Crossfire Server, Trunk
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? */
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
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
Definition: book.h:37
PLAYER
@ PLAYER
Definition: object.h:112
global.h
apply_sign
static void apply_sign(object *sign, object *op, int autoapply)
Definition: sign.cpp:51
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_apply
void register_apply(int ob_type, apply_func method)
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)
Definition: ob_types.cpp:89
commongive.inv
inv
Definition: commongive.py:29
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:233
TRANSPORT
@ TRANSPORT
Definition: object.h:113
SIGN
@ SIGN
Definition: object.h:216
FLAG_BLIND
#define FLAG_BLIND
Definition: define.h:336
knowledge_read
void knowledge_read(player *pl, object *book)
Definition: knowledge.cpp:1056
sign_type_apply
static method_ret sign_type_apply(object *op, object *applier, int aflags)
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
object::last_eat
int32_t last_eat
Definition: object.h:366
FLAG_WIZPASS
#define FLAG_WIZPASS
Definition: define.h:314
init_type_sign
void init_type_sign(void)
Definition: sign.cpp:40
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
living::food
int32_t food
Definition: living.h:48
sproto.h
readable_message_type::message_subtype
uint8_t message_subtype
Definition: book.h:38
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:251
reputation.victim
victim
Definition: reputation.py:14
give.op
op
Definition: give.py:33
object::msg
sstring msg
Definition: object.h:330
readable_message_type
Definition: book.h:36
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:593
get_readable_message_type
const readable_message_type * get_readable_message_type(object *readable)
Definition: readable.cpp:2055
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.cpp:308
METHOD_ERROR
#define METHOD_ERROR
Definition: ob_methods.h:17
ob_methods.h
object::stats
living stats
Definition: object.h:378
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:397
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:590
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
sign_type_move_on
static method_ret sign_type_move_on(object *trap, object *victim, object *originator)
Definition: sign.cpp:108