Home | History | Annotate | Line # | Download | only in larn
moreobj.c revision 1.5
      1  1.5  christos /*	$NetBSD: moreobj.c,v 1.5 2001/02/05 00:57:34 christos Exp $	*/
      2  1.2   mycroft 
      3  1.4  christos /*
      4  1.4  christos  * moreobj.c 		Larn is copyrighted 1986 by Noah Morgan.
      5  1.4  christos  *
      6  1.4  christos  * Routines in this file:
      7  1.4  christos  *
      8  1.4  christos  * oaltar() othrone() ochest() ofountain()
      9  1.1       cgd  */
     10  1.4  christos #include <sys/cdefs.h>
     11  1.4  christos #ifndef lint
     12  1.5  christos __RCSID("$NetBSD: moreobj.c,v 1.5 2001/02/05 00:57:34 christos Exp $");
     13  1.4  christos #endif				/* not lint */
     14  1.4  christos #include <stdlib.h>
     15  1.4  christos #include <unistd.h>
     16  1.1       cgd #include "header.h"
     17  1.4  christos #include "extern.h"
     18  1.1       cgd 
     19  1.4  christos static void ohear __P((void));
     20  1.4  christos static void fch __P((int, long *));
     21  1.1       cgd 
     22  1.1       cgd /*
     23  1.1       cgd  *	******
     24  1.1       cgd  *	OALTAR
     25  1.1       cgd  *	******
     26  1.1       cgd  *
     27  1.1       cgd  *	subroutine to process an altar object
     28  1.1       cgd  */
     29  1.4  christos void
     30  1.1       cgd oaltar()
     31  1.4  christos {
     32  1.4  christos 	unsigned long   k;
     33  1.1       cgd 
     34  1.4  christos 	lprcat("\nDo you (p) pray  (d) desecrate");
     35  1.4  christos 	iopts();
     36  1.4  christos 	while (1) {
     37  1.4  christos 		while (1)
     38  1.5  christos 			switch (lgetchar()) {
     39  1.4  christos 			case 'p':
     40  1.4  christos 				lprcat(" pray\nDo you (m) give money or (j) just pray? ");
     41  1.4  christos 				while (1)
     42  1.5  christos 					switch (lgetchar()) {
     43  1.4  christos 					case 'j':
     44  1.4  christos 						if (rnd(100) < 75)
     45  1.4  christos 							lprcat("\nnothing happens");
     46  1.4  christos 						else if (rnd(13) < 4)
     47  1.4  christos 							ohear();
     48  1.4  christos 						else if (rnd(43) == 10) {
     49  1.4  christos 							if (c[WEAR])
     50  1.4  christos 								lprcat("\nYou feel your armor vibrate for a moment");
     51  1.4  christos 							enchantarmor();
     52  1.4  christos 							return;
     53  1.4  christos 						} else if (rnd(43) == 10) {
     54  1.4  christos 							if (c[WIELD])
     55  1.4  christos 								lprcat("\nYou feel your weapon vibrate for a moment");
     56  1.4  christos 							enchweapon();
     57  1.4  christos 							return;
     58  1.4  christos 						} else
     59  1.4  christos 							createmonster(makemonst(level + 1));
     60  1.4  christos 						return;
     61  1.4  christos 
     62  1.4  christos 					case 'm':
     63  1.4  christos 						lprcat("\n\n");
     64  1.4  christos 						cursor(1, 24);
     65  1.4  christos 						cltoeoln();
     66  1.4  christos 						cursor(1, 23);
     67  1.4  christos 						cltoeoln();
     68  1.4  christos 						lprcat("how much do you donate? ");
     69  1.4  christos 						k = readnum((long) c[GOLD]);
     70  1.4  christos 						if (c[GOLD] < k) {
     71  1.4  christos 							lprcat("\nYou don't have that much!");
     72  1.4  christos 							return;
     73  1.1       cgd 						}
     74  1.4  christos 						c[GOLD] -= k;
     75  1.4  christos 						if (k < c[GOLD] / 10 || k < rnd(50)) {
     76  1.4  christos 							createmonster(makemonst(level + 1));
     77  1.4  christos 							c[AGGRAVATE] += 200;
     78  1.4  christos 						} else if (rnd(101) > 50) {
     79  1.4  christos 							ohear();
     80  1.4  christos 							return;
     81  1.4  christos 						} else if (rnd(43) == 5) {
     82  1.4  christos 							if (c[WEAR])
     83  1.4  christos 								lprcat("\nYou feel your armor vibrate for a moment");
     84  1.4  christos 							enchantarmor();
     85  1.4  christos 							return;
     86  1.4  christos 						} else if (rnd(43) == 8) {
     87  1.4  christos 							if (c[WIELD])
     88  1.4  christos 								lprcat("\nYou feel your weapon vibrate for a moment");
     89  1.4  christos 							enchweapon();
     90  1.4  christos 							return;
     91  1.4  christos 						} else
     92  1.4  christos 							lprcat("\nThank You.");
     93  1.4  christos 						bottomline();
     94  1.4  christos 						return;
     95  1.4  christos 
     96  1.4  christos 					case '\33':
     97  1.4  christos 						return;
     98  1.4  christos 					};
     99  1.4  christos 
    100  1.4  christos 			case 'd':
    101  1.4  christos 				lprcat(" desecrate");
    102  1.4  christos 				if (rnd(100) < 60) {
    103  1.4  christos 					createmonster(makemonst(level + 2) + 8);
    104  1.4  christos 					c[AGGRAVATE] += 2500;
    105  1.4  christos 				} else if (rnd(101) < 30) {
    106  1.4  christos 					lprcat("\nThe altar crumbles into a pile of dust before your eyes");
    107  1.4  christos 					forget();	/* remember to destroy
    108  1.4  christos 							 * the altar	 */
    109  1.4  christos 				} else
    110  1.4  christos 					lprcat("\nnothing happens");
    111  1.4  christos 				return;
    112  1.4  christos 
    113  1.4  christos 			case 'i':
    114  1.4  christos 			case '\33':
    115  1.4  christos 				ignore();
    116  1.4  christos 				if (rnd(100) < 30) {
    117  1.4  christos 					createmonster(makemonst(level + 1));
    118  1.4  christos 					c[AGGRAVATE] += rnd(450);
    119  1.4  christos 				} else
    120  1.4  christos 					lprcat("\nnothing happens");
    121  1.4  christos 				return;
    122  1.4  christos 			};
    123  1.1       cgd 	}
    124  1.4  christos }
    125  1.1       cgd 
    126  1.1       cgd /*
    127  1.1       cgd 	function to cast a +3 protection on the player
    128  1.1       cgd  */
    129  1.1       cgd static void
    130  1.1       cgd ohear()
    131  1.4  christos {
    132  1.1       cgd 	lprcat("\nYou have been heard!");
    133  1.4  christos 	if (c[ALTPRO] == 0)
    134  1.4  christos 		c[MOREDEFENSES] += 3;
    135  1.1       cgd 	c[ALTPRO] += 500;	/* protection field */
    136  1.1       cgd 	bottomline();
    137  1.4  christos }
    138  1.1       cgd 
    139  1.1       cgd /*
    140  1.1       cgd 	*******
    141  1.1       cgd 	OTHRONE
    142  1.1       cgd 	*******
    143  1.1       cgd 
    144  1.1       cgd 	subroutine to process a throne object
    145  1.1       cgd  */
    146  1.4  christos void
    147  1.1       cgd othrone(arg)
    148  1.4  christos 	int             arg;
    149  1.4  christos {
    150  1.4  christos 	int    i, k;
    151  1.4  christos 
    152  1.4  christos 	lprcat("\nDo you (p) pry off jewels, (s) sit down");
    153  1.4  christos 	iopts();
    154  1.4  christos 	while (1) {
    155  1.4  christos 		while (1)
    156  1.5  christos 			switch (lgetchar()) {
    157  1.4  christos 			case 'p':
    158  1.4  christos 				lprcat(" pry off");
    159  1.4  christos 				k = rnd(101);
    160  1.4  christos 				if (k < 25) {
    161  1.4  christos 					for (i = 0; i < rnd(4); i++)
    162  1.4  christos 						creategem();	/* gems pop off the
    163  1.4  christos 								 * throne */
    164  1.4  christos 					item[playerx][playery] = ODEADTHRONE;
    165  1.4  christos 					know[playerx][playery] = 0;
    166  1.4  christos 				} else if (k < 40 && arg == 0) {
    167  1.4  christos 					createmonster(GNOMEKING);
    168  1.4  christos 					item[playerx][playery] = OTHRONE2;
    169  1.4  christos 					know[playerx][playery] = 0;
    170  1.4  christos 				} else
    171  1.4  christos 					lprcat("\nnothing happens");
    172  1.4  christos 				return;
    173  1.4  christos 
    174  1.4  christos 			case 's':
    175  1.4  christos 				lprcat(" sit down");
    176  1.4  christos 				k = rnd(101);
    177  1.4  christos 				if (k < 30 && arg == 0) {
    178  1.4  christos 					createmonster(GNOMEKING);
    179  1.4  christos 					item[playerx][playery] = OTHRONE2;
    180  1.4  christos 					know[playerx][playery] = 0;
    181  1.4  christos 				} else if (k < 35) {
    182  1.4  christos 					lprcat("\nZaaaappp!  You've been teleported!\n");
    183  1.4  christos 					beep();
    184  1.4  christos 					oteleport(0);
    185  1.4  christos 				} else
    186  1.4  christos 					lprcat("\nnothing happens");
    187  1.4  christos 				return;
    188  1.4  christos 
    189  1.4  christos 			case 'i':
    190  1.4  christos 			case '\33':
    191  1.4  christos 				ignore();
    192  1.4  christos 				return;
    193  1.4  christos 			};
    194  1.1       cgd 	}
    195  1.4  christos }
    196  1.1       cgd 
    197  1.4  christos void
    198  1.1       cgd odeadthrone()
    199  1.4  christos {
    200  1.4  christos 	int    k;
    201  1.1       cgd 
    202  1.4  christos 	lprcat("\nDo you (s) sit down");
    203  1.4  christos 	iopts();
    204  1.4  christos 	while (1) {
    205  1.4  christos 		while (1)
    206  1.5  christos 			switch (lgetchar()) {
    207  1.4  christos 			case 's':
    208  1.4  christos 				lprcat(" sit down");
    209  1.4  christos 				k = rnd(101);
    210  1.4  christos 				if (k < 35) {
    211  1.4  christos 					lprcat("\nZaaaappp!  You've been teleported!\n");
    212  1.4  christos 					beep();
    213  1.4  christos 					oteleport(0);
    214  1.4  christos 				} else
    215  1.4  christos 					lprcat("\nnothing happens");
    216  1.4  christos 				return;
    217  1.4  christos 
    218  1.4  christos 			case 'i':
    219  1.4  christos 			case '\33':
    220  1.4  christos 				ignore();
    221  1.4  christos 				return;
    222  1.4  christos 			};
    223  1.1       cgd 	}
    224  1.4  christos }
    225  1.1       cgd 
    226  1.1       cgd /*
    227  1.1       cgd 	******
    228  1.1       cgd 	OCHEST
    229  1.1       cgd 	******
    230  1.1       cgd 
    231  1.1       cgd 	subroutine to process a throne object
    232  1.1       cgd  */
    233  1.4  christos void
    234  1.1       cgd ochest()
    235  1.4  christos {
    236  1.4  christos 	int    i, k;
    237  1.4  christos 	lprcat("\nDo you (t) take it, (o) try to open it");
    238  1.4  christos 	iopts();
    239  1.4  christos 	while (1) {
    240  1.4  christos 		while (1)
    241  1.5  christos 			switch (lgetchar()) {
    242  1.4  christos 			case 'o':
    243  1.4  christos 				lprcat(" open it");
    244  1.4  christos 				k = rnd(101);
    245  1.4  christos 				if (k < 40) {
    246  1.4  christos 					lprcat("\nThe chest explodes as you open it");
    247  1.4  christos 					beep();
    248  1.4  christos 					i = rnd(10);
    249  1.4  christos 					lastnum = 281;	/* in case he dies */
    250  1.4  christos 					lprintf("\nYou suffer %d hit points damage!", (long) i);
    251  1.4  christos 					checkloss(i);
    252  1.4  christos 					switch (rnd(10)) {	/* see if he gets a
    253  1.4  christos 								 * curse */
    254  1.4  christos 					case 1:
    255  1.4  christos 						c[ITCHING] += rnd(1000) + 100;
    256  1.4  christos 						lprcat("\nYou feel an irritation spread over your skin!");
    257  1.4  christos 						beep();
    258  1.4  christos 						break;
    259  1.4  christos 
    260  1.4  christos 					case 2:
    261  1.4  christos 						c[CLUMSINESS] += rnd(1600) + 200;
    262  1.4  christos 						lprcat("\nYou begin to lose hand to eye coordination!");
    263  1.4  christos 						beep();
    264  1.4  christos 						break;
    265  1.4  christos 
    266  1.4  christos 					case 3:
    267  1.4  christos 						c[HALFDAM] += rnd(1600) + 200;
    268  1.4  christos 						beep();
    269  1.4  christos 						lprcat("\nA sickness engulfs you!");
    270  1.4  christos 						break;
    271  1.4  christos 					};
    272  1.4  christos 					item[playerx][playery] = know[playerx][playery] = 0;
    273  1.4  christos 					if (rnd(100) < 69)
    274  1.4  christos 						creategem();	/* gems from the chest */
    275  1.4  christos 					dropgold(rnd(110 * iarg[playerx][playery] + 200));
    276  1.4  christos 					for (i = 0; i < rnd(4); i++)
    277  1.4  christos 						something(iarg[playerx][playery] + 2);
    278  1.4  christos 				} else
    279  1.4  christos 					lprcat("\nnothing happens");
    280  1.4  christos 				return;
    281  1.4  christos 
    282  1.4  christos 			case 't':
    283  1.4  christos 				lprcat(" take");
    284  1.4  christos 				if (take(OCHEST, iarg[playerx][playery]) == 0)
    285  1.4  christos 					item[playerx][playery] = know[playerx][playery] = 0;
    286  1.4  christos 				return;
    287  1.4  christos 
    288  1.4  christos 			case 'i':
    289  1.4  christos 			case '\33':
    290  1.4  christos 				ignore();
    291  1.4  christos 				return;
    292  1.4  christos 			};
    293  1.1       cgd 	}
    294  1.4  christos }
    295  1.1       cgd 
    296  1.1       cgd /*
    297  1.1       cgd 	*********
    298  1.1       cgd 	OFOUNTAIN
    299  1.1       cgd 	*********
    300  1.1       cgd  */
    301  1.1       cgd 
    302  1.4  christos void
    303  1.1       cgd ofountain()
    304  1.4  christos {
    305  1.4  christos 	int    x;
    306  1.1       cgd 	cursors();
    307  1.4  christos 	lprcat("\nDo you (d) drink, (w) wash yourself");
    308  1.4  christos 	iopts();
    309  1.4  christos 	while (1)
    310  1.5  christos 		switch (lgetchar()) {
    311  1.4  christos 		case 'd':
    312  1.4  christos 			lprcat("drink");
    313  1.4  christos 			if (rnd(1501) < 2) {
    314  1.4  christos 				lprcat("\nOops!  You seem to have caught the dreadful sleep!");
    315  1.4  christos 				beep();
    316  1.4  christos 				lflush();
    317  1.4  christos 				sleep(3);
    318  1.4  christos 				died(280);
    319  1.4  christos 				return;
    320  1.4  christos 			}
    321  1.4  christos 			x = rnd(100);
    322  1.4  christos 			if (x < 7) {
    323  1.4  christos 				c[HALFDAM] += 200 + rnd(200);
    324  1.4  christos 				lprcat("\nYou feel a sickness coming on");
    325  1.4  christos 			} else if (x < 13)
    326  1.4  christos 				quaffpotion(23);	/* see invisible */
    327  1.4  christos 			else if (x < 45)
    328  1.4  christos 				lprcat("\nnothing seems to have happened");
    329  1.4  christos 			else if (rnd(3) != 2)
    330  1.4  christos 				fntchange(1);	/* change char levels upward	 */
    331  1.4  christos 			else
    332  1.4  christos 				fntchange(-1);	/* change char levels
    333  1.4  christos 						 * downward	 */
    334  1.4  christos 			if (rnd(12) < 3) {
    335  1.4  christos 				lprcat("\nThe fountains bubbling slowly quiets");
    336  1.4  christos 				item[playerx][playery] = ODEADFOUNTAIN;	/* dead fountain */
    337  1.4  christos 				know[playerx][playery] = 0;
    338  1.4  christos 			}
    339  1.4  christos 			return;
    340  1.1       cgd 
    341  1.1       cgd 		case '\33':
    342  1.4  christos 		case 'i':
    343  1.4  christos 			ignore();
    344  1.4  christos 			return;
    345  1.1       cgd 
    346  1.4  christos 		case 'w':
    347  1.4  christos 			lprcat("wash yourself");
    348  1.4  christos 			if (rnd(100) < 11) {
    349  1.4  christos 				x = rnd((level << 2) + 2);
    350  1.4  christos 				lprintf("\nOh no!  The water was foul!  You suffer %d hit points!", (long) x);
    351  1.4  christos 				lastnum = 273;
    352  1.4  christos 				losehp(x);
    353  1.4  christos 				bottomline();
    354  1.4  christos 				cursors();
    355  1.4  christos 			} else if (rnd(100) < 29)
    356  1.4  christos 				lprcat("\nYou got the dirt off!");
    357  1.4  christos 			else if (rnd(100) < 31)
    358  1.4  christos 				lprcat("\nThis water seems to be hard water!  The dirt didn't come off!");
    359  1.4  christos 			else if (rnd(100) < 34)
    360  1.4  christos 				createmonster(WATERLORD);	/* make water lord		 */
    361  1.4  christos 			else
    362  1.4  christos 				lprcat("\nnothing seems to have happened");
    363  1.4  christos 			return;
    364  1.1       cgd 		}
    365  1.4  christos }
    366  1.1       cgd 
    367  1.1       cgd /*
    368  1.1       cgd 	***
    369  1.1       cgd 	FCH
    370  1.1       cgd 	***
    371  1.1       cgd 
    372  1.1       cgd 	subroutine to process an up/down of a character attribute for ofountain
    373  1.1       cgd  */
    374  1.1       cgd static void
    375  1.4  christos fch(how, x)
    376  1.4  christos 	int             how;
    377  1.4  christos 	long           *x;
    378  1.4  christos {
    379  1.4  christos 	if (how < 0) {
    380  1.4  christos 		lprcat(" went down by one!");
    381  1.4  christos 		--(*x);
    382  1.4  christos 	} else {
    383  1.4  christos 		lprcat(" went up by one!");
    384  1.4  christos 		(*x)++;
    385  1.4  christos 	}
    386  1.1       cgd 	bottomline();
    387  1.4  christos }
    388  1.1       cgd 
    389  1.1       cgd /*
    390  1.1       cgd 	a subroutine to raise or lower character levels
    391  1.1       cgd 	if x > 0 they are raised   if x < 0 they are lowered
    392  1.1       cgd  */
    393  1.4  christos void
    394  1.1       cgd fntchange(how)
    395  1.4  christos 	int             how;
    396  1.4  christos {
    397  1.4  christos 	long   j;
    398  1.1       cgd 	lprc('\n');
    399  1.4  christos 	switch (rnd(9)) {
    400  1.4  christos 	case 1:
    401  1.4  christos 		lprcat("Your strength");
    402  1.4  christos 		fch(how, &c[0]);
    403  1.4  christos 		break;
    404  1.4  christos 	case 2:
    405  1.4  christos 		lprcat("Your intelligence");
    406  1.4  christos 		fch(how, &c[1]);
    407  1.4  christos 		break;
    408  1.4  christos 	case 3:
    409  1.4  christos 		lprcat("Your wisdom");
    410  1.4  christos 		fch(how, &c[2]);
    411  1.4  christos 		break;
    412  1.4  christos 	case 4:
    413  1.4  christos 		lprcat("Your constitution");
    414  1.4  christos 		fch(how, &c[3]);
    415  1.4  christos 		break;
    416  1.4  christos 	case 5:
    417  1.4  christos 		lprcat("Your dexterity");
    418  1.4  christos 		fch(how, &c[4]);
    419  1.4  christos 		break;
    420  1.4  christos 	case 6:
    421  1.4  christos 		lprcat("Your charm");
    422  1.4  christos 		fch(how, &c[5]);
    423  1.4  christos 		break;
    424  1.4  christos 	case 7:
    425  1.4  christos 		j = rnd(level + 1);
    426  1.4  christos 		if (how < 0) {
    427  1.4  christos 			lprintf("You lose %d hit point", (long) j);
    428  1.4  christos 			if (j > 1)
    429  1.4  christos 				lprcat("s!");
    430  1.4  christos 			else
    431  1.4  christos 				lprc('!');
    432  1.4  christos 			losemhp((int) j);
    433  1.4  christos 		} else {
    434  1.4  christos 			lprintf("You gain %d hit point", (long) j);
    435  1.4  christos 			if (j > 1)
    436  1.4  christos 				lprcat("s!");
    437  1.4  christos 			else
    438  1.4  christos 				lprc('!');
    439  1.4  christos 			raisemhp((int) j);
    440  1.4  christos 		}
    441  1.4  christos 		bottomline();
    442  1.4  christos 		break;
    443  1.4  christos 
    444  1.4  christos 	case 8:
    445  1.4  christos 		j = rnd(level + 1);
    446  1.4  christos 		if (how > 0) {
    447  1.4  christos 			lprintf("You just gained %d spell", (long) j);
    448  1.4  christos 			raisemspells((int) j);
    449  1.4  christos 			if (j > 1)
    450  1.4  christos 				lprcat("s!");
    451  1.4  christos 			else
    452  1.4  christos 				lprc('!');
    453  1.4  christos 		} else {
    454  1.4  christos 			lprintf("You just lost %d spell", (long) j);
    455  1.4  christos 			losemspells((int) j);
    456  1.4  christos 			if (j > 1)
    457  1.4  christos 				lprcat("s!");
    458  1.4  christos 			else
    459  1.4  christos 				lprc('!');
    460  1.4  christos 		}
    461  1.4  christos 		bottomline();
    462  1.4  christos 		break;
    463  1.4  christos 
    464  1.4  christos 	case 9:
    465  1.4  christos 		j = 5 * rnd((level + 1) * (level + 1));
    466  1.4  christos 		if (how < 0) {
    467  1.4  christos 			lprintf("You just lost %d experience point", (long) j);
    468  1.4  christos 			if (j > 1)
    469  1.4  christos 				lprcat("s!");
    470  1.4  christos 			else
    471  1.4  christos 				lprc('!');
    472  1.4  christos 			loseexperience((long) j);
    473  1.4  christos 		} else {
    474  1.4  christos 			lprintf("You just gained %d experience point", (long) j);
    475  1.4  christos 			if (j > 1)
    476  1.4  christos 				lprcat("s!");
    477  1.4  christos 			else
    478  1.4  christos 				lprc('!');
    479  1.4  christos 			raiseexperience((long) j);
    480  1.1       cgd 		}
    481  1.4  christos 		break;
    482  1.4  christos 	}
    483  1.1       cgd 	cursors();
    484  1.4  christos }
    485