/
timeout.c
2636 lines (2419 loc) · 83.1 KB
/
timeout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* NetHack 3.7 timeout.c $NHDT-Date: 1606243387 2020/11/24 18:43:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.122 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2018. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
static void stoned_dialogue(void);
static void vomiting_dialogue(void);
static void choke_dialogue(void);
static void levitation_dialogue(void);
static void larva_dialogue(void);
static void slime_dialogue(void);
static void slimed_to_death(struct kinfo *);
static void phaze_dialogue(void);
static void done_timeout(int, int);
static void slip_or_trip(void);
static void see_lamp_flicker(struct obj *, const char *);
static void lantern_message(struct obj *);
static void cleanup_burn(ANY_P *, long);
/* used by wizard mode #timeout and #wizintrinsic; order by 'interest'
for timeout countdown, where most won't occur in normal play */
const struct propname {
int prop_num;
const char *prop_name;
} propertynames[] = {
{ INVULNERABLE, "invulnerable" },
{ STONED, "petrifying" },
{ LARVACARRIER, "hosting monster eggs" },
{ SLIMED, "becoming slime" },
{ STRANGLED, "strangling" },
{ SICK, "fatally sick" },
{ STUNNED, "stunned" },
{ CONFUSION, "confused" },
{ AFRAID, "afraid" },
{ HALLUC, "hallucinating" },
{ BLINDED, "blinded" },
{ DEAF, "deafness" },
{ VOMITING, "vomiting" },
{ GLIB, "slippery fingers" },
{ WOUNDED_LEGS, "wounded legs" },
{ SLEEPY, "sleepy" },
{ TELEPORT, "teleporting" },
{ POLYMORPH, "polymorphing" },
{ LEVITATION, "levitating" },
{ FAST, "very fast" }, /* timed 'FAST' is very fast */
{ CLAIRVOYANT, "clairvoyant" },
{ DETECT_MONSTERS, "monster detection" },
{ SEE_INVIS, "see invisible" },
{ INVIS, "invisible" },
/* timed displacement is possible via eating a displacer beast corpse */
{ DISPLACED, "displaced" },
/* timed pass-walls is a potential prayer result if surrounded by stone
with nowhere to be safely teleported to */
{ PASSES_WALLS, "pass thru walls" },
/*
* Properties beyond here don't have timed values during normal play,
* so there's not much point in trying to order them sensibly.
* They're either on or off based on equipment, role, actions, &c.
*/
{ FIRE_RES, "fire resistance" },
{ COLD_RES, "cold resistance" },
{ SLEEP_RES, "sleep resistance" },
{ DISINT_RES, "disintegration resistance" },
{ SHOCK_RES, "shock resistance" },
{ POISON_RES, "poison resistance" },
{ ACID_RES, "acid resistance" },
{ STONE_RES, "stoning resistance" },
{ DRAIN_RES, "drain resistance" },
{ SICK_RES, "sickness resistance" },
{ ANTIMAGIC, "magic resistance" },
{ HALLUC_RES, "hallucination resistance" },
{ FUMBLING, "fumbling" },
{ HUNGER, "voracious hunger" },
{ TELEPAT, "telepathic" },
{ WARNING, "warning" },
{ WARN_OF_MON, "warn: monster type or class" },
{ WARN_UNDEAD, "warn: undead" },
{ SEARCHING, "searching" },
{ INFRAVISION, "infravision" },
{ ADORNED, "adorned (+/- Cha)" },
{ STEALTH, "stealthy" },
{ AGGRAVATE_MONSTER, "monster aggravation" },
{ CONFLICT, "conflict" },
{ JUMPING, "jumping" },
{ TELEPORT_CONTROL, "teleport control" },
{ FLYING, "flying" },
{ WWALKING, "water walking" },
{ SWIMMING, "swimming" },
{ MAGICAL_BREATHING, "magical breathing" },
{ SLOW_DIGESTION, "slow digestion" },
{ HALF_SPDAM, "half spell damage" },
{ HALF_PHDAM, "half physical damage" },
{ REGENERATION, "HP regeneration" },
{ ENERGY_REGENERATION, "energy regeneration" },
{ PROTECTION, "extra protection" },
{ PROT_FROM_SHAPE_CHANGERS, "protection from shape changers" },
{ POLYMORPH_CONTROL, "polymorph control" },
{ UNCHANGING, "unchanging" },
{ REFLECTING, "reflecting" },
{ FREE_ACTION, "free action" },
{ FIXED_ABIL, "fixed abilities" },
{ WITHERING, "withering away"},
{ STABLE, "extraodinarily stable" },
{ LIFESAVED, "life will be saved" },
{ 0, 0 },
};
/* He is being petrified - dialogue by inmet!tower */
static NEARDATA const char *const stoned_texts[] = {
"You are slowing down.", /* 5 */
"Your limbs are stiffening.", /* 4 */
"Your limbs have turned to stone.", /* 3 */
"You have turned to stone.", /* 2 */
"You are a statue." /* 1 */
};
static void
stoned_dialogue(void)
{
register long i = (Stoned & TIMEOUT);
if (i > 0L && i <= SIZE(stoned_texts)) {
char buf[BUFSZ];
Strcpy(buf, stoned_texts[SIZE(stoned_texts) - i]);
if (nolimbs(g.youmonst.data) && strstri(buf, "limbs"))
(void) strsubst(buf, "limbs", "extremities");
pline1(buf);
}
switch ((int) i) {
case 5: /* slowing down */
HFast = 0L;
if (g.multi > 0)
nomul(0);
break;
case 4: /* limbs stiffening */
/* just one move left to save oneself so quit fiddling around;
don't stop attempt to eat tin--might be lizard or acidic */
if (!Popeye(STONED))
stop_occupation();
if (g.multi > 0)
nomul(0);
break;
case 3: /* limbs turned to stone */
stop_occupation();
nomul(-3); /* can't move anymore */
g.multi_reason = "getting stoned";
g.nomovemsg = You_can_move_again; /* not unconscious */
/* "your limbs have turned to stone" so terminate wounded legs */
if (Wounded_legs && !u.usteed)
heal_legs(2);
break;
case 2: /* turned to stone */
if ((HDeaf & TIMEOUT) > 0L && (HDeaf & TIMEOUT) < 5L)
set_itimeout(&HDeaf, 5L); /* avoid Hear_again at tail end */
/* if also vomiting or turning into slime, stop those (no messages) */
if (Vomiting)
make_vomiting(0L, FALSE);
if (Slimed)
make_slimed(0L, (char *) 0);
break;
default:
break;
}
exercise(A_DEX, FALSE);
}
/* hero is getting sicker and sicker prior to vomiting */
static NEARDATA const char *const vomiting_texts[] = {
"are feeling mildly nauseated.", /* 14 */
"feel slightly confused.", /* 11 */
"can't seem to think straight.", /* 8 */
"feel incredibly sick.", /* 5 */
"are about to vomit." /* 2 */
};
static void
vomiting_dialogue(void)
{
const char *txt = 0;
char buf[BUFSZ];
long v = (Vomiting & TIMEOUT);
/* note: nhtimeout() hasn't decremented timed properties for the
current turn yet, so we use Vomiting-1 here */
switch ((int) (v - 1L)) {
case 14:
txt = vomiting_texts[0];
break;
case 11:
txt = vomiting_texts[1];
if (strstri(txt, " confused") && Confusion)
txt = strsubst(strcpy(buf, txt), " confused", " more confused");
break;
case 6:
make_stunned((HStun & TIMEOUT) + (long) d(2, 4), FALSE);
if (!Popeye(VOMITING))
stop_occupation();
/*FALLTHRU*/
case 9:
make_confused((HConfusion & TIMEOUT) + (long) d(2, 4), FALSE);
if (g.multi > 0)
nomul(0);
break;
case 8:
txt = vomiting_texts[2];
if (strstri(txt, " think") && Stunned)
txt = strsubst(strcpy(buf, txt), "can't seem to ", "can't ");
break;
case 5:
txt = vomiting_texts[3];
break;
case 2:
txt = vomiting_texts[4];
if (cantvomit(g.youmonst.data))
txt = "gag uncontrollably.";
else if (Hallucination)
/* "hurl" is short for "hurl chunks" which is slang for
relatively violent vomiting... */
txt = "are about to hurl!";
break;
case 0:
stop_occupation();
if (!cantvomit(g.youmonst.data)) {
morehungry(20);
/* case 2 used to be "You suddenly vomit!" but it wasn't sudden
since you've just been through the earlier messages of the
countdown, and it was still possible to move around between
that message and "You can move again." (from vomit()'s
nomul(-2)) with no intervening message; give one here to
have more specific point at which hero became unable to move
[vomit() issues its own message for the cantvomit() case
and for the FAINTING-or-worse case where stomach is empty] */
if (u.uhs < FAINTING)
You("%s!", !Hallucination ? "vomit" : "hurl chunks");
}
vomit();
break;
default:
break;
}
if (txt)
You1(txt);
exercise(A_CON, FALSE);
}
static NEARDATA const char *const choke_texts[] = {
"You find it hard to breathe.",
"You're gasping for air.",
"You can no longer breathe.",
"You're turning %s.",
"You suffocate."
};
static NEARDATA const char *const choke_texts2[] = {
"Your %s is becoming constricted.",
"Your blood is having trouble reaching your brain.",
"The pressure on your %s increases.",
"Your consciousness is fading.",
"You suffocate."
};
static void
choke_dialogue(void)
{
register long i = (Strangled & TIMEOUT);
if (i > 0 && i <= SIZE(choke_texts)) {
if (Breathless || !rn2(50))
pline(choke_texts2[SIZE(choke_texts2) - i], body_part(NECK));
else {
const char *str = choke_texts[SIZE(choke_texts) - i];
if (index(str, '%'))
pline(str, hcolor(NH_BLUE));
else
pline1(str);
}
}
exercise(A_STR, FALSE);
}
static NEARDATA const char *const levi_texts[] = {
"You float slightly lower.",
"You wobble unsteadily %s the %s."
};
static void
levitation_dialogue(void)
{
/* -1 because the last message comes via float_down() */
long i = (((HLevitation & TIMEOUT) - 1L) / 2L);
if (ELevitation)
return;
if (!ACCESSIBLE(levl[u.ux][u.uy].typ)
&& !is_pool_or_lava(u.ux,u.uy))
return;
if (((HLevitation & TIMEOUT) % 2L) && i > 0L && i <= SIZE(levi_texts)) {
const char *s = levi_texts[SIZE(levi_texts) - i];
if (index(s, '%')) {
boolean danger = (is_pool_or_lava(u.ux, u.uy)
&& !Is_waterlevel(&u.uz));
pline(s, danger ? "over" : "in",
danger ? surface(u.ux, u.uy) : "air");
} else
pline1(s);
}
}
static NEARDATA const char *const larva_texts[] = {
"You are feeling a little strange.",
"Your skin is crawling.",
"You can feel something moving inside your body!",
"%s burst from your body!"
};
static void
larva_dialogue()
{
register long i = (LarvaCarrier & TIMEOUT) / 2L;
if (((LarvaCarrier & TIMEOUT) % 2L) && i >= 0L && i < SIZE(larva_texts)) {
char buf[BUFSZ];
Strcpy(buf, larva_texts[SIZE(larva_texts) - i - 1L]);
if (index(buf, '%')) {
pline(buf,
makeplural(Hallucination ? rndmonnam(NULL) : "Insect"));
} else
pline1(buf);
}
if (i <= 4L) {
stop_occupation();
}
exercise(A_CON, FALSE);
}
static NEARDATA const char *const slime_texts[] = {
"You are turning a little %s.", /* 5 */
"Your limbs are getting oozy.", /* 4 */
"Your skin begins to peel away.", /* 3 */
"You are turning into %s.", /* 2 */
"You have become %s." /* 1 */
};
static void
slime_dialogue(void)
{
long t = (Slimed & TIMEOUT), i = t / 2L;
if (t == 1L) {
/* display as green slime during "You have become green slime."
but don't worry about not being able to see self; if already
mimicking something else at the time, implicitly be revealed */
g.youmonst.m_ap_type = M_AP_MONSTER;
g.youmonst.mappearance = PM_GREEN_SLIME;
/* no message given when 't' is odd, so no automatic update of
self; force one */
newsym(u.ux, u.uy);
}
if ((t % 2L) != 0L && i >= 0L && i < SIZE(slime_texts)) {
char buf[BUFSZ];
Strcpy(buf, slime_texts[SIZE(slime_texts) - i - 1L]);
if (nolimbs(g.youmonst.data) && strstri(buf, "limbs"))
(void) strsubst(buf, "limbs", "extremities");
if (index(buf, '%')) {
if (i == 4L) { /* "you are turning green" */
if (!Blind) /* [what if you're already green?] */
pline(buf, hcolor(NH_GREEN));
} else
pline(buf,
an(Hallucination ? rndmonnam(NULL) : "green slime"));
} else
pline1(buf);
}
switch (i) {
case 3L: /* limbs becoming oozy */
HFast = 0L; /* lose intrinsic speed */
if (!Popeye(SLIMED))
stop_occupation();
if (g.multi > 0)
nomul(0);
break;
case 2L: /* skin begins to peel */
if ((HDeaf & TIMEOUT) > 0L && (HDeaf & TIMEOUT) < 5L)
set_itimeout(&HDeaf, 5L); /* avoid Hear_again at tail end */
break;
case 1L: /* turning into slime */
/* if also turning to stone, stop doing that (no message) */
if (Stoned)
make_stoned(0L, (char *) 0, KILLED_BY_AN, (char *) 0);
break;
}
exercise(A_DEX, FALSE);
}
void
burn_away_slime(void)
{
if (Slimed) {
make_slimed(0L, "The slime that covers you is burned away!");
}
}
/* countdown timer for turning into green slime has run out; kill our hero */
static void
slimed_to_death(struct kinfo* kptr)
{
uchar save_mvflags;
/* redundant: polymon() cures sliming when polying into green slime */
if (Upolyd && g.youmonst.data == &mons[PM_GREEN_SLIME]) {
dealloc_killer(kptr);
return;
}
/* more sure killer reason is set up */
if (kptr && kptr->name[0]) {
g.killer.format = kptr->format;
Strcpy(g.killer.name, kptr->name);
} else {
g.killer.format = NO_KILLER_PREFIX;
Strcpy(g.killer.name, "turned into green slime");
}
dealloc_killer(kptr);
/*
* Polymorph into a green slime, which might destroy some worn armor
* (potentially affecting bones) and dismount from steed.
* Can't be Unchanging; wouldn't have turned into slime if we were.
* Despite lack of Unchanging, neither done() nor savelife() calls
* rehumanize() if hero dies while polymorphed.
* polymon() undoes the slime countdown's mimick-green-slime hack
* but does not perform polyself()'s light source bookkeeping.
* No longer need to manually increment uconduct.polyselfs to reflect
* [formerly implicit] change of form; polymon() takes care of that.
* Temporarily ungenocide if necessary.
*/
if (emits_light(g.youmonst.data))
del_light_source(LS_MONSTER, monst_to_any(&g.youmonst));
save_mvflags = g.mvitals[PM_GREEN_SLIME].mvflags;
g.mvitals[PM_GREEN_SLIME].mvflags = save_mvflags & ~G_GENOD;
/* become a green slime; also resets youmonst.m_ap_type+.mappearance */
(void) polymon(PM_GREEN_SLIME);
g.mvitals[PM_GREEN_SLIME].mvflags = save_mvflags;
done_timeout(TURNED_SLIME, SLIMED);
/* life-saved; even so, hero still has turned into green slime;
player may have genocided green slimes after being infected */
if ((g.mvitals[PM_GREEN_SLIME].mvflags & G_GENOD) != 0) {
char slimebuf[BUFSZ];
g.killer.format = KILLED_BY;
Strcpy(g.killer.name, "slimicide");
/* vary the message depending upon whether life-save was due to
amulet or due to declining to die in explore or wizard mode */
Strcpy(slimebuf, "green slime has been annihilated...");
if (iflags.last_msg == PLNMSG_OK_DONT_DIE)
/* follows "OK, so you don't die." and arg is second sentence */
pline("Yes, you do. %s", upstart(slimebuf));
else
/* follows "The medallion crumbles to dust." */
pline("Unfortunately, %s", slimebuf);
/* die again; no possibility of amulet this time */
done(GENOCIDED); /* [should it be done_timeout(GENOCIDED, SLIMED)?] */
/* could be life-saved again (only in explore or wizard mode)
but green slimes are gone; just stay in current form */
}
return;
}
/* Intrinsic Passes_walls is temporary when your god is trying to fix
all troubles and then TROUBLE_STUCK_IN_WALL calls safe_teleds() but
it can't find anywhere to place you. If that happens you get a small
value for (HPasses_walls & TIMEOUT) to move somewhere yourself.
Message given is "you feel much slimmer" as a joke hint that you can
move between things which are closely packed--like the substance of
solid rock! */
static NEARDATA const char *const phaze_texts[] = {
"You start to feel bloated.",
"You are feeling rather flabby.",
};
static void
phaze_dialogue(void)
{
long i = ((HPasses_walls & TIMEOUT) / 2L);
if (EPasses_walls || (HPasses_walls & ~TIMEOUT))
return;
if (((HPasses_walls & TIMEOUT) % 2L) && i > 0L && i <= SIZE(phaze_texts))
pline1(phaze_texts[SIZE(phaze_texts) - i]);
}
/* when a status timeout is fatal, keep the status line indicator shown
during end of game rundown (and potential dumplog);
timeout has already counted down to 0 by the time we get here */
static void
done_timeout(int how, int which)
{
long *intrinsic_p = &u.uprops[which].intrinsic;
*intrinsic_p |= I_SPECIAL; /* affects final disclosure */
done(how);
/* life-saved */
*intrinsic_p &= ~I_SPECIAL;
g.context.botl = TRUE;
}
void
nh_timeout(void)
{
register struct prop *upp;
struct kinfo *kptr;
boolean was_flying;
int sleeptime;
int m_idx;
int baseluck = (flags.moonphase == FULL_MOON) ? 1 : 0;
if (flags.friday13)
baseluck -= 1;
if (g.quest_status.killed_leader)
baseluck -= 4;
if (u.uluck != baseluck
&& g.moves % ((u.uhave.amulet || u.ugangr) ? 300 : 600) == 0) {
/* Cursed luckstones stop bad luck from timing out; blessed luckstones
* stop good luck from timing out; normal luckstones stop both;
* neither is stopped if you don't have a luckstone.
* Luck is based at 0 usually, +1 if a full moon and -1 on Friday 13th
*/
register int time_luck = stone_luck(FALSE);
boolean nostone = !carrying(LUCKSTONE) && !stone_luck(TRUE);
if (u.uluck > baseluck && (nostone || time_luck < 0))
u.uluck--;
else if (u.uluck < baseluck && (nostone || time_luck > 0))
u.uluck++;
}
if (u.uinvulnerable)
return; /* things past this point could kill you */
if (Stoned)
stoned_dialogue();
if (LarvaCarrier)
larva_dialogue();
if (Slimed)
slime_dialogue();
if (Vomiting)
vomiting_dialogue();
if (Strangled)
choke_dialogue();
if (HLevitation & TIMEOUT)
levitation_dialogue();
if (HPasses_walls & TIMEOUT)
phaze_dialogue();
if (u.mtimedone && !--u.mtimedone) {
if (Unchanging ||
(ublindf && ublindf->otyp == MASK))
u.mtimedone = rnd(100 * g.youmonst.data->mlevel + 1);
else if (is_were(g.youmonst.data))
you_unwere(FALSE); /* if polycontrl, asks whether to rehumanize */
else
rehumanize();
}
if (u.ucreamed)
u.ucreamed--;
/* Dissipate spell-based protection. */
if (u.usptime) {
if (--u.usptime == 0 && u.uspellprot) {
u.usptime = u.uspmtime;
u.uspellprot--;
find_ac();
if (!Blind)
Norep("The %s haze around you %s.", hcolor(NH_GOLDEN),
u.uspellprot ? "becomes less dense" : "disappears");
}
}
if (u.ugallop) {
if (--u.ugallop == 0L && u.usteed)
pline("%s stops galloping.", Monnam(u.usteed));
}
was_flying = Flying;
for (upp = u.uprops; upp < u.uprops + SIZE(u.uprops); upp++)
if (!(upp->intrinsic & HAVEPARTIAL) /* partial intrinsics do not time out */
&& (upp->intrinsic & TIMEOUT)
&& !(--upp->intrinsic & TIMEOUT)) {
kptr = find_delayed_killer((int) (upp - u.uprops));
switch (upp - u.uprops) {
case STONED:
if (kptr && kptr->name[0]) {
g.killer.format = kptr->format;
Strcpy(g.killer.name, kptr->name);
} else {
g.killer.format = NO_KILLER_PREFIX;
Strcpy(g.killer.name, "killed by petrification");
}
dealloc_killer(kptr);
/* (unlike sliming, you aren't changing form here) */
done_timeout(STONING, STONED);
break;
case LARVACARRIER:
/* must be in this order for bones files. */
create_critters(rnd(3), &mons[u.ueggpm], TRUE);
losehp(d(1, 5), "being eaten from the inside by insects", KILLED_BY);
u.uhp = (int) (u.uhp / 2);
break;
case SLIMED:
slimed_to_death(kptr); /* done_timeout(TURNED_SLIME,SLIMED) */
break;
case VOMITING:
if (uamul && uamul->otyp == AMULET_OF_NAUSEA) {
make_vomiting((long) rnd(100), FALSE);
} else {
make_vomiting(0L, TRUE);
} break;
case SICK:
/* You might be able to bounce back from food poisoning, but not
* other forms of illness. */
if ((u.usick_type & SICK_NONVOMITABLE) == 0
&& rn2(100) < ACURR(A_CON)) {
You("have recovered from your illness.");
make_sick(0, NULL, FALSE, SICK_ALL);
exercise(A_CON, FALSE);
adjattrib(A_CON, -1, 1);
break;
}
You("die from your illness.");
if (kptr && kptr->name[0]) {
g.killer.format = kptr->format;
Strcpy(g.killer.name, kptr->name);
} else {
g.killer.format = KILLED_BY_AN;
g.killer.name[0] = 0; /* take the default */
}
dealloc_killer(kptr);
if ((m_idx = name_to_mon(g.killer.name,
(int *) 0)) >= LOW_PM) {
if (type_is_pname(&mons[m_idx])) {
g.killer.format = KILLED_BY;
} else if (mons[m_idx].geno & G_UNIQ) {
Strcpy(g.killer.name, the(g.killer.name));
g.killer.format = KILLED_BY;
}
}
done_timeout(POISONING, SICK);
u.usick_type = 0;
break;
case WITHERING:
You("are no longer withering away.");
g.context.botl = TRUE;
break;
case STABLE:
You("are a little less sure of your footing.");
break;
case REFLECTING:
You("are no longer as shiny.");
break;
case REGENERATION:
You_feel("your metabolism returning to normal.");
break;
case WWALKING:
You("feel heavier.");
break;
case FAST:
if (!Very_fast)
You_feel("yourself slow down%s.",
Fast ? " a bit" : "");
break;
case CONFUSION:
/* So make_confused works properly */
set_itimeout(&HConfusion, 1L);
make_confused(0L, TRUE);
if (!Confusion)
stop_occupation();
break;
case STUNNED:
set_itimeout(&HStun, 1L);
make_stunned(0L, TRUE);
if (!Stunned)
stop_occupation();
break;
case AFRAID:
set_itimeout(&HAfraid, 1L);
make_afraid(0L, TRUE);
if (!Afraid)
stop_occupation();
break;
case BLINDED:
set_itimeout(&Blinded, 1L);
make_blinded(0L, TRUE);
if (!Blind)
stop_occupation();
break;
case DEAF:
set_itimeout(&HDeaf, 1L);
make_deaf(0L, TRUE);
g.context.botl = TRUE;
if (!Deaf)
stop_occupation();
break;
case INVIS:
newsym(u.ux, u.uy);
if (!Invis && !BInvis && !Blind) {
You(!See_invisible
? "are no longer invisible."
: "can no longer see through yourself.");
stop_occupation();
}
break;
case SEE_INVIS:
set_mimic_blocking(); /* do special mimic handling */
see_monsters(); /* make invis mons appear */
newsym(u.ux, u.uy); /* make self appear */
stop_occupation();
break;
case WOUNDED_LEGS:
heal_legs(0);
stop_occupation();
break;
case HALLUC:
set_itimeout(&HHallucination, 1L);
(void) make_hallucinated(0L, TRUE, 0L);
if (!Hallucination)
stop_occupation();
break;
case SLEEPY:
if (unconscious() || how_resistant(SLEEP_RES) == 100) {
incr_itimeout(&HSleepy, rnd(100));
} else if (Sleepy) {
You("fall asleep.");
sleeptime = resist_reduce(rnd(20), SLEEP_RES);
fall_asleep(-sleeptime, TRUE);
incr_itimeout(&HSleepy, sleeptime + rnd(100));
}
break;
case LEVITATION:
/* timed Flying is via #wizintrinsic only; still, we want to
avoid float_down() reporting "you have stopped levitating
and are now flying" if both are timing out together;
relies on knowing that Lev timeout is handled before Fly */
if ((HFlying & TIMEOUT) == 1L)
--HFlying; /* bypass pending 'case FLYING' */
(void) float_down(I_SPECIAL | TIMEOUT, 0L);
break;
case FLYING:
/* timed Flying is via #wizintrinsic only */
if (was_flying && !Flying) {
g.context.botl = 1;
You("land.");
spoteffects(TRUE);
}
break;
case DISPLACED:
if (!Displaced) /* give a message */
toggle_displacement((struct obj *) 0, 0L, FALSE);
break;
case WARN_OF_MON:
/* timed Warn_of_mon is via #wizintrinsic only */
if (!Warn_of_mon) {
g.context.warntype.speciesidx = NON_PM;
if (g.context.warntype.species) {
You("are no longer warned about %s.",
makeplural(g.context.warntype.species->pmnames[NEUTRAL]));
g.context.warntype.species = (struct permonst *) 0;
}
}
break;
case PASSES_WALLS:
if (!Passes_walls) {
if (stuck_in_wall())
You_feel("hemmed in again.");
else
pline("You're back to your %s self again.",
!Upolyd ? "normal" : "unusual");
}
break;
case STRANGLED:
g.killer.format = KILLED_BY;
Strcpy(g.killer.name,
(u.uburied) ? "suffocation" : "strangulation");
done_timeout(DIED, STRANGLED);
/* must be declining to die in explore|wizard mode;
treat like being cured of strangulation by prayer */
if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) {
Your("amulet vanishes!");
useup(uamul);
}
break;
case FUMBLING:
/* call this only when a move took place. */
/* otherwise handle fumbling msgs locally. */
if (u.umoved && !(Levitation || Flying)) {
slip_or_trip();
nomul(-2);
g.multi_reason = "fumbling";
g.nomovemsg = "";
/* The more you are carrying the more likely you
* are to make noise when you fumble. Adjustments
* to this number must be thoroughly play tested.
*/
if ((inv_weight() > -500)) {
You("make a lot of noise!");
wake_nearby();
}
}
/* from outside means slippery ice; don't reset
counter if that's the only fumble reason */
HFumbling &= ~FROMOUTSIDE;
if (Fumbling)
incr_itimeout(&HFumbling, rnd(20));
if (iflags.defer_decor) {
/* 'mention_decor' was deferred for message sequencing
reasons; catch up now */
deferred_decor(FALSE);
}
break;
case DETECT_MONSTERS:
see_monsters();
break;
case GLIB:
make_glib(0); /* might update persistent inventory */
break;
}
}
run_timers();
}
void
fall_asleep(int how_long, boolean wakeup_msg)
{
stop_occupation();
nomul(how_long);
g.multi_reason = "sleeping";
/* generally don't notice sounds while sleeping */
if (wakeup_msg && g.multi == how_long) {
/* caller can follow with a direct call to Hear_again() if
there's a need to override this when wakeup_msg is true */
incr_itimeout(&HDeaf, how_long);
g.context.botl = TRUE;
g.afternmv = Hear_again; /* this won't give any messages */
}
/* early wakeup from combat won't be possible until next monster turn */
u.usleep = g.monstermoves;
g.nomovemsg = wakeup_msg ? "You wake up." : You_can_move_again;
}
/* Attach an explosion timeout to a given explosive device */
void
attach_bomb_blow_timeout(bomb, fuse, yours)
struct obj *bomb;
int fuse;
boolean yours;
{
long expiretime;
if (bomb->cursed && !rn2(2)) return; /* doesn't arm if not armed */
/* Now if you play with other people's property... */
if (yours && (!carried(bomb) && costly_spot(bomb->ox, bomb->oy) &&
(!bomb->no_charge || bomb->unpaid))) {
verbalize("You play with it, you pay for it!");
bill_dummy_object(bomb);
}
expiretime = stop_timer(BOMB_BLOW, (genericptr_t) bomb);
if (expiretime > 0L) fuse = fuse - (expiretime - g.monstermoves);
bomb->yours = yours;
bomb->oarmed = TRUE;
(void) start_timer((long)fuse, TIMER_OBJECT, BOMB_BLOW, obj_to_any(bomb));
}
/* timer callback routine: detonate the explosives */
void
bomb_blow(arg, timeout)
anything *arg;
long timeout;
{
struct obj *bomb;
xchar x,y;
boolean silent, underwater;
struct monst *mtmp = (struct monst *)0;
bomb = arg->a_obj;
silent = (timeout != g.monstermoves); /* exploded while away */
if (get_obj_location(bomb, &x, &y, BURIED_TOO | CONTAINED_TOO)) {
switch(bomb->where) {
case OBJ_MINVENT:
mtmp = bomb->ocarry;
if (bomb == MON_WEP(mtmp)) {
bomb->owornmask &= ~W_WEP;
MON_NOWEP(mtmp);
}
if (!silent) {
if (canseemon(mtmp))
You("see %s engulfed in an explosion!", mon_nam(mtmp));
}
mtmp->mhp -= d(2,5);
if (mtmp->mhp < 1) {
if(!bomb->yours)
monkilled(mtmp,
(silent ? "" : "explosion"),
AD_PHYS);
else xkilled(mtmp, !silent);
}
break;
case OBJ_INVENT:
/* This shouldn't be silent! */
pline("Something explodes inside your knapsack!");
if (bomb == uwep) {
uwepgone();
stop_occupation();
} else if (bomb == uswapwep) {
uswapwepgone();
stop_occupation();
} else if (bomb == uquiver) {
uqwepgone();
stop_occupation();
}
losehp(d(2,5), "carrying live explosives", KILLED_BY);
break;
case OBJ_FLOOR:
underwater = is_pool(x, y);
if (!silent) {
if (x == u.ux && y == u.uy) {
if (underwater && (Flying || Levitation))
pline_The("water boils beneath you.");
else if (underwater && Wwalking)
pline_The("water erupts around you.");
else pline("A bomb explodes under your %s!",
makeplural(body_part(FOOT)));
} else if (cansee(x, y))
You(underwater ?
"see a plume of water shoot up." :
"see a bomb explode.");
}
if (underwater && (Flying || Levitation || Wwalking)) {
if (Wwalking && x == u.ux && y == u.uy) {
struct trap trap;
trap.ntrap = NULL;
trap.tx = x;
trap.ty = y;
trap.launch.x = -1;
trap.launch.y = -1;
trap.ttyp = RUST_TRAP;
trap.tseen = 0;
trap.once = 0;
trap.madeby_u = 0;
trap.dst.dnum = -1;
trap.dst.dlevel = -1;
dotrap(&trap, 0);
}
goto free_bomb;
}
break;
default: /* Buried, contained, etc. */
if (!silent)
You_hear("a muffled explosion.");
goto free_bomb;
break;
}
grenade_explode(bomb, x, y, bomb->yours);
free_bomb:
if (carried(bomb)) {
useup(bomb);
} else if (bomb) {
obj_extract_self(bomb);
obfree(bomb, (struct obj *)0);
}
newsym(x, y);
return;
} /* Migrating grenades "blow up in midair" */
}
/* Attach an egg hatch timeout to the given egg.
* when = Time to hatch, usually only passed if re-creating an
* existing hatch timer. Pass 0L for random hatch time.
*/
void