Crossfire Server, Trunk
book.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 */
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 method_ret book_type_apply(object *op, object *applier, int aflags);
34 
38 void init_type_book(void) {
40 }
41 
50 static method_ret book_type_apply(object *op, object *applier, int aflags) {
51  int lev_diff;
52  object *skill_ob;
53  (void)aflags;
54 
55  if (applier->type != PLAYER)
56  return METHOD_UNHANDLED;
57 
58  if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
60  "You are unable to read while blind.");
61  return METHOD_OK;
62  }
63 
64  /* need a literacy skill to read stuff! */
65  skill_ob = find_skill_by_name(applier, op->skill);
66  if (!skill_ob) {
68  "You are unable to decipher the strange symbols.");
69  return METHOD_OK;
70  }
71  lev_diff = op->level-(skill_ob->level+5);
72  if (!QUERY_FLAG(applier, FLAG_WIZ) && lev_diff > 0) {
73  if (lev_diff < 2)
75  "This book is just barely beyond your comprehension.");
76  else if (lev_diff < 3)
78  "This book is slightly beyond your comprehension.");
79  else if (lev_diff < 5)
81  "This book is beyond your comprehension.");
82  else if (lev_diff < 8)
84  "This book is quite a bit beyond your comprehension.");
85  else if (lev_diff < 15)
87  "This book is way beyond your comprehension.");
88  else
90  "This book is totally beyond your comprehension.");
91  return METHOD_OK;
92  }
93 
94  if (op->msg == NULL) {
96  "You open the %s and find it empty.",
97  op->name);
98  } else {
99  char desc[MAX_BUF];
101 
102  draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, applier, msgType->message_type, msgType->message_subtype,
103  "You open the %s and start reading.\n%s",
104  ob_describe(op, applier, 0, desc, sizeof(desc)), op->msg);
105  if (applier->contr)
106  knowledge_read(applier->contr, op);
107  }
108 
109  /* gain xp from reading */
111  /* only if not read before */
112  int exp_gain = calc_skill_exp(applier, op, skill_ob);
113 
114  if (!QUERY_FLAG(op, FLAG_IDENTIFIED)) {
115  /*exp_gain *= 2; because they just identified it too */
117  }
118  change_exp(applier, exp_gain, skill_ob->skill, 0);
119  /* so no more xp gained from this book */
121  // Since we now send info to the client on whether a book is read or not,
122  // we must update the item regardless of whether it was identified or not.
123  /* If in a container, update how it looks */
124  if (op->env)
126  else
127  applier->contr->socket->update_look = 1;
128  }
129  return METHOD_OK;
130 }
readable_message_type::message_type
uint8_t message_type
Definition: book.h:37
PLAYER
@ PLAYER
Definition: object.h:112
global.h
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
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
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,...) PRINTF_ARGS(6
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:233
object::level
int16_t level
Definition: object.h:361
FLAG_BLIND
#define FLAG_BLIND
Definition: define.h:336
book_type_apply
static method_ret book_type_apply(object *op, object *applier, int aflags)
Definition: book.cpp:50
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
socket_struct::update_look
uint32_t update_look
Definition: newserver.h:104
knowledge_read
void knowledge_read(player *pl, object *book)
Definition: knowledge.cpp:1053
METHOD_UNHANDLED
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
object::contr
struct player * contr
Definition: object.h:284
calc_skill_exp
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.cpp:667
ob_describe
char * ob_describe(const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Definition: ob_methods.cpp:91
object::type
uint8_t type
Definition: object.h:348
UPD_FLAGS
#define UPD_FLAGS
Definition: newclient.h:304
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.cpp:2168
sproto.h
readable_message_type::message_subtype
uint8_t message_subtype
Definition: book.h:38
BOOK
@ BOOK
Definition: object.h:119
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.cpp:211
MAX_BUF
#define MAX_BUF
Definition: define.h:35
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
init_type_book
void init_type_book(void)
Definition: book.cpp:38
give.op
op
Definition: give.py:33
object::skill
sstring skill
Definition: object.h:329
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.cpp:359
readable_message_type
Definition: book.h:36
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:593
UPD_NAME
#define UPD_NAME
Definition: newclient.h:307
get_readable_message_type
const readable_message_type * get_readable_message_type(object *readable)
Definition: readable.cpp:2039
player::socket
socket_struct * socket
Definition: player.h:107
ob_methods.h
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:397
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:590
FLAG_IDENTIFIED
#define FLAG_IDENTIFIED
Definition: define.h:261