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