Debian Codegraph @

types/book/book.c

raw symbols SCIP
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 [email protected]
22 */
23 /** @file book.c
24 * The implementation of the Book class of objects.
25 */
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(ob_methods *context, object *op,
33 object *applier, int aflags);
34
35 /**
36 * Initializer for the BOOK object type.
37 */
38 void init_type_book(void) {
39 register_apply(BOOK, book_type_apply);
40 }
41
42 /**
43 * Handles reading a regular (ie not containing a spell) book.
44 * @param context The method context
45 * @param op The Book to apply
46 * @param applier The object attempting to apply the Book
47 * @param aflags Special flags (always apply/unapply)
48 * @retval METHOD_UNHANDLED If the Book wasn't read by a player
49 * @retval METHOD_OK If applier was a player
50 */
51 static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
52 int lev_diff;
53 object *skill_ob;
54
55 if (applier->type != PLAYER)
56 return METHOD_UNHANDLED;
57
58 if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
59 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
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) {
67 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
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)
74 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
75 "This book is just barely beyond your comprehension.");
76 else if (lev_diff < 3)
77 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
78 "This book is slightly beyond your comprehension.");
79 else if (lev_diff < 5)
80 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
81 "This book is beyond your comprehension.");
82 else if (lev_diff < 8)
83 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
84 "This book is quite a bit beyond your comprehension.");
85 else if (lev_diff < 15)
86 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
87 "This book is way beyond your comprehension.");
88 else
89 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
90 "This book is totally beyond your comprehension.");
91 return METHOD_OK;
92 }
93
94 if (op->msg == NULL) {
95 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
96 "You open the %s and find it empty.",
97 op->name);
98 } else {
99 char desc[MAX_BUF];
100 const readable_message_type *msgType = get_readable_message_type(op);
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 */
110 if (!QUERY_FLAG(op, FLAG_NO_SKILL_IDENT)) {
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 */
116 SET_FLAG(op, FLAG_IDENTIFIED);
117 /* If in a container, update how it looks */
118 if (op->env)
119 esrv_update_item(UPD_FLAGS|UPD_NAME, applier, op);
120 else
121 applier->contr->socket.update_look = 1;
122 }
123 change_exp(applier, exp_gain, skill_ob->skill, 0);
124 /* so no more xp gained from this book */
125 SET_FLAG(op, FLAG_NO_SKILL_IDENT);
126 }
127 return METHOD_OK;
128 }