]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.eat.c
1 /* $NetBSD: hack.eat.c,v 1.12 2011/08/07 06:03:45 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.eat.c,v 1.12 2011/08/07 06:03:45 dholland Exp $");
71 static char POISONOUS
[] = "ADKSVabhks";
73 /* hunger texts used on bottom line (each 8 chars long) */
82 const char *const hu_stat
[] = {
92 static int opentin(void);
93 static int Meatdone(void);
94 static int unfaint(void);
95 static void newuhs(boolean
);
96 static int eatcorpse(struct obj
*);
105 #define TTSZ SIZE(tintxts)
106 static const struct {
110 { "It contains first quality peaches - what a surprise!", 40 },
111 { "It contains salmon - not bad!", 60 },
112 { "It contains apple juice - perhaps not what you hoped for.", 20 },
113 { "It contains some nondescript substance, tasting awfully.", 500 },
114 { "It contains rotten meat. You vomit.", -50 },
115 { "It turns out to be empty.", 0 }
120 int usedtime
, reqtime
;
128 if (!carried(tin
.tin
)) /* perhaps it was stolen? */
129 return (0); /* %% probably we should use tinoid */
130 if (tin
.usedtime
++ >= 50) {
131 pline("You give up your attempt to open the tin.");
134 if (tin
.usedtime
< tin
.reqtime
)
135 return (1); /* still busy */
137 pline("You succeed in opening the tin.");
141 pline("%s", tintxts
[r
].txt
);
142 lesshungry(tintxts
[r
].nut
);
143 if (r
== 1) { /* SALMON */
145 pline("Eating salmon made your fingers very slippery.");
148 pline("It contains spinach - this makes you feel like Popeye!");
151 u
.ustr
+= rnd(((u
.ustr
< 17) ? 19 : 118) - u
.ustr
);
152 if (u
.ustr
> u
.ustrmax
)
171 struct objclass
*ftmp
;
174 /* Is there some food (probably a heavy corpse) here on the ground? */
176 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
) {
177 if (otmp
->ox
== u
.ux
&& otmp
->oy
== u
.uy
&&
178 otmp
->olet
== FOOD_SYM
) {
179 pline("There %s %s here; eat %s? [ny] ",
180 (otmp
->quan
== 1) ? "is" : "are",
182 (otmp
->quan
== 1) ? "it" : "one");
183 if (readchar() == 'y') {
185 (void) splitobj(otmp
, 1);
193 otmp
= getobj("%", "eat");
197 if (otmp
->otyp
== TIN
) {
199 switch (uwep
->otyp
) {
214 pline("Using your %s you try to open the tin.",
215 aobjnam(uwep
, NULL
));
218 pline("It is not so easy to open this tin.");
220 pline("The tin slips out of your hands.");
221 if (otmp
->quan
> 1) {
224 obj
= splitobj(otmp
, 1);
231 tmp
= 10 + rn2(1 + 500 / ((int) (u
.ulevel
+ u
.ustr
)));
236 occupation
= opentin
;
237 occtxt
= "opening the tin";
240 ftmp
= &objects
[otmp
->otyp
];
241 multi
= -ftmp
->oc_delay
;
242 if (otmp
->otyp
>= CORPSE
&& eatcorpse(otmp
))
244 if (!rn2(7) && otmp
->otyp
!= FORTUNE_COOKIE
) {
245 pline("Blecch! Rotten food!");
247 pline("You feel rather light headed.");
248 Confusion
+= d(2, 4);
249 } else if (!rn2(4) && !Blind
) {
250 pline("Everything suddenly goes dark.");
253 } else if (!rn2(3)) {
255 pline("The world spins and you slap against the floor.");
257 pline("The world spins and goes dark.");
259 nomovemsg
= "You are conscious again.";
261 lesshungry(ftmp
->nutrition
/ 4);
263 if (u
.uhunger
>= 1500) {
264 pline("You choke over your food.");
266 killer
= ftmp
->oc_name
;
269 switch (otmp
->otyp
) {
271 if (u
.uhunger
<= 200)
272 pline("That food really hit the spot!");
273 else if (u
.uhunger
<= 700)
274 pline("That satiated your stomach!");
276 pline("You're having a hard time getting all that food down.");
279 lesshungry(ftmp
->nutrition
);
281 nomovemsg
= "You finished your meal.";
284 pline("Yak - dog food!");
285 more_experienced(1, 0);
291 Sick
= 0; /* David Neves */
292 pline("What a relief!");
295 lesshungry(ftmp
->nutrition
);
298 if (otmp
->otyp
>= CORPSE
)
299 pline("That %s tasted terrible!", ftmp
->oc_name
);
301 pline("That %s was delicious!", ftmp
->oc_name
);
302 lesshungry(ftmp
->nutrition
);
303 if (otmp
->otyp
== DEAD_LIZARD
&& (Confusion
> 2))
307 if (otmp
->otyp
== CARROT
&& !Blind
) {
310 pline("Your vision improves.");
313 if (otmp
->otyp
== FORTUNE_COOKIE
) {
315 pline("This cookie has a scrap of paper inside!");
316 pline("What a pity, that you cannot read it!");
319 } else if (otmp
->otyp
== LUMP_OF_ROYAL_JELLY
) {
320 /* This stuff seems to be VERY healthy! */
323 if (u
.ustr
< u
.ustrmax
)
326 if (u
.uhp
> u
.uhpmax
) {
337 if (multi
< 0 && !nomovemsg
) {
338 static char msgbuf
[BUFSZ
];
339 (void) snprintf(msgbuf
, sizeof(msgbuf
),
340 "You finished eating the %s.",
348 /* called in hack.main.c */
359 * a3: if(Hunger & LEFT_RING) u.uhunger--; if(Hunger &
360 * RIGHT_RING) u.uhunger--; etc.
363 if (moves
% 20 == 0) { /* jimt@asgb */
372 /* called after vomiting and after performing feats of magic */
380 /* called after eating something (and after drinking fruit juice) */
399 int newhs
, h
= u
.uhunger
;
401 newhs
= (h
> 1000) ? SATIATED
:
402 (h
> 150) ? NOT_HUNGRY
:
404 (h
> 0) ? WEAK
: FAINTING
;
406 if (newhs
== FAINTING
) {
407 if (u
.uhs
== FAINTED
)
409 if (u
.uhs
<= WEAK
|| rn2(20 - u
.uhunger
/ 10) >= 19) {
410 if (u
.uhs
!= FAINTED
&& multi
>= 0 /* %% */ ) {
411 pline("You faint from lack of food.");
412 nomul(-10 + (u
.uhunger
/ 10));
413 nomovemsg
= "You regain consciousness.";
417 } else if (u
.uhunger
< -(int) (200 + 25 * u
.ulevel
)) {
421 pline("You die from starvation.");
425 if (newhs
!= u
.uhs
) {
426 if (newhs
>= WEAK
&& u
.uhs
< WEAK
)
427 losestr(1); /* this may kill you -- see below */
428 else if (newhs
< WEAK
&& u
.uhs
>= WEAK
&& u
.ustr
< u
.ustrmax
)
432 pline((!incr
) ? "You only feel hungry now." :
433 (u
.uhunger
< 145) ? "You feel hungry." :
434 "You are beginning to feel hungry.");
437 pline((!incr
) ? "You feel weak now." :
438 (u
.uhunger
< 45) ? "You feel weak." :
439 "You are beginning to feel weak.");
445 pline("You die from hunger and exhaustion.");
446 killer
= "exhaustion";
452 #define CORPSE_I_TO_C(otyp) (char) ((otyp >= DEAD_ACID_BLOB)\
453 ? 'a' + (otyp - DEAD_ACID_BLOB)\
454 : '@' + (otyp - DEAD_HUMAN))
456 poisonous(struct obj
*otmp
)
458 return (strchr(POISONOUS
, CORPSE_I_TO_C(otmp
->otyp
)) != 0);
461 /* returns 1 if some text was printed */
463 eatcorpse(struct obj
*otmp
)
465 char let
= CORPSE_I_TO_C(otmp
->otyp
);
467 if (let
!= 'a' && moves
> otmp
->age
+ 50 + rn2(100)) {
469 pline("Ulch -- that meat was tainted!");
470 pline("You get very sick.");
472 u
.usick_cause
= objects
[otmp
->otyp
].oc_name
;
473 } else if (strchr(POISONOUS
, let
) && rn2(5)) {
475 pline("Ecch -- that must have been poisonous!");
476 if (!Poison_resistance
) {
478 losehp(rnd(15), "poisonous corpse");
480 pline("You don't seem affected by the poison.");
481 } else if (strchr("ELNOPQRUuxz", let
) && rn2(5)) {
483 pline("You feel sick.");
484 losehp(rnd(8), "cadaver");
490 Teleportation
|= INTRINSIC
;
500 pline("You cannibal! You will be sorry for this!");
504 Aggravate_monster
|= INTRINSIC
;
508 Invis
= 50 + rn2(100);
513 See_invisible
|= INTRINSIC
;
525 Fire_resistance
|= INTRINSIC
;
528 Telepat
|= INTRINSIC
;
532 Cold_resistance
|= INTRINSIC
;
536 Poison_resistance
|= INTRINSIC
;
539 pline("You turn to stone.");
540 killer
= "dead cockatrice";
545 pline("What a pity - you just destroyed a future piece of art!");
551 pline("You cannot resist the temptation to mimic a treasure chest.");
555 nomovemsg
= "You now again prefer mimicking a human.";