Home | History | Annotate | Line # | Download | only in larn
global.c revision 1.7
      1  1.7  christos /*	$NetBSD: global.c,v 1.7 2001/02/05 00:57:33 christos Exp $	*/
      2  1.6  christos 
      3  1.6  christos /*
      4  1.6  christos  * global.c 		Larn is copyrighted 1986 by Noah Morgan.
      5  1.6  christos  *
      6  1.6  christos  * raiselevel()		subroutine to raise the player one level
      7  1.6  christos  * loselevel()		subroutine to lower the player by one level
      8  1.6  christos  * raiseexperience(x)	subroutine to increase experience points
      9  1.6  christos  * loseexperience(x)	subroutine to lose experience points
     10  1.6  christos  * losehp(x)		subroutine to remove hit points from the player
     11  1.6  christos  * losemhp(x)		subroutine to remove max # hit points from the player
     12  1.6  christos  * raisehp(x) 		subroutine to gain hit points
     13  1.6  christos  * raisemhp(x)		subroutine to gain maximum hit points
     14  1.6  christos  * losespells(x)	subroutine to lose spells
     15  1.6  christos  * losemspells(x)	subroutine to lose maximum spells
     16  1.6  christos  * raisespells(x)	subroutine to gain spells
     17  1.6  christos  * raisemspells(x)	subroutine to gain maximum spells
     18  1.6  christos  * recalc()		function to recalculate the armor class of the player
     19  1.6  christos  * makemonst(lev)	function to return monster number for a randomly
     20  1.6  christos  *			selected monster
     21  1.6  christos  * positionplayer()	function to be sure player is not in a wall
     22  1.6  christos  * quit()		subroutine to ask if the player really wants to quit
     23  1.6  christos  */
     24  1.6  christos #include <sys/cdefs.h>
     25  1.2   mycroft #ifndef lint
     26  1.7  christos __RCSID("$NetBSD: global.c,v 1.7 2001/02/05 00:57:33 christos Exp $");
     27  1.2   mycroft #endif /* not lint */
     28  1.2   mycroft 
     29  1.6  christos #include <string.h>
     30  1.6  christos #include <unistd.h>
     31  1.1       cgd #include "header.h"
     32  1.6  christos #include "extern.h"
     33  1.7  christos extern int      score[], dropflag;
     34  1.7  christos extern int      random;		/* the random number seed		*/
     35  1.7  christos extern char     *what[], *who[];
     36  1.6  christos extern char     winner[];
     37  1.7  christos extern char     sciv[SCORESIZE + 1][26][2];
     38  1.7  christos extern char    *password;
     39  1.7  christos 
     40  1.1       cgd /*
     41  1.1       cgd 	***********
     42  1.1       cgd 	RAISE LEVEL
     43  1.1       cgd 	***********
     44  1.1       cgd 	raiselevel()
     45  1.1       cgd 
     46  1.1       cgd 	subroutine to raise the player one level
     47  1.1       cgd 	uses the skill[] array to find level boundarys
     48  1.1       cgd 	uses c[EXPERIENCE]  c[LEVEL]
     49  1.1       cgd  */
     50  1.6  christos void
     51  1.1       cgd raiselevel()
     52  1.6  christos {
     53  1.6  christos 	if (c[LEVEL] < MAXPLEVEL)
     54  1.6  christos 		raiseexperience((long) (skill[c[LEVEL]] - c[EXPERIENCE]));
     55  1.6  christos }
     56  1.1       cgd 
     57  1.1       cgd /*
     58  1.1       cgd 	***********
     59  1.1       cgd 	LOOSE LEVEL
     60  1.1       cgd 	***********
     61  1.1       cgd     loselevel()
     62  1.1       cgd 
     63  1.1       cgd 	subroutine to lower the players character level by one
     64  1.1       cgd  */
     65  1.6  christos void
     66  1.1       cgd loselevel()
     67  1.6  christos {
     68  1.6  christos 	if (c[LEVEL] > 1)
     69  1.6  christos 		loseexperience((long) (c[EXPERIENCE] - skill[c[LEVEL] - 1] + 1));
     70  1.6  christos }
     71  1.1       cgd 
     72  1.1       cgd /*
     73  1.1       cgd 	****************
     74  1.1       cgd 	RAISE EXPERIENCE
     75  1.1       cgd 	****************
     76  1.1       cgd 	raiseexperience(x)
     77  1.1       cgd 
     78  1.1       cgd 	subroutine to increase experience points
     79  1.1       cgd  */
     80  1.6  christos void
     81  1.1       cgd raiseexperience(x)
     82  1.6  christos 	long   x;
     83  1.6  christos {
     84  1.6  christos 	int    i, tmp;
     85  1.6  christos 	i = c[LEVEL];
     86  1.6  christos 	c[EXPERIENCE] += x;
     87  1.6  christos 	while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) {
     88  1.6  christos 		tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1;
     89  1.6  christos 		c[LEVEL]++;
     90  1.6  christos 		raisemhp((int) (rnd(3) + rnd((tmp > 0) ? tmp : 1)));
     91  1.6  christos 		raisemspells((int) rund(3));
     92  1.6  christos 		if (c[LEVEL] < 7 - c[HARDGAME])
     93  1.6  christos 			raisemhp((int) (c[CONSTITUTION] >> 2));
     94  1.6  christos 	}
     95  1.6  christos 	if (c[LEVEL] != i) {
     96  1.1       cgd 		cursors();
     97  1.6  christos 		beep();
     98  1.6  christos 		lprintf("\nWelcome to level %d", (long) c[LEVEL]);	/* if we changed levels	 */
     99  1.6  christos 	}
    100  1.1       cgd 	bottomline();
    101  1.6  christos }
    102  1.1       cgd 
    103  1.1       cgd /*
    104  1.1       cgd 	****************
    105  1.1       cgd 	LOOSE EXPERIENCE
    106  1.1       cgd 	****************
    107  1.1       cgd 	loseexperience(x)
    108  1.1       cgd 
    109  1.1       cgd 	subroutine to lose experience points
    110  1.1       cgd  */
    111  1.6  christos void
    112  1.1       cgd loseexperience(x)
    113  1.6  christos 	long   x;
    114  1.6  christos {
    115  1.6  christos 	int    i, tmp;
    116  1.6  christos 	i = c[LEVEL];
    117  1.6  christos 	c[EXPERIENCE] -= x;
    118  1.6  christos 	if (c[EXPERIENCE] < 0)
    119  1.6  christos 		c[EXPERIENCE] = 0;
    120  1.6  christos 	while (c[EXPERIENCE] < skill[c[LEVEL] - 1]) {
    121  1.6  christos 		if (--c[LEVEL] <= 1)
    122  1.6  christos 			c[LEVEL] = 1;	/* down one level		 */
    123  1.6  christos 		tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1;	/* lose hpoints */
    124  1.6  christos 		losemhp((int) rnd((tmp > 0) ? tmp : 1));	/* lose hpoints */
    125  1.6  christos 		if (c[LEVEL] < 7 - c[HARDGAME])
    126  1.6  christos 			losemhp((int) (c[CONSTITUTION] >> 2));
    127  1.6  christos 		losemspells((int) rund(3));	/* lose spells		 */
    128  1.6  christos 	}
    129  1.6  christos 	if (i != c[LEVEL]) {
    130  1.1       cgd 		cursors();
    131  1.6  christos 		beep();
    132  1.6  christos 		lprintf("\nYou went down to level %d!", (long) c[LEVEL]);
    133  1.6  christos 	}
    134  1.1       cgd 	bottomline();
    135  1.6  christos }
    136  1.1       cgd 
    137  1.1       cgd /*
    138  1.1       cgd 	********
    139  1.1       cgd 	LOOSE HP
    140  1.1       cgd 	********
    141  1.1       cgd 	losehp(x)
    142  1.1       cgd 	losemhp(x)
    143  1.1       cgd 
    144  1.1       cgd 	subroutine to remove hit points from the player
    145  1.1       cgd 	warning -- will kill player if hp goes to zero
    146  1.1       cgd  */
    147  1.6  christos void
    148  1.1       cgd losehp(x)
    149  1.6  christos 	int    x;
    150  1.6  christos {
    151  1.6  christos 	if ((c[HP] -= x) <= 0) {
    152  1.6  christos 		beep();
    153  1.6  christos 		lprcat("\n");
    154  1.6  christos 		nap(3000);
    155  1.6  christos 		died(lastnum);
    156  1.1       cgd 	}
    157  1.6  christos }
    158  1.1       cgd 
    159  1.6  christos void
    160  1.1       cgd losemhp(x)
    161  1.6  christos 	int    x;
    162  1.6  christos {
    163  1.6  christos 	c[HP] -= x;
    164  1.6  christos 	if (c[HP] < 1)
    165  1.6  christos 		c[HP] = 1;
    166  1.6  christos 	c[HPMAX] -= x;
    167  1.6  christos 	if (c[HPMAX] < 1)
    168  1.6  christos 		c[HPMAX] = 1;
    169  1.6  christos }
    170  1.1       cgd 
    171  1.1       cgd /*
    172  1.1       cgd 	********
    173  1.1       cgd 	RAISE HP
    174  1.1       cgd 	********
    175  1.1       cgd 	raisehp(x)
    176  1.1       cgd 	raisemhp(x)
    177  1.1       cgd 
    178  1.1       cgd 	subroutine to gain maximum hit points
    179  1.1       cgd  */
    180  1.6  christos void
    181  1.1       cgd raisehp(x)
    182  1.6  christos 	int    x;
    183  1.6  christos {
    184  1.6  christos 	if ((c[HP] += x) > c[HPMAX])
    185  1.6  christos 		c[HP] = c[HPMAX];
    186  1.6  christos }
    187  1.1       cgd 
    188  1.6  christos void
    189  1.1       cgd raisemhp(x)
    190  1.6  christos 	int    x;
    191  1.6  christos {
    192  1.6  christos 	c[HPMAX] += x;
    193  1.6  christos 	c[HP] += x;
    194  1.6  christos }
    195  1.1       cgd 
    196  1.1       cgd /*
    197  1.1       cgd 	************
    198  1.1       cgd 	RAISE SPELLS
    199  1.1       cgd 	************
    200  1.1       cgd 	raisespells(x)
    201  1.1       cgd 	raisemspells(x)
    202  1.1       cgd 
    203  1.1       cgd 	subroutine to gain maximum spells
    204  1.1       cgd  */
    205  1.6  christos void
    206  1.1       cgd raisespells(x)
    207  1.6  christos 	int    x;
    208  1.6  christos {
    209  1.6  christos 	if ((c[SPELLS] += x) > c[SPELLMAX])
    210  1.6  christos 		c[SPELLS] = c[SPELLMAX];
    211  1.6  christos }
    212  1.1       cgd 
    213  1.6  christos void
    214  1.1       cgd raisemspells(x)
    215  1.6  christos 	int    x;
    216  1.6  christos {
    217  1.6  christos 	c[SPELLMAX] += x;
    218  1.6  christos 	c[SPELLS] += x;
    219  1.6  christos }
    220  1.1       cgd 
    221  1.1       cgd /*
    222  1.1       cgd 	************
    223  1.1       cgd 	LOOSE SPELLS
    224  1.1       cgd 	************
    225  1.1       cgd 	losespells(x)
    226  1.1       cgd 	losemspells(x)
    227  1.1       cgd 
    228  1.1       cgd 	subroutine to lose maximum spells
    229  1.1       cgd  */
    230  1.6  christos void
    231  1.1       cgd losespells(x)
    232  1.6  christos 	int    x;
    233  1.6  christos {
    234  1.6  christos 	if ((c[SPELLS] -= x) < 0)
    235  1.6  christos 		c[SPELLS] = 0;
    236  1.6  christos }
    237  1.1       cgd 
    238  1.6  christos void
    239  1.1       cgd losemspells(x)
    240  1.6  christos 	int    x;
    241  1.6  christos {
    242  1.6  christos 	if ((c[SPELLMAX] -= x) < 0)
    243  1.6  christos 		c[SPELLMAX] = 0;
    244  1.6  christos 	if ((c[SPELLS] -= x) < 0)
    245  1.6  christos 		c[SPELLS] = 0;
    246  1.6  christos }
    247  1.1       cgd 
    248  1.1       cgd /*
    249  1.1       cgd 	makemonst(lev)
    250  1.1       cgd 		int lev;
    251  1.1       cgd 
    252  1.1       cgd 	function to return monster number for a randomly selected monster
    253  1.6  christos 		for the given cave level
    254  1.1       cgd  */
    255  1.6  christos int
    256  1.1       cgd makemonst(lev)
    257  1.6  christos 	int    lev;
    258  1.6  christos {
    259  1.6  christos 	int    tmp, x;
    260  1.6  christos 	if (lev < 1)
    261  1.6  christos 		lev = 1;
    262  1.6  christos 	if (lev > 12)
    263  1.6  christos 		lev = 12;
    264  1.6  christos 	tmp = WATERLORD;
    265  1.1       cgd 	if (lev < 5)
    266  1.6  christos 		while (tmp == WATERLORD)
    267  1.6  christos 			tmp = rnd((x = monstlevel[lev - 1]) ? x : 1);
    268  1.6  christos 	else
    269  1.6  christos 		while (tmp == WATERLORD)
    270  1.6  christos 			tmp = rnd((x = monstlevel[lev - 1] - monstlevel[lev - 4]) ? x : 1) + monstlevel[lev - 4];
    271  1.6  christos 
    272  1.6  christos 	while (monster[tmp].genocided && tmp < MAXMONST)
    273  1.6  christos 		tmp++;		/* genocided? */
    274  1.6  christos 	return (tmp);
    275  1.6  christos }
    276  1.1       cgd 
    277  1.1       cgd /*
    278  1.1       cgd 	positionplayer()
    279  1.1       cgd 
    280  1.1       cgd 	function to be sure player is not in a wall
    281  1.1       cgd  */
    282  1.6  christos void
    283  1.1       cgd positionplayer()
    284  1.6  christos {
    285  1.6  christos 	int             try;
    286  1.1       cgd 	try = 2;
    287  1.1       cgd 	while ((item[playerx][playery] || mitem[playerx][playery]) && (try))
    288  1.6  christos 		if (++playerx >= MAXX - 1) {
    289  1.1       cgd 			playerx = 1;
    290  1.6  christos 			if (++playery >= MAXY - 1) {
    291  1.6  christos 				playery = 1;
    292  1.6  christos 				--try;
    293  1.1       cgd 			}
    294  1.6  christos 		}
    295  1.6  christos 	if (try == 0)
    296  1.6  christos 		lprcat("Failure in positionplayer\n");
    297  1.6  christos }
    298  1.1       cgd 
    299  1.1       cgd /*
    300  1.1       cgd 	recalc()	function to recalculate the armor class of the player
    301  1.1       cgd  */
    302  1.6  christos void
    303  1.1       cgd recalc()
    304  1.6  christos {
    305  1.6  christos 	int    i, j, k;
    306  1.1       cgd 	c[AC] = c[MOREDEFENSES];
    307  1.6  christos 	if (c[WEAR] >= 0)
    308  1.6  christos 		switch (iven[c[WEAR]]) {
    309  1.6  christos 		case OSHIELD:
    310  1.6  christos 			c[AC] += 2 + ivenarg[c[WEAR]];
    311  1.6  christos 			break;
    312  1.6  christos 		case OLEATHER:
    313  1.6  christos 			c[AC] += 2 + ivenarg[c[WEAR]];
    314  1.6  christos 			break;
    315  1.6  christos 		case OSTUDLEATHER:
    316  1.6  christos 			c[AC] += 3 + ivenarg[c[WEAR]];
    317  1.6  christos 			break;
    318  1.6  christos 		case ORING:
    319  1.6  christos 			c[AC] += 5 + ivenarg[c[WEAR]];
    320  1.6  christos 			break;
    321  1.6  christos 		case OCHAIN:
    322  1.6  christos 			c[AC] += 6 + ivenarg[c[WEAR]];
    323  1.6  christos 			break;
    324  1.6  christos 		case OSPLINT:
    325  1.6  christos 			c[AC] += 7 + ivenarg[c[WEAR]];
    326  1.6  christos 			break;
    327  1.6  christos 		case OPLATE:
    328  1.6  christos 			c[AC] += 9 + ivenarg[c[WEAR]];
    329  1.6  christos 			break;
    330  1.6  christos 		case OPLATEARMOR:
    331  1.6  christos 			c[AC] += 10 + ivenarg[c[WEAR]];
    332  1.6  christos 			break;
    333  1.6  christos 		case OSSPLATE:
    334  1.6  christos 			c[AC] += 12 + ivenarg[c[WEAR]];
    335  1.6  christos 			break;
    336  1.6  christos 		}
    337  1.1       cgd 
    338  1.6  christos 	if (c[SHIELD] >= 0)
    339  1.6  christos 		if (iven[c[SHIELD]] == OSHIELD)
    340  1.6  christos 			c[AC] += 2 + ivenarg[c[SHIELD]];
    341  1.6  christos 	if (c[WIELD] < 0)
    342  1.6  christos 		c[WCLASS] = 0;
    343  1.6  christos 	else {
    344  1.1       cgd 		i = ivenarg[c[WIELD]];
    345  1.6  christos 		switch (iven[c[WIELD]]) {
    346  1.6  christos 		case ODAGGER:
    347  1.6  christos 			c[WCLASS] = 3 + i;
    348  1.6  christos 			break;
    349  1.6  christos 		case OBELT:
    350  1.6  christos 			c[WCLASS] = 7 + i;
    351  1.6  christos 			break;
    352  1.6  christos 		case OSHIELD:
    353  1.6  christos 			c[WCLASS] = 8 + i;
    354  1.6  christos 			break;
    355  1.6  christos 		case OSPEAR:
    356  1.6  christos 			c[WCLASS] = 10 + i;
    357  1.6  christos 			break;
    358  1.6  christos 		case OFLAIL:
    359  1.6  christos 			c[WCLASS] = 14 + i;
    360  1.6  christos 			break;
    361  1.6  christos 		case OBATTLEAXE:
    362  1.6  christos 			c[WCLASS] = 17 + i;
    363  1.6  christos 			break;
    364  1.6  christos 		case OLANCE:
    365  1.6  christos 			c[WCLASS] = 19 + i;
    366  1.6  christos 			break;
    367  1.6  christos 		case OLONGSWORD:
    368  1.6  christos 			c[WCLASS] = 22 + i;
    369  1.6  christos 			break;
    370  1.6  christos 		case O2SWORD:
    371  1.6  christos 			c[WCLASS] = 26 + i;
    372  1.6  christos 			break;
    373  1.6  christos 		case OSWORD:
    374  1.6  christos 			c[WCLASS] = 32 + i;
    375  1.6  christos 			break;
    376  1.6  christos 		case OSWORDofSLASHING:
    377  1.6  christos 			c[WCLASS] = 30 + i;
    378  1.6  christos 			break;
    379  1.6  christos 		case OHAMMER:
    380  1.6  christos 			c[WCLASS] = 35 + i;
    381  1.6  christos 			break;
    382  1.6  christos 		default:
    383  1.6  christos 			c[WCLASS] = 0;
    384  1.1       cgd 		}
    385  1.6  christos 	}
    386  1.1       cgd 	c[WCLASS] += c[MOREDAM];
    387  1.1       cgd 
    388  1.6  christos 	/* now for regeneration abilities based on rings	 */
    389  1.6  christos 	c[REGEN] = 1;
    390  1.6  christos 	c[ENERGY] = 0;
    391  1.6  christos 	j = 0;
    392  1.6  christos 	for (k = 25; k > 0; k--)
    393  1.6  christos 		if (iven[k]) {
    394  1.6  christos 			j = k;
    395  1.6  christos 			k = 0;
    396  1.6  christos 		}
    397  1.6  christos 	for (i = 0; i <= j; i++) {
    398  1.6  christos 		switch (iven[i]) {
    399  1.6  christos 		case OPROTRING:
    400  1.6  christos 			c[AC] += ivenarg[i] + 1;
    401  1.6  christos 			break;
    402  1.6  christos 		case ODAMRING:
    403  1.6  christos 			c[WCLASS] += ivenarg[i] + 1;
    404  1.6  christos 			break;
    405  1.6  christos 		case OBELT:
    406  1.6  christos 			c[WCLASS] += ((ivenarg[i] << 1)) + 2;
    407  1.6  christos 			break;
    408  1.6  christos 
    409  1.6  christos 		case OREGENRING:
    410  1.6  christos 			c[REGEN] += ivenarg[i] + 1;
    411  1.6  christos 			break;
    412  1.6  christos 		case ORINGOFEXTRA:
    413  1.6  christos 			c[REGEN] += 5 * (ivenarg[i] + 1);
    414  1.6  christos 			break;
    415  1.6  christos 		case OENERGYRING:
    416  1.6  christos 			c[ENERGY] += ivenarg[i] + 1;
    417  1.6  christos 			break;
    418  1.1       cgd 		}
    419  1.1       cgd 	}
    420  1.6  christos }
    421  1.1       cgd 
    422  1.1       cgd 
    423  1.1       cgd /*
    424  1.1       cgd 	quit()
    425  1.1       cgd 
    426  1.1       cgd 	subroutine to ask if the player really wants to quit
    427  1.1       cgd  */
    428  1.6  christos void
    429  1.1       cgd quit()
    430  1.6  christos {
    431  1.6  christos 	int    i;
    432  1.6  christos 	cursors();
    433  1.6  christos 	strcpy(lastmonst, "");
    434  1.1       cgd 	lprcat("\n\nDo you really want to quit?");
    435  1.6  christos 	while (1) {
    436  1.7  christos 		i = lgetchar();
    437  1.6  christos 		if (i == 'y') {
    438  1.6  christos 			died(300);
    439  1.6  christos 			return;
    440  1.6  christos 		}
    441  1.6  christos 		if ((i == 'n') || (i == '\33')) {
    442  1.6  christos 			lprcat(" no");
    443  1.6  christos 			lflush();
    444  1.6  christos 			return;
    445  1.6  christos 		}
    446  1.6  christos 		lprcat("\n");
    447  1.6  christos 		setbold();
    448  1.6  christos 		lprcat("Yes");
    449  1.6  christos 		resetbold();
    450  1.6  christos 		lprcat(" or ");
    451  1.6  christos 		setbold();
    452  1.6  christos 		lprcat("No");
    453  1.6  christos 		resetbold();
    454  1.6  christos 		lprcat(" please?   Do you want to quit? ");
    455  1.1       cgd 	}
    456  1.6  christos }
    457  1.1       cgd 
    458  1.1       cgd /*
    459  1.1       cgd 	function to ask --more-- then the user must enter a space
    460  1.1       cgd  */
    461  1.6  christos void
    462  1.1       cgd more()
    463  1.6  christos {
    464  1.6  christos 	lprcat("\n  --- press ");
    465  1.6  christos 	standout("space");
    466  1.6  christos 	lprcat(" to continue --- ");
    467  1.7  christos 	while (lgetchar() != ' ');
    468  1.6  christos }
    469  1.1       cgd 
    470  1.1       cgd /*
    471  1.1       cgd 	function to put something in the players inventory
    472  1.1       cgd 	returns 0 if success, 1 if a failure
    473  1.1       cgd  */
    474  1.6  christos int
    475  1.6  christos take(itm, arg)
    476  1.6  christos 	int             itm, arg;
    477  1.6  christos {
    478  1.6  christos 	int    i, limit;
    479  1.6  christos 	/* cursors(); */
    480  1.6  christos 	if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
    481  1.6  christos 		limit = 26;
    482  1.6  christos 	for (i = 0; i < limit; i++)
    483  1.6  christos 		if (iven[i] == 0) {
    484  1.6  christos 			iven[i] = itm;
    485  1.6  christos 			ivenarg[i] = arg;
    486  1.6  christos 			limit = 0;
    487  1.6  christos 			switch (itm) {
    488  1.6  christos 			case OPROTRING:
    489  1.6  christos 			case ODAMRING:
    490  1.6  christos 			case OBELT:
    491  1.6  christos 				limit = 1;
    492  1.6  christos 				break;
    493  1.6  christos 			case ODEXRING:
    494  1.6  christos 				c[DEXTERITY] += ivenarg[i] + 1;
    495  1.6  christos 				limit = 1;
    496  1.6  christos 				break;
    497  1.6  christos 			case OSTRRING:
    498  1.6  christos 				c[STREXTRA] += ivenarg[i] + 1;
    499  1.6  christos 				limit = 1;
    500  1.6  christos 				break;
    501  1.6  christos 			case OCLEVERRING:
    502  1.6  christos 				c[INTELLIGENCE] += ivenarg[i] + 1;
    503  1.6  christos 				limit = 1;
    504  1.6  christos 				break;
    505  1.6  christos 			case OHAMMER:
    506  1.6  christos 				c[DEXTERITY] += 10;
    507  1.6  christos 				c[STREXTRA] += 10;
    508  1.6  christos 				c[INTELLIGENCE] -= 10;
    509  1.6  christos 				limit = 1;
    510  1.6  christos 				break;
    511  1.6  christos 
    512  1.6  christos 			case OORBOFDRAGON:
    513  1.6  christos 				c[SLAYING]++;
    514  1.6  christos 				break;
    515  1.6  christos 			case OSPIRITSCARAB:
    516  1.6  christos 				c[NEGATESPIRIT]++;
    517  1.6  christos 				break;
    518  1.6  christos 			case OCUBEofUNDEAD:
    519  1.6  christos 				c[CUBEofUNDEAD]++;
    520  1.6  christos 				break;
    521  1.6  christos 			case ONOTHEFT:
    522  1.6  christos 				c[NOTHEFT]++;
    523  1.6  christos 				break;
    524  1.6  christos 			case OSWORDofSLASHING:
    525  1.6  christos 				c[DEXTERITY] += 5;
    526  1.6  christos 				limit = 1;
    527  1.6  christos 				break;
    528  1.6  christos 			};
    529  1.6  christos 			lprcat("\nYou pick up:");
    530  1.6  christos 			srcount = 0;
    531  1.6  christos 			show3(i);
    532  1.6  christos 			if (limit)
    533  1.6  christos 				bottomline();
    534  1.6  christos 			return (0);
    535  1.6  christos 		}
    536  1.6  christos 	lprcat("\nYou can't carry anything else");
    537  1.6  christos 	return (1);
    538  1.6  christos }
    539  1.1       cgd 
    540  1.1       cgd /*
    541  1.6  christos 	subroutine to drop an object
    542  1.6  christos 	returns 1 if something there already else 0
    543  1.1       cgd  */
    544  1.6  christos int
    545  1.1       cgd drop_object(k)
    546  1.6  christos 	int             k;
    547  1.6  christos {
    548  1.6  christos 	int             itm;
    549  1.6  christos 	if ((k < 0) || (k > 25))
    550  1.6  christos 		return (0);
    551  1.6  christos 	itm = iven[k];
    552  1.6  christos 	cursors();
    553  1.6  christos 	if (itm == 0) {
    554  1.6  christos 		lprintf("\nYou don't have item %c! ", k + 'a');
    555  1.6  christos 		return (1);
    556  1.6  christos 	}
    557  1.6  christos 	if (item[playerx][playery]) {
    558  1.6  christos 		beep();
    559  1.6  christos 		lprcat("\nThere's something here already");
    560  1.6  christos 		return (1);
    561  1.6  christos 	}
    562  1.6  christos 	if (playery == MAXY - 1 && playerx == 33)
    563  1.6  christos 		return (1);	/* not in entrance */
    564  1.1       cgd 	item[playerx][playery] = itm;
    565  1.1       cgd 	iarg[playerx][playery] = ivenarg[k];
    566  1.6  christos 	srcount = 0;
    567  1.6  christos 	lprcat("\n  You drop:");
    568  1.6  christos 	show3(k);		/* show what item you dropped */
    569  1.6  christos 	know[playerx][playery] = 0;
    570  1.6  christos 	iven[k] = 0;
    571  1.6  christos 	if (c[WIELD] == k)
    572  1.6  christos 		c[WIELD] = -1;
    573  1.6  christos 	if (c[WEAR] == k)
    574  1.6  christos 		c[WEAR] = -1;
    575  1.6  christos 	if (c[SHIELD] == k)
    576  1.6  christos 		c[SHIELD] = -1;
    577  1.6  christos 	adjustcvalues(itm, ivenarg[k]);
    578  1.6  christos 	dropflag = 1;		/* say dropped an item so wont ask to pick it
    579  1.6  christos 				 * up right away */
    580  1.6  christos 	return (0);
    581  1.6  christos }
    582  1.1       cgd 
    583  1.1       cgd /*
    584  1.1       cgd 	function to enchant armor player is currently wearing
    585  1.1       cgd  */
    586  1.6  christos void
    587  1.1       cgd enchantarmor()
    588  1.6  christos {
    589  1.6  christos 	int    tmp;
    590  1.6  christos 	if (c[WEAR] < 0) {
    591  1.6  christos 		if (c[SHIELD] < 0) {
    592  1.6  christos 			cursors();
    593  1.6  christos 			beep();
    594  1.6  christos 			lprcat("\nYou feel a sense of loss");
    595  1.6  christos 			return;
    596  1.6  christos 		} else {
    597  1.6  christos 			tmp = iven[c[SHIELD]];
    598  1.6  christos 			if (tmp != OSCROLL)
    599  1.6  christos 				if (tmp != OPOTION) {
    600  1.6  christos 					ivenarg[c[SHIELD]]++;
    601  1.6  christos 					bottomline();
    602  1.6  christos 				}
    603  1.6  christos 		}
    604  1.6  christos 	}
    605  1.1       cgd 	tmp = iven[c[WEAR]];
    606  1.6  christos 	if (tmp != OSCROLL)
    607  1.6  christos 		if (tmp != OPOTION) {
    608  1.6  christos 			ivenarg[c[WEAR]]++;
    609  1.6  christos 			bottomline();
    610  1.6  christos 		}
    611  1.6  christos }
    612  1.1       cgd 
    613  1.1       cgd /*
    614  1.1       cgd 	function to enchant a weapon presently being wielded
    615  1.1       cgd  */
    616  1.6  christos void
    617  1.1       cgd enchweapon()
    618  1.6  christos {
    619  1.6  christos 	int    tmp;
    620  1.6  christos 	if (c[WIELD] < 0) {
    621  1.6  christos 		cursors();
    622  1.6  christos 		beep();
    623  1.6  christos 		lprcat("\nYou feel a sense of loss");
    624  1.6  christos 		return;
    625  1.6  christos 	}
    626  1.1       cgd 	tmp = iven[c[WIELD]];
    627  1.6  christos 	if (tmp != OSCROLL)
    628  1.6  christos 		if (tmp != OPOTION) {
    629  1.6  christos 			ivenarg[c[WIELD]]++;
    630  1.6  christos 			if (tmp == OCLEVERRING)
    631  1.6  christos 				c[INTELLIGENCE]++;
    632  1.6  christos 			else if (tmp == OSTRRING)
    633  1.6  christos 				c[STREXTRA]++;
    634  1.6  christos 			else if (tmp == ODEXRING)
    635  1.6  christos 				c[DEXTERITY]++;
    636  1.6  christos 			bottomline();
    637  1.6  christos 		}
    638  1.6  christos }
    639  1.1       cgd 
    640  1.1       cgd /*
    641  1.1       cgd 	routine to tell if player can carry one more thing
    642  1.1       cgd 	returns 1 if pockets are full, else 0
    643  1.1       cgd  */
    644  1.6  christos int
    645  1.1       cgd pocketfull()
    646  1.6  christos {
    647  1.6  christos 	int    i, limit;
    648  1.6  christos 	if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
    649  1.6  christos 		limit = 26;
    650  1.6  christos 	for (i = 0; i < limit; i++)
    651  1.6  christos 		if (iven[i] == 0)
    652  1.6  christos 			return (0);
    653  1.6  christos 	return (1);
    654  1.6  christos }
    655  1.1       cgd 
    656  1.1       cgd /*
    657  1.1       cgd 	function to return 1 if a monster is next to the player else returns 0
    658  1.1       cgd  */
    659  1.6  christos int
    660  1.1       cgd nearbymonst()
    661  1.6  christos {
    662  1.6  christos 	int    tmp, tmp2;
    663  1.6  christos 	for (tmp = playerx - 1; tmp < playerx + 2; tmp++)
    664  1.6  christos 		for (tmp2 = playery - 1; tmp2 < playery + 2; tmp2++)
    665  1.6  christos 			if (mitem[tmp][tmp2])
    666  1.6  christos 				return (1);	/* if monster nearby */
    667  1.6  christos 	return (0);
    668  1.6  christos }
    669  1.1       cgd 
    670  1.1       cgd /*
    671  1.1       cgd 	function to steal an item from the players pockets
    672  1.1       cgd 	returns 1 if steals something else returns 0
    673  1.1       cgd  */
    674  1.6  christos int
    675  1.1       cgd stealsomething()
    676  1.6  christos {
    677  1.6  christos 	int    i, j;
    678  1.6  christos 	j = 100;
    679  1.6  christos 	while (1) {
    680  1.6  christos 		i = rund(26);
    681  1.6  christos 		if (iven[i])
    682  1.6  christos 			if (c[WEAR] != i)
    683  1.6  christos 				if (c[WIELD] != i)
    684  1.6  christos 					if (c[SHIELD] != i) {
    685  1.6  christos 						srcount = 0;
    686  1.6  christos 						show3(i);
    687  1.6  christos 						adjustcvalues(iven[i], ivenarg[i]);
    688  1.6  christos 						iven[i] = 0;
    689  1.6  christos 						return (1);
    690  1.6  christos 					}
    691  1.6  christos 		if (--j <= 0)
    692  1.6  christos 			return (0);
    693  1.1       cgd 	}
    694  1.6  christos }
    695  1.1       cgd 
    696  1.1       cgd /*
    697  1.1       cgd 	function to return 1 is player carrys nothing else return 0
    698  1.1       cgd  */
    699  1.6  christos int
    700  1.1       cgd emptyhanded()
    701  1.6  christos {
    702  1.6  christos 	int    i;
    703  1.6  christos 	for (i = 0; i < 26; i++)
    704  1.6  christos 		if (iven[i])
    705  1.6  christos 			if (i != c[WIELD])
    706  1.6  christos 				if (i != c[WEAR])
    707  1.6  christos 					if (i != c[SHIELD])
    708  1.6  christos 						return (0);
    709  1.6  christos 	return (1);
    710  1.6  christos }
    711  1.1       cgd 
    712  1.1       cgd /*
    713  1.1       cgd 	function to create a gem on a square near the player
    714  1.1       cgd  */
    715  1.6  christos void
    716  1.1       cgd creategem()
    717  1.6  christos {
    718  1.6  christos 	int    i, j;
    719  1.6  christos 	switch (rnd(4)) {
    720  1.6  christos 	case 1:
    721  1.6  christos 		i = ODIAMOND;
    722  1.6  christos 		j = 50;
    723  1.6  christos 		break;
    724  1.6  christos 	case 2:
    725  1.6  christos 		i = ORUBY;
    726  1.6  christos 		j = 40;
    727  1.6  christos 		break;
    728  1.6  christos 	case 3:
    729  1.6  christos 		i = OEMERALD;
    730  1.6  christos 		j = 30;
    731  1.6  christos 		break;
    732  1.6  christos 	default:
    733  1.6  christos 		i = OSAPPHIRE;
    734  1.6  christos 		j = 20;
    735  1.6  christos 		break;
    736  1.6  christos 	};
    737  1.6  christos 	createitem(i, rnd(j) + j / 10);
    738  1.6  christos }
    739  1.1       cgd 
    740  1.1       cgd /*
    741  1.1       cgd 	function to change character levels as needed when dropping an object
    742  1.1       cgd 	that affects these characteristics
    743  1.1       cgd  */
    744  1.6  christos void
    745  1.6  christos adjustcvalues(itm, arg)
    746  1.6  christos 	int             itm, arg;
    747  1.6  christos {
    748  1.6  christos 	int    flag;
    749  1.6  christos 	flag = 0;
    750  1.6  christos 	switch (itm) {
    751  1.6  christos 	case ODEXRING:
    752  1.6  christos 		c[DEXTERITY] -= arg + 1;
    753  1.6  christos 		flag = 1;
    754  1.6  christos 		break;
    755  1.6  christos 	case OSTRRING:
    756  1.6  christos 		c[STREXTRA] -= arg + 1;
    757  1.6  christos 		flag = 1;
    758  1.6  christos 		break;
    759  1.6  christos 	case OCLEVERRING:
    760  1.6  christos 		c[INTELLIGENCE] -= arg + 1;
    761  1.6  christos 		flag = 1;
    762  1.6  christos 		break;
    763  1.6  christos 	case OHAMMER:
    764  1.6  christos 		c[DEXTERITY] -= 10;
    765  1.6  christos 		c[STREXTRA] -= 10;
    766  1.6  christos 		c[INTELLIGENCE] += 10;
    767  1.6  christos 		flag = 1;
    768  1.6  christos 		break;
    769  1.6  christos 	case OSWORDofSLASHING:
    770  1.6  christos 		c[DEXTERITY] -= 5;
    771  1.6  christos 		flag = 1;
    772  1.6  christos 		break;
    773  1.6  christos 	case OORBOFDRAGON:
    774  1.6  christos 		--c[SLAYING];
    775  1.6  christos 		return;
    776  1.6  christos 	case OSPIRITSCARAB:
    777  1.6  christos 		--c[NEGATESPIRIT];
    778  1.6  christos 		return;
    779  1.6  christos 	case OCUBEofUNDEAD:
    780  1.6  christos 		--c[CUBEofUNDEAD];
    781  1.6  christos 		return;
    782  1.6  christos 	case ONOTHEFT:
    783  1.6  christos 		--c[NOTHEFT];
    784  1.6  christos 		return;
    785  1.6  christos 	case OLANCE:
    786  1.6  christos 		c[LANCEDEATH] = 0;
    787  1.6  christos 		return;
    788  1.6  christos 	case OPOTION:
    789  1.6  christos 	case OSCROLL:
    790  1.6  christos 		return;
    791  1.6  christos 
    792  1.6  christos 	default:
    793  1.6  christos 		flag = 1;
    794  1.6  christos 	};
    795  1.6  christos 	if (flag)
    796  1.6  christos 		bottomline();
    797  1.6  christos }
    798  1.1       cgd 
    799  1.1       cgd /*
    800  1.1       cgd 	function to read a string from token input "string"
    801  1.1       cgd 	returns a pointer to the string
    802  1.1       cgd  */
    803  1.6  christos void
    804  1.1       cgd gettokstr(str)
    805  1.6  christos 	char  *str;
    806  1.6  christos {
    807  1.6  christos 	int    i, j;
    808  1.6  christos 	i = 50;
    809  1.7  christos 	while ((lgetchar() != '"') && (--i > 0));
    810  1.6  christos 	i = 36;
    811  1.6  christos 	while (--i > 0) {
    812  1.7  christos 		if ((j = lgetchar()) != '"')
    813  1.6  christos 			*str++ = j;
    814  1.6  christos 		else
    815  1.6  christos 			i = 0;
    816  1.6  christos 	}
    817  1.1       cgd 	*str = 0;
    818  1.6  christos 	i = 50;
    819  1.6  christos 	if (j != '"')
    820  1.6  christos 		/* if end due to too long, then find closing quote */
    821  1.7  christos 		while ((lgetchar() != '"') && (--i > 0));
    822  1.6  christos }
    823  1.1       cgd 
    824  1.1       cgd /*
    825  1.1       cgd 	function to ask user for a password (no echo)
    826  1.1       cgd 	returns 1 if entered correctly, 0 if not
    827  1.1       cgd  */
    828  1.6  christos static char     gpwbuf[33];
    829  1.6  christos int
    830  1.1       cgd getpassword()
    831  1.6  christos {
    832  1.6  christos 	int    i, j;
    833  1.6  christos 	char  *gpwp;
    834  1.6  christos 	scbr();			/* system("stty -echo cbreak"); */
    835  1.6  christos 	gpwp = gpwbuf;
    836  1.6  christos 	lprcat("\nEnter Password: ");
    837  1.6  christos 	lflush();
    838  1.1       cgd 	i = strlen(password);
    839  1.6  christos 	for (j = 0; j < i; j++)
    840  1.6  christos 		read(0, gpwp++, 1);
    841  1.6  christos 	gpwbuf[i] = 0;
    842  1.6  christos 	sncbr();		/* system("stty echo -cbreak"); */
    843  1.6  christos 	if (strcmp(gpwbuf, password) != 0) {
    844  1.6  christos 		lprcat("\nSorry\n");
    845  1.6  christos 		lflush();
    846  1.6  christos 		return (0);
    847  1.6  christos 	} else
    848  1.6  christos 		return (1);
    849  1.6  christos }
    850  1.1       cgd 
    851  1.1       cgd /*
    852  1.1       cgd 	subroutine to get a yes or no response from the user
    853  1.1       cgd 	returns y or n
    854  1.1       cgd  */
    855  1.6  christos int
    856  1.1       cgd getyn()
    857  1.6  christos {
    858  1.6  christos 	int    i;
    859  1.6  christos 	i = 0;
    860  1.6  christos 	while (i != 'y' && i != 'n' && i != '\33')
    861  1.7  christos 		i = lgetchar();
    862  1.6  christos 	return (i);
    863  1.6  christos }
    864  1.1       cgd 
    865  1.1       cgd /*
    866  1.1       cgd 	function to calculate the pack weight of the player
    867  1.1       cgd 	returns the number of pounds the player is carrying
    868  1.1       cgd  */
    869  1.6  christos int
    870  1.1       cgd packweight()
    871  1.6  christos {
    872  1.6  christos 	int    i, j, k;
    873  1.6  christos 	k = c[GOLD] / 1000;
    874  1.6  christos 	j = 25;
    875  1.6  christos 	while ((iven[j] == 0) && (j > 0))
    876  1.6  christos 		--j;
    877  1.6  christos 	for (i = 0; i <= j; i++)
    878  1.6  christos 		switch (iven[i]) {
    879  1.6  christos 		case 0:
    880  1.6  christos 			break;
    881  1.6  christos 		case OSSPLATE:
    882  1.6  christos 		case OPLATEARMOR:
    883  1.6  christos 			k += 40;
    884  1.6  christos 			break;
    885  1.6  christos 		case OPLATE:
    886  1.6  christos 			k += 35;
    887  1.6  christos 			break;
    888  1.6  christos 		case OHAMMER:
    889  1.6  christos 			k += 30;
    890  1.6  christos 			break;
    891  1.6  christos 		case OSPLINT:
    892  1.6  christos 			k += 26;
    893  1.6  christos 			break;
    894  1.6  christos 		case OSWORDofSLASHING:
    895  1.6  christos 		case OCHAIN:
    896  1.6  christos 		case OBATTLEAXE:
    897  1.6  christos 		case O2SWORD:
    898  1.6  christos 			k += 23;
    899  1.6  christos 			break;
    900  1.6  christos 		case OLONGSWORD:
    901  1.6  christos 		case OSWORD:
    902  1.6  christos 		case ORING:
    903  1.6  christos 		case OFLAIL:
    904  1.6  christos 			k += 20;
    905  1.6  christos 			break;
    906  1.6  christos 		case OLANCE:
    907  1.6  christos 		case OSTUDLEATHER:
    908  1.6  christos 			k += 15;
    909  1.6  christos 			break;
    910  1.6  christos 		case OLEATHER:
    911  1.6  christos 		case OSPEAR:
    912  1.6  christos 			k += 8;
    913  1.6  christos 			break;
    914  1.6  christos 		case OORBOFDRAGON:
    915  1.6  christos 		case OBELT:
    916  1.6  christos 			k += 4;
    917  1.6  christos 			break;
    918  1.6  christos 		case OSHIELD:
    919  1.6  christos 			k += 7;
    920  1.6  christos 			break;
    921  1.6  christos 		case OCHEST:
    922  1.6  christos 			k += 30 + ivenarg[i];
    923  1.6  christos 			break;
    924  1.6  christos 		default:
    925  1.6  christos 			k++;
    926  1.6  christos 		};
    927  1.6  christos 	return (k);
    928  1.6  christos }
    929  1.1       cgd 
    930  1.1       cgd #ifndef MACRORND
    931  1.6  christos /* macros to generate random numbers   1<=rnd(N)<=N   0<=rund(N)<=N-1 */
    932  1.6  christos int
    933  1.1       cgd rnd(x)
    934  1.6  christos 	int             x;
    935  1.6  christos {
    936  1.6  christos 	return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)) + 1);
    937  1.6  christos }
    938  1.1       cgd 
    939  1.6  christos int
    940  1.1       cgd rund(x)
    941  1.6  christos 	int             x;
    942  1.6  christos {
    943  1.6  christos 	return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)));
    944  1.6  christos }
    945  1.6  christos #endif	/* MACRORND */
    946