Crossfire Server, Trunk
scroll.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 scroll_type_apply(object *op, object *applier, int aflags);
33 
37 void init_type_scroll(void) {
39 }
40 
55 static method_ret scroll_type_apply(object *scroll,
56  object *applier, int aflags) {
57  object *skapplier;
58  object *head;
59  sstring name;
60  (void)aflags;
61 
62  head = HEAD(applier);
63 
64  if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
66  "You are unable to read while blind.");
67  return METHOD_OK;
68  }
69 
70  if (!scroll->inv || scroll->inv->type != SPELL) {
72  "The scroll just doesn't make sense!");
73  return METHOD_OK;
74  }
75 
76  if (applier->type == PLAYER) {
77  /* players need a literacy skill to read stuff! */
78  int exp_gain;
79 
80  /* hard code literacy - scroll->skill points to where the exp
81  * should go for anything killed by the spell.
82  */
83  skapplier = find_skill_by_number(applier, SK_LITERACY);
84 
85  if (!skapplier) {
87  "You are unable to decipher the strange symbols.");
88  return METHOD_OK;
89  }
90 
91  if (!QUERY_FLAG(scroll, FLAG_IDENTIFIED))
92  scroll = identify(scroll);
93 
94  if (QUERY_FLAG(scroll, FLAG_CURSED) || QUERY_FLAG(scroll, FLAG_DAMNED)) {
95  /* Player made a mistake, let's shake her/him :)
96  * a failure of -35 means merely mana drain, -80 means
97  * mana blast. But if server settings say 'no failure effect',
98  * we still want to drain mana.
99  * As for power, hey, better take care what you apply :)
100  */
101  int failure = -35;
102 
104  failure = -rndm(35, 100);
105  scroll_failure(applier, failure, MAX(20, (scroll->level-skapplier->level)*5));
107  return METHOD_OK;
108  }
109 
110  if ((exp_gain = calc_skill_exp(applier, scroll, skapplier)))
111  change_exp(applier, exp_gain, skapplier->skill, 0);
112  }
113 
114  /* need to keep the name, as the scroll may be destroyed when on the ground (reading a scroll of alchemy for instance) */
115  name = scroll->inv->name;
116  cast_spell(applier, scroll, head->facing, scroll->inv, NULL);
117 
118  if (QUERY_FLAG(scroll, FLAG_BLESSED) && die_roll(1, 100, applier, 1) < 10) {
120  "Your scroll of %s glows for a second!",
121  name);
122  } else {
124  "The scroll of %s turns to dust.",
125  name);
126 
128  }
129  return METHOD_OK;
130 }
PLAYER
@ PLAYER
Definition: object.h:107
global.h
find_skill_by_number
object * find_skill_by_number(object *who, int skillno)
Definition: main.c:376
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
cast_spell
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1420
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
FLAG_BLESSED
#define FLAG_BLESSED
Definition: define.h:369
scroll_failure
void scroll_failure(object *op, int failure, int power)
Definition: apply.c:1597
FLAG_BLIND
#define FLAG_BLIND
Definition: define.h:336
MAX
#define MAX(x, y)
Definition: compat.h:24
settings
struct Settings settings
Definition: init.c:39
identify
object * identify(object *op)
Definition: item.c:1409
object_decrease_nrof_by_one
#define object_decrease_nrof_by_one(xyz)
Definition: compat.h:32
obj::name
sstring name
Definition: object.h:314
MSG_TYPE_APPLY_SUCCESS
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:603
SK_LITERACY
@ SK_LITERACY
Definition: skills.h:27
calc_skill_exp
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.c:658
HEAD
#define HEAD(op)
Definition: object.h:593
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
sstring
const typedef char * sstring
Definition: global.h:40
rndm
int rndm(int min, int max)
Definition: utils.c:162
sproto.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
NDI_BLACK
#define NDI_BLACK
Definition: newclient.h:242
Settings::spell_failure_effects
uint8_t spell_failure_effects
Definition: global.h:264
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
die_roll
int die_roll(int num, int size, const object *op, int goodbad)
Definition: utils.c:122
obj::facing
int8_t facing
Definition: object.h:340
init_type_scroll
void init_type_scroll(void)
Definition: scroll.c:37
give.op
op
Definition: give.py:33
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2168
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:604
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
scroll_type_apply
static method_ret scroll_type_apply(object *op, object *applier, int aflags)
Definition: scroll.c:55
SCROLL
@ SCROLL
Definition: object.h:221
ob_methods.h
TRUE
#define TRUE
Definition: compat.h:11
SPELL
@ SPELL
Definition: object.h:214
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
FLAG_CURSED
#define FLAG_CURSED
Definition: define.h:316
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
obj::inv
struct obj * inv
Definition: object.h:293
FLAG_IDENTIFIED
#define FLAG_IDENTIFIED
Definition: define.h:261
give.name
name
Definition: give.py:27