-
Notifications
You must be signed in to change notification settings - Fork 540
Expand file tree
/
Copy patheat.c
More file actions
3352 lines (3110 loc) · 113 KB
/
eat.c
File metadata and controls
3352 lines (3110 loc) · 113 KB
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 eat.c $NHDT-Date: 1574900825 2019/11/28 00:27:05 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.206 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
STATIC_PTR int NDECL(eatmdone);
STATIC_PTR int NDECL(eatfood);
STATIC_PTR struct obj *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 unsigned FDECL(obj_nutrition, (struct obj *));
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(consume_tin, (const char *));
STATIC_DCL void FDECL(start_tin, (struct obj *));
STATIC_DCL int FDECL(eatcorpse, (struct obj *));
STATIC_DCL void FDECL(start_eating, (struct obj *, BOOLEAN_P));
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 *, BOOLEAN_P));
STATIC_DCL boolean FDECL(maybe_cannibal, (int, BOOLEAN_P));
char msgbuf[BUFSZ];
/* 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])
/* Rider corpses are treated as non-rotting so that attempting to eat one
will be sure to reach the stage of eating where that meal is fatal */
#define nonrotting_corpse(mnum) \
((mnum) == PM_LIZARD || (mnum) == PM_LICHEN || is_rider(&mons[mnum]))
/* non-rotting non-corpses; unlike lizard corpses, these items will behave
as if rotten if they are cursed (fortune cookies handled elsewhere) */
#define nonrotting_food(otyp) \
((otyp) == LEMBAS_WAFER || (otyp) == CRAM_RATION)
STATIC_OVL NEARDATA const char comestibles[] = { FOOD_CLASS, 0 };
STATIC_OVL NEARDATA const char offerfodder[] = { FOOD_CLASS, AMULET_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;
/* see hunger states in hack.h - texts used on bottom line */
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;
/* Ghouls only eat non-veggy corpses or eggs (see dogfood()) */
if (u.umonnum == PM_GHOUL)
return (boolean)((obj->otyp == CORPSE
&& !vegan(&mons[obj->corpsenm]))
|| (obj->otyp == EGG));
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);
}
/* used for hero init, life saving (if choking), and prayer results of fix
starving, fix weak from hunger, or golden glow boon (if u.uhunger < 900) */
void
init_uhunger()
{
context.botl = (u.uhs != NOT_HUNGRY || ATEMP(A_STR) < 0);
u.uhunger = 900;
u.uhs = NOT_HUNGRY;
if (ATEMP(A_STR) < 0) {
ATEMP(A_STR) = 0;
(void) encumber_msg();
}
}
/* tin types [SPINACH_TIN = -1, overrides corpsenm, nut==600] */
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() */
/* called after mimicing is over */
STATIC_PTR int
eatmdone(VOID_ARGS)
{
/* release `eatmbuf' */
if (eatmbuf) {
if (nomovemsg == eatmbuf)
nomovemsg = 0;
free((genericptr_t) eatmbuf), eatmbuf = 0;
}
/* update display */
if (U_AP_TYPE) {
youmonst.m_ap_type = M_AP_NOTHING;
newsym(u.ux, u.uy);
}
return 0;
}
/* called when hallucination is toggled */
void
eatmupdate()
{
const char *altmsg = 0;
int altapp = 0; /* lint suppression */
if (!eatmbuf || nomovemsg != eatmbuf)
return;
if (is_obj_mappear(&youmonst,ORANGE) && !Hallucination) {
/* revert from hallucinatory to "normal" mimicking */
altmsg = "You now prefer mimicking yourself.";
altapp = GOLD_PIECE;
} else if (is_obj_mappear(&youmonst,GOLD_PIECE) && Hallucination) {
/* won't happen; anything which might make immobilized
hero begin hallucinating (black light attack, theft
of Grayswandir) will terminate the mimicry first */
altmsg = "Your rind escaped intact.";
altapp = ORANGE;
}
if (altmsg) {
/* replace end-of-mimicking message */
if (strlen(altmsg) > strlen(eatmbuf)) {
free((genericptr_t) eatmbuf);
eatmbuf = (char *) alloc(strlen(altmsg) + 1);
}
nomovemsg = strcpy(eatmbuf, altmsg);
/* update current image */
youmonst.mappearance = altapp;
newsym(u.ux, u.uy);
}
}
/* ``[the(] singular(food, xname) [)]'' */
STATIC_OVL const char *
food_xname(food, the_pfx)
struct obj *food;
boolean the_pfx;
{
const char *result;
if (food->otyp == CORPSE) {
result = corpse_xname(food, (const char *) 0,
CXN_SINGULAR | (the_pfx ? CXN_PFX_THE : 0));
/* not strictly needed since pname values are capitalized
and the() is a no-op for them */
if (type_is_pname(&mons[food->corpsenm]))
the_pfx = FALSE;
} 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.
*
* To a full belly all food is bad. (It.)
*/
STATIC_OVL void
choke(food)
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, "very rich meal");
} else {
killer.format = KILLED_BY;
Strcpy(killer.name, killer_xname(food));
}
} 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;
if (!piece) {
impossible("recalc_wt without piece");
return;
}
debugpline1("Old weight = %d", piece->owt);
debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime,
context.victual.reqtime);
piece->owt = weight(piece);
debugpline1("New weight = %d", piece->owt);
}
/* called when eating interrupted by an event */
void
reset_eat()
{
/* 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) {
debugpline0("reset_eat...");
context.victual.doreset = TRUE;
}
return;
}
/* base nutrition of a food-class object */
STATIC_OVL unsigned
obj_nutrition(otmp)
struct obj *otmp;
{
unsigned nut = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit
: otmp->globby ? otmp->owt
: (unsigned) objects[otmp->otyp].oc_nutrition;
if (otmp->otyp == LEMBAS_WAFER) {
if (maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF)))
nut += nut / 4; /* 800 -> 1000 */
else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
nut -= nut / 4; /* 800 -> 600 */
/* prevent polymorph making a partly eaten wafer
become more nutritious than an untouched one */
if (otmp->oeaten >= nut)
otmp->oeaten = (otmp->oeaten < objects[LEMBAS_WAFER].oc_nutrition)
? (nut - 1) : nut;
} else if (otmp->otyp == CRAM_RATION) {
if (maybe_polyd(is_dwarf(youmonst.data), Race_if(PM_DWARF)))
nut += nut / 6; /* 600 -> 700 */
}
return nut;
}
STATIC_OVL struct obj *
touchfood(otmp)
struct obj *otmp;
{
if (otmp->quan > 1L) {
if (!carried(otmp))
(void) splitobj(otmp, otmp->quan - 1L);
else
otmp = splitobj(otmp, 1L);
debugpline0("split object,");
}
if (!otmp->oeaten) {
costly_alteration(otmp, COST_BITE);
otmp->oeaten = obj_nutrition(otmp);
}
if (carried(otmp)) {
freeinv(otmp);
if (inv_cnt(FALSE) >= 52) {
sellobj_state(SELL_DONTSELL);
dropy(otmp);
sellobj_state(SELL_NORMAL);
} else {
otmp->nomerge = 1; /* used to prevent merge */
otmp = addinv(otmp);
otmp->nomerge = 0;
}
}
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)
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 used to result 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()
{
debugpline0("do_reset_eat...");
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);
}
/* called each move during eating process */
STATIC_PTR int
eatfood(VOID_ARGS)
{
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;
{
struct obj *piece = context.victual.piece;
piece->in_use = TRUE;
occupation = 0; /* do this early, so newuhs() knows we're done */
newuhs(FALSE);
if (nomovemsg) {
if (message)
pline1(nomovemsg);
nomovemsg = 0;
} else if (message)
You("finish eating %s.", food_xname(piece, TRUE));
if (piece->otyp == CORPSE || piece->globby)
cpostfx(piece->corpsenm);
else
fpostfx(piece);
if (carried(piece))
useup(piece);
else
useupf(piece, 1L);
context.victual.piece = (struct obj *) 0;
context.victual.o_id = 0;
context.victual.fullwarn = context.victual.eating =
context.victual.doreset = FALSE;
}
void
eating_conducts(pd)
struct permonst *pd;
{
u.uconduct.food++;
if (!vegan(pd))
u.uconduct.unvegan++;
if (!vegetarian(pd))
violated_vegetarian();
}
/* handle side-effects of mind flayer's tentacle attack */
int
eat_brains(magr, mdef, visflag, dmg_p)
struct monst *magr, *mdef;
boolean visflag;
int *dmg_p; /* for dishing out extra damage in lieu of Int loss */
{
struct permonst *pd = mdef->data;
boolean give_nutrit = FALSE;
int result = MM_HIT, xtra_dmg = rnd(10);
if (noncorporeal(pd)) {
if (visflag)
pline("%s brain is unharmed.",
(mdef == &youmonst) ? "Your" : s_suffix(Monnam(mdef)));
return MM_MISS; /* side-effects can't occur */
} else if (magr == &youmonst) {
You("eat %s brain!", s_suffix(mon_nam(mdef)));
} else if (mdef == &youmonst) {
Your("brain is eaten!");
} else { /* monster against monster */
if (visflag && canspotmon(mdef))
pline("%s brain is eaten!", s_suffix(Monnam(mdef)));
}
if (flesh_petrifies(pd)) {
/* mind flayer has attempted to eat the brains of a petrification
inducing critter (most likely Medusa; attacking a cockatrice via
tentacle-touch should have been caught before reaching this far) */
if (magr == &youmonst) {
if (!Stone_resistance && !Stoned)
make_stoned(5L, (char *) 0, KILLED_BY_AN, pd->mname);
} else {
/* no need to check for poly_when_stoned or Stone_resistance;
mind flayers don't have those capabilities */
if (visflag && canseemon(magr))
pline("%s turns to stone!", Monnam(magr));
monstone(magr);
if (!DEADMONSTER(magr)) {
/* life-saved; don't continue eating the brains */
return MM_MISS;
} else {
if (magr->mtame && !visflag)
/* parallels mhitm.c's brief_feeling */
You("have a sad thought for a moment, then it passes.");
return MM_AGR_DIED;
}
}
}
if (magr == &youmonst) {
/*
* player mind flayer is eating something's brain
*/
eating_conducts(pd);
if (mindless(pd)) { /* (cannibalism not possible here) */
pline("%s doesn't notice.", Monnam(mdef));
/* all done; no extra harm inflicted upon target */
return MM_MISS;
} else if (is_rider(pd)) {
pline("Ingesting that is fatal.");
Sprintf(killer.name, "unwisely ate the brain of %s", pd->mname);
killer.format = NO_KILLER_PREFIX;
done(DIED);
/* life-saving needed to reach here */
exercise(A_WIS, FALSE);
*dmg_p += xtra_dmg; /* Rider takes extra damage */
} else {
morehungry(-rnd(30)); /* cannot choke */
if (ABASE(A_INT) < AMAX(A_INT)) {
/* recover lost Int; won't increase current max */
ABASE(A_INT) += rnd(4);
if (ABASE(A_INT) > AMAX(A_INT))
ABASE(A_INT) = AMAX(A_INT);
context.botl = 1;
}
exercise(A_WIS, TRUE);
*dmg_p += xtra_dmg;
}
/* targetting another mind flayer or your own underlying species
is cannibalism */
(void) maybe_cannibal(monsndx(pd), TRUE);
} else if (mdef == &youmonst) {
/*
* monster mind flayer is eating hero's brain
*/
/* no such thing as mindless players */
if (ABASE(A_INT) <= ATTRMIN(A_INT)) {
static NEARDATA const char brainlessness[] = "brainlessness";
if (Lifesaved) {
Strcpy(killer.name, brainlessness);
killer.format = KILLED_BY;
done(DIED);
/* amulet of life saving has now been used up */
pline("Unfortunately your brain is still gone.");
/* sanity check against adding other forms of life-saving */
u.uprops[LIFESAVED].extrinsic =
u.uprops[LIFESAVED].intrinsic = 0L;
} else {
Your("last thought fades away.");
}
Strcpy(killer.name, brainlessness);
killer.format = KILLED_BY;
done(DIED);
/* can only get here when in wizard or explore mode and user has
explicitly chosen not to die; arbitrarily boost intelligence */
ABASE(A_INT) = ATTRMIN(A_INT) + 2;
You_feel("like a scarecrow.");
}
give_nutrit = TRUE; /* in case a conflicted pet is doing this */
exercise(A_WIS, FALSE);
/* caller handles Int and memory loss */
} else { /* mhitm */
/*
* monster mind flayer is eating another monster's brain
*/
if (mindless(pd)) {
if (visflag && canspotmon(mdef))
pline("%s doesn't notice.", Monnam(mdef));
return MM_MISS;
} else if (is_rider(pd)) {
mondied(magr);
if (DEADMONSTER(magr))
result = MM_AGR_DIED;
/* Rider takes extra damage regardless of whether attacker dies */
*dmg_p += xtra_dmg;
} else {
*dmg_p += xtra_dmg;
give_nutrit = TRUE;
if (*dmg_p >= mdef->mhp && visflag && canspotmon(mdef))
pline("%s last thought fades away...",
s_suffix(Monnam(mdef)));
}
}
if (give_nutrit && magr->mtame && !magr->isminion) {
EDOG(magr)->hungrytime += rnd(60);
magr->mconf = 0;
}
return result;
}
/* eating a corpse or egg of one's own species is usually naughty */
STATIC_OVL boolean
maybe_cannibal(pm, allowmsg)
int pm;
boolean allowmsg;
{
static NEARDATA long ate_brains = 0L;
struct permonst *fptr = &mons[pm]; /* food type */
/* when poly'd into a mind flayer, multiple tentacle hits in one
turn cause multiple digestion checks to occur; avoid giving
multiple luck penalties for the same attack */
if (moves == ate_brains)
return FALSE;
ate_brains = moves; /* ate_anything, not just brains... */
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))
|| (u.ulycn >= LOW_PM && were_beastie(pm) == u.ulycn))) {
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:
/* cannibals are allowed to eat domestic animals without penalty */
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);
/* life-saving needed to reach here */
exercise(A_WIS, FALSE);
/* 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 && !slimeproof(youmonst.data)) {
You("don't feel very well.");
make_slimed(10L, (char *) 0);
delayed_killer(SLIMED, KILLED_BY_AN, "");
}
/* Fall through */
default:
if (acidic(&mons[pm]) && Stoned)
fix_petrification();
break;
}
}
void
fix_petrification()
{
char buf[BUFSZ];
if (Hallucination)
Sprintf(buf, "What a pity--you just ruined a future piece of %sart!",
ACURR(A_CHA) > 15 ? "fine " : "");
else
Strcpy(buf, "You feel limber!");
make_stoned(0L, buf, 0, (char *) 0);
}
/*
* 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(), but we're not that nice.
*/
/* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */
STATIC_OVL int
intrinsic_possible(type, ptr)
int type;
register struct permonst *ptr;
{
int res = 0;
#ifdef DEBUG
#define ifdebugresist(Msg) \
do { \
if (res) \
debugpline0(Msg); \
} while (0)
#else
#define ifdebugresist(Msg) /*empty*/
#endif
switch (type) {
case FIRE_RES:
res = (ptr->mconveys & MR_FIRE) != 0;
ifdebugresist("can get fire resistance");
break;
case SLEEP_RES:
res = (ptr->mconveys & MR_SLEEP) != 0;
ifdebugresist("can get sleep resistance");
break;
case COLD_RES:
res = (ptr->mconveys & MR_COLD) != 0;
ifdebugresist("can get cold resistance");
break;
case DISINT_RES:
res = (ptr->mconveys & MR_DISINT) != 0;
ifdebugresist("can get disintegration resistance");
break;
case SHOCK_RES: /* shock (electricity) resistance */
res = (ptr->mconveys & MR_ELEC) != 0;
ifdebugresist("can get shock resistance");
break;
case POISON_RES:
res = (ptr->mconveys & MR_POISON) != 0;
ifdebugresist("can get poison resistance");
break;
case TELEPORT:
res = can_teleport(ptr);
ifdebugresist("can get teleport");
break;
case TELEPORT_CONTROL:
res = control_teleport(ptr);
ifdebugresist("can get teleport control");
break;
case TELEPAT:
res = telepathic(ptr);
ifdebugresist("can get telepathy");
break;
default:
/* res stays 0 */
break;
}
#undef ifdebugresist
return res;
}
/* 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;
debugpline1("Attempting to give intrinsic %d", type);
/* 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:
debugpline0("Trying to give fire resistance");
if (!(HFire_resistance & FROMOUTSIDE)) {
You(Hallucination ? "be chillin'." : "feel a momentary chill.");
HFire_resistance |= FROMOUTSIDE;
}
break;
case SLEEP_RES:
debugpline0("Trying to give sleep resistance");
if (!(HSleep_resistance & FROMOUTSIDE)) {
You_feel("wide awake.");
HSleep_resistance |= FROMOUTSIDE;
}
break;
case COLD_RES:
debugpline0("Trying to give cold resistance");
if (!(HCold_resistance & FROMOUTSIDE)) {
You_feel("full of hot air.");
HCold_resistance |= FROMOUTSIDE;
}
break;
case DISINT_RES:
debugpline0("Trying to give disintegration resistance");
if (!(HDisint_resistance & FROMOUTSIDE)) {
You_feel(Hallucination ? "totally together, man." : "very firm.");
HDisint_resistance |= FROMOUTSIDE;
}
break;
case SHOCK_RES: /* shock (electricity) resistance */
debugpline0("Trying to give shock resistance");
if (!(HShock_resistance & FROMOUTSIDE)) {
if (Hallucination)
You_feel("grounded in reality.");
else
Your("health currently feels amplified!");
HShock_resistance |= FROMOUTSIDE;
}
break;
case POISON_RES:
debugpline0("Trying to give poison resistance");
if (!(HPoison_resistance & FROMOUTSIDE)) {
You_feel(Poison_resistance ? "especially healthy." : "healthy.");
HPoison_resistance |= FROMOUTSIDE;
}
break;
case TELEPORT:
debugpline0("Trying to give teleport");
if (!(HTeleportation & FROMOUTSIDE)) {
You_feel(Hallucination ? "diffuse." : "very jumpy.");
HTeleportation |= FROMOUTSIDE;
}
break;
case TELEPORT_CONTROL:
debugpline0("Trying to give teleport control");
if (!(HTeleport_control & FROMOUTSIDE)) {
You_feel(Hallucination ? "centered in your personal space."
: "in control of yourself.");
HTeleport_control |= FROMOUTSIDE;
}
break;
case TELEPAT:
debugpline0("Trying to give telepathy");
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:
debugpline0("Tried to give an impossible intrinsic");
break;
}
}
/* called after completely consuming a corpse */
STATIC_OVL void
cpostfx(pm)
int pm;
{
int tmp = 0;
int catch_lycanthropy = NON_PM;
boolean check_intrinsics = 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 = PM_WERERAT;
break;
case PM_HUMAN_WEREJACKAL:
catch_lycanthropy = PM_WEREJACKAL;
break;
case PM_HUMAN_WEREWOLF:
catch_lycanthropy = PM_WEREWOLF;
break;
case PM_NURSE:
if (Upolyd)
u.mh = u.mhmax;
else
u.uhp = u.uhpmax;
make_blinded(0L, !u.ucreamed);
context.botl = 1;
check_intrinsics = TRUE; /* might also convey poison resistance */
break;
case PM_STALKER:
if (!Invis) {
set_itimeout(&HInvis, (long) rn1(100, 50));
if (!Blind && !BInvis)
self_invis_message();