Prevent crash due to buffer overflow detection (and on some platforms probably actual...
[rogue-pphs.git] / daemons.c
1 /*
2 * All the daemon and fuse functions are in here
3 *
4 * @(#)daemons.c 3.7 (Berkeley) 6/15/81
5 *
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include "curses.h"
14 #include "rogue.h"
15
16 /*
17 * doctor:
18 * A healing daemon that restors hit points after rest
19 */
20
21 doctor()
22 {
23 register int lv, ohp;
24
25 lv = pstats.s_lvl;
26 ohp = pstats.s_hpt;
27 quiet++;
28 if (lv < 8)
29 {
30 if (quiet > 20 - lv*2)
31 pstats.s_hpt++;
32 }
33 else
34 if (quiet >= 3)
35 pstats.s_hpt += rnd(lv - 7)+1;
36 if (ISRING(LEFT, R_REGEN))
37 pstats.s_hpt++;
38 if (ISRING(RIGHT, R_REGEN))
39 pstats.s_hpt++;
40 if (ohp != pstats.s_hpt)
41 {
42 if (pstats.s_hpt > max_hp)
43 pstats.s_hpt = max_hp;
44 quiet = 0;
45 }
46 }
47
48 /*
49 * Swander:
50 * Called when it is time to start rolling for wandering monsters
51 */
52
53 swander()
54 {
55 start_daemon(rollwand, 0, BEFORE);
56 }
57
58 /*
59 * rollwand:
60 * Called to roll to see if a wandering monster starts up
61 */
62
63 int between = 0;
64
65 rollwand()
66 {
67 if (++between >= 4)
68 {
69 if (roll(1, 6) == 4)
70 {
71 wanderer();
72 kill_daemon(rollwand);
73 fuse(swander, 0, WANDERTIME, BEFORE);
74 }
75 between = 0;
76 }
77 }
78
79 /*
80 * unconfuse:
81 * Release the poor player from his confusion
82 */
83
84 unconfuse()
85 {
86 player.t_flags &= ~ISHUH;
87 msg("You feel less confused now");
88 }
89
90
91 /*
92 * unsee:
93 * He lost his see invisible power
94 */
95
96 unsee()
97 {
98 player.t_flags &= ~CANSEE;
99 }
100
101 /*
102 * sight:
103 * He gets his sight back
104 */
105
106 sight()
107 {
108 if (on(player, ISBLIND))
109 {
110 extinguish(sight);
111 player.t_flags &= ~ISBLIND;
112 light(&hero);
113 msg("The veil of darkness lifts");
114 }
115 }
116
117 /*
118 * nohaste:
119 * End the hasting
120 */
121
122 nohaste()
123 {
124 player.t_flags &= ~ISHASTE;
125 msg("You feel yourself slowing down.");
126 }
127
128 /*
129 * digest the hero's food
130 */
131 stomach()
132 {
133 register int oldfood;
134
135 if (food_left <= 0)
136 {
137 /*
138 * the hero is fainting
139 */
140 if (no_command || rnd(100) > 20)
141 return;
142 no_command = rnd(8)+4;
143 if (!terse)
144 addmsg("You feel too weak from lack of food. ");
145 msg("You faint");
146 running = FALSE;
147 count = 0;
148 hungry_state = 3;
149 }
150 else
151 {
152 oldfood = food_left;
153 food_left -= ring_eat(LEFT) + ring_eat(RIGHT) + 1 - amulet;
154
155 if (food_left < MORETIME && oldfood >= MORETIME)
156 {
157 msg("You are starting to feel weak");
158 hungry_state = 2;
159 }
160 else if (food_left < 2 * MORETIME && oldfood >= 2 * MORETIME)
161 {
162 if (!terse)
163 msg("You are starting to get hungry");
164 else
165 msg("Getting hungry");
166 hungry_state = 1;
167 }
168 }
169 }