Debian Codegraph @

types/scroll/scroll.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 scroll.c
24 * The implementation of the Scroll 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 scroll_type_apply(ob_methods *context, object *op, object *applier, int aflags);
33
34 /**
35 * Initializer for the scroll object type.
36 */
37 void init_type_scroll(void) {
38 register_apply(SCROLL, scroll_type_apply);
39 }
40
41 /**
42 * Handles reading a spell scroll.
43 * @param context
44 * The method context
45 * @param scroll
46 * The scroll to apply
47 * @param applier
48 * The object attempting to apply the scroll
49 * @param aflags
50 * Special flags (always apply/unapply)
51 * @return METHOD_OK
52 * @todo
53 * should handle scroll failure differently if god-like scroll.
54 * @todo
55 * Tweak failure parameters.
56 */
57 static method_ret scroll_type_apply(ob_methods *context, object *scroll,
58 object *applier, int aflags) {
59 object *skapplier;
60 object *head;
61 sstring name;
62
63 head = HEAD(applier);
64
65 if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
66 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
67 "You are unable to read while blind.");
68 return METHOD_OK;
69 }
70
71 if (!scroll->inv || scroll->inv->type != SPELL) {
72 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
73 "The scroll just doesn't make sense!");
74 return METHOD_OK;
75 }
76
77 if (applier->type == PLAYER) {
78 /* players need a literacy skill to read stuff! */
79 int exp_gain;
80
81 /* hard code literacy - scroll->skill points to where the exp
82 * should go for anything killed by the spell.
83 */
84 skapplier = find_skill_by_number(applier, SK_LITERACY);
85
86 if (!skapplier) {
87 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
88 "You are unable to decipher the strange symbols.");
89 return METHOD_OK;
90 }
91
92 if (!QUERY_FLAG(scroll, FLAG_IDENTIFIED))
93 scroll = identify(scroll);
94
95 if (QUERY_FLAG(scroll, FLAG_CURSED) || QUERY_FLAG(scroll, FLAG_DAMNED)) {
96 /* Player made a mistake, let's shake her/him :)
97 * a failure of -35 means merely mana drain, -80 means
98 * mana blast. But if server settings say 'no failure effect',
99 * we still want to drain mana.
100 * As for power, hey, better take care what you apply :)
101 */
102 int failure = -35;
103
104 if (settings.spell_failure_effects == TRUE)
105 failure = -rndm(35, 100);
106 scroll_failure(applier, failure, MAX(20, (scroll->level-skapplier->level)*5));
107 object_decrease_nrof_by_one(scroll);
108 return METHOD_OK;
109 }
110
111 if ((exp_gain = calc_skill_exp(applier, scroll, skapplier)))
112 change_exp(applier, exp_gain, skapplier->skill, 0);
113 }
114
115 /* need to keep the name, as the scroll may be destroyed when on the ground (reading a scroll of alchemy for instance) */
116 name = scroll->inv->name;
117 cast_spell(applier, scroll, head->facing, scroll->inv, NULL);
118
119 if (QUERY_FLAG(scroll, FLAG_BLESSED) && die_roll(1, 100, applier, 1) < 10) {
120 draw_ext_info_format(NDI_BLACK, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
121 "Your scroll of %s glows for a second!",
122 name);
123 } else {
124 draw_ext_info_format(NDI_BLACK, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
125 "The scroll of %s turns to dust.",
126 name);
127
128 object_decrease_nrof_by_one(scroll);
129 }
130 return METHOD_OK;
131 }