comparison arogue5/daemons.c @ 63:0ed67132cf10

Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 09 Aug 2012 22:58:48 +0000
parents
children f2951c4e28d9
comparison
equal deleted inserted replaced
62:0ef99244acb8 63:0ed67132cf10
1 /*
2 * All the daemon and fuse functions are in here
3 *
4 * Advanced Rogue
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
6 * All rights reserved.
7 *
8 * Based on "Rogue: Exploring the Dungeons of Doom"
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * All rights reserved.
11 *
12 * See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 #include "curses.h"
16 #include "rogue.h"
17
18 int between = 0;
19
20 /*
21 * doctor:
22 * A healing daemon that restors hit points after rest
23 */
24
25 doctor(tp)
26 register struct thing *tp;
27 {
28 register int ohp;
29 register int limit, new_points;
30 register struct stats *curp; /* current stats pointer */
31 register struct stats *maxp; /* max stats pointer */
32
33 curp = &(tp->t_stats);
34 maxp = &(tp->maxstats);
35 if (curp->s_hpt == maxp->s_hpt) {
36 tp->t_quiet = 0;
37 return;
38 }
39 tp->t_quiet++;
40 switch (tp->t_ctype) {
41 case C_MAGICIAN:
42 limit = 8 - curp->s_lvl;
43 new_points = curp->s_lvl - 3;
44 when C_THIEF:
45 limit = 8 - curp->s_lvl;
46 new_points = curp->s_lvl - 2;
47 when C_CLERIC:
48 limit = 8 - curp->s_lvl;
49 new_points = curp->s_lvl - 3;
50 when C_FIGHTER:
51 limit = 16 - curp->s_lvl*2;
52 new_points = curp->s_lvl - 5;
53 when C_MONSTER:
54 limit = 16 - curp->s_lvl;
55 new_points = curp->s_lvl - 6;
56 otherwise:
57 debug("what a strange character you are!");
58 return;
59 }
60 ohp = curp->s_hpt;
61 if (off(*tp, HASDISEASE) && off(*tp, DOROT)) {
62 if (curp->s_lvl < 8) {
63 if (tp->t_quiet > limit) {
64 curp->s_hpt++;
65 tp->t_quiet = 0;
66 }
67 }
68 else {
69 if (tp->t_quiet >= 3) {
70 curp->s_hpt += rnd(new_points)+1;
71 tp->t_quiet = 0;
72 }
73 }
74 }
75 if (tp == &player) {
76 if (ISRING(LEFT_1, R_REGEN)) curp->s_hpt++;
77 if (ISRING(LEFT_2, R_REGEN)) curp->s_hpt++;
78 if (ISRING(LEFT_3, R_REGEN)) curp->s_hpt++;
79 if (ISRING(LEFT_4, R_REGEN)) curp->s_hpt++;
80 if (ISRING(RIGHT_1, R_REGEN)) curp->s_hpt++;
81 if (ISRING(RIGHT_2, R_REGEN)) curp->s_hpt++;
82 if (ISRING(RIGHT_3, R_REGEN)) curp->s_hpt++;
83 if (ISRING(RIGHT_4, R_REGEN)) curp->s_hpt++;
84 }
85 if (on(*tp, ISREGEN))
86 curp->s_hpt += curp->s_lvl/10 + 1;
87 if (ohp != curp->s_hpt) {
88 if (curp->s_hpt >= maxp->s_hpt) {
89 curp->s_hpt = maxp->s_hpt;
90 if (off(*tp, WASTURNED) && on(*tp, ISFLEE) && tp != &player) {
91 turn_off(*tp, ISFLEE);
92 tp->t_oldpos = tp->t_pos; /* Start our trek over */
93 }
94 }
95 }
96 }
97
98 /*
99 * Swander:
100 * Called when it is time to start rolling for wandering monsters
101 */
102
103 swander()
104 {
105 daemon(rollwand, 0, BEFORE);
106 }
107
108 /*
109 * rollwand:
110 * Called to roll to see if a wandering monster starts up
111 */
112
113 rollwand()
114 {
115 if (++between >= 4)
116 {
117 /* Theives may not awaken a monster */
118 if ((roll(1, 6) == 4) &&
119 ((player.t_ctype != C_THIEF) || (rnd(30) >= dex_compute()))) {
120 if (levtype != POSTLEV)
121 wanderer();
122 kill_daemon(rollwand);
123 fuse(swander, 0, WANDERTIME, BEFORE);
124 }
125 between = 0;
126 }
127 }
128 /*
129 * this function is a daemon called each turn when the character is a thief
130 */
131 trap_look()
132 {
133 if (rnd(100) < (2*dex_compute() + 5*pstats.s_lvl))
134 search(TRUE, FALSE);
135 }
136
137 /*
138 * unconfuse:
139 * Release the poor player from his confusion
140 */
141
142 unconfuse()
143 {
144 turn_off(player, ISHUH);
145 msg("You feel less confused now");
146 }
147
148
149 /*
150 * unsee:
151 * He lost his see invisible power
152 */
153
154 unsee()
155 {
156 if (!ISWEARING(R_SEEINVIS)) {
157 turn_off(player, CANSEE);
158 msg("The tingling feeling leaves your eyes");
159 }
160 }
161
162 /*
163 * unstink:
164 * Remove to-hit handicap from player
165 */
166
167 unstink()
168 {
169 turn_off(player, HASSTINK);
170 }
171
172 /*
173 * unclrhead:
174 * Player is no longer immune to confusion
175 */
176
177 unclrhead()
178 {
179 turn_off(player, ISCLEAR);
180 msg("The blue aura about your head fades away.");
181 }
182
183 /*
184 * unphase:
185 * Player can no longer walk through walls
186 */
187
188 unphase()
189 {
190 turn_off(player, CANINWALL);
191 msg("Your dizzy feeling leaves you.");
192 if (!step_ok(hero.y, hero.x, NOMONST, &player)) death(D_PETRIFY);
193 }
194
195 /*
196 * land:
197 * Player can no longer fly
198 */
199
200 land()
201 {
202 turn_off(player, ISFLY);
203 msg("You regain your normal weight");
204 running = FALSE;
205 }
206
207 /*
208 * sight:
209 * He gets his sight back
210 */
211
212 sight()
213 {
214 if (on(player, ISBLIND))
215 {
216 extinguish(sight);
217 turn_off(player, ISBLIND);
218 light(&hero);
219 msg("The veil of darkness lifts");
220 }
221 }
222
223 /*
224 * res_strength:
225 * Restore player's strength
226 */
227
228 res_strength()
229 {
230
231 /* If lost_str is non-zero, restore that amount of strength,
232 * else all of it
233 */
234 if (lost_str) {
235 chg_str(lost_str);
236 lost_str = 0;
237 }
238
239 /* Otherwise, put player at the maximum strength */
240 else {
241 pstats.s_str = max_stats.s_str + ring_value(R_ADDSTR);
242 }
243
244 updpack(TRUE);
245 }
246
247 /*
248 * nohaste:
249 * End the hasting
250 */
251
252 nohaste()
253 {
254 turn_off(player, ISHASTE);
255 msg("You feel yourself slowing down.");
256 }
257
258 /*
259 * noslow:
260 * End the slowing
261 */
262
263 noslow()
264 {
265 turn_off(player, ISSLOW);
266 msg("You feel yourself speeding up.");
267 }
268
269 /*
270 * suffocate:
271 * If this gets called, the player has suffocated
272 */
273
274 suffocate()
275 {
276 death(D_SUFFOCATION);
277 }
278
279 /*
280 * digest the hero's food
281 */
282 stomach()
283 {
284 register int oldfood, old_hunger, food_use, i;
285
286 old_hunger = hungry_state;
287 if (food_left <= 0)
288 {
289 /*
290 * the hero is fainting
291 */
292 if (no_command || rnd(100) > 20)
293 return;
294 no_command = rnd(8)+4;
295 if (!terse)
296 addmsg("You feel too weak from lack of food. ");
297 msg("You faint");
298 running = FALSE;
299 count = 0;
300 hungry_state = F_FAINT;
301 }
302 else
303 {
304 oldfood = food_left;
305 food_use = 0;
306 for (i=0; i<MAXRELIC; i++) { /* each relic eats an additional food */
307 if (cur_relic[i])
308 food_use++;
309 }
310 food_use += (ring_eat(LEFT_1) + ring_eat(LEFT_2) +
311 ring_eat(LEFT_3) + ring_eat(LEFT_4) +
312 ring_eat(RIGHT_1) + ring_eat(RIGHT_2) +
313 ring_eat(RIGHT_3) + ring_eat(RIGHT_4) +
314 foodlev);
315 if (food_use < 1)
316 food_use = 1;
317 food_left -= food_use;
318 if (food_left < MORETIME && oldfood >= MORETIME) {
319 msg("You are starting to feel weak");
320 running = FALSE;
321 hungry_state = F_WEAK;
322 }
323 else if (food_left < 2 * MORETIME && oldfood >= 2 * MORETIME)
324 {
325 msg(terse ? "Getting hungry" : "You are starting to get hungry");
326 running = FALSE;
327 hungry_state = F_HUNGRY;
328 }
329
330 }
331 if (old_hunger != hungry_state)
332 updpack(TRUE);
333 wghtchk();
334 }
335 /*
336 * daemon for curing the diseased
337 */
338 cure_disease()
339 {
340 turn_off(player, HASDISEASE);
341 if (off (player, HASINFEST))
342 msg(terse ? "You feel yourself improving"
343 : "You begin to feel yourself improving again");
344 }
345
346 /*
347 * daemon for adding back dexterity
348 */
349 un_itch()
350 {
351 if (--lost_dext < 1) {
352 lost_dext = 0;
353 turn_off(player, HASITCH);
354 }
355 res_dexterity(1);
356 }
357 /*
358 * appear:
359 * Become visible again
360 */
361 appear()
362 {
363 turn_off(player, ISINVIS);
364 PLAYER = VPLAYER;
365 msg("The tingling feeling leaves your body");
366 light(&hero);
367 }
368 /*
369 * dust_appear:
370 * dust of disappearance wears off
371 */
372 dust_appear()
373 {
374 turn_off(player, ISINVIS);
375 PLAYER = VPLAYER;
376 msg("You become visible again");
377 light(&hero);
378 }
379 /*
380 * unchoke:
381 * the effects of "dust of choking and sneezing" wear off
382 */
383 unchoke()
384 {
385 if (!find_slot(unconfuse))
386 turn_off(player, ISHUH);
387 if (!find_slot(sight))
388 turn_off(player, ISBLIND);
389 light(&hero);
390 msg("Your throat and eyes return to normal");
391 }
392 /*
393 * make some potion for the guy in the Alchemy jug
394 */
395 alchemy(obj)
396 register struct object *obj;
397 {
398 register struct object *tobj = NULL;
399 register struct linked_list *item;
400
401 /*
402 * verify that the object pointer we have still points to an alchemy
403 * jug (hopefully the right one!) because the hero could have thrown
404 * it away
405 */
406 for (item = pack; item != NULL; item = next(item)) {
407 tobj = OBJPTR(item);
408 if (tobj == obj &&
409 tobj->o_type == MM &&
410 tobj->o_which== MM_JUG &&
411 tobj->o_ac == JUG_EMPTY )
412 break;
413 }
414 if (item == NULL) { /* not in the pack, check the level */
415 for (item = lvl_obj; item != NULL; item = next(item)) {
416 tobj = OBJPTR(item);
417 if (tobj == obj &&
418 tobj->o_type == MM &&
419 tobj->o_which== MM_JUG &&
420 tobj->o_ac == JUG_EMPTY )
421 break;
422 }
423 }
424 if (item == NULL) /* can't find it.....too bad */
425 return;
426
427 switch(rnd(9)) {
428 case 0: tobj->o_ac = P_PHASE;
429 when 1: tobj->o_ac = P_CLEAR;
430 when 2: tobj->o_ac = P_SEEINVIS;
431 when 3: tobj->o_ac = P_HEALING;
432 when 4: tobj->o_ac = P_MFIND;
433 when 5: tobj->o_ac = P_TFIND;
434 when 6: tobj->o_ac = P_HASTE;
435 when 7: tobj->o_ac = P_RESTORE;
436 when 8: tobj->o_ac = P_FLY;
437 }
438 }
439 /*
440 * otto's irresistable dance wears off
441 */
442
443 undance()
444 {
445 turn_off(player, ISDANCE);
446 msg ("Your feet take a break.....whew!");
447 }
448
449 /*
450 * if he has our favorite necklace of strangulation then take damage every turn
451 */
452 strangle()
453 {
454 if ((pstats.s_hpt -= 6) <= 0) death(D_STRANGLE);
455 }
456 /*
457 * if he has on the gauntlets of fumbling he might drop his weapon each turn
458 */
459 fumble()
460 {
461 register struct linked_list *item;
462
463 if(cur_weapon!=NULL && cur_weapon->o_type!=RELIC && rnd(100)<3) {
464 for (item = pack; item != NULL; item = next(item)) {
465 if (OBJPTR(item) == cur_weapon)
466 break;
467 }
468 if (item != NULL) {
469 drop(item);
470 running = FALSE;
471 }
472 }
473 }
474 /*
475 * this is called each turn the hero has the ring of searching on
476 */
477 ring_search()
478 {
479 search(FALSE, FALSE);
480 }
481 /*
482 * this is called each turn the hero has the ring of teleportation on
483 */
484 ring_teleport()
485 {
486 if (rnd(100) < 2) teleport();
487 }