comparison xrogue/player.c @ 133:e6179860cb76

Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Tue, 21 Apr 2015 08:55:20 -0400
parents
children ce0cf824c192
comparison
equal deleted inserted replaced
124:d10fc4a065ac 133:e6179860cb76
1 /*
2 player.c - functions for dealing with special player abilities
3
4 XRogue: Expeditions into the Dungeons of Doom
5 Copyright (C) 1991 Robert Pietkivitch
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
10 All rights reserved.
11
12 See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 #include <ctype.h>
16 #include <curses.h>
17 #include "rogue.h"
18
19 /*
20 * affect:
21 * cleric affecting undead
22 */
23
24 affect()
25 {
26 register struct linked_list *item;
27 register struct thing *tp;
28 register char *mname;
29 bool see;
30 coord new_pos;
31 int lvl;
32
33 if (!(player.t_ctype == C_CLERIC ||
34 (player.t_ctype == C_PALADIN && pstats.s_lvl > 4) ||
35 cur_relic[HEIL_ANKH] != 0)) {
36 msg("You cannot affect undead.");
37 return;
38 }
39
40 new_pos.y = hero.y + player.t_newpos.y;
41 new_pos.x = hero.x + player.t_newpos.x;
42
43 if (cansee(new_pos.y, new_pos.x)) see = TRUE;
44 else see = FALSE;
45
46 /* Anything there? */
47 if (new_pos.y < 0 || new_pos.y > lines-3 ||
48 new_pos.x < 0 || new_pos.x > cols-1 ||
49 mvwinch(mw, new_pos.y, new_pos.x) == ' ') {
50 msg("Nothing to affect.");
51 return;
52 }
53
54 if ((item = find_mons(new_pos.y, new_pos.x)) == 0) {
55 debug("Affect what @ %d,%d?", new_pos.y, new_pos.x);
56 return;
57 }
58 tp = THINGPTR(item);
59 mname = monster_name(tp);
60
61 if (on(player, ISINVIS) && off(*tp, CANSEE)) {
62 msg("%s%s cannot see you", see ? "The " : "It",
63 see ? mname : "");
64 return;
65 }
66
67 if (off(*tp, TURNABLE) || on(*tp, WASTURNED))
68 goto annoy;
69 turn_off(*tp, TURNABLE);
70
71 lvl = pstats.s_lvl;
72 if (player.t_ctype == C_PALADIN && cur_relic[HEIL_ANKH] == 0) {
73 lvl -= 4;
74 }
75 /* Can cleric kill it? */
76 if (lvl >= 3 * tp->t_stats.s_lvl) {
77 unsigned long test; /* For overflow check */
78
79 msg("You have destroyed %s%s.", see ? "the " : "it", see ? mname : "");
80 test = pstats.s_exp + tp->t_stats.s_exp;
81
82 /* Be sure there is no overflow before increasing experience */
83 if (test > pstats.s_exp) pstats.s_exp = test;
84 killed(item, FALSE, TRUE, TRUE);
85 check_level();
86 return;
87 }
88
89 /* Can cleric turn it? */
90 if (rnd(100) + 1 >
91 (100 * ((2 * tp->t_stats.s_lvl) - lvl)) / lvl) {
92 unsigned long test; /* Overflow test */
93
94 /* Make the monster flee */
95 turn_on(*tp, WASTURNED); /* No more fleeing after this */
96 turn_on(*tp, ISFLEE);
97 runto(tp, &hero);
98
99 /* Disrupt it */
100 dsrpt_monster(tp, TRUE, TRUE);
101
102 /* Let player know */
103 msg("You have turned %s%s.", see ? "the " : "it", see ? mname : "");
104
105 /* get points for turning monster -- but check overflow first */
106 test = pstats.s_exp + tp->t_stats.s_exp/2;
107 if (test > pstats.s_exp) pstats.s_exp = test;
108 check_level();
109
110 /* If monster was suffocating, stop it */
111 if (on(*tp, DIDSUFFOCATE)) {
112 turn_off(*tp, DIDSUFFOCATE);
113 extinguish(suffocate);
114 }
115
116 /* If monster held us, stop it */
117 if (on(*tp, DIDHOLD) && (--hold_count == 0))
118 turn_off(player, ISHELD);
119 turn_off(*tp, DIDHOLD);
120
121 /* It is okay to turn tail */
122 tp->t_oldpos = tp->t_pos;
123
124 return;
125 }
126
127 /* Otherwise -- no go */
128 annoy:
129 if (see && tp->t_stats.s_intel > 16)
130 msg("%s laughs at you...", prname(mname, TRUE));
131 else
132 msg("You do not affect %s%s.", see ? "the " : "it", see ? mname : "");
133
134 /* Annoy monster */
135 if (off(*tp, ISFLEE)) runto(tp, &hero);
136 }
137
138 /*
139 * the cleric asks his deity for a spell
140 */
141
142 pray()
143 {
144 register int num_prayers, prayer_ability, which_prayer;
145
146 which_prayer = num_prayers = prayer_ability = 0;
147
148 if (player.t_ctype != C_CLERIC && player.t_ctype != C_PALADIN &&
149 cur_relic[HEIL_ANKH] == 0) {
150 msg("You are not permitted to pray.");
151 return;
152 }
153 if (cur_misc[WEAR_CLOAK] != NULL &&
154 cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) {
155 msg("You can't seem to pray!");
156 return;
157 }
158
159 prayer_ability = pstats.s_lvl * pstats.s_wisdom - 5;
160 if (player.t_ctype != C_CLERIC)
161 prayer_ability /= 2;
162
163 if (cur_relic[HEIL_ANKH]) prayer_ability += 75;
164
165 if (player.t_action != C_PRAY) {
166 num_prayers = 0;
167
168 /* Get the number of avilable prayers */
169 if (pstats.s_wisdom > 16)
170 num_prayers += pstats.s_wisdom - 16;
171
172 num_prayers += pstats.s_lvl;
173 if (cur_relic[HEIL_ANKH])
174 num_prayers += pstats.s_wisdom - 18;
175
176 if (player.t_ctype != C_CLERIC)
177 num_prayers /= 2;
178
179 if (num_prayers > MAXPRAYERS)
180 num_prayers = MAXPRAYERS;
181 if (num_prayers < 1) {
182 msg("You are not permitted to pray yet.");
183 return;
184 }
185
186 /* Prompt for prayer */
187 if (pick_spell( cleric_spells,
188 prayer_ability,
189 num_prayers,
190 pray_time,
191 "offer",
192 "prayer"))
193 player.t_action = C_PRAY;
194
195 return;
196 }
197
198 /* We've waited our required praying time. */
199 which_prayer = player.t_selection;
200 player.t_selection = 0;
201 player.t_action = A_NIL;
202
203 if (cleric_spells[which_prayer].s_cost + pray_time > prayer_ability) {
204 msg("Your prayer fails.");
205 return;
206 }
207
208 msg("Your prayer has been granted. ");
209
210 if (cleric_spells[which_prayer].s_type == TYP_POTION)
211 quaff( cleric_spells[which_prayer].s_which,
212 NULL,
213 cleric_spells[which_prayer].s_flag,
214 FALSE);
215 else if (cleric_spells[which_prayer].s_type == TYP_SCROLL)
216 read_scroll( cleric_spells[which_prayer].s_which,
217 cleric_spells[which_prayer].s_flag,
218 FALSE);
219 else if (cleric_spells[which_prayer].s_type == TYP_STICK) {
220 if (!player_zap(cleric_spells[which_prayer].s_which,
221 cleric_spells[which_prayer].s_flag)) {
222 after = FALSE;
223 return;
224 }
225 }
226 pray_time += cleric_spells[which_prayer].s_cost;
227 }
228
229 /*
230 * the magician is going to try and cast a spell
231 */
232
233 cast()
234 {
235 register int spell_ability, which_spell, num_spells;
236
237 if (player.t_ctype != C_MAGICIAN && player.t_ctype != C_RANGER) {
238 msg("You are not permitted to cast spells.");
239 return;
240 }
241 if (cur_misc[WEAR_CLOAK] != NULL &&
242 cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) {
243 msg("You can't seem to cast spells!");
244 return;
245 }
246 spell_ability = pstats.s_lvl * pstats.s_intel - 5;
247 if (player.t_ctype != C_MAGICIAN)
248 spell_ability /= 2;
249
250 if (player.t_action != C_CAST) {
251 /*
252 * Get the number of avilable spells
253 */
254 num_spells = 0;
255 if (pstats.s_intel > 16)
256 num_spells += pstats.s_intel - 16;
257
258 num_spells += pstats.s_lvl;
259 if (player.t_ctype != C_MAGICIAN)
260 num_spells /= 2;
261 if (num_spells > MAXSPELLS)
262 num_spells = MAXSPELLS;
263 if (num_spells < 1) {
264 msg("You are not allowed to cast spells yet.");
265 return;
266 }
267
268 /* prompt for spell */
269 if (pick_spell( magic_spells,
270 spell_ability,
271 num_spells,
272 spell_power,
273 "cast",
274 "spell"))
275 player.t_action = C_CAST;
276 return;
277 }
278
279 /* We've waited our required casting time. */
280 which_spell = player.t_selection;
281 player.t_selection = 0;
282 player.t_action = A_NIL;
283
284 if ((spell_power + magic_spells[which_spell].s_cost) > spell_ability) {
285 msg("Your attempt fails.");
286 return;
287 }
288
289 msg("Your spell is successful. ");
290
291 if (magic_spells[which_spell].s_type == TYP_POTION)
292 quaff( magic_spells[which_spell].s_which,
293 NULL,
294 magic_spells[which_spell].s_flag,
295 FALSE);
296 else if (magic_spells[which_spell].s_type == TYP_SCROLL)
297 read_scroll( magic_spells[which_spell].s_which,
298 magic_spells[which_spell].s_flag,
299 FALSE);
300 else if (magic_spells[which_spell].s_type == TYP_STICK) {
301 if (!player_zap(magic_spells[which_spell].s_which,
302 magic_spells[which_spell].s_flag)) {
303 after = FALSE;
304 return;
305 }
306 }
307 spell_power += magic_spells[which_spell].s_cost;
308 }
309
310 /*
311 * the druid asks his deity for a spell
312 */
313
314 chant()
315 {
316 register int num_chants, chant_ability, which_chant;
317
318 which_chant = num_chants = chant_ability = 0;
319
320 if (player.t_ctype != C_DRUID && player.t_ctype != C_MONK) {
321 msg("You are not permitted to chant.");
322 return;
323 }
324 if (cur_misc[WEAR_CLOAK] != NULL &&
325 cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) {
326 msg("You can't seem to chant!");
327 return;
328 }
329 chant_ability = pstats.s_lvl * pstats.s_wisdom - 5;
330 if (player.t_ctype != C_DRUID)
331 chant_ability /= 2;
332
333 if (player.t_action != C_CHANT) {
334 num_chants = 0;
335
336 /* Get the number of avilable chants */
337 if (pstats.s_wisdom > 16)
338 num_chants += pstats.s_wisdom - 16;
339
340 num_chants += pstats.s_lvl;
341
342 if (player.t_ctype != C_DRUID)
343 num_chants /= 2;
344
345 if (num_chants > MAXCHANTS)
346 num_chants = MAXCHANTS;
347
348 if (num_chants < 1) {
349 msg("You are not permitted to chant yet.");
350 return;
351 }
352
353 /* Prompt for chant */
354 if (pick_spell( druid_spells,
355 chant_ability,
356 num_chants,
357 chant_time,
358 "sing",
359 "chant"))
360 player.t_action = C_CHANT;
361
362 return;
363 }
364
365 /* We've waited our required chanting time. */
366 which_chant = player.t_selection;
367 player.t_selection = 0;