Crossfire Server, Trunk
book.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 */
26 #include <global.h>
27 #include <ob_methods.h>
28 #include <ob_types.h>
29 #include <sounds.h>
30 #include <sproto.h>
31 
32 static method_ret book_type_apply(object *op, object *applier, int aflags);
33 
37 void init_type_book(void) {
39 }
40 
49 static method_ret book_type_apply(object *op, object *applier, int aflags) {
50  int lev_diff;
51  object *skill_ob;
52  (void)aflags;
53 
54  if (applier->type != PLAYER)
55  return METHOD_UNHANDLED;
56 
57  if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
59  "You are unable to read while blind.");
60  return METHOD_OK;
61  }
62 
63  /* need a literacy skill to read stuff! */
64  skill_ob = find_skill_by_name(applier, op->skill);
65  if (!skill_ob) {
67  "You are unable to decipher the strange symbols.");
68  return METHOD_OK;
69  }
70  lev_diff = op->level-(skill_ob->level+5);
71  if (!QUERY_FLAG(applier, FLAG_WIZ) && lev_diff > 0) {
72  if (lev_diff < 2)
74  "This book is just barely beyond your comprehension.");
75  else if (lev_diff < 3)
77  "This book is slightly beyond your comprehension.");
78  else if (lev_diff < 5)
80  "This book is beyond your comprehension.");
81  else if (lev_diff < 8)
83  "This book is quite a bit beyond your comprehension.");
84  else if (lev_diff < 15)
86  "This book is way beyond your comprehension.");
87  else
89  "This book is totally beyond your comprehension.");
90  return METHOD_OK;
91  }
92 
93  if (op->msg == NULL) {
95  "You open the %s and find it empty.",
96  op->name);
97  } else {
98  char desc[MAX_BUF];
100 
101  draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, applier, msgType->message_type, msgType->message_subtype,
102  "You open the %s and start reading.\n%s",
103  ob_describe(op, applier, 0, desc, sizeof(desc)), op->msg);
104  if (applier->contr)
105  knowledge_read(applier->contr, op);
106  }
107 
108  /* gain xp from reading */
110  /* only if not read before */
111  int exp_gain = calc_skill_exp(applier, op, skill_ob);
112 
113  if (!QUERY_FLAG(op, FLAG_IDENTIFIED)) {
114  /*exp_gain *= 2; because they just identified it too */
116  }
117  change_exp(applier, exp_gain, skill_ob->skill, 0);
118  /* so no more xp gained from this book */
120  // Since we now send info to the client on whether a book is read or not,
121  // we must update the item regardless of whether it was identified or not.
122  /* If in a container, update how it looks */
123  if (op->env)
125  else
126  applier->contr->socket.update_look = 1;
127  }
128  return METHOD_OK;
129 }
readable_message_type::message_type
uint8_t message_type
Definition: book.h:37
PLAYER
@ PLAYER
Definition: object.h:107
global.h
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
book_type_apply
static method_ret book_type_apply(object *op, object *applier, int aflags)
Definition: book.c:49
pl::socket
socket_struct socket
Definition: player.h:107
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
FLAG_BLIND
#define FLAG_BLIND
Definition: define.h:336
socket_struct::update_look
uint32_t update_look
Definition: newserver.h:104
knowledge_read
void knowledge_read(player *pl, object *book)
Definition: knowledge.c:1053
METHOD_UNHANDLED
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
get_readable_message_type
const readable_message_type * get_readable_message_type(object *readable)
Definition: readable.c:2096
calc_skill_exp
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.c:658
UPD_FLAGS
#define UPD_FLAGS
Definition: newclient.h:315
sproto.h
readable_message_type::message_subtype
uint8_t message_subtype
Definition: book.h:38
BOOK
@ BOOK
Definition: object.h:114
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
find_skill_by_name
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:202
MAX_BUF
#define MAX_BUF
Definition: define.h:35
init_type_book
void init_type_book(void)
Definition: book.c:37
ob_describe
char * ob_describe(const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Definition: ob_methods.c:91
register_apply
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
obj::type
uint8_t type
Definition: object.h:343
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
obj::contr
struct pl * contr
Definition: object.h:279
give.op
op
Definition: give.py:33
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:360
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2168
readable_message_type
Definition: book.h:36
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:604
UPD_NAME
#define UPD_NAME
Definition: newclient.h:318
obj::skill
sstring skill
Definition: object.h:324
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.c:309
ob_methods.h
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
FLAG_NO_SKILL_IDENT
#define FLAG_NO_SKILL_IDENT
Definition: define.h:335
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:601
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:319
obj::level
int16_t level
Definition: object.h:356
FLAG_IDENTIFIED
#define FLAG_IDENTIFIED
Definition: define.h:261