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