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