Home | History | Annotate | Line # | Download | only in hack
hack.potion.c revision 1.5
      1  1.5       jsm /*	$NetBSD: hack.potion.c,v 1.5 2001/03/25 20:44:02 jsm Exp $	*/
      2  1.4  christos 
      3  1.2   mycroft /*
      4  1.2   mycroft  * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
      5  1.2   mycroft  */
      6  1.2   mycroft 
      7  1.4  christos #include <sys/cdefs.h>
      8  1.2   mycroft #ifndef lint
      9  1.5       jsm __RCSID("$NetBSD: hack.potion.c,v 1.5 2001/03/25 20:44:02 jsm Exp $");
     10  1.4  christos #endif				/* not lint */
     11  1.1       cgd 
     12  1.1       cgd #include "hack.h"
     13  1.4  christos #include "extern.h"
     14  1.4  christos 
     15  1.4  christos int
     16  1.4  christos dodrink()
     17  1.4  christos {
     18  1.4  christos 	struct obj     *otmp, *objs;
     19  1.4  christos 	struct monst   *mtmp;
     20  1.4  christos 	int             unkn = 0, nothing = 0;
     21  1.1       cgd 
     22  1.1       cgd 	otmp = getobj("!", "drink");
     23  1.4  christos 	if (!otmp)
     24  1.4  christos 		return (0);
     25  1.4  christos 	if (!strcmp(objects[otmp->otyp].oc_descr, "smoky") && !rn2(13)) {
     26  1.1       cgd 		ghost_from_bottle();
     27  1.1       cgd 		goto use_it;
     28  1.1       cgd 	}
     29  1.4  christos 	switch (otmp->otyp) {
     30  1.1       cgd 	case POT_RESTORE_STRENGTH:
     31  1.1       cgd 		unkn++;
     32  1.1       cgd 		pline("Wow!  This makes you feel great!");
     33  1.4  christos 		if (u.ustr < u.ustrmax) {
     34  1.1       cgd 			u.ustr = u.ustrmax;
     35  1.1       cgd 			flags.botl = 1;
     36  1.1       cgd 		}
     37  1.1       cgd 		break;
     38  1.1       cgd 	case POT_BOOZE:
     39  1.1       cgd 		unkn++;
     40  1.1       cgd 		pline("Ooph!  This tastes like liquid fire!");
     41  1.4  christos 		Confusion += d(3, 8);
     42  1.1       cgd 		/* the whiskey makes us feel better */
     43  1.4  christos 		if (u.uhp < u.uhpmax)
     44  1.4  christos 			losehp(-1, "bottle of whiskey");
     45  1.4  christos 		if (!rn2(4)) {
     46  1.1       cgd 			pline("You pass out.");
     47  1.1       cgd 			multi = -rnd(15);
     48  1.1       cgd 			nomovemsg = "You awake with a headache.";
     49  1.1       cgd 		}
     50  1.1       cgd 		break;
     51  1.1       cgd 	case POT_INVISIBILITY:
     52  1.4  christos 		if (Invis || See_invisible)
     53  1.4  christos 			nothing++;
     54  1.1       cgd 		else {
     55  1.4  christos 			if (!Blind)
     56  1.4  christos 				pline("Gee!  All of a sudden, you can't see yourself.");
     57  1.4  christos 			else
     58  1.4  christos 				pline("You feel rather airy."), unkn++;
     59  1.4  christos 			newsym(u.ux, u.uy);
     60  1.1       cgd 		}
     61  1.4  christos 		Invis += rn1(15, 31);
     62  1.1       cgd 		break;
     63  1.1       cgd 	case POT_FRUIT_JUICE:
     64  1.1       cgd 		pline("This tastes like fruit juice.");
     65  1.1       cgd 		lesshungry(20);
     66  1.1       cgd 		break;
     67  1.1       cgd 	case POT_HEALING:
     68  1.1       cgd 		pline("You begin to feel better.");
     69  1.1       cgd 		flags.botl = 1;
     70  1.1       cgd 		u.uhp += rnd(10);
     71  1.4  christos 		if (u.uhp > u.uhpmax)
     72  1.1       cgd 			u.uhp = ++u.uhpmax;
     73  1.4  christos 		if (Blind)
     74  1.4  christos 			Blind = 1;	/* see on next move */
     75  1.4  christos 		if (Sick)
     76  1.4  christos 			Sick = 0;
     77  1.1       cgd 		break;
     78  1.1       cgd 	case POT_PARALYSIS:
     79  1.4  christos 		if (Levitation)
     80  1.1       cgd 			pline("You are motionlessly suspended.");
     81  1.1       cgd 		else
     82  1.1       cgd 			pline("Your feet are frozen to the floor!");
     83  1.4  christos 		nomul(-(rn1(10, 25)));
     84  1.1       cgd 		break;
     85  1.1       cgd 	case POT_MONSTER_DETECTION:
     86  1.4  christos 		if (!fmon) {
     87  1.1       cgd 			strange_feeling(otmp, "You feel threatened.");
     88  1.4  christos 			return (1);
     89  1.1       cgd 		} else {
     90  1.1       cgd 			cls();
     91  1.4  christos 			for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
     92  1.4  christos 				if (mtmp->mx > 0)
     93  1.4  christos 					at(mtmp->mx, mtmp->my, mtmp->data->mlet);
     94  1.1       cgd 			prme();
     95  1.1       cgd 			pline("You sense the presence of monsters.");
     96  1.1       cgd 			more();
     97  1.1       cgd 			docrt();
     98  1.1       cgd 		}
     99  1.1       cgd 		break;
    100  1.1       cgd 	case POT_OBJECT_DETECTION:
    101  1.4  christos 		if (!fobj) {
    102  1.1       cgd 			strange_feeling(otmp, "You feel a pull downward.");
    103  1.4  christos 			return (1);
    104  1.1       cgd 		} else {
    105  1.4  christos 			for (objs = fobj; objs; objs = objs->nobj)
    106  1.4  christos 				if (objs->ox != u.ux || objs->oy != u.uy)
    107  1.4  christos 					goto outobjmap;
    108  1.4  christos 			pline("You sense the presence of objects close nearby.");
    109  1.4  christos 			break;
    110  1.4  christos 	outobjmap:
    111  1.1       cgd 			cls();
    112  1.4  christos 			for (objs = fobj; objs; objs = objs->nobj)
    113  1.4  christos 				at(objs->ox, objs->oy, objs->olet);
    114  1.1       cgd 			prme();
    115  1.1       cgd 			pline("You sense the presence of objects.");
    116  1.1       cgd 			more();
    117  1.1       cgd 			docrt();
    118  1.1       cgd 		}
    119  1.1       cgd 		break;
    120  1.1       cgd 	case POT_SICKNESS:
    121  1.1       cgd 		pline("Yech! This stuff tastes like poison.");
    122  1.4  christos 		if (Poison_resistance)
    123  1.4  christos 			pline("(But in fact it was biologically contaminated orange juice.)");
    124  1.4  christos 		losestr(rn1(4, 3));
    125  1.1       cgd 		losehp(rnd(10), "contaminated potion");
    126  1.1       cgd 		break;
    127  1.1       cgd 	case POT_CONFUSION:
    128  1.4  christos 		if (!Confusion)
    129  1.1       cgd 			pline("Huh, What?  Where am I?");
    130  1.1       cgd 		else
    131  1.1       cgd 			nothing++;
    132  1.4  christos 		Confusion += rn1(7, 16);
    133  1.1       cgd 		break;
    134  1.1       cgd 	case POT_GAIN_STRENGTH:
    135  1.1       cgd 		pline("Wow do you feel strong!");
    136  1.4  christos 		if (u.ustr >= 118)
    137  1.4  christos 			break;	/* > 118 is impossible */
    138  1.4  christos 		if (u.ustr > 17)
    139  1.4  christos 			u.ustr += rnd(118 - u.ustr);
    140  1.4  christos 		else
    141  1.4  christos 			u.ustr++;
    142  1.4  christos 		if (u.ustr > u.ustrmax)
    143  1.4  christos 			u.ustrmax = u.ustr;
    144  1.1       cgd 		flags.botl = 1;
    145  1.1       cgd 		break;
    146  1.1       cgd 	case POT_SPEED:
    147  1.4  christos 		if (Wounded_legs) {
    148  1.1       cgd 			heal_legs();
    149  1.1       cgd 			unkn++;
    150  1.1       cgd 			break;
    151  1.1       cgd 		}
    152  1.4  christos 		if (!(Fast & ~INTRINSIC))
    153  1.1       cgd 			pline("You are suddenly moving much faster.");
    154  1.1       cgd 		else
    155  1.1       cgd 			pline("Your legs get new energy."), unkn++;
    156  1.4  christos 		Fast += rn1(10, 100);
    157  1.1       cgd 		break;
    158  1.1       cgd 	case POT_BLINDNESS:
    159  1.4  christos 		if (!Blind)
    160  1.1       cgd 			pline("A cloud of darkness falls upon you.");
    161  1.1       cgd 		else
    162  1.1       cgd 			nothing++;
    163  1.4  christos 		Blind += rn1(100, 250);
    164  1.1       cgd 		seeoff(0);
    165  1.1       cgd 		break;
    166  1.4  christos 	case POT_GAIN_LEVEL:
    167  1.1       cgd 		pluslvl();
    168  1.1       cgd 		break;
    169  1.1       cgd 	case POT_EXTRA_HEALING:
    170  1.1       cgd 		pline("You feel much better.");
    171  1.1       cgd 		flags.botl = 1;
    172  1.4  christos 		u.uhp += d(2, 20) + 1;
    173  1.4  christos 		if (u.uhp > u.uhpmax)
    174  1.1       cgd 			u.uhp = (u.uhpmax += 2);
    175  1.4  christos 		if (Blind)
    176  1.4  christos 			Blind = 1;
    177  1.4  christos 		if (Sick)
    178  1.4  christos 			Sick = 0;
    179  1.1       cgd 		break;
    180  1.1       cgd 	case POT_LEVITATION:
    181  1.4  christos 		if (!Levitation)
    182  1.1       cgd 			float_up();
    183  1.1       cgd 		else
    184  1.1       cgd 			nothing++;
    185  1.1       cgd 		Levitation += rnd(100);
    186  1.1       cgd 		u.uprops[PROP(RIN_LEVITATION)].p_tofn = float_down;
    187  1.1       cgd 		break;
    188  1.1       cgd 	default:
    189  1.1       cgd 		impossible("What a funny potion! (%u)", otmp->otyp);
    190  1.4  christos 		return (0);
    191  1.1       cgd 	}
    192  1.4  christos 	if (nothing) {
    193  1.4  christos 		unkn++;
    194  1.4  christos 		pline("You have a peculiar feeling for a moment, then it passes.");
    195  1.1       cgd 	}
    196  1.4  christos 	if (otmp->dknown && !objects[otmp->otyp].oc_name_known) {
    197  1.4  christos 		if (!unkn) {
    198  1.1       cgd 			objects[otmp->otyp].oc_name_known = 1;
    199  1.4  christos 			more_experienced(0, 10);
    200  1.4  christos 		} else if (!objects[otmp->otyp].oc_uname)
    201  1.1       cgd 			docall(otmp);
    202  1.1       cgd 	}
    203  1.1       cgd use_it:
    204  1.1       cgd 	useup(otmp);
    205  1.4  christos 	return (1);
    206  1.1       cgd }
    207  1.1       cgd 
    208  1.4  christos void
    209  1.1       cgd pluslvl()
    210  1.1       cgd {
    211  1.4  christos 	int num;
    212  1.1       cgd 
    213  1.1       cgd 	pline("You feel more experienced.");
    214  1.1       cgd 	num = rnd(10);
    215  1.1       cgd 	u.uhpmax += num;
    216  1.1       cgd 	u.uhp += num;
    217  1.4  christos 	if (u.ulevel < 14) {
    218  1.4  christos 		u.uexp = newuexp() + 1;
    219  1.1       cgd 		pline("Welcome to experience level %u.", ++u.ulevel);
    220  1.1       cgd 	}
    221  1.1       cgd 	flags.botl = 1;
    222  1.1       cgd }
    223  1.1       cgd 
    224  1.4  christos void
    225  1.4  christos strange_feeling(obj, txt)
    226  1.4  christos 	struct obj     *obj;
    227  1.5       jsm 	const char           *txt;
    228  1.1       cgd {
    229  1.4  christos 	if (flags.beginner)
    230  1.4  christos 		pline("You have a strange feeling for a moment, then it passes.");
    231  1.1       cgd 	else
    232  1.4  christos 		pline(txt);
    233  1.4  christos 	if (!objects[obj->otyp].oc_name_known && !objects[obj->otyp].oc_uname)
    234  1.1       cgd 		docall(obj);
    235  1.1       cgd 	useup(obj);
    236  1.1       cgd }
    237  1.1       cgd 
    238  1.5       jsm const char           *const bottlenames[] = {
    239  1.1       cgd 	"bottle", "phial", "flagon", "carafe", "flask", "jar", "vial"
    240  1.1       cgd };
    241  1.1       cgd 
    242  1.4  christos void
    243  1.1       cgd potionhit(mon, obj)
    244  1.4  christos 	struct monst   *mon;
    245  1.4  christos 	struct obj     *obj;
    246  1.1       cgd {
    247  1.5       jsm 	const char           *botlnam = bottlenames[rn2(SIZE(bottlenames))];
    248  1.4  christos 	boolean         uclose, isyou = (mon == &youmonst);
    249  1.1       cgd 
    250  1.4  christos 	if (isyou) {
    251  1.1       cgd 		uclose = TRUE;
    252  1.1       cgd 		pline("The %s crashes on your head and breaks into shivers.",
    253  1.4  christos 		      botlnam);
    254  1.1       cgd 		losehp(rnd(2), "thrown potion");
    255  1.1       cgd 	} else {
    256  1.4  christos 		uclose = (dist(mon->mx, mon->my) < 3);
    257  1.1       cgd 		/* perhaps 'E' and 'a' have no head? */
    258  1.1       cgd 		pline("The %s crashes on %s's head and breaks into shivers.",
    259  1.4  christos 		      botlnam, monnam(mon));
    260  1.4  christos 		if (rn2(5) && mon->mhp > 1)
    261  1.1       cgd 			mon->mhp--;
    262  1.1       cgd 	}
    263  1.1       cgd 	pline("The %s evaporates.", xname(obj));
    264  1.1       cgd 
    265  1.4  christos 	if (!isyou && !rn2(3))
    266  1.4  christos 		switch (obj->otyp) {
    267  1.1       cgd 
    268  1.4  christos 		case POT_RESTORE_STRENGTH:
    269  1.4  christos 		case POT_GAIN_STRENGTH:
    270  1.4  christos 		case POT_HEALING:
    271  1.4  christos 		case POT_EXTRA_HEALING:
    272  1.4  christos 			if (mon->mhp < mon->mhpmax) {
    273  1.4  christos 				mon->mhp = mon->mhpmax;
    274  1.4  christos 				pline("%s looks sound and hale again!", Monnam(mon));
    275  1.4  christos 			}
    276  1.4  christos 			break;
    277  1.4  christos 		case POT_SICKNESS:
    278  1.4  christos 			if (mon->mhpmax > 3)
    279  1.4  christos 				mon->mhpmax /= 2;
    280  1.4  christos 			if (mon->mhp > 2)
    281  1.4  christos 				mon->mhp /= 2;
    282  1.4  christos 			break;
    283  1.4  christos 		case POT_CONFUSION:
    284  1.4  christos 		case POT_BOOZE:
    285  1.4  christos 			mon->mconf = 1;
    286  1.4  christos 			break;
    287  1.4  christos 		case POT_INVISIBILITY:
    288  1.4  christos 			unpmon(mon);
    289  1.4  christos 			mon->minvis = 1;
    290  1.4  christos 			pmon(mon);
    291  1.4  christos 			break;
    292  1.4  christos 		case POT_PARALYSIS:
    293  1.4  christos 			mon->mfroz = 1;
    294  1.4  christos 			break;
    295  1.4  christos 		case POT_SPEED:
    296  1.4  christos 			mon->mspeed = MFAST;
    297  1.4  christos 			break;
    298  1.4  christos 		case POT_BLINDNESS:
    299  1.4  christos 			mon->mblinded |= 64 + rn2(64);
    300  1.4  christos 			break;
    301  1.4  christos 			/*
    302  1.4  christos 			 * case POT_GAIN_LEVEL: case POT_LEVITATION: case
    303  1.4  christos 			 * POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case
    304  1.4  christos 			 * POT_OBJECT_DETECTION: break;
    305  1.4  christos 			 */
    306  1.1       cgd 		}
    307  1.4  christos 	if (uclose && rn2(5))
    308  1.1       cgd 		potionbreathe(obj);
    309  1.1       cgd 	obfree(obj, Null(obj));
    310  1.1       cgd }
    311  1.1       cgd 
    312  1.4  christos void
    313  1.1       cgd potionbreathe(obj)
    314  1.4  christos 	struct obj     *obj;
    315  1.1       cgd {
    316  1.4  christos 	switch (obj->otyp) {
    317  1.1       cgd 	case POT_RESTORE_STRENGTH:
    318  1.1       cgd 	case POT_GAIN_STRENGTH:
    319  1.4  christos 		if (u.ustr < u.ustrmax)
    320  1.4  christos 			u.ustr++, flags.botl = 1;
    321  1.1       cgd 		break;
    322  1.1       cgd 	case POT_HEALING:
    323  1.1       cgd 	case POT_EXTRA_HEALING:
    324  1.4  christos 		if (u.uhp < u.uhpmax)
    325  1.4  christos 			u.uhp++, flags.botl = 1;
    326  1.1       cgd 		break;
    327  1.1       cgd 	case POT_SICKNESS:
    328  1.4  christos 		if (u.uhp <= 5)
    329  1.4  christos 			u.uhp = 1;
    330  1.4  christos 		else
    331  1.4  christos 			u.uhp -= 5;
    332  1.1       cgd 		flags.botl = 1;
    333  1.1       cgd 		break;
    334  1.1       cgd 	case POT_CONFUSION:
    335  1.1       cgd 	case POT_BOOZE:
    336  1.4  christos 		if (!Confusion)
    337  1.1       cgd 			pline("You feel somewhat dizzy.");
    338  1.1       cgd 		Confusion += rnd(5);
    339  1.1       cgd 		break;
    340  1.1       cgd 	case POT_INVISIBILITY:
    341  1.1       cgd 		pline("For an instant you couldn't see your right hand.");
    342  1.1       cgd 		break;
    343  1.1       cgd 	case POT_PARALYSIS:
    344  1.1       cgd 		pline("Something seems to be holding you.");
    345  1.1       cgd 		nomul(-rnd(5));
    346  1.1       cgd 		break;
    347  1.1       cgd 	case POT_SPEED:
    348  1.1       cgd 		Fast += rnd(5);
    349  1.1       cgd 		pline("Your knees seem more flexible now.");
    350  1.1       cgd 		break;
    351  1.1       cgd 	case POT_BLINDNESS:
    352  1.4  christos 		if (!Blind)
    353  1.4  christos 			pline("It suddenly gets dark.");
    354  1.1       cgd 		Blind += rnd(5);
    355  1.1       cgd 		seeoff(0);
    356  1.1       cgd 		break;
    357  1.4  christos 		/*
    358  1.4  christos 		 * case POT_GAIN_LEVEL: case POT_LEVITATION: case
    359  1.4  christos 		 * POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case
    360  1.4  christos 		 * POT_OBJECT_DETECTION: break;
    361  1.4  christos 		 */
    362  1.1       cgd 	}
    363  1.1       cgd 	/* note: no obfree() */
    364  1.1       cgd }
    365  1.1       cgd 
    366  1.1       cgd /*
    367  1.1       cgd  * -- rudimentary -- to do this correctly requires much more work
    368  1.1       cgd  * -- all sharp weapons get one or more qualities derived from the potions
    369  1.1       cgd  * -- texts on scrolls may be (partially) wiped out; do they become blank?
    370  1.1       cgd  * --   or does their effect change, like under Confusion?
    371  1.1       cgd  * -- all objects may be made invisible by POT_INVISIBILITY
    372  1.1       cgd  * -- If the flask is small, can one dip a large object? Does it magically
    373  1.1       cgd  * --   become a jug? Etc.
    374  1.1       cgd  */
    375  1.4  christos int
    376  1.4  christos dodip()
    377  1.4  christos {
    378  1.4  christos 	struct obj     *potion, *obj;
    379  1.1       cgd 
    380  1.4  christos 	if (!(obj = getobj("#", "dip")))
    381  1.4  christos 		return (0);
    382  1.4  christos 	if (!(potion = getobj("!", "dip into")))
    383  1.4  christos 		return (0);
    384  1.1       cgd 	pline("Interesting...");
    385  1.4  christos 	if (obj->otyp == ARROW || obj->otyp == DART ||
    386  1.4  christos 	    obj->otyp == CROSSBOW_BOLT) {
    387  1.4  christos 		if (potion->otyp == POT_SICKNESS) {
    388  1.1       cgd 			useup(potion);
    389  1.4  christos 			if (obj->spe < 7)
    390  1.4  christos 				obj->spe++;	/* %% */
    391  1.1       cgd 		}
    392  1.1       cgd 	}
    393  1.4  christos 	return (1);
    394  1.1       cgd }
    395  1.1       cgd 
    396  1.4  christos void
    397  1.4  christos ghost_from_bottle()
    398  1.4  christos {
    399  1.4  christos 	struct monst   *mtmp;
    400  1.1       cgd 
    401  1.4  christos 	if (!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) {
    402  1.1       cgd 		pline("This bottle turns out to be empty.");
    403  1.1       cgd 		return;
    404  1.1       cgd 	}
    405  1.1       cgd 	mnexto(mtmp);
    406  1.1       cgd 	pline("As you open the bottle, an enormous ghost emerges!");
    407  1.1       cgd 	pline("You are frightened to death, and unable to move.");
    408  1.1       cgd 	nomul(-3);
    409  1.1       cgd }
    410