/
magic.c
228 lines (224 loc) · 5.84 KB
/
magic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "constants.h"
#include "config.h"
#include "types.h"
#include "externs.h"
/* Throw a magic spell -RAK- */
cast()
{
int i, j, item_val, dir;
int choice, chance, result;
int dumy, y_dumy, x_dumy;
int redraw;
register struct flags *f_ptr;
register struct misc *p_ptr;
register treasure_type *i_ptr;
register spell_type *m_ptr;
reset_flag = TRUE;
if (py.flags.blind > 0)
msg_print("You can't see to read your spell book!");
else if (no_light())
msg_print("You have no light to read by.");
else if (py.flags.confused > 0)
msg_print("You are too confused...");
else if (class[py.misc.pclass].mspell)
if (inven_ctr > 0)
{
if (find_range(90, -1, &i, &j))
{
redraw = FALSE;
if (get_item(&item_val, "Use which spell-book?",
&redraw, i, j))
{
if ((result = cast_spell("Cast which spell?", item_val,
&choice, &chance, &redraw)) == TRUE)
{
m_ptr = &magic_spell[py.misc.pclass][choice];
reset_flag = FALSE;
if (randint(100) < chance)
msg_print("You failed to get the spell off!");
else
{
y_dumy = char_row;
x_dumy = char_col;
/* Spells... */
choice++;
switch(choice)
{
case 1:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_bolt(0, dir, char_row, char_col,
damroll("2d6")+1, "Magic Missile");
break;
case 2:
(void) detect_monsters();
break;
case 3:
teleport(10);
break;
case 4:
(void) light_area(char_row, char_col);
break;
case 5:
(void) hp_player(damroll("4d4"), "a magic spell.");
break;
case 6:
(void) detect_sdoor();
(void) detect_trap();
break;
case 7:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_ball(2, dir, char_row, char_col, 9,
"Stinking Cloud");
break;
case 8:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
(void) confuse_monster(dir, char_row, char_col);
break;
case 9:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_bolt(1, dir, char_row, char_col,
damroll("3d8")+1, "Lightning Bolt");
break;
case 10:
(void) td_destroy();
break;
case 11:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
(void) sleep_monster(dir, char_row, char_col);
break;
case 12:
(void) cure_poison();
break;
case 13:
teleport((int)(py.misc.lev*5));
break;
case 14:
for (i = 22; i < INVEN_MAX; i++)
{
i_ptr = &inventory[i];
i_ptr->flags = (i_ptr->flags & 0x7FFFFFFF);
}
break;
case 15:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_bolt(4, dir, char_row, char_col,
damroll("4d8")+1, "Frost Bolt");
break;
case 16:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
(void) wall_to_mud(dir, char_row, char_col);
break;
case 17:
(void) create_food();
break;
case 18:
(void) recharge(20);
break;
case 19:
(void) sleep_monsters1(char_row, char_col);
break;
case 20:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
(void) poly_monster(dir, char_row, char_col);
break;
case 21:
(void) ident_spell();
break;
case 22:
(void) sleep_monsters2();
break;
case 23:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_bolt(5, dir, char_row, char_col,
damroll("6d8")+1, "Fire Bolt");
break;
case 24:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
(void)speed_monster(dir, char_row, char_col, -1);
break;
case 25:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_ball(4, dir, char_row, char_col, 33,
"Frost Ball");
break;
case 26:
(void) recharge(60);
break;
case 27:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
(void) teleport_monster(dir, char_row, char_col);
break;
case 28:
f_ptr = &py.flags;
f_ptr->fast += randint(20) + py.misc.lev;
break;
case 29:
if (get_dir("Which direction?", &dir,
&dumy, &y_dumy, &x_dumy))
fire_ball(5, dir, char_row, char_col, 49,
"Fire Ball");
break;
case 30:
(void) destroy_area(char_row, char_col);
break;
case 31:
(void) genocide();
default:
break;
}
/* End of spells... */
if (!reset_flag)
{
p_ptr = &py.misc;
p_ptr->exp += m_ptr->sexp;
prt_experience();
m_ptr->sexp = 0;
}
}
p_ptr = &py.misc;
if (!reset_flag)
{
if (m_ptr->smana > p_ptr->cmana)
{
msg_print("You faint from the effort!");
py.flags.paralysis =
randint(5*(int)(m_ptr->smana-(int)p_ptr->cmana));
p_ptr->cmana = 0.0;
if (randint(3) == 1)
{
msg_print("You have damaged your health!");
py.stats.ccon = de_statp(py.stats.ccon);
prt_constitution();
}
}
else
p_ptr->cmana -= (double)m_ptr->smana;
prt_cmana();
}
}
else if (result == -1)
msg_print("You don't know any spells in that book.");
}
else
if (redraw) draw_cave();
}
else
msg_print("But you are not carrying any spell-books!");
}
else
msg_print("But you are not carrying any spell-books!");
else
msg_print("You can't cast spells!");
}