NetBSD/games/hack/hack.eat.c

556 lines
14 KiB
C
Raw Normal View History

/* $NetBSD: hack.eat.c,v 1.8 2009/06/07 20:13:18 dholland Exp $ */
1997-10-19 20:56:41 +04:00
1993-08-02 21:16:36 +04:00
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
* Amsterdam
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Stichting Centrum voor Wiskunde en
* Informatica, nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1993-08-02 21:16:36 +04:00
*/
1997-10-19 20:56:41 +04:00
#include <sys/cdefs.h>
1993-08-02 21:16:36 +04:00
#ifndef lint
__RCSID("$NetBSD: hack.eat.c,v 1.8 2009/06/07 20:13:18 dholland Exp $");
1997-10-19 20:56:41 +04:00
#endif /* not lint */
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
#include "hack.h"
#include "extern.h"
char POISONOUS[] = "ADKSVabhks";
1993-03-21 12:45:37 +03:00
/* 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
const char *const hu_stat[] = {
1993-03-21 12:45:37 +03:00
"Satiated",
" ",
"Hungry ",
"Weak ",
"Fainting",
"Fainted ",
"Starved "
};
1997-10-19 20:56:41 +04:00
void
init_uhunger(void)
1997-10-19 20:56:41 +04:00
{
1993-03-21 12:45:37 +03:00
u.uhunger = 900;
u.uhs = NOT_HUNGRY;
}
#define TTSZ SIZE(tintxts)
const struct {
const char *txt;
1997-10-19 20:56:41 +04:00
int nut;
} tintxts[] = {
{ "It contains first quality peaches - what a surprise!", 40 },
{ "It contains salmon - not bad!", 60 },
{ "It contains apple juice - perhaps not what you hoped for.", 20 },
{ "It contains some nondescript substance, tasting awfully.", 500 },
{ "It contains rotten meat. You vomit.", -50 },
{ "It turns out to be empty.", 0 }
1993-03-21 12:45:37 +03:00
};
static struct {
1997-10-19 20:56:41 +04:00
struct obj *tin;
int usedtime, reqtime;
} tin;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
int
opentin(void)
1997-10-19 20:56:41 +04:00
{
int r;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!carried(tin.tin)) /* perhaps it was stolen? */
return (0); /* %% probably we should use tinoid */
if (tin.usedtime++ >= 50) {
1993-03-21 12:45:37 +03:00
pline("You give up your attempt to open the tin.");
1997-10-19 20:56:41 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (tin.usedtime < tin.reqtime)
return (1); /* still busy */
1993-03-21 12:45:37 +03:00
pline("You succeed in opening the tin.");
useup(tin.tin);
1997-10-19 20:56:41 +04:00
r = rn2(2 * TTSZ);
if (r < TTSZ) {
pline(tintxts[r].txt);
lesshungry(tintxts[r].nut);
if (r == 1) { /* SALMON */
Glib = rnd(15);
pline("Eating salmon made your fingers very slippery.");
}
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
pline("It contains spinach - this makes you feel like Popeye!");
lesshungry(600);
if (u.ustr < 118)
u.ustr += rnd(((u.ustr < 17) ? 19 : 118) - u.ustr);
if (u.ustr > u.ustrmax)
u.ustrmax = u.ustr;
flags.botl = 1;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
Meatdone(void)
1997-10-19 20:56:41 +04:00
{
1993-03-21 12:45:37 +03:00
u.usym = '@';
prme();
1997-10-19 20:56:41 +04:00
return 0;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
doeat(void)
1997-10-19 20:56:41 +04:00
{
struct obj *otmp;
struct objclass *ftmp;
int tmp;
1993-03-21 12:45:37 +03:00
/* Is there some food (probably a heavy corpse) here on the ground? */
1997-10-19 20:56:41 +04:00
if (!Levitation)
for (otmp = fobj; otmp; otmp = otmp->nobj) {
if (otmp->ox == u.ux && otmp->oy == u.uy &&
otmp->olet == FOOD_SYM) {
pline("There %s %s here; eat %s? [ny] ",
(otmp->quan == 1) ? "is" : "are",
doname(otmp),
(otmp->quan == 1) ? "it" : "one");
if (readchar() == 'y') {
if (otmp->quan != 1)
(void) splitobj(otmp, 1);
freeobj(otmp);
otmp = addinv(otmp);
addtobill(otmp);
goto gotit;
}
1993-03-21 12:45:37 +03:00
}
}
otmp = getobj("%", "eat");
1997-10-19 20:56:41 +04:00
if (!otmp)
return (0);
1993-03-21 12:45:37 +03:00
gotit:
1997-10-19 20:56:41 +04:00
if (otmp->otyp == TIN) {
if (uwep) {
switch (uwep->otyp) {
1993-03-21 12:45:37 +03:00
case CAN_OPENER:
tmp = 1;
break;
case DAGGER:
case CRYSKNIFE:
tmp = 3;
break;
case PICK_AXE:
case AXE:
tmp = 6;
break;
default:
goto no_opener;
}
pline("Using your %s you try to open the tin.",
1997-10-19 20:56:41 +04:00
aobjnam(uwep, (char *) 0));
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
no_opener:
1993-03-21 12:45:37 +03:00
pline("It is not so easy to open this tin.");
1997-10-19 20:56:41 +04:00
if (Glib) {
1993-03-21 12:45:37 +03:00
pline("The tin slips out of your hands.");
1997-10-19 20:56:41 +04:00
if (otmp->quan > 1) {
struct obj *obj;
1993-03-21 12:45:37 +03:00
obj = splitobj(otmp, 1);
1997-10-19 20:56:41 +04:00
if (otmp == uwep)
setuwep(obj);
1993-03-21 12:45:37 +03:00
}
dropx(otmp);
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
tmp = 10 + rn2(1 + 500 / ((int) (u.ulevel + u.ustr)));
1993-03-21 12:45:37 +03:00
}
tin.reqtime = tmp;
tin.usedtime = 0;
tin.tin = otmp;
occupation = opentin;
occtxt = "opening the tin";
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
ftmp = &objects[otmp->otyp];
multi = -ftmp->oc_delay;
1997-10-19 20:56:41 +04:00
if (otmp->otyp >= CORPSE && eatcorpse(otmp))
goto eatx;
if (!rn2(7) && otmp->otyp != FORTUNE_COOKIE) {
1993-03-21 12:45:37 +03:00
pline("Blecch! Rotten food!");
1997-10-19 20:56:41 +04:00
if (!rn2(4)) {
1993-03-21 12:45:37 +03:00
pline("You feel rather light headed.");
1997-10-19 20:56:41 +04:00
Confusion += d(2, 4);
} else if (!rn2(4) && !Blind) {
1993-03-21 12:45:37 +03:00
pline("Everything suddenly goes dark.");
1997-10-19 20:56:41 +04:00
Blind = d(2, 10);
1993-03-21 12:45:37 +03:00
seeoff(0);
1997-10-19 20:56:41 +04:00
} else if (!rn2(3)) {
if (Blind)
pline("The world spins and you slap against the floor.");
1993-03-21 12:45:37 +03:00
else
1997-10-19 20:56:41 +04:00
pline("The world spins and goes dark.");
1993-03-21 12:45:37 +03:00
nomul(-rnd(10));
nomovemsg = "You are conscious again.";
}
lesshungry(ftmp->nutrition / 4);
} else {
1997-10-19 20:56:41 +04:00
if (u.uhunger >= 1500) {
1993-03-21 12:45:37 +03:00
pline("You choke over your food.");
pline("You die...");
killer = ftmp->oc_name;
done("choked");
}
1997-10-19 20:56:41 +04:00
switch (otmp->otyp) {
1993-03-21 12:45:37 +03:00
case FOOD_RATION:
1997-10-19 20:56:41 +04:00
if (u.uhunger <= 200)
1993-03-21 12:45:37 +03:00
pline("That food really hit the spot!");
1997-10-19 20:56:41 +04:00
else if (u.uhunger <= 700)
1993-03-21 12:45:37 +03:00
pline("That satiated your stomach!");
else {
1997-10-19 20:56:41 +04:00
pline("You're having a hard time getting all that food down.");
1993-03-21 12:45:37 +03:00
multi -= 2;
}
lesshungry(ftmp->nutrition);
1997-10-19 20:56:41 +04:00
if (multi < 0)
nomovemsg = "You finished your meal.";
1993-03-21 12:45:37 +03:00
break;
case TRIPE_RATION:
pline("Yak - dog food!");
1997-10-19 20:56:41 +04:00
more_experienced(1, 0);
1993-03-21 12:45:37 +03:00
flags.botl = 1;
1997-10-19 20:56:41 +04:00
if (rn2(2)) {
1993-03-21 12:45:37 +03:00
pline("You vomit.");
morehungry(20);
1997-10-19 20:56:41 +04:00
if (Sick) {
1993-03-21 12:45:37 +03:00
Sick = 0; /* David Neves */
pline("What a relief!");
}
1997-10-19 20:56:41 +04:00
} else
lesshungry(ftmp->nutrition);
1993-03-21 12:45:37 +03:00
break;
default:
1997-10-19 20:56:41 +04:00
if (otmp->otyp >= CORPSE)
pline("That %s tasted terrible!", ftmp->oc_name);
1993-03-21 12:45:37 +03:00
else
1997-10-19 20:56:41 +04:00
pline("That %s was delicious!", ftmp->oc_name);
1993-03-21 12:45:37 +03:00
lesshungry(ftmp->nutrition);
1997-10-19 20:56:41 +04:00
if (otmp->otyp == DEAD_LIZARD && (Confusion > 2))
1993-03-21 12:45:37 +03:00
Confusion = 2;
else
#ifdef QUEST
1997-10-19 20:56:41 +04:00
if (otmp->otyp == CARROT && !Blind) {
1993-03-21 12:45:37 +03:00
u.uhorizon++;
setsee();
pline("Your vision improves.");
} else
1997-10-19 20:56:41 +04:00
#endif /* QUEST */
if (otmp->otyp == FORTUNE_COOKIE) {
if (Blind) {
pline("This cookie has a scrap of paper inside!");
pline("What a pity, that you cannot read it!");
} else
outrumor();
} else if (otmp->otyp == LUMP_OF_ROYAL_JELLY) {
1993-03-21 12:45:37 +03:00
/* This stuff seems to be VERY healthy! */
1997-10-19 20:56:41 +04:00
if (u.ustrmax < 118)
u.ustrmax++;
if (u.ustr < u.ustrmax)
u.ustr++;
1993-03-21 12:45:37 +03:00
u.uhp += rnd(20);
1997-10-19 20:56:41 +04:00
if (u.uhp > u.uhpmax) {
if (!rn2(17))
u.uhpmax++;
1993-03-21 12:45:37 +03:00
u.uhp = u.uhpmax;
}
heal_legs();
}
break;
}
}
eatx:
1997-10-19 20:56:41 +04:00
if (multi < 0 && !nomovemsg) {
static char msgbuf[BUFSZ];
(void) snprintf(msgbuf, sizeof(msgbuf),
"You finished eating the %s.",
1997-10-19 20:56:41 +04:00
ftmp->oc_name);
1993-03-21 12:45:37 +03:00
nomovemsg = msgbuf;
}
useup(otmp);
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
/* called in hack.main.c */
1997-10-19 20:56:41 +04:00
void
gethungry(void)
1997-10-19 20:56:41 +04:00
{
1993-03-21 12:45:37 +03:00
--u.uhunger;
1997-10-19 20:56:41 +04:00
if (moves % 2) {
if (Regeneration)
u.uhunger--;
if (Hunger)
u.uhunger--;
/*
* a3: if(Hunger & LEFT_RING) u.uhunger--; if(Hunger &
* RIGHT_RING) u.uhunger--; etc.
*/
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (moves % 20 == 0) { /* jimt@asgb */
if (uleft)
u.uhunger--;
if (uright)
u.uhunger--;
1993-03-21 12:45:37 +03:00
}
newuhs(TRUE);
}
/* called after vomiting and after performing feats of magic */
1997-10-19 20:56:41 +04:00
void
morehungry(int num)
1997-10-19 20:56:41 +04:00
{
1993-03-21 12:45:37 +03:00
u.uhunger -= num;
newuhs(TRUE);
}
/* called after eating something (and after drinking fruit juice) */
1997-10-19 20:56:41 +04:00
void
lesshungry(int num)
1997-10-19 20:56:41 +04:00
{
1993-03-21 12:45:37 +03:00
u.uhunger += num;
newuhs(FALSE);
}
1997-10-19 20:56:41 +04:00
int
unfaint(void)
1997-10-19 20:56:41 +04:00
{
1993-03-21 12:45:37 +03:00
u.uhs = FAINTING;
flags.botl = 1;
1997-10-19 20:56:41 +04:00
return 0;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
void
newuhs(boolean incr)
1997-10-19 20:56:41 +04:00
{
int newhs, h = u.uhunger;
1993-03-21 12:45:37 +03:00
newhs = (h > 1000) ? SATIATED :
(h > 150) ? NOT_HUNGRY :
(h > 50) ? HUNGRY :
(h > 0) ? WEAK : FAINTING;
1997-10-19 20:56:41 +04:00
if (newhs == FAINTING) {
if (u.uhs == FAINTED)
1993-03-21 12:45:37 +03:00
newhs = FAINTED;
1997-10-19 20:56:41 +04:00
if (u.uhs <= WEAK || rn2(20 - u.uhunger / 10) >= 19) {
if (u.uhs != FAINTED && multi >= 0 /* %% */ ) {
1993-03-21 12:45:37 +03:00
pline("You faint from lack of food.");
1997-10-19 20:56:41 +04:00
nomul(-10 + (u.uhunger / 10));
1993-03-21 12:45:37 +03:00
nomovemsg = "You regain consciousness.";
afternmv = unfaint;
newhs = FAINTED;
}
1997-10-19 20:56:41 +04:00
} else if (u.uhunger < -(int) (200 + 25 * u.ulevel)) {
1993-03-21 12:45:37 +03:00
u.uhs = STARVED;
flags.botl = 1;
bot();
pline("You die from starvation.");
done("starved");
}
}
1997-10-19 20:56:41 +04:00
if (newhs != u.uhs) {
if (newhs >= WEAK && u.uhs < WEAK)
1993-03-21 12:45:37 +03:00
losestr(1); /* this may kill you -- see below */
1997-10-19 20:56:41 +04:00
else if (newhs < WEAK && u.uhs >= WEAK && u.ustr < u.ustrmax)
1993-03-21 12:45:37 +03:00
losestr(-1);
1997-10-19 20:56:41 +04:00
switch (newhs) {
1993-03-21 12:45:37 +03:00
case HUNGRY:
pline((!incr) ? "You only feel hungry now." :
(u.uhunger < 145) ? "You feel hungry." :
1997-10-19 20:56:41 +04:00
"You are beginning to feel hungry.");
1993-03-21 12:45:37 +03:00
break;
case WEAK:
pline((!incr) ? "You feel weak now." :
(u.uhunger < 45) ? "You feel weak." :
1997-10-19 20:56:41 +04:00
"You are beginning to feel weak.");
1993-03-21 12:45:37 +03:00
break;
}
u.uhs = newhs;
flags.botl = 1;
1997-10-19 20:56:41 +04:00
if (u.uhp < 1) {
1993-03-21 12:45:37 +03:00
pline("You die from hunger and exhaustion.");
killer = "exhaustion";
done("starved");
}
}
}
#define CORPSE_I_TO_C(otyp) (char) ((otyp >= DEAD_ACID_BLOB)\
? 'a' + (otyp - DEAD_ACID_BLOB)\
: '@' + (otyp - DEAD_HUMAN))
1997-10-19 20:56:41 +04:00
int
poisonous(struct obj *otmp)
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
return (strchr(POISONOUS, CORPSE_I_TO_C(otmp->otyp)) != 0);
1993-03-21 12:45:37 +03:00
}
/* returns 1 if some text was printed */
1997-10-19 20:56:41 +04:00
int
eatcorpse(struct obj *otmp)
1997-10-19 20:56:41 +04:00
{
char let = CORPSE_I_TO_C(otmp->otyp);
int tp = 0;
if (let != 'a' && moves > otmp->age + 50 + rn2(100)) {
1993-03-21 12:45:37 +03:00
tp++;
pline("Ulch -- that meat was tainted!");
pline("You get very sick.");
Sick = 10 + rn2(10);
u.usick_cause = objects[otmp->otyp].oc_name;
1997-10-19 20:56:41 +04:00
} else if (strchr(POISONOUS, let) && rn2(5)) {
1993-03-21 12:45:37 +03:00
tp++;
pline("Ecch -- that must have been poisonous!");
1997-10-19 20:56:41 +04:00
if (!Poison_resistance) {
1993-03-21 12:45:37 +03:00
losestr(rnd(4));
losehp(rnd(15), "poisonous corpse");
} else
pline("You don't seem affected by the poison.");
1997-10-19 20:56:41 +04:00
} else if (strchr("ELNOPQRUuxz", let) && rn2(5)) {
1993-03-21 12:45:37 +03:00
tp++;
pline("You feel sick.");
losehp(rnd(8), "cadaver");
}
1997-10-19 20:56:41 +04:00
switch (let) {
1993-03-21 12:45:37 +03:00
case 'L':
case 'N':
case 't':
Teleportation |= INTRINSIC;
break;
case 'W':
pluslvl();
break;
case 'n':
u.uhp = u.uhpmax;
flags.botl = 1;
/* fall into next case */
case '@':
pline("You cannibal! You will be sorry for this!");
/* not tp++; */
/* fall into next case */
case 'd':
Aggravate_monster |= INTRINSIC;
break;
case 'I':
1997-10-19 20:56:41 +04:00
if (!Invis) {
Invis = 50 + rn2(100);
if (!See_invisible)
1993-03-21 12:45:37 +03:00
newsym(u.ux, u.uy);
} else {
Invis |= INTRINSIC;
See_invisible |= INTRINSIC;
}
/* fall into next case */
case 'y':
#ifdef QUEST
u.uhorizon++;
1997-10-19 20:56:41 +04:00
#endif /* QUEST */
1993-03-21 12:45:37 +03:00
/* fall into next case */
case 'B':
Confusion = 50;
break;
case 'D':
Fire_resistance |= INTRINSIC;
break;
case 'E':
Telepat |= INTRINSIC;
break;
case 'F':
case 'Y':
Cold_resistance |= INTRINSIC;
break;
case 'k':
case 's':
Poison_resistance |= INTRINSIC;
break;
case 'c':
pline("You turn to stone.");
killer = "dead cockatrice";
done("died");
/* NOTREACHED */
case 'a':
1997-10-19 20:56:41 +04:00
if (Stoned) {
pline("What a pity - you just destroyed a future piece of art!");
tp++;
Stoned = 0;
}
break;
1993-03-21 12:45:37 +03:00
case 'M':
1997-10-19 20:56:41 +04:00
pline("You cannot resist the temptation to mimic a treasure chest.");
tp++;
nomul(-30);
afternmv = Meatdone;
nomovemsg = "You now again prefer mimicking a human.";
u.usym = '$';
prme();
break;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
return (tp);
1993-03-21 12:45:37 +03:00
}