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