Atrinik Server  4.0
wand.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <object.h>
34 #include <object_methods.h>
35 
37 
41 #define WAND_BASE_CHARGES 13
42 
44 static int ranged_fire_func(object *op, object *shooter, int dir, double *delay)
45 {
46  HARD_ASSERT(op != NULL);
47  HARD_ASSERT(shooter != NULL);
48 
49  if (op->stats.sp < 0 || op->stats.sp >= NROFREALSPELLS) {
50  draw_info_format(COLOR_WHITE, shooter,
51  "The %s is broken.",
52  op->name);
54  }
55 
56  if (op->stats.food <= 0) {
57  play_sound_player_only(CONTR(shooter),
58  CMD_SOUND_EFFECT,
59  "rod.ogg",
60  0,
61  0,
62  0,
63  0);
64  draw_info_format(COLOR_WHITE, shooter,
65  "The %s says poof.",
66  op->name);
68  }
69 
70  if (cast_spell(shooter, op, dir, op->stats.sp, 0, CAST_WAND, NULL)) {
72  op->stats.food--;
73  }
74 
75  if (delay != NULL) {
76  *delay = op->last_grace;
77  }
78 
79  return OBJECT_METHOD_OK;
80 }
81 
83 static int
85  object **ret,
86  int difficulty,
87  treasure_affinity_t *affinity,
88  int flags)
89 {
90  HARD_ASSERT(op != NULL);
91  HARD_ASSERT(difficulty > 0);
92 
93  /* Avoid processing if the item is already special. */
96  }
97 
98  op->stats.sp = spell_get_random(difficulty, SPELL_USE_WAND);
99  if (op->stats.sp == SP_NO_SPELL) {
100  log_error("Failed to generate a spell for wand: %s",
101  object_get_str(op));
102  object_remove(op, 0);
103  object_destroy(op);
104  return OBJECT_METHOD_ERROR;
105  }
106 
108 
109  /* Charges */
110  op->stats.food = WAND_BASE_CHARGES + rndm(1, spells[op->stats.sp].charges);
111 
112  /* Calculate the level. Essentially -20 below the difficulty at worst, or
113  * +15 above the difficulty at best. */
114  int level = difficulty - 20 + rndm(0, 15);
115  level = MIN(MAX(level, 1), MAXLEVEL);
116  op->level = level;
117 
118  return OBJECT_METHOD_OK;
119 }
120 
125 {
126  OBJECT_METHODS(WAND)->apply_func = object_apply_item;
127  OBJECT_METHODS(WAND)->ranged_fire_func = ranged_fire_func;
128  OBJECT_METHODS(WAND)->process_treasure_func = process_treasure_func;
129 }
void object_destroy(object *ob)
Definition: object.c:1441
static int process_treasure_func(object *op, object **ret, int difficulty, treasure_affinity_t *affinity, int flags)
Definition: wand.c:84
#define NROFREALSPELLS
Definition: define.h:664
#define WAND
Definition: define.h:445
#define OBJECT_METHOD_ERROR
#define CAST_WAND
Definition: spells.h:277
#define WAND_BASE_CHARGES
Definition: wand.c:41
int16_t sp
Definition: living.h:78
void object_remove(object *op, int flags)
Definition: object.c:1623
int cast_spell(object *op, object *caster, int dir, int type, int ability, int item, const char *stringarg)
Definition: spell_util.c:192
#define FLAG_BEEN_APPLIED
Definition: define.h:934
const char * object_get_str(const object *op)
Definition: object.c:3151
int charges
Definition: spells.h:144
void play_sound_player_only(player *pl, int type, const char *filename, int x, int y, int loop, int volume)
Definition: sounds.c:66
#define SP_NO_SPELL
Definition: spells.h:202
const char * name
Definition: object.h:168
#define SET_FLAG(xyz, p)
Definition: define.h:741
int16_t last_grace
Definition: object.h:316
OBJECT_TYPE_INIT_DEFINE(wand)
Definition: wand.c:124
#define OBJECT_METHOD_UNHANDLED
spell_struct spells[NROFREALSPELLS]
Definition: spellist.h:34
#define MAXLEVEL
Definition: global.h:221
bool process_treasure_is_special(object *op)
int object_apply_item(object *op, object *applier, int aflags)
Definition: apply.c:110
living stats
Definition: object.h:481
#define OBJECT_METHODS(type)
int spell_get_random(int level, int flags)
Definition: spell_util.c:1230
#define OBJECT_METHOD_OK
#define FLAG_IS_MAGICAL
Definition: define.h:1129
#define SPELL_USE_WAND
Definition: spells.h:97
static int ranged_fire_func(object *op, object *shooter, int dir, double *delay)
Definition: wand.c:44
int8_t level
Definition: object.h:347
int16_t food
Definition: living.h:84