Home | History | Annotate | Line # | Download | only in phantasia
interplayer.c revision 1.11
      1 /*	$NetBSD: interplayer.c,v 1.11 2009/08/12 08:21:41 dholland Exp $	*/
      2 
      3 /*
      4  * interplayer.c - player to player routines for Phantasia
      5  */
      6 
      7 #include "include.h"
      8 #undef bool
      9 #include <curses.h>
     10 
     11 static long allocvoid(void);
     12 static void battleplayer(long);
     13 static void myturn(void);
     14 static void tampered(int, double, double);
     15 
     16 void
     17 checkbattle(void)
     18 {
     19 	long    foeloc = 0L;	/* location in file of person to fight */
     20 
     21 	Users = 0;
     22 	fseek(Playersfp, 0L, SEEK_SET);
     23 
     24 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
     25 		if (Other.p_status != S_OFF
     26 		    && Other.p_status != S_NOTUSED
     27 		    && Other.p_status != S_HUNGUP
     28 		    && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR))
     29 			/* player is on and not a cloaked valar */
     30 		{
     31 			++Users;
     32 
     33 			if (Player.p_x == Other.p_x
     34 			    && Player.p_y == Other.p_y
     35 			/* same coordinates */
     36 			    && foeloc != Fileloc
     37 			/* not self */
     38 			    && Player.p_status == S_PLAYING
     39 			    && (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE)
     40 			/* both are playing */
     41 			    && Other.p_specialtype != SC_VALAR
     42 			    && Player.p_specialtype != SC_VALAR)
     43 				/* neither is valar */
     44 			{
     45 				battleplayer(foeloc);
     46 				return;
     47 			}
     48 		}
     49 		foeloc += SZ_PLAYERSTRUCT;
     50 	}
     51 }
     52 
     53 static void
     54 battleplayer(long foeplace)
     55 {
     56 	double  dtemp;		/* for temporary calculations */
     57 	double  oldhits = 0.0;	/* previous damage inflicted by foe */
     58 	int     loop;		/* for timing out */
     59 	int     ch;		/* input */
     60 	short   oldtampered;	/* old value of foe's p_tampered */
     61 
     62 	Lines = 8;
     63 	Luckout = FALSE;
     64 	mvaddstr(4, 0, "Preparing for battle!\n");
     65 	refresh();
     66 
     67 #ifdef SYS5
     68 	flushinp();
     69 #endif
     70 
     71 	/* set up variables, file, etc. */
     72 	Player.p_status = S_INBATTLE;
     73 	Shield = Player.p_energy;
     74 
     75 	/* if p_tampered is not 0, someone else may try to change it (king,
     76 	 * etc.) */
     77 	Player.p_tampered = oldtampered = 1;
     78 	Player.p_1scratch = 0.0;
     79 	Player.p_istat = I_OFF;
     80 
     81 	readrecord(&Other, foeplace);
     82 	if (fabs(Player.p_level - Other.p_level) > 20.0)
     83 		/* see if players are greatly mismatched */
     84 	{
     85 		dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level);
     86 		if (dtemp < -0.5)
     87 			/* foe outweighs this one */
     88 			Player.p_speed *= 2.0;
     89 	}
     90 	writerecord(&Player, Fileloc);	/* write out all our info */
     91 
     92 	if (Player.p_blindness)
     93 		Enemyname = "someone";
     94 	else
     95 		Enemyname = Other.p_name;
     96 
     97 	mvprintw(6, 0, "You have encountered %s   Level: %.0f\n", Enemyname, Other.p_level);
     98 	refresh();
     99 
    100 	for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop)
    101 		/* wait for foe to respond */
    102 	{
    103 		readrecord(&Other, foeplace);
    104 		sleep(1);
    105 	}
    106 
    107 	if (Other.p_status != S_INBATTLE)
    108 		/* foe did not respond */
    109 	{
    110 		mvprintw(5, 0, "%s is not responding.\n", Enemyname);
    111 		goto LEAVE;
    112 	}
    113 	/* else, we are ready to battle */
    114 
    115 	move(4, 0);
    116 	clrtoeol();
    117 
    118 	/*
    119          * determine who is first master
    120          * if neither player is faster, check level
    121          * if neither level is greater, battle is not allowed
    122          * (this should never happen, but we have to handle it)
    123          */
    124 	if (Player.p_speed > Other.p_speed)
    125 		Foestrikes = FALSE;
    126 	else
    127 		if (Other.p_speed > Player.p_speed)
    128 			Foestrikes = TRUE;
    129 		else
    130 			if (Player.p_level > Other.p_level)
    131 				Foestrikes = FALSE;
    132 			else
    133 				if (Other.p_level > Player.p_level)
    134 					Foestrikes = TRUE;
    135 				else
    136 					/* no one is faster */
    137 				{
    138 					printw("You can't fight %s yet.", Enemyname);
    139 					goto LEAVE;
    140 				}
    141 
    142 	for (;;) {
    143 		displaystats();
    144 		readmessage();
    145 		mvprintw(1, 26, "%20.0f", Shield);	/* overprint energy */
    146 
    147 		if (!Foestrikes)
    148 			/* take action against foe */
    149 			myturn();
    150 		else
    151 			/* wait for foe to take action */
    152 		{
    153 			mvaddstr(4, 0, "Waiting...\n");
    154 			clrtoeol();
    155 			refresh();
    156 
    157 			for (loop = 0; loop < 20; ++loop)
    158 				/* wait for foe to act */
    159 			{
    160 				readrecord(&Other, foeplace);
    161 				if (Other.p_1scratch != oldhits)
    162 					/* p_1scratch changes to indicate
    163 					 * action */
    164 					break;
    165 				else
    166 					/* wait and try again */
    167 				{
    168 					sleep(1);
    169 					addch('.');
    170 					refresh();
    171 				}
    172 			}
    173 
    174 			if (Other.p_1scratch == oldhits) {
    175 				/* timeout */
    176 				mvaddstr(22, 0, "Timeout: waiting for response.  Do you want to wait ? ");
    177 				ch = getanswer("NY", FALSE);
    178 				move(22, 0);
    179 				clrtobot();
    180 				if (ch == 'Y')
    181 					continue;
    182 				else
    183 					break;
    184 			} else
    185 				/* foe took action */
    186 			{
    187 				switch (Other.p_istat) {
    188 				case I_RAN:	/* foe ran away */
    189 					mvprintw(Lines++, 0, "%s ran away!", Enemyname);
    190 					break;
    191 
    192 				case I_STUCK:	/* foe tried to run, but
    193 						 * couldn't */
    194 					mvprintw(Lines++, 0, "%s tried to run away.", Enemyname);
    195 					break;
    196 
    197 				case I_BLEWIT:	/* foe tried to luckout, but
    198 						 * didn't */
    199 					mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname);
    200 					break;
    201 
    202 				default:
    203 					dtemp = Other.p_1scratch - oldhits;
    204 					mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp);
    205 					Shield -= dtemp;
    206 					break;
    207 				}
    208 
    209 				oldhits = Other.p_1scratch;	/* keep track of old
    210 								 * hits */
    211 
    212 				if (Other.p_tampered != oldtampered)
    213 					/* p_tampered changes to relinquish
    214 					 * turn */
    215 				{
    216 					oldtampered = Other.p_tampered;
    217 					Foestrikes = FALSE;
    218 				}
    219 			}
    220 		}
    221 
    222 		/* decide what happens next */
    223 		refresh();
    224 		if (Lines > LINES - 2) {
    225 			more(Lines);
    226 			move(Lines = 8, 0);
    227 			clrtobot();
    228 		}
    229 		if (Other.p_istat == I_KILLED || Shield < 0.0)
    230 			/* we died */
    231 		{
    232 			Shield = -2.0;	/* insure this value is negative */
    233 			break;
    234 		}
    235 		if (Player.p_istat == I_KILLED)
    236 			/* we killed foe; award treasre */
    237 		{
    238 			mvprintw(Lines++, 0, "You killed %s!", Enemyname);
    239 			Player.p_experience += Other.p_experience;
    240 			Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0;
    241 			Player.p_amulets += Other.p_amulets;
    242 			Player.p_charms += Other.p_charms;
    243 			collecttaxes(Other.p_gold, Other.p_gems);
    244 			Player.p_sword = MAX(Player.p_sword, Other.p_sword);
    245 			Player.p_shield = MAX(Player.p_shield, Other.p_shield);
    246 			Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver);
    247 			if (Other.p_virgin && !Player.p_virgin) {
    248 				mvaddstr(Lines++, 0, "You have rescued a virgin.  Will you be honorable ? ");
    249 				if ((ch = getanswer("YN", FALSE)) == 'Y')
    250 					Player.p_virgin = TRUE;
    251 				else {
    252 					++Player.p_sin;
    253 					Player.p_experience += 8000.0;
    254 				}
    255 			}
    256 			sleep(3);	/* give other person time to die */
    257 			break;
    258 		} else
    259 			if (Player.p_istat == I_RAN || Other.p_istat == I_RAN)
    260 				/* either player ran away */
    261 				break;
    262 	}
    263 
    264 LEAVE:
    265 	/* clean up things and leave */
    266 	writerecord(&Player, Fileloc);	/* update a final time */
    267 	altercoordinates(0.0, 0.0, A_NEAR);	/* move away from battle site */
    268 	Player.p_energy = Shield;	/* set energy to actual value */
    269 	Player.p_tampered = T_OFF;	/* clear p_tampered */
    270 
    271 	more(Lines);		/* pause */
    272 
    273 	move(4, 0);
    274 	clrtobot();		/* clear bottom area of screen */
    275 
    276 	if (Player.p_energy < 0.0)
    277 		/* we are dead */
    278 		death("Interterminal battle");
    279 }
    280 
    281 static void
    282 myturn(void)
    283 {
    284 	double  dtemp;		/* for temporary calculations */
    285 	int     ch;		/* input */
    286 
    287 	mvaddstr(7, 0, "1:Fight  2:Run Away!  3:Power Blast  ");
    288 	if (Luckout)
    289 		clrtoeol();
    290 	else
    291 		addstr("4:Luckout  ");
    292 
    293 	ch = inputoption();
    294 	move(Lines = 8, 0);
    295 	clrtobot();
    296 
    297 	switch (ch) {
    298 	default:		/* fight */
    299 		dtemp = ROLL(2.0, Player.p_might);
    300 HIT:
    301 		mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp);
    302 		Player.p_sin += 0.5;
    303 		Player.p_1scratch += dtemp;
    304 		Player.p_istat = I_OFF;
    305 		break;
    306 
    307 	case '2':		/* run away */
    308 		Player.p_1scratch -= 1.0;	/* change this to indicate
    309 						 * action */
    310 		if (drandom() > 0.25) {
    311 			mvaddstr(Lines++, 0, "You got away!");
    312 			Player.p_istat = I_RAN;
    313 		} else {
    314 			mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
    315 			Player.p_istat = I_STUCK;
    316 		}
    317 		break;
    318 
    319 	case '3':		/* power blast */
    320 		dtemp = MIN(Player.p_mana, Player.p_level * 5.0);
    321 		Player.p_mana -= dtemp;
    322 		dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0;
    323 		mvprintw(Lines++, 0, "You blasted %s !", Enemyname);
    324 		goto HIT;
    325 
    326 	case '4':		/* luckout */
    327 		if (Luckout || drandom() > 0.1) {
    328 			if (Luckout)
    329 				mvaddstr(Lines++, 0, "You already tried that!");
    330 			else {
    331 				mvaddstr(Lines++, 0, "Not this time . . .");
    332 				Luckout = TRUE;
    333 			}
    334 
    335 			Player.p_1scratch -= 1.0;
    336 			Player.p_istat = I_BLEWIT;
    337 		} else {
    338 			mvaddstr(Lines++, 0, "You just lucked out!");
    339 			Player.p_1scratch = Other.p_energy * 1.1;
    340 		}
    341 		break;
    342 	}
    343 
    344 	refresh();
    345 	Player.p_1scratch = floor(Player.p_1scratch);	/* clean up any mess */
    346 
    347 	if (Player.p_1scratch > Other.p_energy)
    348 		Player.p_istat = I_KILLED;
    349 	else
    350 		if (drandom() * Player.p_speed < drandom() * Other.p_speed)
    351 			/* relinquish control */
    352 		{
    353 			++Player.p_tampered;
    354 			Foestrikes = TRUE;
    355 		}
    356 	writerecord(&Player, Fileloc);	/* let foe know what we did */
    357 }
    358 
    359 void
    360 checktampered(void)
    361 {
    362 	long    loc = 0L;	/* location in energy void file */
    363 
    364 	/* first check for energy voids */
    365 	fseek(Energyvoidfp, 0L, SEEK_SET);
    366 	while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
    367 		if (Enrgyvoid.ev_active
    368 		    && Enrgyvoid.ev_x == Player.p_x
    369 		    && Enrgyvoid.ev_y == Player.p_y)
    370 			/* sitting on one */
    371 		{
    372 			if (loc > 0L)
    373 				/* not the holy grail; inactivate energy void */
    374 			{
    375 				Enrgyvoid.ev_active = FALSE;
    376 				writevoid(&Enrgyvoid, loc);
    377 				tampered(T_NRGVOID, 0.0, 0.0);
    378 			} else
    379 				if (Player.p_status != S_CLOAKED)
    380 					/* holy grail */
    381 					tampered(T_GRAIL, 0.0, 0.0);
    382 			break;
    383 		} else
    384 			loc += SZ_VOIDSTRUCT;
    385 
    386 	/* now check for other things */
    387 	readrecord(&Other, Fileloc);
    388 	if (Other.p_tampered != T_OFF)
    389 		tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch);
    390 }
    391 
    392 static void
    393 tampered(int what, double arg1, double arg2)
    394 {
    395 	long    loc;		/* location in file of other players */
    396 
    397 	Changed = TRUE;
    398 	move(4, 0);
    399 
    400 	Player.p_tampered = T_OFF;	/* no longer tampered with */
    401 
    402 	switch (what) {
    403 	case T_NRGVOID:
    404 		addstr("You've hit an energy void !\n");
    405 		Player.p_mana /= 3.0;
    406 		Player.p_energy /= 2.0;
    407 		Player.p_gold = floor(Player.p_gold / 1.25) + 0.1;
    408 		altercoordinates(0.0, 0.0, A_NEAR);
    409 		break;
    410 
    411 	case T_TRANSPORT:
    412 		addstr("The king transported you !  ");
    413 		if (Player.p_charms > 0) {
    414 			addstr("But your charm saved you. . .\n");
    415 			--Player.p_charms;
    416 		} else {
    417 			altercoordinates(0.0, 0.0, A_FAR);
    418 			addch('\n');
    419 		}
    420 		break;
    421 
    422 	case T_BESTOW:
    423 		printw("The king has bestowed %.0f gold pieces on you !\n", arg1);
    424 		Player.p_gold += arg1;
    425 		break;
    426 
    427 	case T_CURSED:
    428 		addstr("You've been cursed !  ");
    429 		if (Player.p_blessing) {
    430 			addstr("But your blessing saved you. . .\n");
    431 			Player.p_blessing = FALSE;
    432 		} else {
    433 			addch('\n');
    434 			Player.p_poison += 2.0;
    435 			Player.p_energy = 10.0;
    436 			Player.p_maxenergy *= 0.95;
    437 			Player.p_status = S_PLAYING;	/* no longer cloaked */
    438 		}
    439 		break;
    440 
    441 	case T_VAPORIZED:
    442 		addstr("You have been vaporized!\n");
    443 		more(7);
    444 		death("Vaporization");
    445 		break;
    446 
    447 	case T_MONSTER:
    448 		addstr("The Valar zapped you with a monster!\n");
    449 		more(7);
    450 		encounter((int) arg1);
    451 		return;
    452 
    453 	case T_BLESSED:
    454 		addstr("The Valar has blessed you!\n");
    455 		Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield;
    456 		Player.p_mana += 500.0;
    457 		Player.p_strength += 0.5;
    458 		Player.p_brains += 0.5;
    459 		Player.p_magiclvl += 0.5;
    460 		Player.p_poison = MIN(0.5, Player.p_poison);
    461 		break;
    462 
    463 	case T_RELOCATE:
    464 		addstr("You've been relocated. . .\n");
    465 		altercoordinates(arg1, arg2, A_FORCED);
    466 		break;
    467 
    468 	case T_HEAL:
    469 		addstr("You've been healed!\n");
    470 		Player.p_poison -= 0.25;
    471 		Player.p_energy = Player.p_maxenergy + Player.p_shield;
    472 		break;
    473 
    474 	case T_EXVALAR:
    475 		addstr("You are no longer Valar!\n");
    476 		Player.p_specialtype = SC_COUNCIL;
    477 		break;
    478 
    479 	case T_GRAIL:
    480 		addstr("You have found The Holy Grail!!\n");
    481 		if (Player.p_specialtype < SC_COUNCIL)
    482 			/* must be council of wise to behold grail */
    483 		{
    484 			addstr("However, you are not experienced enough to behold it.\n");
    485 			Player.p_sin *= Player.p_sin;
    486 			Player.p_mana += 1000;
    487 		} else
    488 			if (Player.p_specialtype == SC_VALAR
    489 			    || Player.p_specialtype == SC_EXVALAR) {
    490 				addstr("You have made it to the position of Valar once already.\n");
    491 				addstr("The Grail is of no more use to you now.\n");
    492 			} else {
    493 				addstr("It is now time to see if you are worthy to behold it. . .\n");
    494 				refresh();
    495 				sleep(4);
    496 
    497 				if (drandom() / 2.0 < Player.p_sin) {
    498 					addstr("You have failed!\n");
    499 					Player.p_strength =
    500 					    Player.p_mana =
    501 					    Player.p_energy =
    502 					    Player.p_maxenergy =
    503 					    Player.p_magiclvl =
    504 					    Player.p_brains =
    505 					    Player.p_experience =
    506 					    Player.p_quickness = 1.0;
    507 
    508 					altercoordinates(1.0, 1.0, A_FORCED);
    509 					Player.p_level = 0.0;
    510 				} else {
    511 					addstr("You made to position of Valar!\n");
    512 					Player.p_specialtype = SC_VALAR;
    513 					Player.p_lives = 5;
    514 					fseek(Playersfp, 0L, SEEK_SET);
    515 					loc = 0L;
    516 					while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    517 						/* search for existing valar */
    518 						if (Other.p_specialtype == SC_VALAR
    519 						    && Other.p_status != S_NOTUSED)
    520 							/* found old valar */
    521 						{
    522 							Other.p_tampered = T_EXVALAR;
    523 							writerecord(&Other, loc);
    524 							break;
    525 						} else
    526 							loc += SZ_PLAYERSTRUCT;
    527 				}
    528 			}
    529 
    530 		/* move grail to new location */
    531 		Enrgyvoid.ev_active = TRUE;
    532 		Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
    533 		Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
    534 		writevoid(&Enrgyvoid, 0L);
    535 		break;
    536 	}
    537 	refresh();
    538 	sleep(2);
    539 }
    540 
    541 void
    542 userlist(phbool ingameflag)
    543 {
    544 	int     numusers = 0;	/* number of users on file */
    545 
    546 	if (ingameflag && Player.p_blindness) {
    547 		mvaddstr(8, 0, "You cannot see anyone.\n");
    548 		return;
    549 	}
    550 	fseek(Playersfp, 0L, SEEK_SET);
    551 	mvaddstr(8, 0,
    552 	    "Name                         X         Y    Lvl Type Login    Status\n");
    553 
    554 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
    555 		if (Other.p_status == S_NOTUSED
    556 		/* record is unused */
    557 		    || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED))
    558 			/* cloaked valar */
    559 		{
    560 			if (!Wizard)
    561 				/* wizard can see everything on file */
    562 				continue;
    563 		}
    564 		++numusers;
    565 
    566 		if (ingameflag &&
    567 		/* must be playing for the rest of these conditions */
    568 		    (Player.p_specialtype >= SC_KING
    569 		/* kings and higher can see others */
    570 			|| Other.p_specialtype >= SC_KING
    571 		/* kings and higher can be seen by others */
    572 			|| Circle >= CIRCLE(Other.p_x, Other.p_y)
    573 		/* those nearer the origin can be seen */
    574 			|| Player.p_palantir)
    575 		/* palantir enables one to see others */
    576 		    && (Other.p_status != S_CLOAKED
    577 			|| (Player.p_specialtype == SC_VALAR && Player.p_palantir))
    578 		/* not cloaked; valar can see through cloak with a palantir */
    579 		    && Other.p_specialtype != SC_VALAR)
    580 			/* not a valar */
    581 			/* coordinates should be printed */
    582 			printw("%-20s  %8.0f  %8.0f ",
    583 			    Other.p_name, Other.p_x, Other.p_y);
    584 		else
    585 			/* cannot see player's coordinates */
    586 			printw("%-20s %19.19s ",
    587 			    Other.p_name, descrlocation(&Other, TRUE));
    588 
    589 		printw("%6.0f %s  %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE),
    590 		    Other.p_login, descrstatus(&Other));
    591 
    592 		if ((numusers % (LINES - 10)) == 0) {
    593 			more(LINES - 1);
    594 			move(9, 0);
    595 			clrtobot();
    596 		}
    597 	}
    598 
    599 	printw("Total players on file = %d\n", numusers);
    600 	refresh();
    601 }
    602 
    603 void
    604 throneroom(void)
    605 {
    606 	FILE   *fp;		/* to clear energy voids */
    607 	long    loc = 0L;	/* location of old king in player file */
    608 
    609 	if (Player.p_specialtype < SC_KING)
    610 		/* not already king -- assumes crown */
    611 	{
    612 		fseek(Playersfp, 0L, SEEK_SET);
    613 		while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    614 			if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
    615 				/* found old king */
    616 			{
    617 				if (Other.p_status != S_OFF)
    618 					/* old king is playing */
    619 				{
    620 					mvaddstr(4, 0, "The king is playing, so you cannot steal his throne\n");
    621 					altercoordinates(0.0, 0.0, A_NEAR);
    622 					move(6, 0);
    623 					return;
    624 				} else
    625 					/* old king is not playing - remove
    626 					 * him/her */
    627 				{
    628 					Other.p_specialtype = SC_NONE;
    629 					if (Other.p_crowns)
    630 						--Other.p_crowns;
    631 					writerecord(&Other, loc);
    632 					break;
    633 				}
    634 			} else
    635 				loc += SZ_PLAYERSTRUCT;
    636 
    637 		/* make player new king */
    638 		Changed = TRUE;
    639 		Player.p_specialtype = SC_KING;
    640 		mvaddstr(4, 0, "You have become king!\n");
    641 
    642 		/* let everyone else know */
    643 		fp = fopen(_PATH_MESS, "w");
    644 		fprintf(fp, "All hail the new king!");
    645 		fclose(fp);
    646 
    647 		/* clear all energy voids; retain location of holy grail */
    648 		fseek(Energyvoidfp, 0L, SEEK_SET);
    649 		fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
    650 		fp = fopen(_PATH_VOID, "w");
    651 		fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
    652 		fclose(fp);
    653 	}
    654 	mvaddstr(6, 0, "0:Decree  ");
    655 }
    656 
    657 void
    658 dotampered(void)
    659 {
    660 	short   tamper;		/* value for tampering with other players */
    661 	const char   *option;		/* pointer to option description */
    662 	double  temp1 = 0.0, temp2 = 0.0;	/* other tampering values */
    663 	int     ch;		/* input */
    664 	long    loc;		/* location in energy void file */
    665 	FILE   *fp;		/* for opening gold file */
    666 
    667 	move(6, 0);
    668 	clrtoeol();
    669 	if (Player.p_specialtype < SC_COUNCIL && !Wizard)
    670 		/* king options */
    671 	{
    672 		addstr("1:Transport  2:Curse  3:Energy Void  4:Bestow  5:Collect Taxes  ");
    673 
    674 		ch = getanswer(" ", TRUE);
    675 		move(6, 0);
    676 		clrtoeol();
    677 		move(4, 0);
    678 		switch (ch) {
    679 		case '1':	/* transport someone */
    680 			tamper = T_TRANSPORT;
    681 			option = "transport";
    682 			break;
    683 
    684 		case '2':	/* curse another */
    685 			tamper = T_CURSED;
    686 			option = "curse";
    687 			break;
    688 
    689 		case '3':	/* create energy void */
    690 			if ((loc = allocvoid()) > 20L * (long)SZ_VOIDSTRUCT)
    691 				/* can only have 20 void active at once */
    692 				mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
    693 			else {
    694 				addstr("Enter the X Y coordinates of void ? ");
    695 				getstring(Databuf, SZ_DATABUF);
    696 				sscanf(Databuf, "%lf %lf", &temp1, &temp2);
    697 				Enrgyvoid.ev_x = floor(temp1);
    698 				Enrgyvoid.ev_y = floor(temp2);
    699 				Enrgyvoid.ev_active = TRUE;
    700 				writevoid(&Enrgyvoid, loc);
    701 				mvaddstr(5, 0, "It is done.\n");
    702 			}
    703 			return;
    704 
    705 		case '4':	/* bestow gold to subject */
    706 			tamper = T_BESTOW;
    707 			addstr("How much gold to bestow ? ");
    708 			temp1 = infloat();
    709 			if (temp1 > Player.p_gold || temp1 < 0) {
    710 				mvaddstr(5, 0, "You don't have that !\n");
    711 				return;
    712 			}
    713 			/* adjust gold after we are sure it will be given to
    714 			 * someone */
    715 			option = "give gold to";
    716 			break;
    717 
    718 		case '5':	/* collect accumulated taxes */
    719 			if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)
    720 				/* collect taxes */
    721 			{
    722 				fread((char *) &temp1, sizeof(double), 1, fp);
    723 				fseek(fp, 0L, SEEK_SET);
    724 				/* clear out value */
    725 				temp2 = 0.0;
    726 				fwrite((char *) &temp2, sizeof(double), 1, fp);
    727 				fclose(fp);
    728 			}
    729 			mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1);
    730 			Player.p_gold += floor(temp1);
    731 			return;
    732 
    733 		default:
    734 			return;
    735 		}
    736 		/* end of king options */
    737 	} else
    738 		/* council of wise, valar, wizard options */
    739 	{
    740 		addstr("1:Heal  ");
    741 		if (Player.p_palantir || Wizard)
    742 			addstr("2:Seek Grail  ");
    743 		if (Player.p_specialtype == SC_VALAR || Wizard)
    744 			addstr("3:Throw Monster  4:Relocate  5:Bless  ");
    745 		if (Wizard)
    746 			addstr("6:Vaporize  ");
    747 
    748 		ch = getanswer(" ", TRUE);
    749 		if (!Wizard) {
    750 			if (ch > '2' && Player.p_specialtype != SC_VALAR) {
    751 				ILLCMD();
    752 				return;
    753 			}
    754 			if (Player.p_mana < MM_INTERVENE) {
    755 				mvaddstr(5, 0, "No mana left.\n");
    756 				return;
    757 			} else
    758 				Player.p_mana -= MM_INTERVENE;
    759 		}
    760 		switch (ch) {
    761 		case '1':	/* heal another */
    762 			tamper = T_HEAL;
    763 			option = "heal";
    764 			break;
    765 
    766 		case '2':	/* seek grail */
    767 			if (Player.p_palantir)
    768 				/* need a palantir to seek */
    769 			{
    770 				fseek(Energyvoidfp, 0L, SEEK_SET);
    771 				fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
    772 				temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y);
    773 				temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0);	/* add some error */
    774 				mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1);
    775 			} else
    776 				/* no palantir */
    777 				mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
    778 			return;
    779 
    780 		case '3':	/* lob monster at someone */
    781 			mvaddstr(4, 0, "Which monster [0-99] ? ");
    782 			temp1 = infloat();
    783 			temp1 = MAX(0.0, MIN(99.0, temp1));
    784 			tamper = T_MONSTER;
    785 			option = "throw a monster at";
    786 			break;
    787 
    788 		case '4':	/* move another player */
    789 			mvaddstr(4, 0, "New X Y coordinates ? ");
    790 			getstring(Databuf, SZ_DATABUF);
    791 			sscanf(Databuf, "%lf %lf", &temp1, &temp2);
    792 			tamper = T_RELOCATE;
    793 			option = "relocate";
    794 			break;
    795 
    796 		case '5':	/* bless a player */
    797 			tamper = T_BLESSED;
    798 			option = "bless";
    799 			break;
    800 
    801 		case '6':	/* kill off a player */
    802 			if (Wizard) {
    803 				tamper = T_VAPORIZED;
    804 				option = "vaporize";
    805 				break;
    806 			} else
    807 				return;
    808 
    809 		default:
    810 			return;
    811 		}
    812 
    813 		/* adjust age after we are sure intervention will be done */
    814 		/* end of valar, etc. options */
    815 	}
    816 
    817 	for (;;)
    818 		/* prompt for player to affect */
    819 	{
    820 		mvprintw(4, 0, "Who do you want to %s ? ", option);
    821 		getstring(Databuf, SZ_DATABUF);
    822 		truncstring(Databuf);
    823 
    824 		if (Databuf[0] == '\0')
    825 			userlist(TRUE);
    826 		else
    827 			break;
    828 	}
    829 
    830 	if (strcmp(Player.p_name, Databuf) != 0)
    831 		/* name other than self */
    832 	{
    833 		if ((loc = findname(Databuf, &Other)) >= 0L) {
    834 			if (Other.p_tampered != T_OFF) {
    835 				mvaddstr(5, 0, "That person has something pending already.\n");
    836 				return;
    837 			} else {
    838 				if (tamper == T_RELOCATE
    839 				    && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y)
    840 				    && !Wizard)
    841 					mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
    842 				else {
    843 					if (tamper == T_BESTOW)
    844 						Player.p_gold -= floor(temp1);
    845 					if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER ||
    846 						tamper == T_RELOCATE || tamper == T_BLESSED))
    847 						Player.p_age += N_AGE;	/* age penalty */
    848 					Other.p_tampered = tamper;
    849 					Other.p_1scratch = floor(temp1);
    850 					Other.p_2scratch = floor(temp2);
    851 					writerecord(&Other, loc);
    852 					mvaddstr(5, 0, "It is done.\n");
    853 				}
    854 				return;
    855 			}
    856 		} else
    857 			/* player not found */
    858 			mvaddstr(5, 0, "There is no one by that name.\n");
    859 	} else
    860 		/* self */
    861 		mvaddstr(5, 0, "You may not do it to yourself!\n");
    862 }
    863 
    864 void
    865 writevoid(struct energyvoid *vp, long loc)
    866 {
    867 
    868 	fseek(Energyvoidfp, loc, SEEK_SET);
    869 	fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp);
    870 	fflush(Energyvoidfp);
    871 	fseek(Energyvoidfp, 0L, SEEK_SET);
    872 }
    873 
    874 static long
    875 allocvoid(void)
    876 {
    877 	long    loc = 0L;	/* location of new energy void */
    878 
    879 	fseek(Energyvoidfp, 0L, SEEK_SET);
    880 	while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
    881 		if (Enrgyvoid.ev_active)
    882 			loc += SZ_VOIDSTRUCT;
    883 		else
    884 			break;
    885 
    886 	return (loc);
    887 }
    888