-
Notifications
You must be signed in to change notification settings - Fork 452
/
timeout.c
2377 lines (2184 loc) · 73.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.6 timeout.c $NHDT-Date: 1545182148 2018/12/19 01:15:48 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.89 $ */
/* 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"
#include "lev.h" /* for checking save modes */
STATIC_DCL void NDECL(stoned_dialogue);
STATIC_DCL void NDECL(vomiting_dialogue);
STATIC_DCL void NDECL(choke_dialogue);
STATIC_DCL void NDECL(levitation_dialogue);
STATIC_DCL void NDECL(slime_dialogue);
STATIC_DCL void FDECL(slimed_to_death, (struct kinfo *));
STATIC_DCL void NDECL(slip_or_trip);
STATIC_DCL void FDECL(see_lamp_flicker, (struct obj *, const char *));
STATIC_DCL void FDECL(lantern_message, (struct obj *));
STATIC_DCL void FDECL(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" },
{ 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" },
/* 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)" },
{ DISPLACED, "displaced" },
{ 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" },
{ PASSES_WALLS, "pass thru walls" },
{ 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 abilites" },
{ 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_OVL void
stoned_dialogue()
{
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(youmonst.data) && strstri(buf, "limbs"))
(void) strsubst(buf, "limbs", "extremities");
pline1(buf);
}
switch ((int) i) {
case 5: /* slowing down */
HFast = 0L;
if (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 (multi > 0)
nomul(0);
break;
case 3: /* limbs turned to stone */
stop_occupation();
nomul(-3); /* can't move anymore */
multi_reason = "getting stoned";
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_OVL void
vomiting_dialogue()
{
const char *txt = 0;
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];
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 (multi > 0)
nomul(0);
break;
case 8:
txt = vomiting_texts[2];
break;
case 5:
txt = vomiting_texts[3];
break;
case 2:
txt = vomiting_texts[4];
if (cantvomit(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(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_OVL void
choke_dialogue()
{
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_OVL void
levitation_dialogue()
{
/* -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 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_OVL void
slime_dialogue()
{
register long i = (Slimed & TIMEOUT) / 2L;
if (i == 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 */
youmonst.m_ap_type = M_AP_MONSTER;
youmonst.mappearance = PM_GREEN_SLIME;
}
if (((Slimed & TIMEOUT) % 2L) && i >= 0L && i < SIZE(slime_texts)) {
char buf[BUFSZ];
Strcpy(buf, slime_texts[SIZE(slime_texts) - i - 1L]);
if (nolimbs(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 (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()
{
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_OVL void
slimed_to_death(kptr)
struct kinfo *kptr;
{
uchar save_mvflags;
/* redundant: polymon() cures sliming when polying into green slime */
if (Upolyd && youmonst.data == &mons[PM_GREEN_SLIME]) {
dealloc_killer(kptr);
return;
}
/* more sure killer reason is set up */
if (kptr && kptr->name[0]) {
killer.format = kptr->format;
Strcpy(killer.name, kptr->name);
} else {
killer.format = NO_KILLER_PREFIX;
Strcpy(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(youmonst.data))
del_light_source(LS_MONSTER, monst_to_any(&youmonst));
save_mvflags = mvitals[PM_GREEN_SLIME].mvflags;
mvitals[PM_GREEN_SLIME].mvflags = save_mvflags & ~G_GENOD;
(void) polymon(PM_GREEN_SLIME);
mvitals[PM_GREEN_SLIME].mvflags = save_mvflags;
done(TURNED_SLIME);
/* life-saved; even so, hero still has turned into green slime;
player may have genocided green slimes after being infected */
if ((mvitals[PM_GREEN_SLIME].mvflags & G_GENOD) != 0) {
killer.format = KILLED_BY;
Strcpy(killer.name, "slimicide");
/* immediately follows "OK, so you don't die." */
pline("Yes, you do. Green slime has been genocided...");
done(GENOCIDED);
/* 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_OVL void
phaze_dialogue()
{
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]);
}
void
nh_timeout()
{
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 (u.uluck != baseluck
&& 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 (HLevitation & TIMEOUT)
levitation_dialogue();
if (HPasses_walls & TIMEOUT)
phaze_dialogue();
if (u.mtimedone && !--u.mtimedone) {
if (Unchanging)
u.mtimedone = rnd(100 * youmonst.data->mlevel + 1);
else if (is_were(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]) {
killer.format = kptr->format;
Strcpy(killer.name, kptr->name);
} else {
killer.format = NO_KILLER_PREFIX;
Strcpy(killer.name, "killed by petrification");
}
dealloc_killer(kptr);
/* (unlike sliming, you aren't changing form here) */
done(STONING);
break;
case SLIMED:
slimed_to_death(kptr); /* done(TURNED_SLIME) */
break;
case VOMITING:
make_vomiting(0L, TRUE);
break;
case SICK:
You("die from your illness.");
if (kptr && kptr->name[0]) {
killer.format = kptr->format;
Strcpy(killer.name, kptr->name);
} else {
killer.format = KILLED_BY_AN;
killer.name[0] = 0; /* take the default */
}
dealloc_killer(kptr);
if ((m_idx = name_to_mon(killer.name)) >= LOW_PM) {
if (type_is_pname(&mons[m_idx])) {
killer.format = KILLED_BY;
} else if (mons[m_idx].geno & G_UNIQ) {
Strcpy(killer.name, the(killer.name));
killer.format = KILLED_BY;
}
}
u.usick_type = 0;
done(POISONING);
break;
case FAST:
if (!Very_fast)
You_feel("yourself slowing 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);
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:
(void) float_down(I_SPECIAL | TIMEOUT, 0L);
break;
case FLYING:
/* timed Flying is via #wizintrinsic only */
if (was_flying && !Flying) {
context.botl = 1;
You("land.");
spoteffects(TRUE);
}
break;
case WARN_OF_MON:
/* timed Warn_of_mon is via #wizintrinsic only */
if (!Warn_of_mon) {
context.warntype.speciesidx = NON_PM;
if (context.warntype.species) {
You("are no longer warned about %s.",
makeplural(context.warntype.species->mname));
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:
killer.format = KILLED_BY;
Strcpy(killer.name,
(u.uburied) ? "suffocation" : "strangulation");
done(DIED);
/* 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) {
slip_or_trip();
nomul(-2);
multi_reason = "fumbling";
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));
break;
case DETECT_MONSTERS:
see_monsters();
break;
}
}
run_timers();
}
void
fall_asleep(how_long, wakeup_msg)
int how_long;
boolean wakeup_msg;
{
stop_occupation();
nomul(how_long);
multi_reason = "sleeping";
/* generally don't notice sounds while sleeping */
if (wakeup_msg && 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);
context.botl = TRUE;
afternmv = Hear_again; /* this won't give any messages */
}
/* early wakeup from combat won't be possible until next monster turn */
u.usleep = monstermoves;
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(egg, when)
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(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(arg, timeout)
anything *arg;
long timeout;
{
struct obj *egg;
struct monst *mon, *mon2;
coord cc;
xchar 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 != monstermoves); /* 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)
&& !(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)))
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 (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,
as well as being able to see the resulting
monster, checked below
*/
}
switch (egg->where) {
case OBJ_INVENT:
knows_egg = TRUE; /* true even if you are blind */
if (!cansee_hatchspot)
You_feel("%s %s from your pack!", something,
locomotion(mon->data, "drop"));
else
You_see("%s %s out of your pack!", monnambuf,
locomotion(mon->data, "drop"));
if (yours) {
pline("%s cries sound like \"%s%s\"",
siblings ? "Their" : "Its",
flags.female ? "mommy" : "daddy", egg->spe ? "." : "?");
} else if (mon->data->mlet == S_DRAGON && !Deaf) {
verbalize("Gleep!"); /* Mything eggs :-) */
}
break;
case OBJ_FLOOR:
if (cansee_hatchspot) {
knows_egg = TRUE;
You_see("%s hatch.", monnambuf);
redraw = TRUE; /* update egg's map location */
}
break;
case OBJ_MINVENT:
if (cansee_hatchspot) {
/* egg carrying monster might be invisible */
mon2 = egg->ocarry;
if (canseemon(mon2)
&& (!mon2->wormno || cansee(mon2->mx, mon2->my))) {
Sprintf(carriedby, "%s pack",
s_suffix(a_monnam(mon2)));
knows_egg = TRUE;
} else if (is_pool(mon->mx, mon->my)) {
Strcpy(carriedby, "empty water");
} else {
Strcpy(carriedby, "thin air");
}
You_see("%s %s out of %s!", monnambuf,
locomotion(mon->data, "drop"), carriedby);
}
break;
#if 0
case OBJ_MIGRATING:
break;
#endif
default:
impossible("egg hatched where? (%d)", (int) egg->where);
break;
}
if (cansee_hatchspot && knows_egg)
learn_egg_type(mnum);
if (egg->quan > 0) {
/* still some eggs left */
/* Instead of ordinary egg timeout use a short one */
attach_egg_hatch_timeout(egg, (long) rnd(12));
} else if (carried(egg)) {
useup(egg);
} else {
/* free egg here because we use it above */
obj_extract_self(egg);
obfree(egg, (struct obj *) 0);
}
if (redraw)
newsym(x, y);
}
}
/* Learn to recognize eggs of the given type. */
void
learn_egg_type(mnum)
int mnum;
{
/* baby monsters hatch from grown-up eggs */
mnum = little_to_big(mnum);
mvitals[mnum].mvflags |= MV_KNOWS_EGG;
/* we might have just learned about other eggs being carried */
update_inventory();
}
/* Attach a fig_transform timeout to the given figurine. */
void
attach_fig_transform_timeout(figurine)
struct obj *figurine;
{
int i;
/* stop previous timer, if any */
(void) stop_timer(FIG_TRANSFORM, obj_to_any(figurine));
/*
* Decide when to transform the figurine.
*/
i = rnd(9000) + 200;
/* figurine will transform */
(void) start_timer((long) i, TIMER_OBJECT, FIG_TRANSFORM,
obj_to_any(figurine));
}
/* give a fumble message */
STATIC_OVL void
slip_or_trip()
{
struct obj *otmp = vobj_at(u.ux, u.uy), *otmp2;
const char *what;
char buf[BUFSZ];
boolean on_foot = TRUE;
if (u.usteed)
on_foot = FALSE;
if (otmp && on_foot && !u.uinwater && is_pool(u.ux, u.uy))
otmp = 0;
if (otmp && on_foot) { /* trip over something in particular */
/*
If there is only one item, it will have just been named
during the move, so refer to by via pronoun; otherwise,
if the top item has been or can be seen, refer to it by
name; if not, look for rocks to trip over; trip over
anonymous "something" if there aren't any rocks.
*/
what = (iflags.last_msg == PLNMSG_ONE_ITEM_HERE)
? ((otmp->quan == 1L) ? "it"
: Hallucination ? "they" : "them")
: (otmp->dknown || !Blind)
? doname(otmp)
: ((otmp2 = sobj_at(ROCK, u.ux, u.uy)) == 0
? something
: (otmp2->quan == 1L ? "a rock" : "some rocks"));
if (Hallucination) {
what = strcpy(buf, what);
buf[0] = highc(buf[0]);
pline("Egads! %s bite%s your %s!", what,
(!otmp || otmp->quan == 1L) ? "s" : "", body_part(FOOT));
} else {
You("trip over %s.", what);
}