comparison arogue7/player.c @ 125:adfa37e67084

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