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