Home | History | Annotate | Line # | Download | only in phantasia
fight.c revision 1.10
      1  1.10        he /*	$NetBSD: fight.c,v 1.10 2004/04/11 13:35:06 he Exp $	*/
      2   1.2       cgd 
      3   1.1       jtc /*
      4   1.1       jtc  * fight.c   Phantasia monster fighting routines
      5   1.1       jtc  */
      6   1.1       jtc 
      7   1.1       jtc #include "include.h"
      8  1.10        he #undef bool
      9   1.9      ross #include <curses.h>
     10   1.1       jtc 
     11   1.3     lukem void
     12   1.1       jtc encounter(particular)
     13   1.3     lukem 	int     particular;
     14   1.1       jtc {
     15   1.8       jsm 	volatile bool    firsthit = Player.p_blessing;	/* set if player gets
     16   1.8       jsm 							 * the first hit */
     17   1.8       jsm 	volatile int     flockcnt = 1;	/* how many time flocked */
     18   1.3     lukem 
     19   1.3     lukem 	/* let others know what we are doing */
     20   1.3     lukem 	Player.p_status = S_MONSTER;
     21   1.3     lukem 	writerecord(&Player, Fileloc);
     22   1.1       jtc 
     23   1.1       jtc #ifdef SYS5
     24   1.3     lukem 	flushinp();
     25   1.1       jtc #endif
     26   1.1       jtc 
     27   1.3     lukem 	Shield = 0.0;		/* no shield up yet */
     28   1.1       jtc 
     29   1.3     lukem 	if (particular >= 0)
     30   1.3     lukem 		/* monster is specified */
     31   1.3     lukem 		Whichmonster = particular;
     32   1.3     lukem 	else
     33   1.3     lukem 		/* pick random monster */
     34   1.3     lukem 		Whichmonster = pickmonster();
     35   1.1       jtc 
     36   1.3     lukem 	setjmp(Fightenv);	/* this is to enable changing fight state */
     37   1.1       jtc 
     38   1.3     lukem 	move(6, 0);
     39   1.3     lukem 	clrtobot();		/* clear bottom area of screen */
     40   1.1       jtc 
     41   1.3     lukem 	Lines = 9;
     42   1.3     lukem 	callmonster(Whichmonster);	/* set up monster to fight */
     43   1.1       jtc 
     44   1.3     lukem 	Luckout = FALSE;	/* haven't tried to luckout yet */
     45   1.1       jtc 
     46   1.3     lukem 	if (Curmonster.m_type == SM_MORGOTH)
     47   1.3     lukem 		mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n",
     48   1.3     lukem 		    Enemyname);
     49   1.1       jtc 
     50   1.3     lukem 	if (Curmonster.m_type == SM_UNICORN) {
     51   1.3     lukem 		if (Player.p_virgin) {
     52   1.3     lukem 			printw("You just subdued %s, thanks to the virgin.\n", Enemyname);
     53   1.3     lukem 			Player.p_virgin = FALSE;
     54   1.3     lukem 		} else {
     55   1.3     lukem 			printw("You just saw %s running away!\n", Enemyname);
     56   1.3     lukem 			Curmonster.m_experience = 0.0;
     57   1.3     lukem 			Curmonster.m_treasuretype = 0;
     58   1.3     lukem 		}
     59   1.3     lukem 	} else
     60   1.3     lukem 		/* not a special monster */
     61   1.3     lukem 		for (;;)
     62   1.3     lukem 			/* print header, and arbitrate between player and
     63   1.3     lukem 			 * monster */
     64   1.1       jtc 		{
     65   1.3     lukem 			mvprintw(6, 0, "You are being attacked by %s,   EXP: %.0f   (Size: %.0f)\n",
     66   1.3     lukem 			    Enemyname, Curmonster.m_experience, Circle);
     67   1.3     lukem 
     68   1.3     lukem 			displaystats();
     69   1.3     lukem 			mvprintw(1, 26, "%20.0f", Player.p_energy + Shield);	/* overprint energy */
     70   1.3     lukem 			readmessage();
     71   1.3     lukem 
     72   1.3     lukem 			if (Curmonster.m_type == SM_DARKLORD
     73   1.3     lukem 			    && Player.p_blessing
     74   1.3     lukem 			    && Player.p_charms > 0)
     75   1.3     lukem 				/* overpower Dark Lord with blessing and charm */
     76   1.3     lukem 			{
     77   1.3     lukem 				mvprintw(7, 0, "You just overpowered %s!", Enemyname);
     78   1.3     lukem 				Lines = 8;
     79   1.3     lukem 				Player.p_blessing = FALSE;
     80   1.3     lukem 				--Player.p_charms;
     81   1.3     lukem 				break;
     82   1.3     lukem 			}
     83   1.3     lukem 			/* allow paralyzed monster to wake up */
     84   1.3     lukem 			Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed);
     85   1.3     lukem 
     86   1.3     lukem 			if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed
     87   1.3     lukem 			/* monster is faster */
     88   1.3     lukem 			    && Curmonster.m_type != SM_DARKLORD
     89   1.3     lukem 			/* not D. L. */
     90   1.3     lukem 			    && Curmonster.m_type != SM_SHRIEKER
     91   1.3     lukem 			/* not mimic */
     92   1.3     lukem 			    && !firsthit)
     93   1.3     lukem 				/* monster gets a hit */
     94   1.3     lukem 				monsthits();
     95   1.3     lukem 			else
     96   1.3     lukem 				/* player gets a hit */
     97   1.3     lukem 			{
     98   1.3     lukem 				firsthit = FALSE;
     99   1.3     lukem 				playerhits();
    100   1.3     lukem 			}
    101   1.1       jtc 
    102   1.3     lukem 			refresh();
    103   1.1       jtc 
    104   1.3     lukem 			if (Lines > LINES - 2)
    105   1.3     lukem 				/* near bottom of screen - pause */
    106   1.3     lukem 			{
    107   1.3     lukem 				more(Lines);
    108   1.3     lukem 				move(Lines = 8, 0);
    109   1.3     lukem 				clrtobot();
    110   1.3     lukem 			}
    111   1.3     lukem 			if (Player.p_energy <= 0.0)
    112   1.3     lukem 				/* player died */
    113   1.3     lukem 			{
    114   1.3     lukem 				more(Lines);
    115   1.3     lukem 				death(Enemyname);
    116   1.3     lukem 				cancelmonster();
    117   1.3     lukem 				break;	/* fight ends if the player is saved
    118   1.3     lukem 					 * from death */
    119   1.3     lukem 			}
    120   1.3     lukem 			if (Curmonster.m_energy <= 0.0)
    121   1.3     lukem 				/* monster died */
    122   1.3     lukem 				break;
    123   1.1       jtc 		}
    124   1.1       jtc 
    125   1.3     lukem 	/* give player credit for killing monster */
    126   1.3     lukem 	Player.p_experience += Curmonster.m_experience;
    127   1.1       jtc 
    128   1.3     lukem 	if (drandom() < Curmonster.m_flock / 100.0)
    129   1.3     lukem 		/* monster flocks */
    130   1.3     lukem 	{
    131   1.1       jtc 		more(Lines);
    132   1.3     lukem 		++flockcnt;
    133   1.3     lukem 		longjmp(Fightenv, 0);
    134   1.3     lukem 		/* NOTREACHED */
    135   1.3     lukem 	} else
    136   1.3     lukem 		if (Circle > 1.0
    137   1.3     lukem 		    && Curmonster.m_treasuretype > 0
    138   1.3     lukem 		    && drandom() > 0.2 + pow(0.4, (double) (flockcnt / 3 + Circle / 3.0)))
    139   1.3     lukem 			/* monster has treasure; this takes # of flocks and
    140   1.3     lukem 			 * size into account */
    141   1.1       jtc 		{
    142   1.3     lukem 			more(Lines);
    143   1.3     lukem 			awardtreasure();
    144   1.1       jtc 		}
    145   1.3     lukem 	/* pause before returning */
    146   1.3     lukem 	getyx(stdscr, Lines, flockcnt);
    147   1.3     lukem 	more(Lines + 1);
    148   1.3     lukem 
    149   1.3     lukem 	Player.p_ring.ring_inuse = FALSE;	/* not using ring */
    150   1.3     lukem 
    151   1.3     lukem 	/* clean up the screen */
    152   1.3     lukem 	move(4, 0);
    153   1.3     lukem 	clrtobot();
    154   1.3     lukem }
    155   1.1       jtc 
    156   1.3     lukem int
    157   1.3     lukem pickmonster()
    158   1.3     lukem {
    159   1.3     lukem 	if (Player.p_specialtype == SC_VALAR)
    160   1.3     lukem 		/* even chance of any monster */
    161   1.3     lukem 		return ((int) ROLL(0.0, 100.0));
    162   1.3     lukem 
    163   1.3     lukem 	if (Marsh)
    164   1.3     lukem 		/* water monsters */
    165   1.3     lukem 		return ((int) ROLL(0.0, 15.0));
    166   1.1       jtc 
    167   1.3     lukem 	else
    168   1.3     lukem 		if (Circle > 24)
    169   1.3     lukem 			/* even chance of all non-water monsters */
    170   1.3     lukem 			return ((int) ROLL(14.0, 86.0));
    171   1.1       jtc 
    172   1.3     lukem 		else
    173   1.3     lukem 			if (Circle > 15)
    174   1.3     lukem 				/* chance of all non-water monsters, weighted
    175   1.3     lukem 				 * toward middle */
    176   1.3     lukem 				return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0)));
    177   1.1       jtc 
    178   1.3     lukem 			else
    179   1.3     lukem 				if (Circle > 8)
    180   1.3     lukem 					/* not all non-water monsters,
    181   1.3     lukem 					 * weighted toward middle */
    182   1.3     lukem 					return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0)));
    183   1.1       jtc 
    184   1.3     lukem 				else
    185   1.3     lukem 					if (Circle > 3)
    186   1.3     lukem 						/* even chance of some tamer
    187   1.3     lukem 						 * non-water monsters */
    188   1.3     lukem 						return ((int) ROLL(14.0, 50.0));
    189   1.3     lukem 
    190   1.3     lukem 					else
    191   1.3     lukem 						/* even chance of some of the
    192   1.3     lukem 						 * tamest non-water monsters */
    193   1.3     lukem 						return ((int) ROLL(14.0, 25.0));
    194   1.1       jtc }
    195   1.1       jtc 
    196   1.3     lukem void
    197   1.1       jtc playerhits()
    198   1.1       jtc {
    199   1.3     lukem 	double  inflict;	/* damage inflicted */
    200   1.3     lukem 	int     ch;		/* input */
    201   1.1       jtc 
    202   1.3     lukem 	mvaddstr(7, 0, "1:Melee  2:Skirmish  3:Evade  4:Spell  5:Nick  ");
    203   1.3     lukem 
    204   1.4     veego 	if (!Luckout) {
    205   1.3     lukem 		/* haven't tried to luckout yet */
    206   1.3     lukem 		if (Curmonster.m_type == SM_MORGOTH)
    207   1.3     lukem 			/* cannot luckout against Morgoth */
    208   1.3     lukem 			addstr("6:Ally  ");
    209   1.3     lukem 		else
    210   1.3     lukem 			addstr("6:Luckout  ");
    211   1.4     veego 	}
    212   1.1       jtc 
    213   1.3     lukem 	if (Player.p_ring.ring_type != R_NONE)
    214   1.3     lukem 		/* player has a ring */
    215   1.3     lukem 		addstr("7:Use Ring  ");
    216   1.1       jtc 	else
    217   1.3     lukem 		clrtoeol();
    218   1.3     lukem 
    219   1.3     lukem 	ch = inputoption();
    220   1.1       jtc 
    221   1.3     lukem 	move(8, 0);
    222   1.3     lukem 	clrtobot();		/* clear any messages from before */
    223   1.3     lukem 	Lines = 9;
    224   1.3     lukem 	mvaddstr(4, 0, "\n\n");	/* clear status area */
    225   1.1       jtc 
    226   1.3     lukem 	switch (ch) {
    227   1.1       jtc 	case 'T':		/* timeout; lose turn */
    228   1.3     lukem 		break;
    229   1.1       jtc 
    230   1.1       jtc 	case ' ':
    231   1.1       jtc 	case '1':		/* melee */
    232   1.3     lukem 		/* melee affects monster's energy and strength */
    233   1.3     lukem 		inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might)
    234   1.3     lukem 		    + (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
    235   1.3     lukem 
    236   1.3     lukem 		Curmonster.m_melee += inflict;
    237   1.3     lukem 		Curmonster.m_strength = Curmonster.m_o_strength
    238   1.3     lukem 		    - Curmonster.m_melee / Curmonster.m_o_energy
    239   1.3     lukem 		    * Curmonster.m_o_strength / 4.0;
    240   1.3     lukem 		hitmonster(inflict);
    241   1.3     lukem 		break;
    242   1.1       jtc 
    243   1.1       jtc 	case '2':		/* skirmish */
    244   1.3     lukem 		/* skirmish affects monter's energy and speed */
    245   1.3     lukem 		inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might)
    246   1.3     lukem 		    + (Player.p_ring.ring_inuse ? Player.p_might : 0.0);
    247   1.3     lukem 
    248   1.3     lukem 		Curmonster.m_skirmish += inflict;
    249   1.3     lukem 		Curmonster.m_maxspeed = Curmonster.m_o_speed
    250   1.3     lukem 		    - Curmonster.m_skirmish / Curmonster.m_o_energy
    251   1.3     lukem 		    * Curmonster.m_o_speed / 4.0;
    252   1.3     lukem 		hitmonster(inflict);
    253   1.3     lukem 		break;
    254   1.1       jtc 
    255   1.1       jtc 	case '3':		/* evade */
    256   1.3     lukem 		/* use brains and speed to try to evade */
    257   1.3     lukem 		if ((Curmonster.m_type == SM_DARKLORD
    258   1.3     lukem 			|| Curmonster.m_type == SM_SHRIEKER
    259   1.1       jtc 		/* can always run from D. L. and shrieker */
    260   1.3     lukem 			|| drandom() * Player.p_speed * Player.p_brains
    261   1.3     lukem 			> drandom() * Curmonster.m_speed * Curmonster.m_brains)
    262   1.3     lukem 		    && (Curmonster.m_type != SM_MIMIC))
    263   1.3     lukem 			/* cannot run from mimic */
    264   1.1       jtc 		{
    265   1.3     lukem 			mvaddstr(Lines++, 0, "You got away!");
    266   1.3     lukem 			cancelmonster();
    267   1.3     lukem 			altercoordinates(0.0, 0.0, A_NEAR);
    268   1.3     lukem 		} else
    269   1.3     lukem 			mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
    270   1.1       jtc 
    271   1.3     lukem 		break;
    272   1.1       jtc 
    273   1.1       jtc 	case 'M':
    274   1.1       jtc 	case '4':		/* magic spell */
    275   1.3     lukem 		throwspell();
    276   1.3     lukem 		break;
    277   1.1       jtc 
    278   1.1       jtc 	case '5':		/* nick */
    279   1.3     lukem 		/* hit 1 plus sword; give some experience */
    280   1.3     lukem 		inflict = 1.0 + Player.p_sword;
    281   1.3     lukem 		Player.p_experience += floor(Curmonster.m_experience / 10.0);
    282   1.3     lukem 		Curmonster.m_experience *= 0.92;
    283   1.3     lukem 		/* monster gets meaner */
    284   1.3     lukem 		Curmonster.m_maxspeed += 2.0;
    285   1.3     lukem 		Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0;
    286   1.3     lukem 		if (Curmonster.m_type == SM_DARKLORD)
    287   1.3     lukem 			/* Dark Lord; doesn't like to be nicked */
    288   1.1       jtc 		{
    289   1.3     lukem 			mvprintw(Lines++, 0,
    290   1.3     lukem 			    "You hit %s %.0f times, and made him mad!", Enemyname, inflict);
    291   1.3     lukem 			Player.p_quickness /= 2.0;
    292   1.3     lukem 			altercoordinates(0.0, 0.0, A_FAR);
    293   1.3     lukem 			cancelmonster();
    294   1.3     lukem 		} else
    295   1.3     lukem 			hitmonster(inflict);
    296   1.3     lukem 		break;
    297   1.1       jtc 
    298   1.1       jtc 	case 'B':
    299   1.3     lukem 	case '6':		/* luckout */
    300   1.3     lukem 		if (Luckout)
    301   1.3     lukem 			mvaddstr(Lines++, 0, "You already tried that.");
    302   1.3     lukem 		else {
    303   1.3     lukem 			Luckout = TRUE;
    304   1.3     lukem 			if (Curmonster.m_type == SM_MORGOTH)
    305   1.3     lukem 				/* Morgoth; ally */
    306   1.1       jtc 			{
    307   1.3     lukem 				if (drandom() < Player.p_sin / 100.0) {
    308   1.3     lukem 					mvprintw(Lines++, 0, "%s accepted!", Enemyname);
    309   1.3     lukem 					cancelmonster();
    310   1.3     lukem 				} else
    311   1.3     lukem 					mvaddstr(Lines++, 0, "Nope, he's not interested.");
    312   1.3     lukem 			} else
    313   1.3     lukem 				/* normal monster; use brains for success */
    314   1.1       jtc 			{
    315   1.3     lukem 				if ((drandom() + 0.333) * Player.p_brains
    316   1.3     lukem 				    < (drandom() + 0.333) * Curmonster.m_brains)
    317   1.3     lukem 					mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name);
    318   1.3     lukem 				else {
    319   1.3     lukem 					mvaddstr(Lines++, 0, "You made it!");
    320   1.3     lukem 					Curmonster.m_energy = 0.0;
    321   1.3     lukem 				}
    322   1.1       jtc 			}
    323   1.1       jtc 		}
    324   1.3     lukem 		break;
    325   1.1       jtc 
    326   1.1       jtc 	case '7':		/* use ring */
    327   1.3     lukem 		if (Player.p_ring.ring_type != R_NONE) {
    328   1.3     lukem 			mvaddstr(Lines++, 0, "Now using ring.");
    329   1.3     lukem 			Player.p_ring.ring_inuse = TRUE;
    330   1.3     lukem 			if (Player.p_ring.ring_type != R_DLREG)
    331   1.3     lukem 				/* age ring */
    332   1.3     lukem 				--Player.p_ring.ring_duration;
    333   1.1       jtc 		}
    334   1.3     lukem 		break;
    335   1.1       jtc 	}
    336   1.1       jtc 
    337   1.1       jtc }
    338   1.1       jtc 
    339   1.3     lukem void
    340   1.1       jtc monsthits()
    341   1.1       jtc {
    342   1.3     lukem 	double  inflict;	/* damage inflicted */
    343   1.3     lukem 	int     ch;		/* input */
    344   1.1       jtc 
    345   1.3     lukem 	switch (Curmonster.m_type)
    346   1.3     lukem 		/* may be a special monster */
    347   1.1       jtc 	{
    348   1.1       jtc 	case SM_DARKLORD:
    349   1.3     lukem 		/* hits just enough to kill player */
    350   1.3     lukem 		inflict = (Player.p_energy + Shield) * 1.02;
    351   1.3     lukem 		goto SPECIALHIT;
    352   1.1       jtc 
    353   1.1       jtc 	case SM_SHRIEKER:
    354   1.3     lukem 		/* call a big monster */
    355   1.3     lukem 		mvaddstr(Lines++, 0,
    356   1.3     lukem 		    "Shrieeeek!!  You scared it, and it called one of its friends.");
    357   1.3     lukem 		more(Lines);
    358   1.3     lukem 		Whichmonster = (int) ROLL(70.0, 30.0);
    359   1.3     lukem 		longjmp(Fightenv, 0);
    360   1.3     lukem 		/* NOTREACHED */
    361   1.1       jtc 
    362   1.1       jtc 	case SM_BALROG:
    363   1.3     lukem 		/* take experience away */
    364   1.3     lukem 		inflict = ROLL(10.0, Curmonster.m_strength);
    365   1.3     lukem 		inflict = MIN(Player.p_experience, inflict);
    366   1.3     lukem 		mvprintw(Lines++, 0,
    367   1.3     lukem 		    "%s took away %.0f experience points.", Enemyname, inflict);
    368   1.3     lukem 		Player.p_experience -= inflict;
    369   1.3     lukem 		return;
    370   1.1       jtc 
    371   1.1       jtc 	case SM_FAERIES:
    372   1.3     lukem 		if (Player.p_holywater > 0)
    373   1.3     lukem 			/* holy water kills when monster tries to hit */
    374   1.1       jtc 		{
    375   1.3     lukem 			mvprintw(Lines++, 0, "Your holy water killed it!");
    376   1.3     lukem 			--Player.p_holywater;
    377   1.3     lukem 			Curmonster.m_energy = 0.0;
    378   1.3     lukem 			return;
    379   1.1       jtc 		}
    380   1.3     lukem 		break;
    381   1.1       jtc 
    382   1.1       jtc 	case SM_NONE:
    383   1.3     lukem 		/* normal hit */
    384   1.3     lukem 		break;
    385   1.1       jtc 
    386   1.1       jtc 	default:
    387   1.3     lukem 		if (drandom() > 0.2)
    388   1.3     lukem 			/* normal hit */
    389   1.3     lukem 			break;
    390   1.1       jtc 
    391   1.3     lukem 		/* else special things */
    392   1.3     lukem 		switch (Curmonster.m_type) {
    393   1.1       jtc 		case SM_LEANAN:
    394   1.3     lukem 			/* takes some of the player's strength */
    395   1.3     lukem 			inflict = ROLL(1.0, (Circle - 1.0) / 2.0);
    396   1.3     lukem 			inflict = MIN(Player.p_strength, inflict);
    397   1.7       jdc 			mvprintw(Lines++, 0, "%s sapped %.0f of your strength!",
    398   1.3     lukem 			    Enemyname, inflict);
    399   1.3     lukem 			Player.p_strength -= inflict;
    400   1.3     lukem 			Player.p_might -= inflict;
    401   1.3     lukem 			break;
    402   1.1       jtc 
    403   1.1       jtc 		case SM_SARUMAN:
    404   1.3     lukem 			if (Player.p_palantir)
    405   1.3     lukem 				/* take away palantir */
    406   1.1       jtc 			{
    407   1.3     lukem 				mvprintw(Lines++, 0, "Wormtongue stole your palantir!");
    408   1.3     lukem 				Player.p_palantir = FALSE;
    409   1.3     lukem 			} else
    410   1.3     lukem 				if (drandom() > 0.5)
    411   1.3     lukem 					/* gems turn to gold */
    412   1.3     lukem 				{
    413   1.3     lukem 					mvprintw(Lines++, 0,
    414   1.3     lukem 					    "%s transformed your gems into gold!", Enemyname);
    415   1.3     lukem 					Player.p_gold += Player.p_gems;
    416   1.3     lukem 					Player.p_gems = 0.0;
    417   1.3     lukem 				} else
    418   1.3     lukem 					/* scramble some stats */
    419   1.3     lukem 				{
    420   1.3     lukem 					mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname);
    421   1.3     lukem 					scramblestats();
    422   1.3     lukem 				}
    423   1.3     lukem 			break;
    424   1.1       jtc 
    425   1.1       jtc 		case SM_THAUMATURG:
    426   1.3     lukem 			/* transport player */
    427   1.3     lukem 			mvprintw(Lines++, 0, "%s transported you!", Enemyname);
    428   1.3     lukem 			altercoordinates(0.0, 0.0, A_FAR);
    429   1.3     lukem 			cancelmonster();
    430   1.3     lukem 			break;
    431   1.1       jtc 
    432   1.1       jtc 		case SM_VORTEX:
    433   1.3     lukem 			/* suck up some mana */
    434   1.3     lukem 			inflict = ROLL(0, 7.5 * Circle);
    435   1.3     lukem 			inflict = MIN(Player.p_mana, floor(inflict));
    436   1.3     lukem 			mvprintw(Lines++, 0,
    437   1.3     lukem 			    "%s sucked up %.0f of your mana!", Enemyname, inflict);
    438   1.3     lukem 			Player.p_mana -= inflict;
    439   1.3     lukem 			break;
    440   1.1       jtc 
    441   1.1       jtc 		case SM_NAZGUL:
    442   1.3     lukem 			/* try to take ring if player has one */
    443   1.3     lukem 			if (Player.p_ring.ring_type != R_NONE)
    444   1.3     lukem 				/* player has a ring */
    445   1.1       jtc 			{
    446   1.3     lukem 				mvaddstr(Lines++, 0, "Will you relinguish your ring ? ");
    447   1.3     lukem 				ch = getanswer("YN", FALSE);
    448   1.3     lukem 				if (ch == 'Y')
    449   1.3     lukem 					/* take ring away */
    450   1.3     lukem 				{
    451   1.3     lukem 					Player.p_ring.ring_type = R_NONE;
    452   1.3     lukem 					Player.p_ring.ring_inuse = FALSE;
    453   1.3     lukem 					cancelmonster();
    454   1.3     lukem 					break;
    455   1.3     lukem 				}
    456   1.1       jtc 			}
    457   1.3     lukem 			/* otherwise, take some brains */
    458   1.3     lukem 			mvprintw(Lines++, 0,
    459   1.3     lukem 			    "%s neutralized 1/5 of your brain!", Enemyname);
    460   1.3     lukem 			Player.p_brains *= 0.8;
    461   1.3     lukem 			break;
    462   1.1       jtc 
    463   1.1       jtc 		case SM_TIAMAT:
    464   1.3     lukem 			/* take some gold and gems */
    465   1.3     lukem 			mvprintw(Lines++, 0,
    466   1.3     lukem 			    "%s took half your gold and gems and flew off.", Enemyname);
    467   1.3     lukem 			Player.p_gold /= 2.0;
    468   1.3     lukem 			Player.p_gems /= 2.0;
    469   1.3     lukem 			cancelmonster();
    470   1.3     lukem 			break;
    471   1.1       jtc 
    472   1.1       jtc 		case SM_KOBOLD:
    473   1.3     lukem 			/* steal a gold piece and run */
    474   1.3     lukem 			mvprintw(Lines++, 0,
    475   1.3     lukem 			    "%s stole one gold piece and ran away.", Enemyname);
    476   1.3     lukem 			Player.p_gold = MAX(0.0, Player.p_gold - 1.0);
    477   1.3     lukem 			cancelmonster();
    478   1.3     lukem 			break;
    479   1.1       jtc 
    480   1.1       jtc 		case SM_SHELOB:
    481   1.3     lukem 			/* bite and (medium) poison */
    482   1.3     lukem 			mvprintw(Lines++, 0,
    483   1.3     lukem 			    "%s has bitten and poisoned you!", Enemyname);
    484   1.3     lukem 			Player.p_poison -= 1.0;
    485   1.3     lukem 			break;
    486   1.1       jtc 
    487   1.1       jtc 		case SM_LAMPREY:
    488   1.3     lukem 			/* bite and (small) poison */
    489   1.3     lukem 			mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname);
    490   1.3     lukem 			Player.p_poison += 0.25;
    491   1.3     lukem 			break;
    492   1.1       jtc 
    493   1.1       jtc 		case SM_BONNACON:
    494   1.3     lukem 			/* fart and run */
    495   1.3     lukem 			mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname);
    496   1.3     lukem 			Player.p_energy /= 2.0;	/* damage from fumes */
    497   1.3     lukem 			cancelmonster();
    498   1.3     lukem 			break;
    499   1.1       jtc 
    500   1.1       jtc 		case SM_SMEAGOL:
    501   1.3     lukem 			if (Player.p_ring.ring_type != R_NONE)
    502   1.3     lukem 				/* try to steal ring */
    503   1.1       jtc 			{
    504   1.3     lukem 				mvprintw(Lines++, 0,
    505   1.3     lukem 				    "%s tried to steal your ring, ", Enemyname);
    506   1.3     lukem 				if (drandom() > 0.1)
    507   1.3     lukem 					addstr("but was unsuccessful.");
    508   1.3     lukem 				else {
    509   1.3     lukem 					addstr("and ran away with it!");
    510   1.3     lukem 					Player.p_ring.ring_type = R_NONE;
    511   1.3     lukem 					cancelmonster();
    512   1.3     lukem 				}
    513   1.1       jtc 			}
    514   1.3     lukem 			break;
    515   1.1       jtc 
    516   1.1       jtc 		case SM_SUCCUBUS:
    517   1.3     lukem 			/* inflict damage through shield */
    518   1.3     lukem 			inflict = ROLL(15.0, Circle * 10.0);
    519   1.3     lukem 			inflict = MIN(inflict, Player.p_energy);
    520   1.3     lukem 			mvprintw(Lines++, 0, "%s sapped %.0f of your energy.",
    521   1.3     lukem 			    Enemyname, inflict);
    522   1.3     lukem 			Player.p_energy -= inflict;
    523   1.3     lukem 			break;
    524   1.1       jtc 
    525   1.1       jtc 		case SM_CERBERUS:
    526   1.3     lukem 			/* take all metal treasures */
    527   1.3     lukem 			mvprintw(Lines++, 0,
    528   1.3     lukem 			    "%s took all your metal treasures!", Enemyname);
    529   1.3     lukem 			Player.p_crowns = 0;
    530   1.3     lukem 			Player.p_sword =
    531   1.3     lukem 			    Player.p_shield =
    532   1.3     lukem 			    Player.p_gold = 0.0;
    533   1.3     lukem 			cancelmonster();
    534   1.3     lukem 			break;
    535   1.1       jtc 
    536   1.1       jtc 		case SM_UNGOLIANT:
    537   1.3     lukem 			/* (large) poison and take a quickness */
    538   1.3     lukem 			mvprintw(Lines++, 0,
    539   1.3     lukem 			    "%s poisoned you, and took one quik.", Enemyname);
    540   1.3     lukem 			Player.p_poison += 5.0;
    541   1.3     lukem 			Player.p_quickness -= 1.0;
    542   1.3     lukem 			break;
    543   1.1       jtc 
    544   1.1       jtc 		case SM_JABBERWOCK:
    545   1.3     lukem 			/* fly away, and leave either a Jubjub bird or
    546   1.3     lukem 			 * Bonnacon */
    547   1.3     lukem 			mvprintw(Lines++, 0,
    548   1.3     lukem 			    "%s flew away, and left you to contend with one of its friends.",
    549   1.3     lukem 			    Enemyname);
    550   1.6  jdolecek 			Whichmonster = 55 + ((drandom() > 0.5) ? 22 : 0);
    551   1.3     lukem 			longjmp(Fightenv, 0);
    552   1.3     lukem 			/* NOTREACHED */
    553   1.1       jtc 
    554   1.1       jtc 		case SM_TROLL:
    555   1.3     lukem 			/* partially regenerate monster */
    556   1.3     lukem 			mvprintw(Lines++, 0,
    557   1.3     lukem 			    "%s partially regenerated his energy.!", Enemyname);
    558   1.3     lukem 			Curmonster.m_energy +=
    559   1.3     lukem 			    floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0);
    560   1.3     lukem 			Curmonster.m_strength = Curmonster.m_o_strength;
    561   1.3     lukem 			Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
    562   1.3     lukem 			Curmonster.m_maxspeed = Curmonster.m_o_speed;
    563   1.3     lukem 			break;
    564   1.1       jtc 
    565   1.1       jtc 		case SM_WRAITH:
    566   1.3     lukem 			if (!Player.p_blindness)
    567   1.3     lukem 				/* make blind */
    568   1.1       jtc 			{
    569   1.3     lukem 				mvprintw(Lines++, 0, "%s blinded you!", Enemyname);
    570   1.3     lukem 				Player.p_blindness = TRUE;
    571   1.3     lukem 				Enemyname = "A monster";
    572   1.1       jtc 			}
    573   1.3     lukem 			break;
    574   1.1       jtc 		}
    575   1.3     lukem 		return;
    576   1.1       jtc 	}
    577   1.1       jtc 
    578   1.3     lukem 	/* fall through to here if monster inflicts a normal hit */
    579   1.3     lukem 	inflict = drandom() * Curmonster.m_strength + 0.5;
    580   1.1       jtc SPECIALHIT:
    581   1.3     lukem 	mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict);
    582   1.1       jtc 
    583   1.3     lukem 	if ((Shield -= inflict) < 0) {
    584   1.3     lukem 		Player.p_energy += Shield;
    585   1.3     lukem 		Shield = 0.0;
    586   1.1       jtc 	}
    587   1.1       jtc }
    588   1.1       jtc 
    589   1.3     lukem void
    590   1.1       jtc cancelmonster()
    591   1.1       jtc {
    592   1.3     lukem 	Curmonster.m_energy = 0.0;
    593   1.3     lukem 	Curmonster.m_experience = 0.0;
    594   1.3     lukem 	Curmonster.m_treasuretype = 0;
    595   1.3     lukem 	Curmonster.m_flock = 0.0;
    596   1.1       jtc }
    597   1.1       jtc 
    598   1.3     lukem void
    599   1.1       jtc hitmonster(inflict)
    600   1.3     lukem 	double  inflict;
    601   1.1       jtc {
    602   1.3     lukem 	mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
    603   1.3     lukem 	Curmonster.m_energy -= inflict;
    604   1.3     lukem 	if (Curmonster.m_energy > 0.0) {
    605   1.3     lukem 		if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER)
    606   1.3     lukem 			/* special monster didn't die */
    607   1.3     lukem 			monsthits();
    608   1.3     lukem 	} else
    609   1.3     lukem 		/* monster died.  print message. */
    610   1.1       jtc 	{
    611   1.3     lukem 		if (Curmonster.m_type == SM_MORGOTH)
    612   1.3     lukem 			mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . .");
    613   1.3     lukem 		else
    614   1.3     lukem 			/* all other types of monsters */
    615   1.3     lukem 		{
    616   1.3     lukem 			mvprintw(Lines++, 0, "You killed it.  Good work, %s.", Player.p_name);
    617   1.3     lukem 
    618   1.3     lukem 			if (Curmonster.m_type == SM_MIMIC
    619   1.3     lukem 			    && strcmp(Curmonster.m_name, "A Mimic") != 0
    620   1.3     lukem 			    && !Player.p_blindness)
    621   1.3     lukem 				mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic.");
    622   1.3     lukem 		}
    623   1.1       jtc 	}
    624   1.1       jtc }
    625   1.1       jtc 
    626   1.3     lukem void
    627   1.1       jtc throwspell()
    628   1.1       jtc {
    629   1.3     lukem 	double  inflict;	/* damage inflicted */
    630   1.3     lukem 	double  dtemp;		/* for dtemporary calculations */
    631   1.3     lukem 	int     ch;		/* input */
    632   1.3     lukem 
    633   1.3     lukem 	inflict = 0;
    634   1.3     lukem 	mvaddstr(7, 0, "\n\n");	/* clear menu area */
    635   1.3     lukem 
    636   1.3     lukem 	if (Player.p_magiclvl >= ML_ALLORNOTHING)
    637   1.3     lukem 		mvaddstr(7, 0, "1:All or Nothing  ");
    638   1.3     lukem 	if (Player.p_magiclvl >= ML_MAGICBOLT)
    639   1.3     lukem 		addstr("2:Magic Bolt  ");
    640   1.3     lukem 	if (Player.p_magiclvl >= ML_FORCEFIELD)
    641   1.3     lukem 		addstr("3:Force Field  ");
    642   1.3     lukem 	if (Player.p_magiclvl >= ML_XFORM)
    643   1.3     lukem 		addstr("4:Transform  ");
    644   1.3     lukem 	if (Player.p_magiclvl >= ML_INCRMIGHT)
    645   1.3     lukem 		addstr("5:Increase Might\n");
    646   1.3     lukem 	if (Player.p_magiclvl >= ML_INVISIBLE)
    647   1.3     lukem 		mvaddstr(8, 0, "6:Invisibility  ");
    648   1.3     lukem 	if (Player.p_magiclvl >= ML_XPORT)
    649   1.3     lukem 		addstr("7:Transport  ");
    650   1.3     lukem 	if (Player.p_magiclvl >= ML_PARALYZE)
    651   1.3     lukem 		addstr("8:Paralyze  ");
    652   1.3     lukem 	if (Player.p_specialtype >= SC_COUNCIL)
    653   1.3     lukem 		addstr("9:Specify");
    654   1.3     lukem 	mvaddstr(4, 0, "Spell ? ");
    655   1.3     lukem 
    656   1.3     lukem 	ch = getanswer(" ", TRUE);
    657   1.3     lukem 
    658   1.3     lukem 	mvaddstr(7, 0, "\n\n");	/* clear menu area */
    659   1.3     lukem 
    660   1.3     lukem 	if (Curmonster.m_type == SM_MORGOTH && ch != '3')
    661   1.3     lukem 		/* can only throw force field against Morgoth */
    662   1.3     lukem 		ILLSPELL();
    663   1.3     lukem 	else
    664   1.3     lukem 		switch (ch) {
    665   1.3     lukem 		case '1':	/* all or nothing */
    666   1.3     lukem 			if (drandom() < 0.25)
    667   1.3     lukem 				/* success */
    668   1.3     lukem 			{
    669   1.3     lukem 				inflict = Curmonster.m_energy * 1.01 + 1.0;
    670   1.1       jtc 
    671   1.3     lukem 				if (Curmonster.m_type == SM_DARKLORD)
    672   1.3     lukem 					/* all or nothing doesn't quite work
    673   1.3     lukem 					 * against D. L. */
    674   1.3     lukem 					inflict *= 0.9;
    675   1.3     lukem 			} else
    676   1.3     lukem 				/* failure -- monster gets stronger and
    677   1.3     lukem 				 * quicker */
    678   1.3     lukem 			{
    679   1.3     lukem 				Curmonster.m_o_strength = Curmonster.m_strength *= 2.0;
    680   1.3     lukem 				Curmonster.m_maxspeed *= 2.0;
    681   1.3     lukem 				Curmonster.m_o_speed *= 2.0;
    682   1.1       jtc 
    683   1.3     lukem 				/* paralyzed monsters wake up a bit */
    684   1.3     lukem 				Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0);
    685   1.1       jtc 			}
    686   1.1       jtc 
    687   1.3     lukem 			if (Player.p_mana >= MM_ALLORNOTHING)
    688   1.3     lukem 				/* take a mana if player has one */
    689   1.3     lukem 				Player.p_mana -= MM_ALLORNOTHING;
    690   1.1       jtc 
    691   1.3     lukem 			hitmonster(inflict);
    692   1.3     lukem 			break;
    693   1.3     lukem 
    694   1.3     lukem 		case '2':	/* magic bolt */
    695   1.3     lukem 			if (Player.p_magiclvl < ML_MAGICBOLT)
    696   1.3     lukem 				ILLSPELL();
    697   1.3     lukem 			else {
    698   1.3     lukem 				do
    699   1.3     lukem 					/* prompt for amount to expend */
    700   1.3     lukem 				{
    701   1.3     lukem 					mvaddstr(4, 0, "How much mana for bolt? ");
    702   1.3     lukem 					dtemp = floor(infloat());
    703   1.3     lukem 				}
    704   1.3     lukem 				while (dtemp < 0.0 || dtemp > Player.p_mana);
    705   1.3     lukem 
    706   1.3     lukem 				Player.p_mana -= dtemp;
    707   1.3     lukem 
    708   1.3     lukem 				if (Curmonster.m_type == SM_DARKLORD)
    709   1.3     lukem 					/* magic bolts don't work against D.
    710   1.3     lukem 					 * L. */
    711   1.3     lukem 					inflict = 0.0;
    712   1.3     lukem 				else
    713   1.3     lukem 					inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0));
    714   1.3     lukem 				mvaddstr(5, 0, "Magic Bolt fired!\n");
    715   1.3     lukem 				hitmonster(inflict);
    716   1.3     lukem 			}
    717   1.3     lukem 			break;
    718   1.1       jtc 
    719   1.3     lukem 		case '3':	/* force field */
    720   1.3     lukem 			if (Player.p_magiclvl < ML_FORCEFIELD)
    721   1.3     lukem 				ILLSPELL();
    722   1.3     lukem 			else
    723   1.3     lukem 				if (Player.p_mana < MM_FORCEFIELD)
    724   1.3     lukem 					NOMANA();
    725   1.3     lukem 				else {
    726   1.3     lukem 					Player.p_mana -= MM_FORCEFIELD;
    727   1.3     lukem 					Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0;
    728   1.3     lukem 					mvaddstr(5, 0, "Force Field up.\n");
    729   1.3     lukem 				}
    730   1.3     lukem 			break;
    731   1.1       jtc 
    732   1.3     lukem 		case '4':	/* transform */
    733   1.3     lukem 			if (Player.p_magiclvl < ML_XFORM)
    734   1.3     lukem 				ILLSPELL();
    735   1.3     lukem 			else
    736   1.3     lukem 				if (Player.p_mana < MM_XFORM)
    737   1.3     lukem 					NOMANA();
    738   1.3     lukem 				else {
    739   1.3     lukem 					Player.p_mana -= MM_XFORM;
    740   1.3     lukem 					Whichmonster = (int) ROLL(0.0, 100.0);
    741   1.3     lukem 					longjmp(Fightenv, 0);
    742   1.3     lukem 					/* NOTREACHED */
    743   1.3     lukem 				}
    744   1.3     lukem 			break;
    745   1.1       jtc 
    746   1.3     lukem 		case '5':	/* increase might */
    747   1.3     lukem 			if (Player.p_magiclvl < ML_INCRMIGHT)
    748   1.3     lukem 				ILLSPELL();
    749   1.3     lukem 			else
    750   1.3     lukem 				if (Player.p_mana < MM_INCRMIGHT)
    751   1.3     lukem 					NOMANA();
    752   1.3     lukem 				else {
    753   1.3     lukem 					Player.p_mana -= MM_INCRMIGHT;
    754   1.3     lukem 					Player.p_might +=
    755   1.3     lukem 					    (1.2 * (Player.p_strength + Player.p_sword)
    756   1.3     lukem 					    + 5.0 - Player.p_might) / 2.0;
    757   1.3     lukem 					mvprintw(5, 0, "New strength:  %.0f\n", Player.p_might);
    758   1.3     lukem 				}
    759   1.3     lukem 			break;
    760   1.1       jtc 
    761   1.3     lukem 		case '6':	/* invisible */
    762   1.3     lukem 			if (Player.p_magiclvl < ML_INVISIBLE)
    763   1.3     lukem 				ILLSPELL();
    764   1.3     lukem 			else
    765   1.3     lukem 				if (Player.p_mana < MM_INVISIBLE)
    766   1.3     lukem 					NOMANA();
    767   1.3     lukem 				else {
    768   1.3     lukem 					Player.p_mana -= MM_INVISIBLE;
    769   1.3     lukem 					Player.p_speed +=
    770   1.3     lukem 					    (1.2 * (Player.p_quickness + Player.p_quksilver)
    771   1.3     lukem 					    + 5.0 - Player.p_speed) / 2.0;
    772   1.3     lukem 					mvprintw(5, 0, "New quickness:  %.0f\n", Player.p_speed);
    773   1.3     lukem 				}
    774   1.3     lukem 			break;
    775   1.1       jtc 
    776   1.3     lukem 		case '7':	/* transport */
    777   1.3     lukem 			if (Player.p_magiclvl < ML_XPORT)
    778   1.3     lukem 				ILLSPELL();
    779   1.3     lukem 			else
    780   1.3     lukem 				if (Player.p_mana < MM_XPORT)
    781   1.3     lukem 					NOMANA();
    782   1.3     lukem 				else {
    783   1.3     lukem 					Player.p_mana -= MM_XPORT;
    784   1.3     lukem 					if (Player.p_brains + Player.p_magiclvl
    785   1.3     lukem 					    < Curmonster.m_experience / 200.0 * drandom()) {
    786   1.3     lukem 						mvaddstr(5, 0, "Transport backfired!\n");
    787   1.3     lukem 						altercoordinates(0.0, 0.0, A_FAR);
    788   1.3     lukem 						cancelmonster();
    789   1.3     lukem 					} else {
    790   1.3     lukem 						mvprintw(5, 0, "%s is transported.\n", Enemyname);
    791   1.3     lukem 						if (drandom() < 0.3)
    792   1.3     lukem 							/* monster didn't drop
    793   1.3     lukem 							 * its treasure */
    794   1.3     lukem 							Curmonster.m_treasuretype = 0;
    795   1.1       jtc 
    796   1.3     lukem 						Curmonster.m_energy = 0.0;
    797   1.3     lukem 					}
    798   1.3     lukem 				}
    799   1.3     lukem 			break;
    800   1.1       jtc 
    801   1.3     lukem 		case '8':	/* paralyze */
    802   1.3     lukem 			if (Player.p_magiclvl < ML_PARALYZE)
    803   1.3     lukem 				ILLSPELL();
    804   1.3     lukem 			else
    805   1.3     lukem 				if (Player.p_mana < MM_PARALYZE)
    806   1.3     lukem 					NOMANA();
    807   1.3     lukem 				else {
    808   1.3     lukem 					Player.p_mana -= MM_PARALYZE;
    809   1.3     lukem 					if (Player.p_magiclvl >
    810   1.3     lukem 					    Curmonster.m_experience / 1000.0 * drandom()) {
    811   1.3     lukem 						mvprintw(5, 0, "%s is held.\n", Enemyname);
    812   1.3     lukem 						Curmonster.m_speed = -2.0;
    813   1.3     lukem 					} else
    814   1.3     lukem 						mvaddstr(5, 0, "Monster unaffected.\n");
    815   1.3     lukem 				}
    816   1.3     lukem 			break;
    817   1.1       jtc 
    818   1.3     lukem 		case '9':	/* specify */
    819   1.3     lukem 			if (Player.p_specialtype < SC_COUNCIL)
    820   1.3     lukem 				ILLSPELL();
    821   1.3     lukem 			else
    822   1.3     lukem 				if (Player.p_mana < MM_SPECIFY)
    823   1.3     lukem 					NOMANA();
    824   1.3     lukem 				else {
    825   1.3     lukem 					Player.p_mana -= MM_SPECIFY;
    826   1.3     lukem 					mvaddstr(5, 0, "Which monster do you want [0-99] ? ");
    827   1.3     lukem 					Whichmonster = (int) infloat();
    828   1.3     lukem 					Whichmonster = MAX(0, MIN(99, Whichmonster));
    829   1.3     lukem 					longjmp(Fightenv, 0);
    830   1.3     lukem 					/* NOTREACHED */
    831   1.3     lukem 				}
    832   1.3     lukem 			break;
    833   1.3     lukem 		}
    834   1.1       jtc }
    835   1.1       jtc 
    836   1.3     lukem void
    837   1.1       jtc callmonster(which)
    838   1.3     lukem 	int     which;
    839   1.1       jtc {
    840   1.3     lukem 	struct monster Othermonster;	/* to find a name for mimics */
    841   1.1       jtc 
    842   1.3     lukem 	which = MIN(which, 99);	/* make sure within range */
    843   1.1       jtc 
    844   1.3     lukem 	/* fill structure */
    845   1.5       jsm 	fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
    846   1.3     lukem 	fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
    847   1.1       jtc 
    848   1.3     lukem 	/* handle some special monsters */
    849   1.3     lukem 	if (Curmonster.m_type == SM_MODNAR) {
    850   1.3     lukem 		if (Player.p_specialtype < SC_COUNCIL)
    851   1.3     lukem 			/* randomize some stats */
    852   1.3     lukem 		{
    853   1.3     lukem 			Curmonster.m_strength *= drandom() + 0.5;
    854   1.3     lukem 			Curmonster.m_brains *= drandom() + 0.5;
    855   1.3     lukem 			Curmonster.m_speed *= drandom() + 0.5;
    856   1.3     lukem 			Curmonster.m_energy *= drandom() + 0.5;
    857   1.3     lukem 			Curmonster.m_experience *= drandom() + 0.5;
    858   1.3     lukem 			Curmonster.m_treasuretype =
    859   1.3     lukem 			    (int) ROLL(0.0, (double) Curmonster.m_treasuretype);
    860   1.3     lukem 		} else
    861   1.3     lukem 			/* make Modnar into Morgoth */
    862   1.3     lukem 		{
    863   1.3     lukem 			strcpy(Curmonster.m_name, "Morgoth");
    864   1.3     lukem 			Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4
    865   1.3     lukem 			    + drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;
    866   1.3     lukem 			Curmonster.m_brains = Player.p_brains;
    867   1.3     lukem 			Curmonster.m_energy = Player.p_might * 30.0;
    868   1.3     lukem 			Curmonster.m_type = SM_MORGOTH;
    869   1.3     lukem 			Curmonster.m_speed = Player.p_speed * 1.1
    870   1.6  jdolecek 			    + ((Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0);
    871   1.3     lukem 			Curmonster.m_flock = 0.0;
    872   1.3     lukem 			Curmonster.m_treasuretype = 0;
    873   1.3     lukem 			Curmonster.m_experience = 0.0;
    874   1.3     lukem 		}
    875   1.3     lukem 	} else
    876   1.3     lukem 		if (Curmonster.m_type == SM_MIMIC)
    877   1.3     lukem 			/* pick another name */
    878   1.3     lukem 		{
    879   1.3     lukem 			which = (int) ROLL(0.0, 100.0);
    880   1.5       jsm 			fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
    881   1.3     lukem 			fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
    882   1.3     lukem 			strcpy(Curmonster.m_name, Othermonster.m_name);
    883   1.3     lukem 		}
    884   1.3     lukem 	truncstring(Curmonster.m_name);
    885   1.1       jtc 
    886   1.3     lukem 	if (Curmonster.m_type != SM_MORGOTH)
    887   1.3     lukem 		/* adjust stats based on which circle player is in */
    888   1.1       jtc 	{
    889   1.3     lukem 		Curmonster.m_strength *= (1.0 + Circle / 2.0);
    890   1.3     lukem 		Curmonster.m_brains *= Circle;
    891   1.3     lukem 		Curmonster.m_speed += Circle * 1.e-9;
    892   1.3     lukem 		Curmonster.m_energy *= Circle;
    893   1.3     lukem 		Curmonster.m_experience *= Circle;
    894   1.1       jtc 	}
    895   1.3     lukem 	if (Player.p_blindness)
    896   1.3     lukem 		/* cannot see monster if blind */
    897   1.3     lukem 		Enemyname = "A monster";
    898   1.3     lukem 	else
    899   1.3     lukem 		Enemyname = Curmonster.m_name;
    900   1.1       jtc 
    901   1.3     lukem 	if (Player.p_speed <= 0.0)
    902   1.3     lukem 		/* make Player.p_speed positive */
    903   1.1       jtc 	{
    904   1.3     lukem 		Curmonster.m_speed += -Player.p_speed;
    905   1.3     lukem 		Player.p_speed = 1.0;
    906   1.1       jtc 	}
    907   1.3     lukem 	/* fill up the rest of the structure */
    908   1.3     lukem 	Curmonster.m_o_strength = Curmonster.m_strength;
    909   1.3     lukem 	Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed;
    910   1.3     lukem 	Curmonster.m_o_energy = Curmonster.m_energy;
    911   1.3     lukem 	Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
    912   1.1       jtc }
    913   1.1       jtc 
    914   1.3     lukem void
    915   1.1       jtc awardtreasure()
    916   1.1       jtc {
    917   1.3     lukem 	int     whichtreasure;	/* calculated treasure to grant */
    918   1.3     lukem 	int     temp;		/* temporary */
    919   1.3     lukem 	int     ch;		/* input */
    920   1.3     lukem 	double  treasuretype;	/* monster's treasure type */
    921   1.3     lukem 	double  gold = 0.0;	/* gold awarded */
    922   1.3     lukem 	double  gems = 0.0;	/* gems awarded */
    923   1.3     lukem 	double  dtemp;		/* for temporary calculations */
    924   1.3     lukem 
    925   1.3     lukem 	whichtreasure = (int) ROLL(1.0, 3.0);	/* pick a treasure */
    926   1.3     lukem 	treasuretype = (double) Curmonster.m_treasuretype;
    927   1.3     lukem 
    928   1.3     lukem 	move(4, 0);
    929   1.3     lukem 	clrtobot();
    930   1.3     lukem 	move(6, 0);
    931   1.1       jtc 
    932   1.3     lukem 	if (drandom() > 0.65)
    933   1.3     lukem 		/* gold and gems */
    934   1.1       jtc 	{
    935   1.3     lukem 		if (Curmonster.m_treasuretype > 7)
    936   1.3     lukem 			/* gems */
    937   1.3     lukem 		{
    938   1.3     lukem 			gems = ROLL(1.0, (treasuretype - 7.0)
    939   1.3     lukem 			    * (treasuretype - 7.0) * (Circle - 1.0) / 4.0);
    940   1.3     lukem 			printw("You have discovered %.0f gems!", gems);
    941   1.3     lukem 		} else
    942   1.3     lukem 			/* gold */
    943   1.1       jtc 		{
    944   1.3     lukem 			gold = ROLL(treasuretype * 10.0, treasuretype
    945   1.3     lukem 			    * treasuretype * 10.0 * (Circle - 1.0));
    946   1.3     lukem 			printw("You have found %.0f gold pieces.", gold);
    947   1.1       jtc 		}
    948   1.1       jtc 
    949   1.3     lukem 		addstr("  Do you want to pick them up ? ");
    950   1.3     lukem 		ch = getanswer("NY", FALSE);
    951   1.3     lukem 		addstr("\n\n");
    952   1.3     lukem 
    953   1.4     veego 		if (ch == 'Y') {
    954   1.3     lukem 			if (drandom() < treasuretype / 35.0 + 0.04)
    955   1.3     lukem 				/* cursed */
    956   1.3     lukem 			{
    957   1.3     lukem 				addstr("They were cursed!\n");
    958   1.3     lukem 				cursedtreasure();
    959   1.3     lukem 			} else
    960   1.3     lukem 				collecttaxes(gold, gems);
    961   1.4     veego 		}
    962   1.1       jtc 
    963   1.1       jtc 		return;
    964   1.3     lukem 	} else
    965   1.3     lukem 		/* other treasures */
    966   1.3     lukem 	{
    967   1.3     lukem 		addstr("You have found some treasure.  Do you want to inspect it ? ");
    968   1.3     lukem 		ch = getanswer("NY", FALSE);
    969   1.3     lukem 		addstr("\n\n");
    970   1.1       jtc 
    971   1.3     lukem 		if (ch != 'Y')
    972   1.3     lukem 			return;
    973   1.3     lukem 		else
    974   1.3     lukem 			if (drandom() < 0.08 && Curmonster.m_treasuretype != 4) {
    975   1.3     lukem 				addstr("It was cursed!\n");
    976   1.3     lukem 				cursedtreasure();
    977   1.3     lukem 				return;
    978   1.3     lukem 			} else
    979   1.3     lukem 				switch (Curmonster.m_treasuretype) {
    980   1.3     lukem 				case 1:	/* treasure type 1 */
    981   1.3     lukem 					switch (whichtreasure) {
    982   1.3     lukem 					case 1:
    983   1.3     lukem 						addstr("You've discovered a power booster!\n");
    984   1.3     lukem 						Player.p_mana += ROLL(Circle * 4.0, Circle * 30.0);
    985   1.3     lukem 						break;
    986   1.3     lukem 
    987   1.3     lukem 					case 2:
    988   1.3     lukem 						addstr("You have encountered a druid.\n");
    989   1.3     lukem 						Player.p_experience +=
    990   1.3     lukem 						    ROLL(0.0, 2000.0 + Circle * 400.0);
    991   1.3     lukem 						break;
    992   1.3     lukem 
    993   1.3     lukem 					case 3:
    994   1.3     lukem 						addstr("You have found a holy orb.\n");
    995   1.3     lukem 						Player.p_sin = MAX(0.0, Player.p_sin - 0.25);
    996   1.3     lukem 						break;
    997   1.3     lukem 					}
    998   1.3     lukem 					break;
    999   1.3     lukem 					/* end treasure type 1 */
   1000   1.1       jtc 
   1001   1.3     lukem 				case 2:	/* treasure type 2 */
   1002   1.3     lukem 					switch (whichtreasure) {
   1003   1.3     lukem 					case 1:
   1004   1.3     lukem 						addstr("You have found an amulet.\n");
   1005   1.3     lukem 						++Player.p_amulets;
   1006   1.3     lukem 						break;
   1007   1.3     lukem 
   1008   1.3     lukem 					case 2:
   1009   1.3     lukem 						addstr("You've found some holy water!\n");
   1010   1.3     lukem 						++Player.p_holywater;
   1011   1.3     lukem 						break;
   1012   1.3     lukem 
   1013   1.3     lukem 					case 3:
   1014   1.3     lukem 						addstr("You've met a hermit!\n");
   1015   1.3     lukem 						Player.p_sin *= 0.75;
   1016   1.3     lukem 						Player.p_mana += 12.0 * Circle;
   1017   1.3     lukem 						break;
   1018   1.3     lukem 					}
   1019   1.3     lukem 					break;
   1020   1.3     lukem 					/* end treasure type 2 */
   1021   1.1       jtc 
   1022   1.3     lukem 				case 3:	/* treasure type 3 */
   1023   1.3     lukem 					switch (whichtreasure) {
   1024   1.3     lukem 					case 1:
   1025   1.3     lukem 						dtemp = ROLL(7.0, 30.0 + Circle / 10.0);
   1026   1.3     lukem 						printw("You've found a +%.0f shield!\n", dtemp);
   1027   1.3     lukem 						if (dtemp >= Player.p_shield)
   1028   1.3     lukem 							Player.p_shield = dtemp;
   1029   1.3     lukem 						else
   1030   1.3     lukem 							SOMEBETTER();
   1031   1.3     lukem 						break;
   1032   1.3     lukem 
   1033   1.3     lukem 					case 2:
   1034   1.3     lukem 						addstr("You have rescued a virgin.  Will you be honorable ? ");
   1035   1.3     lukem 						ch = getanswer("NY", FALSE);
   1036   1.3     lukem 						addstr("\n\n");
   1037   1.3     lukem 						if (ch == 'Y')
   1038   1.3     lukem 							Player.p_virgin = TRUE;
   1039   1.3     lukem 						else {
   1040   1.3     lukem 							Player.p_experience += 2000.0 * Circle;
   1041   1.3     lukem 							++Player.p_sin;
   1042   1.3     lukem 						}
   1043   1.3     lukem 						break;
   1044   1.3     lukem 
   1045   1.3     lukem 					case 3:
   1046   1.3     lukem 						addstr("You've discovered some athelas!\n");
   1047   1.3     lukem 						--Player.p_poison;
   1048   1.3     lukem 						break;
   1049   1.3     lukem 					}
   1050   1.3     lukem 					break;
   1051   1.3     lukem 					/* end treasure type 3 */
   1052   1.1       jtc 
   1053   1.3     lukem 				case 4:	/* treasure type 4 */
   1054   1.3     lukem 					addstr("You've found a scroll.  Will you read it ? ");
   1055   1.3     lukem 					ch = getanswer("NY", FALSE);
   1056   1.3     lukem 					addstr("\n\n");
   1057   1.3     lukem 
   1058   1.3     lukem 					if (ch == 'Y')
   1059   1.3     lukem 						switch ((int) ROLL(1, 6)) {
   1060   1.3     lukem 						case 1:
   1061   1.3     lukem 							addstr("It throws up a shield for you next monster.\n");
   1062   1.3     lukem 							getyx(stdscr, whichtreasure, ch);
   1063   1.3     lukem 							more(whichtreasure);
   1064   1.3     lukem 							Shield =
   1065   1.3     lukem 							    (Player.p_maxenergy + Player.p_energy) * 5.5 + Circle * 50.0;
   1066   1.3     lukem 							Whichmonster = pickmonster();
   1067   1.3     lukem 							longjmp(Fightenv, 0);
   1068   1.3     lukem 							/* NOTREACHED */
   1069   1.3     lukem 
   1070   1.3     lukem 						case 2:
   1071   1.3     lukem 							addstr("It makes you invisible for you next monster.\n");
   1072   1.3     lukem 							getyx(stdscr, whichtreasure, ch);
   1073   1.3     lukem 							more(whichtreasure);
   1074   1.3     lukem 							Player.p_speed = 1e6;
   1075   1.3     lukem 							Whichmonster = pickmonster();
   1076   1.3     lukem 							longjmp(Fightenv, 0);
   1077   1.3     lukem 							/* NOTREACHED */
   1078   1.3     lukem 
   1079   1.3     lukem 						case 3:
   1080   1.3     lukem 							addstr("It increases your strength ten fold to fight your next monster.\n");
   1081   1.3     lukem 							getyx(stdscr, whichtreasure, ch);
   1082   1.3     lukem 							more(whichtreasure);
   1083   1.3     lukem 							Player.p_might *= 10.0;
   1084   1.3     lukem 							Whichmonster = pickmonster();
   1085   1.3     lukem 							longjmp(Fightenv, 0);
   1086   1.3     lukem 							/* NOTREACHED */
   1087   1.3     lukem 
   1088   1.3     lukem 						case 4:
   1089   1.3     lukem 							addstr("It is a general knowledge scroll.\n");
   1090   1.3     lukem 							Player.p_brains += ROLL(2.0, Circle);
   1091   1.3     lukem 							Player.p_magiclvl += ROLL(1.0, Circle / 2.0);
   1092   1.3     lukem 							break;
   1093   1.3     lukem 
   1094   1.3     lukem 						case 5:
   1095   1.3     lukem 							addstr("It tells you how to pick your next monster.\n");
   1096   1.3     lukem 							addstr("Which monster do you want [0-99] ? ");
   1097   1.3     lukem 							Whichmonster = (int) infloat();
   1098   1.3     lukem 							Whichmonster = MIN(99, MAX(0, Whichmonster));
   1099   1.3     lukem 							longjmp(Fightenv, 0);
   1100   1.3     lukem 
   1101   1.3     lukem 						case 6:
   1102   1.3     lukem 							addstr("It was cursed!\n");
   1103   1.3     lukem 							cursedtreasure();
   1104   1.3     lukem 							break;
   1105   1.3     lukem 						}
   1106   1.3     lukem 					break;
   1107   1.3     lukem 					/* end treasure type 4 */
   1108   1.1       jtc 
   1109   1.3     lukem 				case 5:	/* treasure type 5 */
   1110   1.3     lukem 					switch (whichtreasure) {
   1111   1.3     lukem 					case 1:
   1112   1.3     lukem 						dtemp = ROLL(Circle / 4.0 + 5.0, Circle / 2.0 + 9.0);
   1113   1.3     lukem 						printw("You've discovered a +%.0f dagger.\n", dtemp);
   1114   1.3     lukem 						if (dtemp >= Player.p_sword)
   1115   1.3     lukem 							Player.p_sword = dtemp;
   1116   1.3     lukem 						else
   1117   1.3     lukem 							SOMEBETTER();
   1118   1.3     lukem 						break;
   1119   1.3     lukem 
   1120   1.3     lukem 					case 2:
   1121   1.3     lukem 						dtemp = ROLL(7.5 + Circle * 3.0, Circle * 2.0 + 160.0);
   1122   1.3     lukem 						printw("You have found some +%.0f armour!\n", dtemp);
   1123   1.3     lukem 						if (dtemp >= Player.p_shield)
   1124   1.3     lukem 							Player.p_shield = dtemp;
   1125   1.3     lukem 						else
   1126   1.3     lukem 							SOMEBETTER();
   1127   1.3     lukem 						break;
   1128   1.3     lukem 
   1129   1.3     lukem 					case 3:
   1130   1.3     lukem 						addstr("You've found a tablet.\n");
   1131   1.3     lukem 						Player.p_brains += 4.5 * Circle;
   1132   1.3     lukem 						break;
   1133   1.3     lukem 					}
   1134   1.3     lukem 					break;
   1135   1.3     lukem 					/* end treasure type 5 */
   1136   1.1       jtc 
   1137   1.3     lukem 				case 6:	/* treasure type 6 */
   1138   1.3     lukem 					switch (whichtreasure) {
   1139   1.3     lukem 					case 1:
   1140   1.3     lukem 						addstr("You've found a priest.\n");
   1141   1.3     lukem 						Player.p_energy = Player.p_maxenergy + Player.p_shield;
   1142   1.3     lukem 						Player.p_sin /= 2.0;
   1143   1.3     lukem 						Player.p_mana += 24.0 * Circle;
   1144   1.3     lukem 						Player.p_brains += Circle;
   1145   1.3     lukem 						break;
   1146   1.3     lukem 
   1147   1.3     lukem 					case 2:
   1148   1.3     lukem 						addstr("You have come upon Robin Hood!\n");
   1149   1.3     lukem 						Player.p_shield += Circle * 2.0;
   1150   1.3     lukem 						Player.p_strength += Circle / 2.5 + 1.0;
   1151   1.3     lukem 						break;
   1152   1.3     lukem 
   1153   1.3     lukem 					case 3:
   1154   1.3     lukem 						dtemp = ROLL(2.0 + Circle / 4.0, Circle / 1.2 + 10.0);
   1155   1.3     lukem 						printw("You have found a +%.0f axe!\n", dtemp);
   1156   1.3     lukem 						if (dtemp >= Player.p_sword)
   1157   1.3     lukem 							Player.p_sword = dtemp;
   1158   1.3     lukem 						else
   1159   1.3     lukem 							SOMEBETTER();
   1160   1.3     lukem 						break;
   1161   1.3     lukem 					}
   1162   1.3     lukem 					break;
   1163   1.3     lukem 					/* end treasure type 6 */
   1164   1.1       jtc 
   1165   1.3     lukem 				case 7:	/* treasure type 7 */
   1166   1.3     lukem 					switch (whichtreasure) {
   1167   1.3     lukem 					case 1:
   1168   1.3     lukem 						addstr("You've discovered a charm!\n");
   1169   1.3     lukem 						++Player.p_charms;
   1170   1.3     lukem 						break;
   1171   1.3     lukem 
   1172   1.3     lukem 					case 2:
   1173   1.3     lukem 						addstr("You have encountered Merlyn!\n");
   1174   1.3     lukem 						Player.p_brains += Circle + 5.0;
   1175   1.3     lukem 						Player.p_magiclvl += Circle / 3.0 + 5.0;
   1176   1.3     lukem 						Player.p_mana += Circle * 10.0;
   1177   1.3     lukem 						break;
   1178   1.3     lukem 
   1179   1.3     lukem 					case 3:
   1180   1.3     lukem 						dtemp = ROLL(5.0 + Circle / 3.0, Circle / 1.5 + 20.0);
   1181   1.3     lukem 						printw("You have found a +%.0f war hammer!\n", dtemp);
   1182   1.3     lukem 						if (dtemp >= Player.p_sword)
   1183   1.3     lukem 							Player.p_sword = dtemp;
   1184   1.3     lukem 						else
   1185   1.3     lukem 							SOMEBETTER();
   1186   1.3     lukem 						break;
   1187   1.3     lukem 					}
   1188   1.3     lukem 					break;
   1189   1.3     lukem 					/* end treasure type 7 */
   1190   1.1       jtc 
   1191   1.3     lukem 				case 8:	/* treasure type 8 */
   1192   1.3     lukem 					switch (whichtreasure) {
   1193   1.3     lukem 					case 1:
   1194   1.3     lukem 						addstr("You have found a healing potion.\n");
   1195   1.3     lukem 						Player.p_poison = MIN(-2.0, Player.p_poison - 2.0);
   1196   1.3     lukem 						break;
   1197   1.3     lukem 
   1198   1.3     lukem 					case 2:
   1199   1.3     lukem 						addstr("You have discovered a transporter.  Do you wish to go anywhere ? ");
   1200   1.3     lukem 						ch = getanswer("NY", FALSE);
   1201   1.3     lukem 						addstr("\n\n");
   1202   1.3     lukem 						if (ch == 'Y') {
   1203   1.3     lukem 							double  x, y;
   1204   1.3     lukem 
   1205   1.3     lukem 							addstr("X Y Coordinates ? ");
   1206   1.3     lukem 							getstring(Databuf, SZ_DATABUF);
   1207   1.3     lukem 							sscanf(Databuf, "%lf %lf", &x, &y);
   1208   1.3     lukem 							altercoordinates(x, y, A_FORCED);
   1209   1.3     lukem 						}
   1210   1.3     lukem 						break;
   1211   1.3     lukem 
   1212   1.3     lukem 					case 3:
   1213   1.3     lukem 						dtemp = ROLL(10.0 + Circle / 1.2, Circle * 3.0 + 30.0);
   1214   1.3     lukem 						printw("You've found a +%.0f sword!\n", dtemp);
   1215   1.3     lukem 						if (dtemp >= Player.p_sword)
   1216   1.3     lukem 							Player.p_sword = dtemp;
   1217   1.3     lukem 						else
   1218   1.3     lukem 							SOMEBETTER();
   1219   1.3     lukem 						break;
   1220   1.3     lukem 					}
   1221   1.3     lukem 					break;
   1222   1.3     lukem 					/* end treasure type 8 */
   1223   1.1       jtc 
   1224   1.3     lukem 				case 10:
   1225   1.3     lukem 				case 11:
   1226   1.3     lukem 				case 12:
   1227   1.3     lukem 				case 13:	/* treasure types 10 - 13 */
   1228   1.3     lukem 					if (drandom() < 0.33) {
   1229   1.3     lukem 						if (Curmonster.m_treasuretype == 10) {
   1230   1.3     lukem 							addstr("You've found a pair of elven boots!\n");
   1231   1.3     lukem 							Player.p_quickness += 2.0;
   1232   1.3     lukem 							break;
   1233   1.3     lukem 						} else
   1234   1.3     lukem 							if (Curmonster.m_treasuretype == 11
   1235   1.3     lukem 							    && !Player.p_palantir) {
   1236   1.3     lukem 								addstr("You've acquired Saruman's palantir.\n");
   1237   1.3     lukem 								Player.p_palantir = TRUE;
   1238   1.3     lukem 								break;
   1239   1.3     lukem 							} else
   1240   1.3     lukem 								if (Player.p_ring.ring_type == R_NONE
   1241   1.3     lukem 								    && Player.p_specialtype < SC_COUNCIL
   1242   1.3     lukem 								    && (Curmonster.m_treasuretype == 12
   1243   1.3     lukem 									|| Curmonster.m_treasuretype == 13))
   1244   1.3     lukem 									/* roll
   1245   1.3     lukem 									 *  up
   1246   1.3     lukem 									 * a
   1247   1.3     lukem 									 * ring
   1248   1.3     lukem 									 *  */
   1249   1.3     lukem 								{
   1250   1.3     lukem 									if (drandom() < 0.8)
   1251   1.3     lukem 										/* r
   1252   1.3     lukem 										 * e
   1253   1.3     lukem 										 * g
   1254   1.3     lukem 										 * u
   1255   1.3     lukem 										 * l
   1256   1.3     lukem 										 * a
   1257   1.3     lukem 										 * r
   1258   1.3     lukem 										 *
   1259   1.3     lukem 										 * ri
   1260   1.3     lukem 										 * n
   1261   1.3     lukem 										 * g
   1262   1.3     lukem 										 * s
   1263   1.3     lukem 										 *  */
   1264   1.3     lukem 									{
   1265   1.3     lukem 										if (Curmonster.m_treasuretype == 12) {
   1266   1.3     lukem 											whichtreasure = R_NAZREG;
   1267   1.3     lukem 											temp = 35;
   1268   1.3     lukem 										} else {
   1269   1.3     lukem 											whichtreasure = R_DLREG;
   1270   1.3     lukem 											temp = 0;
   1271   1.3     lukem 										}
   1272   1.3     lukem 									} else
   1273   1.3     lukem 										/* b
   1274   1.3     lukem 										 * a
   1275   1.3     lukem 										 * d
   1276   1.3     lukem 										 *
   1277   1.3     lukem 										 * ri
   1278   1.3     lukem 										 * n
   1279   1.3     lukem 										 * g
   1280   1.3     lukem 										 * s
   1281   1.3     lukem 										 *  */
   1282   1.3     lukem 									{
   1283   1.3     lukem 										whichtreasure = R_BAD;
   1284   1.3     lukem 										temp = 15 + Statptr->c_ringduration + (int) ROLL(0, 5);
   1285   1.3     lukem 									}
   1286   1.3     lukem 
   1287   1.3     lukem 									addstr("You've discovered a ring.  Will you pick it up ? ");
   1288   1.3     lukem 									ch = getanswer("NY", FALSE);
   1289   1.3     lukem 									addstr("\n\n");
   1290   1.3     lukem 
   1291   1.3     lukem 									if (ch == 'Y') {
   1292   1.3     lukem 										Player.p_ring.ring_type = whichtreasure;
   1293   1.3     lukem 										Player.p_ring.ring_duration = temp;
   1294   1.3     lukem 									}
   1295   1.3     lukem 									break;
   1296   1.3     lukem 								}
   1297   1.1       jtc 					}
   1298   1.3     lukem 					/* end treasure types 10 - 13 */
   1299   1.3     lukem 					/* fall through to treasure type 9 if
   1300   1.3     lukem 					 * no treasure from above */
   1301   1.3     lukem 
   1302   1.3     lukem 				case 9:	/* treasure type 9 */
   1303   1.3     lukem 					switch (whichtreasure) {
   1304   1.3     lukem 					case 1:
   1305   1.3     lukem 						if (Player.p_level <= 1000.0
   1306   1.3     lukem 						    && Player.p_crowns <= 3
   1307   1.3     lukem 						    && Player.p_level >= 10.0) {
   1308   1.3     lukem 							addstr("You have found a golden crown!\n");
   1309   1.3     lukem 							++Player.p_crowns;
   1310   1.3     lukem 							break;
   1311   1.3     lukem 						}
   1312   1.3     lukem 						/* fall through otherwise */
   1313   1.3     lukem 
   1314   1.3     lukem 					case 2:
   1315   1.3     lukem 						addstr("You've been blessed!\n");
   1316   1.3     lukem 						Player.p_blessing = TRUE;
   1317   1.3     lukem 						Player.p_sin /= 3.0;
   1318   1.3     lukem 						Player.p_energy = Player.p_maxenergy + Player.p_shield;
   1319   1.3     lukem 						Player.p_mana += 100.0 * Circle;
   1320   1.3     lukem 						break;
   1321   1.3     lukem 
   1322   1.3     lukem 					case 3:
   1323   1.3     lukem 						dtemp = ROLL(1.0, Circle / 5.0 + 5.0);
   1324   1.3     lukem 						dtemp = MIN(dtemp, 99.0);
   1325   1.3     lukem 						printw("You have discovered some +%.0f quicksilver!\n", dtemp);
   1326   1.3     lukem 						if (dtemp >= Player.p_quksilver)
   1327   1.3     lukem 							Player.p_quksilver = dtemp;
   1328   1.3     lukem 						else
   1329   1.3     lukem 							SOMEBETTER();
   1330   1.3     lukem 						break;
   1331   1.1       jtc 					}
   1332   1.1       jtc 					break;
   1333   1.3     lukem 					/* end treasure type 9 */
   1334   1.1       jtc 				}
   1335   1.1       jtc 	}
   1336   1.1       jtc }
   1337   1.1       jtc 
   1338   1.3     lukem void
   1339   1.1       jtc cursedtreasure()
   1340   1.1       jtc {
   1341   1.3     lukem 	if (Player.p_charms > 0) {
   1342   1.3     lukem 		addstr("But your charm saved you!\n");
   1343   1.3     lukem 		--Player.p_charms;
   1344   1.3     lukem 	} else
   1345   1.3     lukem 		if (Player.p_amulets > 0) {
   1346   1.3     lukem 			addstr("But your amulet saved you!\n");
   1347   1.3     lukem 			--Player.p_amulets;
   1348   1.3     lukem 		} else {
   1349   1.3     lukem 			Player.p_energy =
   1350   1.3     lukem 			    (Player.p_maxenergy + Player.p_shield) / 10.0;
   1351   1.3     lukem 			Player.p_poison += 0.25;
   1352   1.3     lukem 		}
   1353   1.1       jtc }
   1354   1.1       jtc 
   1355   1.3     lukem void
   1356   1.1       jtc scramblestats()
   1357   1.1       jtc {
   1358   1.3     lukem 	double  dbuf[6];	/* to put statistic in */
   1359   1.3     lukem 	double  dtemp1, dtemp2;	/* for swapping values */
   1360   1.3     lukem 	int first, second;	/* indices for swapping */
   1361   1.3     lukem 	double *dptr;		/* pointer for filling and emptying buf[] */
   1362   1.3     lukem 
   1363   1.3     lukem 	/* fill buffer */
   1364   1.3     lukem 	dptr = &dbuf[0];
   1365   1.3     lukem 	*dptr++ = Player.p_strength;
   1366   1.3     lukem 	*dptr++ = Player.p_mana;
   1367   1.3     lukem 	*dptr++ = Player.p_brains;
   1368   1.3     lukem 	*dptr++ = Player.p_magiclvl;
   1369   1.3     lukem 	*dptr++ = Player.p_energy;
   1370   1.3     lukem 	*dptr = Player.p_sin;
   1371   1.3     lukem 
   1372   1.3     lukem 	/* pick values to swap */
   1373   1.3     lukem 	first = (int) ROLL(0, 5);
   1374   1.3     lukem 	second = (int) ROLL(0, 5);
   1375   1.3     lukem 
   1376   1.3     lukem 	/* swap values */
   1377   1.3     lukem 	dptr = &dbuf[0];
   1378   1.3     lukem 	dtemp1 = dptr[first];
   1379   1.3     lukem 	/* this expression is split to prevent a compiler loop on some
   1380   1.3     lukem 	 * compilers */
   1381   1.3     lukem 	dtemp2 = dptr[second];
   1382   1.3     lukem 	dptr[first] = dtemp2;
   1383   1.3     lukem 	dptr[second] = dtemp1;
   1384   1.3     lukem 
   1385   1.3     lukem 	/* empty buffer */
   1386   1.3     lukem 	Player.p_strength = *dptr++;
   1387   1.3     lukem 	Player.p_mana = *dptr++;
   1388   1.3     lukem 	Player.p_brains = *dptr++;
   1389   1.3     lukem 	Player.p_magiclvl = *dptr++;
   1390   1.3     lukem 	Player.p_energy = *dptr++;
   1391   1.3     lukem 	Player.p_sin = *dptr;
   1392   1.1       jtc }
   1393