Crossfire Server, Trunk  R20513
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  head = HEAD(applier);
64 
65  if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
67  "You are unable to read while blind.");
68  return METHOD_OK;
69  }
70 
71  if (!scroll->inv || scroll->inv->type != SPELL) {
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_name(applier, skill_names[SK_LITERACY]);
85 
86  if (!skapplier) {
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 
105  failure = -rndm(35, 100);
106  scroll_failure(applier, failure, MAX(20, (scroll->level-skapplier->level)*5));
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) {
121  "Your scroll of %s glows for a second!",
122  name);
123  } else {
125  "The scroll of %s turns to dust.",
126  name);
127 
129  }
130  return METHOD_OK;
131 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Sound-related defines.
#define FLAG_DAMNED
The object is very cursed.
Definition: define.h:318
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Calculates amount of experience can be gained for successful use of a skill.
Definition: skill_util.c:658
Typedefs for ob_methods.
Definition: ob_methods.h:45
See Scroll.
Definition: object.h:221
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:599
const char * skill_names[NUM_SKILLS]
Will contain a number-name mapping for skills, initialized by init_skills().
Definition: skill_util.c:57
#define FLAG_BLESSED
Item has a blessing, opposite of cursed/damned.
Definition: define.h:378
#define TRUE
Definition: compat.h:10
#define MAX(x, y)
Definition: compat.h:20
#define NDI_BLACK
Definition: newclient.h:221
Global type definitions and header inclusions.
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:384
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
int rndm(int min, int max)
Returns a number between min and max.
Definition: utils.c:161
#define METHOD_OK
Definition: ob_methods.h:15
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:596
#define FLAG_IDENTIFIED
Player knows full info about item.
Definition: define.h:261
static method_ret scroll_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Handles reading a spell scroll.
Definition: scroll.c:57
int die_roll(int num, int size, const object *op, int goodbad)
Roll a number of dice (2d3, 4d6).
Definition: utils.c:121
const char * name
The name of the object, obviously...
Definition: object.h:311
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.c:62
See Spell.
Definition: object.h:214
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:594
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:231
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Changes experience to a player/monster.
Definition: living.c:2076
Literacy.
Definition: skills.h:27
const char * skill
Name of the skill this object uses/grants.
Definition: object.h:321
Object type variables.
const char * sstring
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:40
#define FLAG_CURSED
The object is cursed.
Definition: define.h:317
See Player.
Definition: object.h:107
const char * name
Usually monster-name/combination.
Definition: treasure.h:83
#define FLAG_BLIND
If set, object cannot see (visually)
Definition: define.h:337
#define object_decrease_nrof_by_one(xyz)
Definition: compat.h:28
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
struct Settings settings
Server settings.
Definition: init.c:40
void scroll_failure(object *op, int failure, int power)
op made some mistake with a scroll, this takes care of punishment.
Definition: apply.c:1509
#define MSG_TYPE_APPLY_SUCCESS
Was able to apply object.
Definition: newclient.h:598
object * identify(object *op)
Identifies an item.
Definition: item.c:1437
struct obj * inv
Pointer to the first object in the inventory.
Definition: object.h:290
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
void init_type_scroll(void)
Initializer for the scroll object type.
Definition: scroll.c:37
Object type functions and variables.
int16_t level
Level of creature or object.
Definition: object.h:351
int8_t facing
Object is oriented/facing that way.
Definition: object.h:335
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:267
object * find_skill_by_name(object *who, const char *name)
This returns the skill pointer of the given name (the one that accumulates exp, has the level...
Definition: skill_util.c:213
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Main dispatch when someone casts a spell.
Definition: spell_util.c:1471