/
eat.c
2729 lines (2543 loc) · 76 KB
/
eat.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
/* SCCS Id: @(#)eat.c 3.5 2005/06/02 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
/* #define DEBUG */ /* uncomment to enable new eat code debugging */
#ifdef DEBUG
# ifdef WIZARD
#define debugpline if (wizard) pline
# else
#define debugpline pline
# endif
#endif
STATIC_PTR int NDECL(eatmdone);
STATIC_PTR int NDECL(eatfood);
STATIC_PTR void FDECL(costly_tin, (int));
STATIC_PTR int NDECL(opentin);
STATIC_PTR int NDECL(unfaint);
STATIC_DCL const char *FDECL(food_xname, (struct obj *,BOOLEAN_P));
STATIC_DCL void FDECL(choke, (struct obj *));
STATIC_DCL void NDECL(recalc_wt);
STATIC_DCL struct obj *FDECL(touchfood, (struct obj *));
STATIC_DCL void NDECL(do_reset_eat);
STATIC_DCL void FDECL(done_eating, (BOOLEAN_P));
STATIC_DCL void FDECL(cprefx, (int));
STATIC_DCL int FDECL(intrinsic_possible, (int,struct permonst *));
STATIC_DCL void FDECL(givit, (int,struct permonst *));
STATIC_DCL void FDECL(cpostfx, (int));
STATIC_DCL void FDECL(start_tin, (struct obj *));
STATIC_DCL int FDECL(eatcorpse, (struct obj *));
STATIC_DCL void FDECL(start_eating, (struct obj *));
STATIC_DCL void FDECL(fprefx, (struct obj *));
STATIC_DCL void FDECL(fpostfx, (struct obj *));
STATIC_DCL int NDECL(bite);
STATIC_DCL int FDECL(edibility_prompts, (struct obj *));
STATIC_DCL int FDECL(rottenfood, (struct obj *));
STATIC_DCL void NDECL(eatspecial);
STATIC_DCL int FDECL(bounded_increase, (int,int,int));
STATIC_DCL void FDECL(accessory_has_effect, (struct obj *));
STATIC_DCL void FDECL(eataccessory, (struct obj *));
STATIC_DCL const char *FDECL(foodword, (struct obj *));
STATIC_DCL int FDECL(tin_variety, (struct obj *));
STATIC_DCL boolean FDECL(maybe_cannibal, (int,BOOLEAN_P));
char msgbuf[BUFSZ];
/* hunger texts used on bottom line (each 8 chars long) */
#define SATIATED 0
#define NOT_HUNGRY 1
#define HUNGRY 2
#define WEAK 3
#define FAINTING 4
#define FAINTED 5
#define STARVED 6
/* also used to see if you're allowed to eat cats and dogs */
#define CANNIBAL_ALLOWED() (Role_if(PM_CAVEMAN) || Race_if(PM_ORC))
/* monster types that cause hero to be turned into stone if eaten */
#define flesh_petrifies(pm) (touch_petrifies(pm) || (pm) == &mons[PM_MEDUSA])
STATIC_OVL NEARDATA const char comestibles[] = { FOOD_CLASS, 0 };
/* Gold must come first for getobj(). */
STATIC_OVL NEARDATA const char allobj[] = {
COIN_CLASS, WEAPON_CLASS, ARMOR_CLASS, POTION_CLASS, SCROLL_CLASS,
WAND_CLASS, RING_CLASS, AMULET_CLASS, FOOD_CLASS, TOOL_CLASS,
GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, SPBOOK_CLASS, 0 };
STATIC_OVL boolean force_save_hs = FALSE;
const char *hu_stat[] = {
"Satiated",
" ",
"Hungry ",
"Weak ",
"Fainting",
"Fainted ",
"Starved "
};
/*
* Decide whether a particular object can be eaten by the possibly
* polymorphed character. Not used for monster checks.
*/
boolean
is_edible(obj)
register struct obj *obj;
{
/* protect invocation tools but not Rider corpses (handled elsewhere)*/
/* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */
if (objects[obj->otyp].oc_unique)
return FALSE;
/* above also prevents the Amulet from being eaten, so we must never
allow fake amulets to be eaten either [which is already the case] */
if (metallivorous(youmonst.data) && is_metallic(obj) &&
(youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj)))
return TRUE;
if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj) &&
/* [g.cubes can eat containers and retain all contents
as engulfed items, but poly'd player can't do that] */
!Has_contents(obj))
return TRUE;
/* return((boolean)(!!index(comestibles, obj->oclass))); */
return (boolean)(obj->oclass == FOOD_CLASS);
}
void
init_uhunger()
{
u.uhunger = 900;
u.uhs = NOT_HUNGRY;
}
/* tin types */
static const struct {
const char *txt; /* description */
int nut; /* nutrition */
Bitfield(fodder,1); /* stocked by health food shops */
Bitfield(greasy,1); /* causes slippery fingers */
} tintxts[] = {
{"rotten", -50, 0, 0}, /* ROTTEN_TIN = 0 */
{"homemade", 50, 1, 0}, /* HOMEMADE_TIN = 1 */
{"soup made from", 20, 1, 0},
{"french fried", 40, 0, 1},
{"pickled", 40, 1, 0},
{"boiled", 50, 1, 0},
{"smoked", 50, 1, 0},
{"dried", 55, 1, 0},
{"deep fried", 60, 0, 1},
{"szechuan", 70, 1, 0},
{"broiled", 80, 0, 0},
{"stir fried", 80, 0, 1},
{"sauteed", 95, 0, 0},
{"candied", 100, 1, 0},
{"pureed", 500, 1, 0},
{"", 0, 0, 0}
};
#define TTSZ SIZE(tintxts)
static char *eatmbuf = 0; /* set by cpostfx() */
STATIC_PTR
int
eatmdone() /* called after mimicing is over */
{
/* release `eatmbuf' */
if (eatmbuf) {
if (nomovemsg == eatmbuf) nomovemsg = 0;
free((genericptr_t)eatmbuf), eatmbuf = 0;
}
/* update display */
if (youmonst.m_ap_type) {
youmonst.m_ap_type = M_AP_NOTHING;
newsym(u.ux,u.uy);
}
return 0;
}
/* ``[the(] singular(food, xname) [)]'' with awareness of unique monsters */
STATIC_OVL const char *
food_xname(food, the_pfx)
struct obj *food;
boolean the_pfx;
{
const char *result;
int mnum = food->corpsenm;
if (food->otyp == CORPSE && (mons[mnum].geno & G_UNIQ)) {
/* grab xname()'s modifiable return buffer for our own use */
char *bufp = xname(food);
Sprintf(bufp, "%s%s corpse",
(the_pfx && !type_is_pname(&mons[mnum])) ? "the " : "",
s_suffix(mons[mnum].mname));
result = bufp;
} else {
/* the ordinary case */
result = singular(food, xname);
if (the_pfx) result = the(result);
}
return result;
}
/* Created by GAN 01/28/87
* Amended by AKP 09/22/87: if not hard, don't choke, just vomit.
* Amended by 3. 06/12/89: if not hard, sometimes choke anyway, to keep risk.
* 11/10/89: if hard, rarely vomit anyway, for slim chance.
*/
STATIC_OVL void
choke(food) /* To a full belly all food is bad. (It.) */
register struct obj *food;
{
/* only happens if you were satiated */
if (u.uhs != SATIATED) {
if (!food || food->otyp != AMULET_OF_STRANGULATION)
return;
} else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) {
adjalign(-1); /* gluttony is unchivalrous */
You_feel("like a glutton!");
}
exercise(A_CON, FALSE);
if (Breathless || (!Strangled && !rn2(20))) {
/* choking by eating AoS doesn't involve stuffing yourself */
if (food && food->otyp == AMULET_OF_STRANGULATION) {
You("choke, but recover your composure.");
return;
}
You("stuff yourself and then vomit voluminously.");
morehungry(1000); /* you just got *very* sick! */
vomit();
} else {
killer.format = KILLED_BY_AN;
/*
* Note all "killer"s below read "Choked on %s" on the
* high score list & tombstone. So plan accordingly.
*/
if(food) {
You("choke over your %s.", foodword(food));
if (food->oclass == COIN_CLASS) {
Strcpy(killer.name, "a very rich meal");
} else {
Strcpy(killer.name, food_xname(food, FALSE));
if (food->otyp == CORPSE &&
(mons[food->corpsenm].geno & G_UNIQ)) {
if (!type_is_pname(&mons[food->corpsenm]))
Strcpy(killer.name, the(killer.name));
killer.format = KILLED_BY;
} else if (obj_is_pname(food)) {
killer.format = KILLED_BY;
if (food->oartifact >= ART_ORB_OF_DETECTION)
Strcpy(killer.name, the(killer.name));
}
}
} else {
You("choke over it.");
Strcpy(killer.name, "quick snack");
}
You("die...");
done(CHOKING);
}
}
/* modify object wt. depending on time spent consuming it */
STATIC_OVL void
recalc_wt()
{
struct obj *piece = context.victual.piece;
#ifdef DEBUG
debugpline("Old weight = %d", piece->owt);
debugpline("Used time = %d, Req'd time = %d",
context.victual.usedtime, context.victual.reqtime);
#endif
piece->owt = weight(piece);
#ifdef DEBUG
debugpline("New weight = %d", piece->owt);
#endif
}
void
reset_eat() /* called when eating interrupted by an event */
{
/* we only set a flag here - the actual reset process is done after
* the round is spent eating.
*/
if(context.victual.eating && !context.victual.doreset) {
#ifdef DEBUG
debugpline("reset_eat...");
#endif
context.victual.doreset = TRUE;
}
return;
}
STATIC_OVL struct obj *
touchfood(otmp)
register struct obj *otmp;
{
if (otmp->quan > 1L) {
if(!carried(otmp))
(void) splitobj(otmp, otmp->quan - 1L);
else
otmp = splitobj(otmp, 1L);
#ifdef DEBUG
debugpline("split object,");
#endif
}
if (!otmp->oeaten) {
costly_alteration(otmp, COST_BITE);
otmp->oeaten = (otmp->otyp == CORPSE ?
mons[otmp->corpsenm].cnutrit :
objects[otmp->otyp].oc_nutrition);
}
if (carried(otmp)) {
freeinv(otmp);
if (inv_cnt() >= 52) {
sellobj_state(SELL_DONTSELL);
dropy(otmp);
sellobj_state(SELL_NORMAL);
} else {
otmp->oxlth++; /* hack to prevent merge */
otmp = addinv(otmp);
otmp->oxlth--;
}
}
return(otmp);
}
/* When food decays, in the middle of your meal, we don't want to dereference
* any dangling pointers, so set it to null (which should still trigger
* do_reset_eat() at the beginning of eatfood()) and check for null pointers
* in do_reset_eat().
*/
void
food_disappears(obj)
register struct obj *obj;
{
if (obj == context.victual.piece) {
context.victual.piece = (struct obj *)0;
context.victual.o_id = 0;
}
if (obj->timed) obj_stop_timers(obj);
}
/* renaming an object usually results in it having a different address;
so the sequence start eating/opening, get interrupted, name the food,
resume eating/opening would restart from scratch */
void
food_substitution(old_obj, new_obj)
struct obj *old_obj, *new_obj;
{
if (old_obj == context.victual.piece) {
context.victual.piece = new_obj;
context.victual.o_id = new_obj->o_id;
}
if (old_obj == context.tin.tin) {
context.tin.tin = new_obj;
context.tin.o_id =new_obj->o_id;
}
}
STATIC_OVL void
do_reset_eat()
{
#ifdef DEBUG
debugpline("do_reset_eat...");
#endif
if (context.victual.piece) {
context.victual.o_id = 0;
context.victual.piece = touchfood(context.victual.piece);
if (context.victual.piece)
context.victual.o_id = context.victual.piece->o_id;
recalc_wt();
}
context.victual.fullwarn = context.victual.eating = context.victual.doreset = FALSE;
/* Do not set canchoke to FALSE; if we continue eating the same object
* we need to know if canchoke was set when they started eating it the
* previous time. And if we don't continue eating the same object
* canchoke always gets recalculated anyway.
*/
stop_occupation();
newuhs(FALSE);
}
STATIC_PTR
int
eatfood() /* called each move during eating process */
{
if(!context.victual.piece ||
(!carried(context.victual.piece) &&
!obj_here(context.victual.piece, u.ux, u.uy))) {
/* maybe it was stolen? */
do_reset_eat();
return(0);
}
if(!context.victual.eating) return(0);
if(++context.victual.usedtime <= context.victual.reqtime) {
if(bite()) return(0);
return(1); /* still busy */
} else { /* done */
done_eating(TRUE);
return(0);
}
}
STATIC_OVL void
done_eating(message)
boolean message;
{
context.victual.piece->in_use = TRUE;
occupation = 0; /* do this early, so newuhs() knows we're done */
newuhs(FALSE);
if (nomovemsg) {
if (message) pline(nomovemsg);
nomovemsg = 0;
} else if (message)
You("finish eating %s.", food_xname(context.victual.piece, TRUE));
if(context.victual.piece->otyp == CORPSE)
cpostfx(context.victual.piece->corpsenm);
else
fpostfx(context.victual.piece);
if (carried(context.victual.piece)) useup(context.victual.piece);
else useupf(context.victual.piece, 1L);
context.victual.piece = (struct obj *) 0;
context.victual.o_id = 0;
context.victual.fullwarn = context.victual.eating = context.victual.doreset = FALSE;
}
/* eating a corpse or egg of one's own species is usually naughty */
STATIC_OVL boolean
maybe_cannibal(pm, allowmsg)
int pm;
boolean allowmsg;
{
struct permonst *fptr = &mons[pm]; /* food type */
if (!CANNIBAL_ALLOWED() &&
/* non-cannibalistic heroes shouldn't eat own species ever
and also shouldn't eat current species when polymorphed
(even if having the form of something which doesn't care
about cannibalism--hero's innate traits aren't altered) */
(your_race(fptr) ||
(Upolyd && same_race(youmonst.data, fptr)))) {
if (allowmsg) {
if (Upolyd && your_race(fptr))
You("have a bad feeling deep inside.");
You("cannibal! You will regret this!");
}
HAggravate_monster |= FROMOUTSIDE;
change_luck(-rn1(4,2)); /* -5..-2 */
return TRUE;
}
return FALSE;
}
STATIC_OVL void
cprefx(pm)
register int pm;
{
(void) maybe_cannibal(pm,TRUE);
if (flesh_petrifies(&mons[pm])) {
if (!Stone_resistance &&
!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) {
Sprintf(killer.name, "tasting %s meat", mons[pm].mname);
killer.format = KILLED_BY;
You("turn to stone.");
done(STONING);
if (context.victual.piece)
context.victual.eating = FALSE;
return; /* lifesaved */
}
}
switch(pm) {
case PM_LITTLE_DOG:
case PM_DOG:
case PM_LARGE_DOG:
case PM_KITTEN:
case PM_HOUSECAT:
case PM_LARGE_CAT:
if (!CANNIBAL_ALLOWED()) {
You_feel("that eating the %s was a bad idea.", mons[pm].mname);
HAggravate_monster |= FROMOUTSIDE;
}
break;
case PM_LIZARD:
if (Stoned) fix_petrification();
break;
case PM_DEATH:
case PM_PESTILENCE:
case PM_FAMINE:
{
pline("Eating that is instantly fatal.");
Sprintf(killer.name, "unwisely ate the body of %s",
mons[pm].mname);
killer.format = NO_KILLER_PREFIX;
done(DIED);
/* It so happens that since we know these monsters */
/* cannot appear in tins, context.victual.piece will always */
/* be what we want, which is not generally true. */
if (revive_corpse(context.victual.piece)) {
context.victual.piece = (struct obj *)0;
context.victual.o_id = 0;
}
return;
}
case PM_GREEN_SLIME:
if (!Slimed && !Unchanging && !flaming(youmonst.data) &&
youmonst.data != &mons[PM_GREEN_SLIME]) {
You("don't feel very well.");
make_slimed(10L, (char*) 0);
delayed_killer(SLIMED, KILLED_BY_AN, nul);
}
/* Fall through */
default:
if (acidic(&mons[pm]) && Stoned)
fix_petrification();
break;
}
}
void
fix_petrification()
{
Stoned = 0;
dealloc_killer(find_delayed_killer(STONED));
if (Hallucination)
pline("What a pity - you just ruined a future piece of %sart!",
ACURR(A_CHA) > 15 ? "fine " : "");
else
You_feel("limber!");
}
/*
* If you add an intrinsic that can be gotten by eating a monster, add it
* to intrinsic_possible() and givit(). (It must already be in prop.h to
* be an intrinsic property.)
* It would be very easy to make the intrinsics not try to give you one
* that you already had by checking to see if you have it in
* intrinsic_possible() instead of givit().
*/
/* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */
STATIC_OVL int
intrinsic_possible(type, ptr)
int type;
register struct permonst *ptr;
{
switch (type) {
case FIRE_RES:
#ifdef DEBUG
if (ptr->mconveys & MR_FIRE) {
debugpline("can get fire resistance");
return(TRUE);
} else return(FALSE);
#else
return(ptr->mconveys & MR_FIRE);
#endif
case SLEEP_RES:
#ifdef DEBUG
if (ptr->mconveys & MR_SLEEP) {
debugpline("can get sleep resistance");
return(TRUE);
} else return(FALSE);
#else
return(ptr->mconveys & MR_SLEEP);
#endif
case COLD_RES:
#ifdef DEBUG
if (ptr->mconveys & MR_COLD) {
debugpline("can get cold resistance");
return(TRUE);
} else return(FALSE);
#else
return(ptr->mconveys & MR_COLD);
#endif
case DISINT_RES:
#ifdef DEBUG
if (ptr->mconveys & MR_DISINT) {
debugpline("can get disintegration resistance");
return(TRUE);
} else return(FALSE);
#else
return(ptr->mconveys & MR_DISINT);
#endif
case SHOCK_RES: /* shock (electricity) resistance */
#ifdef DEBUG
if (ptr->mconveys & MR_ELEC) {
debugpline("can get shock resistance");
return(TRUE);
} else return(FALSE);
#else
return(ptr->mconveys & MR_ELEC);
#endif
case POISON_RES:
#ifdef DEBUG
if (ptr->mconveys & MR_POISON) {
debugpline("can get poison resistance");
return(TRUE);
} else return(FALSE);
#else
return(ptr->mconveys & MR_POISON);
#endif
case TELEPORT:
#ifdef DEBUG
if (can_teleport(ptr)) {
debugpline("can get teleport");
return(TRUE);
} else return(FALSE);
#else
return(can_teleport(ptr));
#endif
case TELEPORT_CONTROL:
#ifdef DEBUG
if (control_teleport(ptr)) {
debugpline("can get teleport control");
return(TRUE);
} else return(FALSE);
#else
return(control_teleport(ptr));
#endif
case TELEPAT:
#ifdef DEBUG
if (telepathic(ptr)) {
debugpline("can get telepathy");
return(TRUE);
} else return(FALSE);
#else
return(telepathic(ptr));
#endif
default:
return(FALSE);
}
/*NOTREACHED*/
}
/* givit() tries to give you an intrinsic based on the monster's level
* and what type of intrinsic it is trying to give you.
*/
STATIC_OVL void
givit(type, ptr)
int type;
register struct permonst *ptr;
{
register int chance;
#ifdef DEBUG
debugpline("Attempting to give intrinsic %d", type);
#endif
/* some intrinsics are easier to get than others */
switch (type) {
case POISON_RES:
if ((ptr == &mons[PM_KILLER_BEE] ||
ptr == &mons[PM_SCORPION]) && !rn2(4))
chance = 1;
else
chance = 15;
break;
case TELEPORT:
chance = 10;
break;
case TELEPORT_CONTROL:
chance = 12;
break;
case TELEPAT:
chance = 1;
break;
default:
chance = 15;
break;
}
if (ptr->mlevel <= rn2(chance))
return; /* failed die roll */
switch (type) {
case FIRE_RES:
#ifdef DEBUG
debugpline("Trying to give fire resistance");
#endif
if(!(HFire_resistance & FROMOUTSIDE)) {
You(Hallucination ? "be chillin'." :
"feel a momentary chill.");
HFire_resistance |= FROMOUTSIDE;
}
break;
case SLEEP_RES:
#ifdef DEBUG
debugpline("Trying to give sleep resistance");
#endif
if(!(HSleep_resistance & FROMOUTSIDE)) {
You_feel("wide awake.");
HSleep_resistance |= FROMOUTSIDE;
}
break;
case COLD_RES:
#ifdef DEBUG
debugpline("Trying to give cold resistance");
#endif
if(!(HCold_resistance & FROMOUTSIDE)) {
You_feel("full of hot air.");
HCold_resistance |= FROMOUTSIDE;
}
break;
case DISINT_RES:
#ifdef DEBUG
debugpline("Trying to give disintegration resistance");
#endif
if(!(HDisint_resistance & FROMOUTSIDE)) {
You_feel(Hallucination ?
"totally together, man." :
"very firm.");
HDisint_resistance |= FROMOUTSIDE;
}
break;
case SHOCK_RES: /* shock (electricity) resistance */
#ifdef DEBUG
debugpline("Trying to give shock resistance");
#endif
if(!(HShock_resistance & FROMOUTSIDE)) {
if (Hallucination)
You_feel("grounded in reality.");
else
Your("health currently feels amplified!");
HShock_resistance |= FROMOUTSIDE;
}
break;
case POISON_RES:
#ifdef DEBUG
debugpline("Trying to give poison resistance");
#endif
if(!(HPoison_resistance & FROMOUTSIDE)) {
You_feel(Poison_resistance ?
"especially healthy." : "healthy.");
HPoison_resistance |= FROMOUTSIDE;
}
break;
case TELEPORT:
#ifdef DEBUG
debugpline("Trying to give teleport");
#endif
if(!(HTeleportation & FROMOUTSIDE)) {
You_feel(Hallucination ? "diffuse." :
"very jumpy.");
HTeleportation |= FROMOUTSIDE;
}
break;
case TELEPORT_CONTROL:
#ifdef DEBUG
debugpline("Trying to give teleport control");
#endif
if(!(HTeleport_control & FROMOUTSIDE)) {
You_feel(Hallucination ?
"centered in your personal space." :
"in control of yourself.");
HTeleport_control |= FROMOUTSIDE;
}
break;
case TELEPAT:
#ifdef DEBUG
debugpline("Trying to give telepathy");
#endif
if(!(HTelepat & FROMOUTSIDE)) {
You_feel(Hallucination ?
"in touch with the cosmos." :
"a strange mental acuity.");
HTelepat |= FROMOUTSIDE;
/* If blind, make sure monsters show up. */
if (Blind) see_monsters();
}
break;
default:
#ifdef DEBUG
debugpline("Tried to give an impossible intrinsic");
#endif
break;
}
}
STATIC_OVL void
cpostfx(pm) /* called after completely consuming a corpse */
register int pm;
{
register int tmp = 0;
boolean catch_lycanthropy = FALSE;
/* in case `afternmv' didn't get called for previously mimicking
gold, clean up now to avoid `eatmbuf' memory leak */
if (eatmbuf) (void)eatmdone();
switch(pm) {
case PM_NEWT:
/* MRKR: "eye of newt" may give small magical energy boost */
if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) {
int old_uen = u.uen;
u.uen += rnd(3);
if (u.uen > u.uenmax) {
if (!rn2(3)) u.uenmax++;
u.uen = u.uenmax;
}
if (old_uen != u.uen) {
You_feel("a mild buzz.");
context.botl = 1;
}
}
break;
case PM_WRAITH:
pluslvl(FALSE);
break;
case PM_HUMAN_WERERAT:
catch_lycanthropy = TRUE;
u.ulycn = PM_WERERAT;
break;
case PM_HUMAN_WEREJACKAL:
catch_lycanthropy = TRUE;
u.ulycn = PM_WEREJACKAL;
break;
case PM_HUMAN_WEREWOLF:
catch_lycanthropy = TRUE;
u.ulycn = PM_WEREWOLF;
break;
case PM_NURSE:
if (Upolyd) u.mh = u.mhmax;
else u.uhp = u.uhpmax;
context.botl = 1;
break;
case PM_STALKER:
if(!Invis) {
set_itimeout(&HInvis, (long)rn1(100, 50));
if (!Blind && !BInvis) self_invis_message();
} else {
if (!(HInvis & INTRINSIC)) You_feel("hidden!");
HInvis |= FROMOUTSIDE;
HSee_invisible |= FROMOUTSIDE;
}
newsym(u.ux, u.uy);
/* fall into next case */
case PM_YELLOW_LIGHT:
/* fall into next case */
case PM_GIANT_BAT:
make_stunned(HStun + 30,FALSE);
/* fall into next case */
case PM_BAT:
make_stunned(HStun + 30,FALSE);
break;
case PM_GIANT_MIMIC:
tmp += 10;
/* fall into next case */
case PM_LARGE_MIMIC:
tmp += 20;
/* fall into next case */
case PM_SMALL_MIMIC:
tmp += 20;
if (youmonst.data->mlet != S_MIMIC && !Unchanging) {
char buf[BUFSZ];
You_cant("resist the temptation to mimic %s.",
Hallucination ? "an orange" : "a pile of gold");
#ifdef STEED
/* A pile of gold can't ride. */
if (u.usteed) dismount_steed(DISMOUNT_FELL);
#endif
nomul(-tmp);
Sprintf(buf, Hallucination ?
"You suddenly dread being peeled and mimic %s again!" :
"You now prefer mimicking %s again.",
an(Upolyd ? youmonst.data->mname : urace.noun));
eatmbuf = strcpy((char *) alloc(strlen(buf) + 1), buf);
nomovemsg = eatmbuf;
afternmv = eatmdone;
/* ??? what if this was set before? */
youmonst.m_ap_type = M_AP_OBJECT;
youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE;
newsym(u.ux,u.uy);
curs_on_u();
/* make gold symbol show up now */
display_nhwindow(WIN_MAP, TRUE);
}
break;
case PM_QUANTUM_MECHANIC:
Your("velocity suddenly seems very uncertain!");
if (HFast & INTRINSIC) {
HFast &= ~INTRINSIC;
You("seem slower.");
} else {
HFast |= FROMOUTSIDE;
You("seem faster.");
}
break;
case PM_LIZARD:
if (HStun > 2) make_stunned(2L,FALSE);
if (HConfusion > 2) make_confused(2L,FALSE);
break;
case PM_CHAMELEON:
case PM_DOPPELGANGER:
/* case PM_SANDESTIN: */
if (!Unchanging) {
You_feel("a change coming over you.");
polyself(0);
}
break;
case PM_MIND_FLAYER:
case PM_MASTER_MIND_FLAYER:
if (ABASE(A_INT) < ATTRMAX(A_INT)) {
if (!rn2(2)) {
pline("Yum! That was real brain food!");
(void) adjattrib(A_INT, 1, FALSE);
break; /* don't give them telepathy, too */
}
}
else {
pline("For some reason, that tasted bland.");
}
/* fall through to default case */
default: {
register struct permonst *ptr = &mons[pm];
int i, count;
if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU) ||
pm == PM_VIOLET_FUNGUS) {
pline ("Oh wow! Great stuff!");
(void) make_hallucinated(HHallucination + 200,FALSE,0L);
}
if(is_giant(ptr)) gainstr((struct obj *)0, 0);
/* Check the monster for all of the intrinsics. If this
* monster can give more than one, pick one to try to give
* from among all it can give.
*
* If a monster can give 4 intrinsics then you have
* a 1/1 * 1/2 * 2/3 * 3/4 = 1/4 chance of getting the first,
* a 1/2 * 2/3 * 3/4 = 1/4 chance of getting the second,
* a 1/3 * 3/4 = 1/4 chance of getting the third,
* and a 1/4 chance of getting the fourth.
*
* And now a proof by induction:
* it works for 1 intrinsic (1 in 1 of getting it)
* for 2 you have a 1 in 2 chance of getting the second,
* otherwise you keep the first
* for 3 you have a 1 in 3 chance of getting the third,
* otherwise you keep the first or the second
* for n+1 you have a 1 in n+1 chance of getting the (n+1)st,
* otherwise you keep the previous one.
* Elliott Kleinrock, October 5, 1990
*/
count = 0; /* number of possible intrinsics */
tmp = 0; /* which one we will try to give */
for (i = 1; i <= LAST_PROP; i++) {
if (intrinsic_possible(i, ptr)) {
count++;
/* a 1 in count chance of replacing the old
* one with this one, and a count-1 in count
* chance of keeping the old one. (note
* that 1 in 1 and 0 in 1 are what we want
* for the first one
*/
if (!rn2(count)) {
#ifdef DEBUG
debugpline("Intrinsic %d replacing %d",
i, tmp);
#endif
tmp = i;
}
}
}
/* if any found try to give them one */
if (count) givit(tmp, ptr);
}
break;
}
if (catch_lycanthropy && defends(AD_WERE, uwep)) {
if (!touch_artifact(uwep, &youmonst)) {
dropx(uwep);
uwepgone();
}
}
return;
}
void
violated_vegetarian()
{
u.uconduct.unvegetarian++;
if (Role_if(PM_MONK)) {
You_feel("guilty.");
adjalign(-1);
}
return;
}
/* common code to check and possibly charge for 1 context.tin.tin,
* will split() context.tin.tin if necessary */
STATIC_PTR
void
costly_tin(alter_type)
int alter_type; /* COST_xxx */
{
struct obj *tin = context.tin.tin;
if (carried(tin) ? tin->unpaid :
(costly_spot(tin->ox, tin->oy) && !tin->no_charge)) {
if (tin->quan > 1L) {
tin = context.tin.tin = splitobj(tin, 1L);
context.tin.o_id = tin->o_id;
}