Crossfire Server, Branches 1.12  R18729
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(ob_methods *context, object *op, object *applier, int aflags);
33 
37 void init_type_scroll(void) {
39 }
40 
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  if (applier->head)
64  head = applier->head;
65  else
66  head = applier;
67 
68  if (QUERY_FLAG(applier, FLAG_BLIND)&&!QUERY_FLAG(applier, FLAG_WIZ)) {
70  "You are unable to read while blind.", NULL);
71  return METHOD_OK;
72  }
73 
74  if (!scroll->inv || scroll->inv->type != SPELL) {
76  "The scroll just doesn't make sense!", NULL);
77  return METHOD_OK;
78  }
79 
80  if (applier->type == PLAYER) {
81  /* players need a literacy skill to read stuff! */
82  int exp_gain = 0;
83 
84  /* hard code literacy - scroll->skill points to where the exp
85  * should go for anything killed by the spell.
86  */
87  skapplier = find_skill_by_name(applier, skill_names[SK_LITERACY]);
88 
89  if (!skapplier) {
91  "You are unable to decipher the strange symbols.", NULL);
92  return METHOD_OK;
93  }
94 
95  if (!QUERY_FLAG(scroll, FLAG_IDENTIFIED))
96  identify(scroll);
97 
98  if (QUERY_FLAG(scroll, FLAG_CURSED) || QUERY_FLAG(scroll, FLAG_DAMNED)) {
99  /* Player made a mistake, let's shake her/him :)
100  * a failure of -35 means merely mana drain, -80 means
101  * mana blast. But if server settings say 'no failure effect',
102  * we still want to drain mana.
103  * As for power, hey, better take care what you apply :)
104  */
105  int failure = -35;
106 
108  failure = -rndm(35, 100);
109  scroll_failure(applier, failure, MAX(20, (scroll->level-skapplier->level)*5));
110  decrease_ob(scroll);
111  return METHOD_OK;
112  }
113 
114  if ((exp_gain = calc_skill_exp(applier, scroll, skapplier)))
115  change_exp(applier, exp_gain, skapplier->skill, 0);
116  }
117 
118  /* need to keep the name, as the scroll may be destroyed when on the ground (reading a scroll of alchemy for instance) */
119  name = scroll->inv->name;
120  cast_spell(applier, scroll, head->facing, scroll->inv, NULL);
121 
122  if (QUERY_FLAG(scroll, FLAG_BLESSED) && die_roll(1, 100, applier, 1) < 10) {
124  "Your scroll of %s glows for a second!",
125  "Your scroll of %s glows for a second!",
126  name);
127  } else {
129  "The scroll of %s turns to dust.",
130  "The scroll of %s turns to dust.",
131  name);
132 
133  decrease_ob(scroll);
134  }
135  return METHOD_OK;
136 }
#define FLAG_DAMNED
Definition: define.h:614
void change_exp(object *op, sint64 exp, const char *skill_name, int flag)
Definition: living.c:2015
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:519
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
const char * skill_names[NUM_SKILLS]
Definition: skill_util.c:65
#define SCROLL
Definition: define.h:293
#define NDI_BLACK
Definition: newclient.h:195
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175
#define PLAYER
Definition: define.h:113
char method_ret
Definition: ob_methods.h:41
int rndm(int min, int max)
Definition: utils.c:174
uint8 spell_failure_effects
Definition: global.h:357
#define METHOD_OK
Definition: ob_methods.h:42
#define FLAG_IDENTIFIED
Definition: define.h:557
void identify(object *op)
Definition: item.c:1447
sint64 calc_skill_exp(object *who, object *op, object *skill)
Definition: skill_util.c:599
int die_roll(int num, int size, const object *op, int goodbad)
Definition: utils.c:134
const char * name
Definition: object.h:167
#define SPELL
Definition: define.h:283
#define SK_LITERACY
Definition: skills.h:55
#define TRUE
Definition: exp.c:41
sint8 facing
Definition: object.h:186
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:79
#define MAX(x, y)
Definition: define.h:70
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define MSG_TYPE_APPLY
Definition: newclient.h:330
#define FLAG_WIZ
Definition: define.h:527
const char * skill
Definition: object.h:174
const char * sstring
Definition: global.h:84
#define FLAG_CURSED
Definition: define.h:613
#define decrease_ob(xyz)
Definition: global.h:276
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:518
#define FLAG_BLIND
Definition: define.h:633
struct Settings settings
Definition: init.c:48
void scroll_failure(object *op, int failure, int power)
Definition: apply.c:1708
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:516
struct obj * inv
Definition: object.h:148
#define NDI_UNIQUE
Definition: newclient.h:219
static method_ret scroll_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: scroll.c:57
struct obj * head
Definition: object.h:154
#define FLAG_BLESSED
Definition: define.h:674
void init_type_scroll(void)
Definition: scroll.c:37
sint16 level
Definition: object.h:202
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:207
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1308
uint8 type
Definition: object.h:189