forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeout.c
2552 lines (2337 loc) · 82.2 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: 1658390077 2022/07/21 07:54:37 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.142 $ */
/* 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 slime_dialogue(void);
static void slimed_to_death(struct kinfo *);
static void sickness_dialogue(void);
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 */
static const struct propname {
int prop_num;
const char *prop_name;
} propertynames[] = {
{ INVULNERABLE, "invulnerable" },
{ STONED, "petrifying" },
{ SLIMED, "becoming slime" },
{ STRANGLED, "strangling" },
{ SICK, "fatally sick" },
{ STUNNED, "stunned" },
{ CONFUSION, "confused" },
{ 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" },
/* temporary acid resistance and stone resistance can come from eating */
{ ACID_RES, "acid resistance" },
{ STONE_RES, "stoning resistance" },
/* 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,
* but in wizard mode #wizintrinsic can give then as timed effects.
*/
{ FIRE_RES, "fire resistance" },
{ COLD_RES, "cold resistance" },
{ SLEEP_RES, "sleep resistance" },
{ DISINT_RES, "disintegration resistance" },
{ SHOCK_RES, "shock resistance" },
{ POISON_RES, "poison 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" },
{ LIFESAVED, "life will be saved" },
{ 0, 0 },
};
const char *
property_by_index(int idx, int *propertynum)
{
if (!(idx >= 0 && idx < SIZE(propertynames) - 1))
idx = SIZE(propertynames) - 1;
if (propertynum)
*propertynum = propertynames[idx].prop_num;
return propertynames[idx].prop_name;
}
/* 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)
{
long i = (Stoned & TIMEOUT);
if (i > 0L && i <= SIZE(stoned_texts)) {
char buf[BUFSZ];
Strcpy(buf, stoned_texts[SIZE(stoned_texts) - i]);
if (nolimbs(gy.youmonst.data) && strstri(buf, "limbs"))
(void) strsubst(buf, "limbs", "extremities");
urgent_pline("%s", buf);
}
switch ((int) i) {
case 5: /* slowing down */
HFast = 0L;
if (gm.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 (gm.multi > 0)
nomul(0);
break;
case 3: /* limbs turned to stone */
stop_occupation();
nomul(-3); /* can't move anymore */
gm.multi_reason = "getting stoned";
gn.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 (gm.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(gy.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(gy.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);
}
DISABLE_WARNING_FORMAT_NONLITERAL /* RESTORE is after slime_dialogue */
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)
{
long i = (Strangled & TIMEOUT);
if (i > 0 && i <= SIZE(choke_texts)) {
if (Breathless || !rn2(50)) {
urgent_pline(choke_texts2[SIZE(choke_texts2) - i],
body_part(NECK));
} else {
const char *str = choke_texts[SIZE(choke_texts) - i];
if (strchr(str, '%'))
urgent_pline(str, hcolor(NH_BLUE));
else
urgent_pline("%s", str);
}
}
exercise(A_STR, FALSE);
}
static NEARDATA const char *const sickness_texts[] = {
"Your illness feels worse.",
"Your illness is severe.",
"You are at Death's door.",
};
static void
sickness_dialogue(void)
{
long j = (Sick & TIMEOUT), i = j / 2L;
if (i > 0L && i <= SIZE(sickness_texts) && (j % 2) != 0) {
char buf[BUFSZ], pronounbuf[40];
Strcpy(buf, sickness_texts[SIZE(sickness_texts) - i]);
/* change the message slightly for food poisoning */
if ((u.usick_type & SICK_NONVOMITABLE) == 0)
(void) strsubst(buf, "illness", "sickness");
if (Hallucination && strstri(buf, "Death's door")) {
/* youmonst: for Hallucination, mhe()'s mon argument isn't used */
Strcpy(pronounbuf, mhe(&gy.youmonst));
Sprintf(eos(buf), " %s %s inviting you in.",
/* upstart() modifies its argument but vtense() doesn't
care whether or not that has already happened */
upstart(pronounbuf), vtense(pronounbuf, "are"));
}
urgent_pline("%s", buf);
}
exercise(A_CON, 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 (strchr(s, '%')) {
boolean danger = (is_pool_or_lava(u.ux, u.uy)
&& !Is_waterlevel(&u.uz));
urgent_pline(s, danger ? "over" : "in",
danger ? surface(u.ux, u.uy) : "air");
} else
pline1(s);
}
}
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 */
gy.youmonst.m_ap_type = M_AP_MONSTER;
gy.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(gy.youmonst.data) && strstri(buf, "limbs"))
(void) strsubst(buf, "limbs", "extremities");
if (strchr(buf, '%')) {
if (i == 4L) { /* "you are turning green" */
if (!Blind) /* [what if you're already green?] */
urgent_pline(buf, hcolor(NH_GREEN));
} else {
urgent_pline(buf, an(Hallucination ? rndmonnam(NULL)
: "green slime"));
}
} else {
urgent_pline("%s", buf);
}
}
switch (i) {
case 3L: /* limbs becoming oozy */
HFast = 0L; /* lose intrinsic speed */
if (!Popeye(SLIMED))
stop_occupation();
if (gm.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);
}
RESTORE_WARNING_FORMAT_NONLITERAL
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 && gy.youmonst.data == &mons[PM_GREEN_SLIME]) {
dealloc_killer(kptr);
return;
}
/* more sure killer reason is set up */
if (kptr && kptr->name[0]) {
gk.killer.format = kptr->format;
Strcpy(gk.killer.name, kptr->name);
} else {
gk.killer.format = NO_KILLER_PREFIX;
Strcpy(gk.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(gy.youmonst.data))
del_light_source(LS_MONSTER, monst_to_any(&gy.youmonst));
save_mvflags = gm.mvitals[PM_GREEN_SLIME].mvflags;
gm.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);
gm.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 ((gm.mvitals[PM_GREEN_SLIME].mvflags & G_GENOD) != 0) {
char slimebuf[BUFSZ];
gk.killer.format = KILLED_BY;
Strcpy(gk.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 genocided...");
if (iflags.last_msg == PLNMSG_OK_DONT_DIE)
/* follows "OK, so you don't die." and arg is second sentence */
urgent_pline("Yes, you do. %s", upstart(slimebuf));
else
/* follows "The medallion crumbles to dust." */
urgent_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;
gc.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 (gq.quest_status.killed_leader)
baseluck -= 4;
if (u.uluck != baseluck
&& gm.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 (Slimed)
slime_dialogue();
if (Vomiting)
vomiting_dialogue();
if (Strangled)
choke_dialogue();
if (Sick)
sickness_dialogue();
if (HLevitation & TIMEOUT)
levitation_dialogue();
if (HPasses_walls & TIMEOUT)
phaze_dialogue();
if (u.mtimedone && !--u.mtimedone) {
if (Unchanging)
u.mtimedone = rnd(100 * gy.youmonst.data->mlevel + 1);
else if (is_were(gy.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 & TIMEOUT) && !(--upp->intrinsic & TIMEOUT)) {
kptr = find_delayed_killer((int) (upp - u.uprops));
switch (upp - u.uprops) {
case STONED:
if (kptr && kptr->name[0]) {
gk.killer.format = kptr->format;
Strcpy(gk.killer.name, kptr->name);
} else {
gk.killer.format = NO_KILLER_PREFIX;
Strcpy(gk.killer.name, "killed by petrification");
}
dealloc_killer(kptr);
/* (unlike sliming, you aren't changing form here) */
done_timeout(STONING, STONED);
break;
case SLIMED:
slimed_to_death(kptr); /* done_timeout(TURNED_SLIME,SLIMED) */
break;
case VOMITING:
make_vomiting(0L, TRUE);
break;
case SICK:
/* hero 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;
}
urgent_pline("You die from your illness.");
if (kptr && kptr->name[0]) {
gk.killer.format = kptr->format;
Strcpy(gk.killer.name, kptr->name);
} else {
gk.killer.format = KILLED_BY_AN;
gk.killer.name[0] = 0; /* take the default */
}
dealloc_killer(kptr);
if ((m_idx = name_to_mon(gk.killer.name,
(int *) 0)) >= LOW_PM) {
if (type_is_pname(&mons[m_idx])) {
gk.killer.format = KILLED_BY;
} else if (mons[m_idx].geno & G_UNIQ) {
Strcpy(gk.killer.name, the(gk.killer.name));
gk.killer.format = KILLED_BY;
}
}
done_timeout(POISONING, SICK);
u.usick_type = 0;
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 BLINDED:
set_itimeout(&Blinded, 1L);
make_blinded(0L, TRUE);
if (!Blind)
stop_occupation();
break;
case DEAF:
set_itimeout(&HDeaf, 1L);
make_deaf(0L, TRUE);
gc.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() || Sleep_resistance) {
incr_itimeout(&HSleepy, rnd(100));
} else if (Sleepy) {
You("fall asleep.");
sleeptime = rnd(20);
fall_asleep(-sleeptime, TRUE);
incr_itimeout(&HSleepy, sleeptime + rnd(100));
}
break;
case LEVITATION:
/* timed Levitation is ordinary, timed Flying is via
#wizintrinsic only; still, we want to avoid float_down()
reporting "you have stopped levitating and are now flying"
when both are timing out together; if that is about to
happen, end Flying early to skip feedback about it;
assumes Levitation is handled before Flying */
if ((HFlying & TIMEOUT) == 1L)
set_itimeout(&HFlying, 0L); /* bypass 'case FLYING' */
(void) float_down(I_SPECIAL | TIMEOUT, 0L);
break;
case FLYING:
/* timed Flying is via #wizintrinsic only */
if (was_flying && !Flying) {
gc.context.botl = 1;
You("land.");
spoteffects(TRUE);
}
break;
case ACID_RES:
if (!Acid_resistance && !Unaware)
You("no longer feel safe from acid.");
break;
case STONE_RES:
if (!Stone_resistance) {
if (!Unaware)
You("no longer feel secure from petrification.");
/* no-op if not wielding a cockatrice corpse;
uswapwep case is always a no-op (see Gloves_off()) */
wielding_corpse(uwep, (struct obj *) 0, FALSE);
wielding_corpse(uswapwep, (struct obj *) 0, FALSE);
}
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) {
gc.context.warntype.speciesidx = NON_PM;
if (gc.context.warntype.species) {
You("are no longer warned about %s.",
makeplural(gc.context.warntype.species->pmnames[NEUTRAL]));
gc.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:
gk.killer.format = KILLED_BY;
Strcpy(gk.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);
gm.multi_reason = "fumbling";
gn.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);
gm.multi_reason = "sleeping";
#if 0 /* this was broken; the fix for 'how_long' will result in changed
* behavior for sounds that don't go through You_hear() so needs
* testing */
/* You_hear() produces "You dream that you hear ..." when sleeping;
other sound messages will either honor or ignore Deaf */
if (wakeup_msg && gm.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 */
/* 3.7: how_long is negative so wasn't actually incrementing the
deafness timeout when it used to be passed as-is */
incr_itimeout(&HDeaf, abs(how_long));
gc.context.botl = TRUE;
ga.afternmv = Hear_again; /* this won't give any messages */
}
#endif
/* early wakeup from combat won't be possible until next monster turn */
u.usleep = gm.moves;
gn.nomovemsg = wakeup_msg ? "You wake up." : You_can_move_again;
}
/* 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
attach_egg_hatch_timeout(struct obj* egg, long when)
{
int i;
/* stop previous timer, if any */
(void) stop_timer(HATCH_EGG, obj_to_any(egg));
/*
* Decide if and when to hatch the egg. The old hatch_it() code tried
* once a turn from age 151 to 200 (inclusive), hatching if it rolled
* a number x, 1<=x<=age, where x>150. This yields a chance of
* hatching > 99.9993%. Mimic that here.
*/
if (!when) {
for (i = (MAX_EGG_HATCH_TIME - 50) + 1; i <= MAX_EGG_HATCH_TIME; i++)
if (rnd(i) > 150) {
/* egg will hatch */
when = (long) i;
break;
}
}
if (when) {
(void) start_timer(when, TIMER_OBJECT, HATCH_EGG, obj_to_any(egg));
}
}
/* prevent an egg from ever hatching */
void
kill_egg(struct obj* egg)
{
/* stop previous timer, if any */
(void) stop_timer(HATCH_EGG, obj_to_any(egg));
}
/* timer callback routine: hatch the given egg */
void
hatch_egg(anything *arg, long timeout)
{
struct obj *egg;
struct monst *mon, *mon2;
coord cc;
coordxy x, y;
boolean yours, silent, knows_egg = FALSE;
boolean cansee_hatchspot = FALSE;
int i, mnum, hatchcount = 0;
egg = arg->a_obj;
/* sterilized while waiting */
if (egg->corpsenm == NON_PM)
return;
mon = mon2 = (struct monst *) 0;
mnum = big_to_little(egg->corpsenm);
/* The identity of one's father is learned, not innate */
yours = (egg->spe || (!flags.female && carried(egg) && !rn2(2)));
silent = (timeout != gm.moves); /* hatched while away */
/* only can hatch when in INVENT, FLOOR, MINVENT */
if (get_obj_location(egg, &x, &y, 0)) {
hatchcount = rnd((int) egg->quan);
cansee_hatchspot = cansee(x, y) && !silent;
if (!(mons[mnum].geno & G_UNIQ)
&& !(gm.mvitals[mnum].mvflags & (G_GENOD | G_EXTINCT))) {
for (i = hatchcount; i > 0; i--) {
if (!enexto(&cc, x, y, &mons[mnum])
|| !(mon = makemon(&mons[mnum], cc.x, cc.y,
NO_MINVENT|MM_NOMSG)))
break;
/* tame if your own egg hatches while you're on the
same dungeon level, or any dragon egg which hatches
while it's in your inventory */
if ((yours && !silent)
|| (carried(egg) && mon->data->mlet == S_DRAGON)) {
if (tamedog(mon, (struct obj *) 0)) {
if (carried(egg) && mon->data->mlet != S_DRAGON)
mon->mtame = 20;
}
}
if (gm.mvitals[mnum].mvflags & G_EXTINCT)
break; /* just made last one */
mon2 = mon; /* in case makemon() fails on 2nd egg */
}
if (!mon)
mon = mon2;
hatchcount -= i;
egg->quan -= (long) hatchcount;
}
#if 0
/*
* We could possibly hatch while migrating, but the code isn't
* set up for it...
*/
} else if (obj->where == OBJ_MIGRATING) {
/*
* We can do several things. The first ones that come to
* mind are:
* + Create the hatched monster then place it on the migrating
* mons list. This is tough because all makemon() is made
* to place the monster as well. Makemon() also doesn't lend
* itself well to splitting off a "not yet placed" subroutine.
* + Mark the egg as hatched, then place the monster when we
* place the migrating objects.
* + Or just kill any egg which gets sent to another level.
* Falling is the usual reason such transportation occurs.
*/
cansee_hatchspot = FALSE;
mon = ???;
#endif
}
if (mon) {
char monnambuf[BUFSZ], carriedby[BUFSZ];
boolean siblings = (hatchcount > 1), redraw = FALSE;
if (cansee_hatchspot) {
/* [bug? m_monnam() yields accurate monster type
regardless of hallucination] */
Sprintf(monnambuf, "%s%s", siblings ? "some " : "",
siblings ? makeplural(m_monnam(mon)) : an(m_monnam(mon)));
/* we don't learn the egg type here because learning
an egg type requires either seeing the egg hatch
or being familiar with the egg already,