Mercurial > hg > early-roguelike
annotate arogue5/player.c @ 299:74351bf23e5e
Fix another pointer bug related to object stacks.
author | John "Elwin" Edwards |
---|---|
date | Sun, 11 Feb 2018 15:37:33 -0500 |
parents | 56e748983fa8 |
children | e52a8a7ad4c5 |
rev | line source |
---|---|
63
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
1 /* |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
2 * This file contains functions for dealing with special player abilities |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
3 * |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
4 * Advanced Rogue |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
6 * All rights reserved. |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
7 * |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
8 * See the file LICENSE.TXT for full copyright and licensing information. |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
9 */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
10 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
11 #include "curses.h" |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
12 #include "rogue.h" |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
13 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
14 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
15 /* |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
16 * affect: |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
17 * cleric affecting undead |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
18 */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
19 |
218
56e748983fa8
Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents:
195
diff
changeset
|
20 void |
56e748983fa8
Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents:
195
diff
changeset
|
21 affect(void) |
63
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
22 { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
23 register struct linked_list *item; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
24 register struct thing *tp; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
25 register const char *mname; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
26 bool see; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
27 coord new_pos; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
28 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
29 if (player.t_ctype != C_CLERIC && cur_relic[HEIL_ANKH] == 0) { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
30 msg("Only clerics can affect undead."); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
31 return; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
32 } |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
33 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
34 new_pos.y = hero.y + delta.y; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
35 new_pos.x = hero.x + delta.x; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
36 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
37 if (cansee(new_pos.y, new_pos.x)) see = TRUE; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
38 else see = FALSE; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
39 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
40 /* Anything there? */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
41 if (new_pos.y < 0 || new_pos.y > LINES-3 || |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
42 new_pos.x < 0 || new_pos.x > COLS-1 || |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
43 mvwinch(mw, new_pos.y, new_pos.x) == ' ') { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
44 msg("Nothing to affect."); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
45 return; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
46 } |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
47 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
48 if ((item = find_mons(new_pos.y, new_pos.x)) == NULL) { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
49 debug("Affect what @ %d,%d?", new_pos.y, new_pos.x); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
50 return; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
51 } |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
52 tp = THINGPTR(item); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
53 mname = monsters[tp->t_index].m_name; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
54 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
55 if (on(player, ISINVIS) && off(*tp, CANSEE)) { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
56 sprintf(outstring,"%s%s cannot see you", see ? "The " : "It", |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
57 see ? mname : ""); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
58 msg(outstring); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
59 return; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
60 } |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
61 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
62 if (off(*tp, TURNABLE) || on(*tp, WASTURNED)) |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
63 goto annoy; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
64 turn_off(*tp, TURNABLE); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
65 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
66 /* Can cleric kill it? */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
67 if (pstats.s_lvl >= 3 * tp->t_stats.s_lvl) { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
68 unsigned long test; /* For overflow check */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
69 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
70 sprintf(outstring,"You have destroyed %s%s.", see ? "the " : "it", see ? mname : ""); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
71 msg(outstring); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
72 test = pstats.s_exp + tp->t_stats.s_exp; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
73 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
74 /* Be sure there is no overflow before increasing experience */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
75 if (test > pstats.s_exp) pstats.s_exp = test; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
76 killed(item, FALSE, TRUE); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
77 check_level(TRUE); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
78 return; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
79 } |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
80 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
81 /* Can cleric turn it? */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
82 if (rnd(100) + 1 > |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
83 (100 * ((2 * tp->t_stats.s_lvl) - pstats.s_lvl)) / pstats.s_lvl) { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
84 unsigned long test; /* Overflow test */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
85 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
86 /* Make the monster flee */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
87 turn_on(*tp, WASTURNED); /* No more fleeing after this */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
88 turn_on(*tp, ISFLEE); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
89 runto(tp, &hero); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
90 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
91 /* Let player know */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
92 sprintf(outstring,"You have turned %s%s.", see ? "the " : "it", see ? mname : ""); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
93 msg(outstring); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
94 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
95 /* get points for turning monster -- but check overflow first */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
96 test = pstats.s_exp + tp->t_stats.s_exp/2; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
97 if (test > pstats.s_exp) pstats.s_exp = test; |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
98 check_level(TRUE); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
99 |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
100 /* If monster was suffocating, stop it */ |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
101 if (on(*tp, DIDSUFFOCATE)) { |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
102 turn_off(*tp, DIDSUFFOCATE); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
103 extinguish(suffocate); |
0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
104 } |