xref: /netbsd-src/games/phantasia/interplayer.c (revision e28fc9086cd7f59ab0a7363c8a37303b5a0d04a0)
1*e28fc908Sdholland /*	$NetBSD: interplayer.c,v 1.12 2009/08/31 08:27:16 dholland Exp $	*/
2dcfebd78Scgd 
386a62b8dSjtc /*
486a62b8dSjtc  * interplayer.c - player to player routines for Phantasia
586a62b8dSjtc  */
686a62b8dSjtc 
7*e28fc908Sdholland #include <math.h>
8*e28fc908Sdholland #include <setjmp.h>
9*e28fc908Sdholland #include <stdio.h>
10*e28fc908Sdholland #include <string.h>
11*e28fc908Sdholland #include <unistd.h>
12*e28fc908Sdholland 
13*e28fc908Sdholland #include "macros.h"
14*e28fc908Sdholland #include "phantdefs.h"
15*e28fc908Sdholland #include "phantstruct.h"
16*e28fc908Sdholland #include "phantglobs.h"
17*e28fc908Sdholland #include "pathnames.h"
18*e28fc908Sdholland 
199b1375acShe #undef bool
209209ce5aSross #include <curses.h>
2186a62b8dSjtc 
225305281bSdholland static long allocvoid(void);
235305281bSdholland static void battleplayer(long);
245305281bSdholland static void myturn(void);
255305281bSdholland static void tampered(int, double, double);
265305281bSdholland 
27a232aee2Slukem void
checkbattle(void)28c7a109ccSdholland checkbattle(void)
2986a62b8dSjtc {
3086a62b8dSjtc 	long    foeloc = 0L;	/* location in file of person to fight */
3186a62b8dSjtc 
3286a62b8dSjtc 	Users = 0;
335fb18dd9Sjsm 	fseek(Playersfp, 0L, SEEK_SET);
3486a62b8dSjtc 
35a232aee2Slukem 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
3686a62b8dSjtc 		if (Other.p_status != S_OFF
3786a62b8dSjtc 		    && Other.p_status != S_NOTUSED
3886a62b8dSjtc 		    && Other.p_status != S_HUNGUP
3986a62b8dSjtc 		    && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR))
4086a62b8dSjtc 			/* player is on and not a cloaked valar */
4186a62b8dSjtc 		{
4286a62b8dSjtc 			++Users;
4386a62b8dSjtc 
4486a62b8dSjtc 			if (Player.p_x == Other.p_x
4586a62b8dSjtc 			    && Player.p_y == Other.p_y
4686a62b8dSjtc 			/* same coordinates */
4786a62b8dSjtc 			    && foeloc != Fileloc
4886a62b8dSjtc 			/* not self */
4986a62b8dSjtc 			    && Player.p_status == S_PLAYING
5086a62b8dSjtc 			    && (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE)
5186a62b8dSjtc 			/* both are playing */
5286a62b8dSjtc 			    && Other.p_specialtype != SC_VALAR
5386a62b8dSjtc 			    && Player.p_specialtype != SC_VALAR)
5486a62b8dSjtc 				/* neither is valar */
5586a62b8dSjtc 			{
5686a62b8dSjtc 				battleplayer(foeloc);
5786a62b8dSjtc 				return;
5886a62b8dSjtc 			}
5986a62b8dSjtc 		}
6086a62b8dSjtc 		foeloc += SZ_PLAYERSTRUCT;
6186a62b8dSjtc 	}
6286a62b8dSjtc }
6386a62b8dSjtc 
645305281bSdholland static void
battleplayer(long foeplace)65c7a109ccSdholland battleplayer(long foeplace)
6686a62b8dSjtc {
6786a62b8dSjtc 	double  dtemp;		/* for temporary calculations */
6886a62b8dSjtc 	double  oldhits = 0.0;	/* previous damage inflicted by foe */
69a232aee2Slukem 	int     loop;		/* for timing out */
7086a62b8dSjtc 	int     ch;		/* input */
7186a62b8dSjtc 	short   oldtampered;	/* old value of foe's p_tampered */
7286a62b8dSjtc 
7386a62b8dSjtc 	Lines = 8;
7486a62b8dSjtc 	Luckout = FALSE;
7586a62b8dSjtc 	mvaddstr(4, 0, "Preparing for battle!\n");
7686a62b8dSjtc 	refresh();
7786a62b8dSjtc 
7886a62b8dSjtc #ifdef SYS5
7986a62b8dSjtc 	flushinp();
8086a62b8dSjtc #endif
8186a62b8dSjtc 
8286a62b8dSjtc 	/* set up variables, file, etc. */
8386a62b8dSjtc 	Player.p_status = S_INBATTLE;
8486a62b8dSjtc 	Shield = Player.p_energy;
8586a62b8dSjtc 
86a232aee2Slukem 	/* if p_tampered is not 0, someone else may try to change it (king,
87a232aee2Slukem 	 * etc.) */
8886a62b8dSjtc 	Player.p_tampered = oldtampered = 1;
8986a62b8dSjtc 	Player.p_1scratch = 0.0;
9086a62b8dSjtc 	Player.p_istat = I_OFF;
9186a62b8dSjtc 
9286a62b8dSjtc 	readrecord(&Other, foeplace);
9386a62b8dSjtc 	if (fabs(Player.p_level - Other.p_level) > 20.0)
9486a62b8dSjtc 		/* see if players are greatly mismatched */
9586a62b8dSjtc 	{
9686a62b8dSjtc 		dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level);
9786a62b8dSjtc 		if (dtemp < -0.5)
9886a62b8dSjtc 			/* foe outweighs this one */
9986a62b8dSjtc 			Player.p_speed *= 2.0;
10086a62b8dSjtc 	}
10186a62b8dSjtc 	writerecord(&Player, Fileloc);	/* write out all our info */
10286a62b8dSjtc 
10386a62b8dSjtc 	if (Player.p_blindness)
10486a62b8dSjtc 		Enemyname = "someone";
10586a62b8dSjtc 	else
10686a62b8dSjtc 		Enemyname = Other.p_name;
10786a62b8dSjtc 
10886a62b8dSjtc 	mvprintw(6, 0, "You have encountered %s   Level: %.0f\n", Enemyname, Other.p_level);
10986a62b8dSjtc 	refresh();
11086a62b8dSjtc 
11186a62b8dSjtc 	for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop)
11286a62b8dSjtc 		/* wait for foe to respond */
11386a62b8dSjtc 	{
11486a62b8dSjtc 		readrecord(&Other, foeplace);
11586a62b8dSjtc 		sleep(1);
11686a62b8dSjtc 	}
11786a62b8dSjtc 
11886a62b8dSjtc 	if (Other.p_status != S_INBATTLE)
11986a62b8dSjtc 		/* foe did not respond */
12086a62b8dSjtc 	{
12186a62b8dSjtc 		mvprintw(5, 0, "%s is not responding.\n", Enemyname);
12286a62b8dSjtc 		goto LEAVE;
12386a62b8dSjtc 	}
12486a62b8dSjtc 	/* else, we are ready to battle */
12586a62b8dSjtc 
12686a62b8dSjtc 	move(4, 0);
12786a62b8dSjtc 	clrtoeol();
12886a62b8dSjtc 
12986a62b8dSjtc 	/*
13086a62b8dSjtc          * determine who is first master
13186a62b8dSjtc          * if neither player is faster, check level
13286a62b8dSjtc          * if neither level is greater, battle is not allowed
13386a62b8dSjtc          * (this should never happen, but we have to handle it)
13486a62b8dSjtc          */
13586a62b8dSjtc 	if (Player.p_speed > Other.p_speed)
13686a62b8dSjtc 		Foestrikes = FALSE;
137a232aee2Slukem 	else
138a232aee2Slukem 		if (Other.p_speed > Player.p_speed)
13986a62b8dSjtc 			Foestrikes = TRUE;
140a232aee2Slukem 		else
141a232aee2Slukem 			if (Player.p_level > Other.p_level)
14286a62b8dSjtc 				Foestrikes = FALSE;
143a232aee2Slukem 			else
144a232aee2Slukem 				if (Other.p_level > Player.p_level)
14586a62b8dSjtc 					Foestrikes = TRUE;
14686a62b8dSjtc 				else
14786a62b8dSjtc 					/* no one is faster */
14886a62b8dSjtc 				{
14986a62b8dSjtc 					printw("You can't fight %s yet.", Enemyname);
15086a62b8dSjtc 					goto LEAVE;
15186a62b8dSjtc 				}
15286a62b8dSjtc 
153a232aee2Slukem 	for (;;) {
15486a62b8dSjtc 		displaystats();
15586a62b8dSjtc 		readmessage();
15686a62b8dSjtc 		mvprintw(1, 26, "%20.0f", Shield);	/* overprint energy */
15786a62b8dSjtc 
15886a62b8dSjtc 		if (!Foestrikes)
15986a62b8dSjtc 			/* take action against foe */
16086a62b8dSjtc 			myturn();
16186a62b8dSjtc 		else
16286a62b8dSjtc 			/* wait for foe to take action */
16386a62b8dSjtc 		{
16486a62b8dSjtc 			mvaddstr(4, 0, "Waiting...\n");
16586a62b8dSjtc 			clrtoeol();
16686a62b8dSjtc 			refresh();
16786a62b8dSjtc 
16886a62b8dSjtc 			for (loop = 0; loop < 20; ++loop)
16986a62b8dSjtc 				/* wait for foe to act */
17086a62b8dSjtc 			{
17186a62b8dSjtc 				readrecord(&Other, foeplace);
17286a62b8dSjtc 				if (Other.p_1scratch != oldhits)
173a232aee2Slukem 					/* p_1scratch changes to indicate
174a232aee2Slukem 					 * action */
17586a62b8dSjtc 					break;
17686a62b8dSjtc 				else
17786a62b8dSjtc 					/* wait and try again */
17886a62b8dSjtc 				{
17986a62b8dSjtc 					sleep(1);
18086a62b8dSjtc 					addch('.');
18186a62b8dSjtc 					refresh();
18286a62b8dSjtc 				}
18386a62b8dSjtc 			}
18486a62b8dSjtc 
185a232aee2Slukem 			if (Other.p_1scratch == oldhits) {
18686a62b8dSjtc 				/* timeout */
18786a62b8dSjtc 				mvaddstr(22, 0, "Timeout: waiting for response.  Do you want to wait ? ");
18886a62b8dSjtc 				ch = getanswer("NY", FALSE);
18986a62b8dSjtc 				move(22, 0);
19086a62b8dSjtc 				clrtobot();
19186a62b8dSjtc 				if (ch == 'Y')
19286a62b8dSjtc 					continue;
19386a62b8dSjtc 				else
19486a62b8dSjtc 					break;
195a232aee2Slukem 			} else
19686a62b8dSjtc 				/* foe took action */
19786a62b8dSjtc 			{
198a232aee2Slukem 				switch (Other.p_istat) {
19986a62b8dSjtc 				case I_RAN:	/* foe ran away */
20086a62b8dSjtc 					mvprintw(Lines++, 0, "%s ran away!", Enemyname);
20186a62b8dSjtc 					break;
20286a62b8dSjtc 
203a232aee2Slukem 				case I_STUCK:	/* foe tried to run, but
204a232aee2Slukem 						 * couldn't */
20586a62b8dSjtc 					mvprintw(Lines++, 0, "%s tried to run away.", Enemyname);
20686a62b8dSjtc 					break;
20786a62b8dSjtc 
208a232aee2Slukem 				case I_BLEWIT:	/* foe tried to luckout, but
209a232aee2Slukem 						 * didn't */
21086a62b8dSjtc 					mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname);
21186a62b8dSjtc 					break;
21286a62b8dSjtc 
21386a62b8dSjtc 				default:
21486a62b8dSjtc 					dtemp = Other.p_1scratch - oldhits;
21586a62b8dSjtc 					mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp);
21686a62b8dSjtc 					Shield -= dtemp;
21786a62b8dSjtc 					break;
21886a62b8dSjtc 				}
21986a62b8dSjtc 
220a232aee2Slukem 				oldhits = Other.p_1scratch;	/* keep track of old
221a232aee2Slukem 								 * hits */
22286a62b8dSjtc 
22386a62b8dSjtc 				if (Other.p_tampered != oldtampered)
224a232aee2Slukem 					/* p_tampered changes to relinquish
225a232aee2Slukem 					 * turn */
22686a62b8dSjtc 				{
22786a62b8dSjtc 					oldtampered = Other.p_tampered;
22886a62b8dSjtc 					Foestrikes = FALSE;
22986a62b8dSjtc 				}
23086a62b8dSjtc 			}
23186a62b8dSjtc 		}
23286a62b8dSjtc 
23386a62b8dSjtc 		/* decide what happens next */
23486a62b8dSjtc 		refresh();
235a232aee2Slukem 		if (Lines > LINES - 2) {
23686a62b8dSjtc 			more(Lines);
23786a62b8dSjtc 			move(Lines = 8, 0);
23886a62b8dSjtc 			clrtobot();
23986a62b8dSjtc 		}
24086a62b8dSjtc 		if (Other.p_istat == I_KILLED || Shield < 0.0)
24186a62b8dSjtc 			/* we died */
24286a62b8dSjtc 		{
24386a62b8dSjtc 			Shield = -2.0;	/* insure this value is negative */
24486a62b8dSjtc 			break;
24586a62b8dSjtc 		}
24686a62b8dSjtc 		if (Player.p_istat == I_KILLED)
24786a62b8dSjtc 			/* we killed foe; award treasre */
24886a62b8dSjtc 		{
24986a62b8dSjtc 			mvprintw(Lines++, 0, "You killed %s!", Enemyname);
25086a62b8dSjtc 			Player.p_experience += Other.p_experience;
25186a62b8dSjtc 			Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0;
25286a62b8dSjtc 			Player.p_amulets += Other.p_amulets;
25386a62b8dSjtc 			Player.p_charms += Other.p_charms;
25486a62b8dSjtc 			collecttaxes(Other.p_gold, Other.p_gems);
25586a62b8dSjtc 			Player.p_sword = MAX(Player.p_sword, Other.p_sword);
25686a62b8dSjtc 			Player.p_shield = MAX(Player.p_shield, Other.p_shield);
25786a62b8dSjtc 			Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver);
258a232aee2Slukem 			if (Other.p_virgin && !Player.p_virgin) {
25986a62b8dSjtc 				mvaddstr(Lines++, 0, "You have rescued a virgin.  Will you be honorable ? ");
26086a62b8dSjtc 				if ((ch = getanswer("YN", FALSE)) == 'Y')
26186a62b8dSjtc 					Player.p_virgin = TRUE;
262a232aee2Slukem 				else {
26386a62b8dSjtc 					++Player.p_sin;
26486a62b8dSjtc 					Player.p_experience += 8000.0;
26586a62b8dSjtc 				}
26686a62b8dSjtc 			}
26786a62b8dSjtc 			sleep(3);	/* give other person time to die */
26886a62b8dSjtc 			break;
269a232aee2Slukem 		} else
270a232aee2Slukem 			if (Player.p_istat == I_RAN || Other.p_istat == I_RAN)
27186a62b8dSjtc 				/* either player ran away */
27286a62b8dSjtc 				break;
27386a62b8dSjtc 	}
27486a62b8dSjtc 
27586a62b8dSjtc LEAVE:
27686a62b8dSjtc 	/* clean up things and leave */
27786a62b8dSjtc 	writerecord(&Player, Fileloc);	/* update a final time */
27886a62b8dSjtc 	altercoordinates(0.0, 0.0, A_NEAR);	/* move away from battle site */
27986a62b8dSjtc 	Player.p_energy = Shield;	/* set energy to actual value */
28086a62b8dSjtc 	Player.p_tampered = T_OFF;	/* clear p_tampered */
28186a62b8dSjtc 
28286a62b8dSjtc 	more(Lines);		/* pause */
28386a62b8dSjtc 
28486a62b8dSjtc 	move(4, 0);
28586a62b8dSjtc 	clrtobot();		/* clear bottom area of screen */
28686a62b8dSjtc 
28786a62b8dSjtc 	if (Player.p_energy < 0.0)
28886a62b8dSjtc 		/* we are dead */
28986a62b8dSjtc 		death("Interterminal battle");
29086a62b8dSjtc }
29186a62b8dSjtc 
2925305281bSdholland static void
myturn(void)293c7a109ccSdholland myturn(void)
29486a62b8dSjtc {
29586a62b8dSjtc 	double  dtemp;		/* for temporary calculations */
29686a62b8dSjtc 	int     ch;		/* input */
29786a62b8dSjtc 
29886a62b8dSjtc 	mvaddstr(7, 0, "1:Fight  2:Run Away!  3:Power Blast  ");
29986a62b8dSjtc 	if (Luckout)
30086a62b8dSjtc 		clrtoeol();
30186a62b8dSjtc 	else
30286a62b8dSjtc 		addstr("4:Luckout  ");
30386a62b8dSjtc 
30486a62b8dSjtc 	ch = inputoption();
30586a62b8dSjtc 	move(Lines = 8, 0);
30686a62b8dSjtc 	clrtobot();
30786a62b8dSjtc 
308a232aee2Slukem 	switch (ch) {
30986a62b8dSjtc 	default:		/* fight */
31086a62b8dSjtc 		dtemp = ROLL(2.0, Player.p_might);
31186a62b8dSjtc HIT:
31286a62b8dSjtc 		mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp);
31386a62b8dSjtc 		Player.p_sin += 0.5;
31486a62b8dSjtc 		Player.p_1scratch += dtemp;
31586a62b8dSjtc 		Player.p_istat = I_OFF;
31686a62b8dSjtc 		break;
31786a62b8dSjtc 
31886a62b8dSjtc 	case '2':		/* run away */
319a232aee2Slukem 		Player.p_1scratch -= 1.0;	/* change this to indicate
320a232aee2Slukem 						 * action */
321a232aee2Slukem 		if (drandom() > 0.25) {
32286a62b8dSjtc 			mvaddstr(Lines++, 0, "You got away!");
32386a62b8dSjtc 			Player.p_istat = I_RAN;
324a232aee2Slukem 		} else {
32586a62b8dSjtc 			mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
32686a62b8dSjtc 			Player.p_istat = I_STUCK;
32786a62b8dSjtc 		}
32886a62b8dSjtc 		break;
32986a62b8dSjtc 
33086a62b8dSjtc 	case '3':		/* power blast */
33186a62b8dSjtc 		dtemp = MIN(Player.p_mana, Player.p_level * 5.0);
33286a62b8dSjtc 		Player.p_mana -= dtemp;
33386a62b8dSjtc 		dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0;
33486a62b8dSjtc 		mvprintw(Lines++, 0, "You blasted %s !", Enemyname);
33586a62b8dSjtc 		goto HIT;
33686a62b8dSjtc 
33786a62b8dSjtc 	case '4':		/* luckout */
338a232aee2Slukem 		if (Luckout || drandom() > 0.1) {
33986a62b8dSjtc 			if (Luckout)
34086a62b8dSjtc 				mvaddstr(Lines++, 0, "You already tried that!");
341a232aee2Slukem 			else {
34286a62b8dSjtc 				mvaddstr(Lines++, 0, "Not this time . . .");
34386a62b8dSjtc 				Luckout = TRUE;
34486a62b8dSjtc 			}
34586a62b8dSjtc 
34686a62b8dSjtc 			Player.p_1scratch -= 1.0;
34786a62b8dSjtc 			Player.p_istat = I_BLEWIT;
348a232aee2Slukem 		} else {
34986a62b8dSjtc 			mvaddstr(Lines++, 0, "You just lucked out!");
35086a62b8dSjtc 			Player.p_1scratch = Other.p_energy * 1.1;
35186a62b8dSjtc 		}
35286a62b8dSjtc 		break;
35386a62b8dSjtc 	}
35486a62b8dSjtc 
35586a62b8dSjtc 	refresh();
35686a62b8dSjtc 	Player.p_1scratch = floor(Player.p_1scratch);	/* clean up any mess */
35786a62b8dSjtc 
35886a62b8dSjtc 	if (Player.p_1scratch > Other.p_energy)
35986a62b8dSjtc 		Player.p_istat = I_KILLED;
360a232aee2Slukem 	else
361a232aee2Slukem 		if (drandom() * Player.p_speed < drandom() * Other.p_speed)
36286a62b8dSjtc 			/* relinquish control */
36386a62b8dSjtc 		{
36486a62b8dSjtc 			++Player.p_tampered;
36586a62b8dSjtc 			Foestrikes = TRUE;
36686a62b8dSjtc 		}
36786a62b8dSjtc 	writerecord(&Player, Fileloc);	/* let foe know what we did */
36886a62b8dSjtc }
36986a62b8dSjtc 
370a232aee2Slukem void
checktampered(void)371c7a109ccSdholland checktampered(void)
37286a62b8dSjtc {
37386a62b8dSjtc 	long    loc = 0L;	/* location in energy void file */
37486a62b8dSjtc 
37586a62b8dSjtc 	/* first check for energy voids */
3765fb18dd9Sjsm 	fseek(Energyvoidfp, 0L, SEEK_SET);
37786a62b8dSjtc 	while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
37886a62b8dSjtc 		if (Enrgyvoid.ev_active
37986a62b8dSjtc 		    && Enrgyvoid.ev_x == Player.p_x
38086a62b8dSjtc 		    && Enrgyvoid.ev_y == Player.p_y)
38186a62b8dSjtc 			/* sitting on one */
38286a62b8dSjtc 		{
38386a62b8dSjtc 			if (loc > 0L)
38486a62b8dSjtc 				/* not the holy grail; inactivate energy void */
38586a62b8dSjtc 			{
38686a62b8dSjtc 				Enrgyvoid.ev_active = FALSE;
38786a62b8dSjtc 				writevoid(&Enrgyvoid, loc);
38886a62b8dSjtc 				tampered(T_NRGVOID, 0.0, 0.0);
389a232aee2Slukem 			} else
390a232aee2Slukem 				if (Player.p_status != S_CLOAKED)
39186a62b8dSjtc 					/* holy grail */
39286a62b8dSjtc 					tampered(T_GRAIL, 0.0, 0.0);
39386a62b8dSjtc 			break;
394a232aee2Slukem 		} else
39586a62b8dSjtc 			loc += SZ_VOIDSTRUCT;
39686a62b8dSjtc 
39786a62b8dSjtc 	/* now check for other things */
39886a62b8dSjtc 	readrecord(&Other, Fileloc);
39986a62b8dSjtc 	if (Other.p_tampered != T_OFF)
40086a62b8dSjtc 		tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch);
40186a62b8dSjtc }
40286a62b8dSjtc 
4035305281bSdholland static void
tampered(int what,double arg1,double arg2)404c7a109ccSdholland tampered(int what, double arg1, double arg2)
40586a62b8dSjtc {
40686a62b8dSjtc 	long    loc;		/* location in file of other players */
40786a62b8dSjtc 
40886a62b8dSjtc 	Changed = TRUE;
40986a62b8dSjtc 	move(4, 0);
41086a62b8dSjtc 
41186a62b8dSjtc 	Player.p_tampered = T_OFF;	/* no longer tampered with */
41286a62b8dSjtc 
413a232aee2Slukem 	switch (what) {
41486a62b8dSjtc 	case T_NRGVOID:
41586a62b8dSjtc 		addstr("You've hit an energy void !\n");
41686a62b8dSjtc 		Player.p_mana /= 3.0;
41786a62b8dSjtc 		Player.p_energy /= 2.0;
41886a62b8dSjtc 		Player.p_gold = floor(Player.p_gold / 1.25) + 0.1;
41986a62b8dSjtc 		altercoordinates(0.0, 0.0, A_NEAR);
42086a62b8dSjtc 		break;
42186a62b8dSjtc 
42286a62b8dSjtc 	case T_TRANSPORT:
42386a62b8dSjtc 		addstr("The king transported you !  ");
424a232aee2Slukem 		if (Player.p_charms > 0) {
42586a62b8dSjtc 			addstr("But your charm saved you. . .\n");
42686a62b8dSjtc 			--Player.p_charms;
427a232aee2Slukem 		} else {
42886a62b8dSjtc 			altercoordinates(0.0, 0.0, A_FAR);
42986a62b8dSjtc 			addch('\n');
43086a62b8dSjtc 		}
43186a62b8dSjtc 		break;
43286a62b8dSjtc 
43386a62b8dSjtc 	case T_BESTOW:
43486a62b8dSjtc 		printw("The king has bestowed %.0f gold pieces on you !\n", arg1);
43586a62b8dSjtc 		Player.p_gold += arg1;
43686a62b8dSjtc 		break;
43786a62b8dSjtc 
43886a62b8dSjtc 	case T_CURSED:
43986a62b8dSjtc 		addstr("You've been cursed !  ");
440a232aee2Slukem 		if (Player.p_blessing) {
44186a62b8dSjtc 			addstr("But your blessing saved you. . .\n");
44286a62b8dSjtc 			Player.p_blessing = FALSE;
443a232aee2Slukem 		} else {
44486a62b8dSjtc 			addch('\n');
44586a62b8dSjtc 			Player.p_poison += 2.0;
44686a62b8dSjtc 			Player.p_energy = 10.0;
44786a62b8dSjtc 			Player.p_maxenergy *= 0.95;
44886a62b8dSjtc 			Player.p_status = S_PLAYING;	/* no longer cloaked */
44986a62b8dSjtc 		}
45086a62b8dSjtc 		break;
45186a62b8dSjtc 
45286a62b8dSjtc 	case T_VAPORIZED:
45386a62b8dSjtc 		addstr("You have been vaporized!\n");
45486a62b8dSjtc 		more(7);
45586a62b8dSjtc 		death("Vaporization");
45686a62b8dSjtc 		break;
45786a62b8dSjtc 
45886a62b8dSjtc 	case T_MONSTER:
45986a62b8dSjtc 		addstr("The Valar zapped you with a monster!\n");
46086a62b8dSjtc 		more(7);
46186a62b8dSjtc 		encounter((int) arg1);
46286a62b8dSjtc 		return;
46386a62b8dSjtc 
46486a62b8dSjtc 	case T_BLESSED:
46586a62b8dSjtc 		addstr("The Valar has blessed you!\n");
46686a62b8dSjtc 		Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield;
46786a62b8dSjtc 		Player.p_mana += 500.0;
46886a62b8dSjtc 		Player.p_strength += 0.5;
46986a62b8dSjtc 		Player.p_brains += 0.5;
47086a62b8dSjtc 		Player.p_magiclvl += 0.5;
47186a62b8dSjtc 		Player.p_poison = MIN(0.5, Player.p_poison);
47286a62b8dSjtc 		break;
47386a62b8dSjtc 
47486a62b8dSjtc 	case T_RELOCATE:
47586a62b8dSjtc 		addstr("You've been relocated. . .\n");
47686a62b8dSjtc 		altercoordinates(arg1, arg2, A_FORCED);
47786a62b8dSjtc 		break;
47886a62b8dSjtc 
47986a62b8dSjtc 	case T_HEAL:
48086a62b8dSjtc 		addstr("You've been healed!\n");
48186a62b8dSjtc 		Player.p_poison -= 0.25;
48286a62b8dSjtc 		Player.p_energy = Player.p_maxenergy + Player.p_shield;
48386a62b8dSjtc 		break;
48486a62b8dSjtc 
48586a62b8dSjtc 	case T_EXVALAR:
48686a62b8dSjtc 		addstr("You are no longer Valar!\n");
48786a62b8dSjtc 		Player.p_specialtype = SC_COUNCIL;
48886a62b8dSjtc 		break;
48986a62b8dSjtc 
49086a62b8dSjtc 	case T_GRAIL:
49186a62b8dSjtc 		addstr("You have found The Holy Grail!!\n");
49286a62b8dSjtc 		if (Player.p_specialtype < SC_COUNCIL)
49386a62b8dSjtc 			/* must be council of wise to behold grail */
49486a62b8dSjtc 		{
49586a62b8dSjtc 			addstr("However, you are not experienced enough to behold it.\n");
49686a62b8dSjtc 			Player.p_sin *= Player.p_sin;
49786a62b8dSjtc 			Player.p_mana += 1000;
498a232aee2Slukem 		} else
499a232aee2Slukem 			if (Player.p_specialtype == SC_VALAR
500a232aee2Slukem 			    || Player.p_specialtype == SC_EXVALAR) {
50186a62b8dSjtc 				addstr("You have made it to the position of Valar once already.\n");
50286a62b8dSjtc 				addstr("The Grail is of no more use to you now.\n");
503a232aee2Slukem 			} else {
50486a62b8dSjtc 				addstr("It is now time to see if you are worthy to behold it. . .\n");
50586a62b8dSjtc 				refresh();
50686a62b8dSjtc 				sleep(4);
50786a62b8dSjtc 
508a232aee2Slukem 				if (drandom() / 2.0 < Player.p_sin) {
50986a62b8dSjtc 					addstr("You have failed!\n");
51086a62b8dSjtc 					Player.p_strength =
51186a62b8dSjtc 					    Player.p_mana =
51286a62b8dSjtc 					    Player.p_energy =
51386a62b8dSjtc 					    Player.p_maxenergy =
51486a62b8dSjtc 					    Player.p_magiclvl =
51586a62b8dSjtc 					    Player.p_brains =
51686a62b8dSjtc 					    Player.p_experience =
51786a62b8dSjtc 					    Player.p_quickness = 1.0;
51886a62b8dSjtc 
51986a62b8dSjtc 					altercoordinates(1.0, 1.0, A_FORCED);
52086a62b8dSjtc 					Player.p_level = 0.0;
521a232aee2Slukem 				} else {
52286a62b8dSjtc 					addstr("You made to position of Valar!\n");
52386a62b8dSjtc 					Player.p_specialtype = SC_VALAR;
52486a62b8dSjtc 					Player.p_lives = 5;
5255fb18dd9Sjsm 					fseek(Playersfp, 0L, SEEK_SET);
52686a62b8dSjtc 					loc = 0L;
52786a62b8dSjtc 					while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
52886a62b8dSjtc 						/* search for existing valar */
52986a62b8dSjtc 						if (Other.p_specialtype == SC_VALAR
53086a62b8dSjtc 						    && Other.p_status != S_NOTUSED)
53186a62b8dSjtc 							/* found old valar */
53286a62b8dSjtc 						{
53386a62b8dSjtc 							Other.p_tampered = T_EXVALAR;
53486a62b8dSjtc 							writerecord(&Other, loc);
53586a62b8dSjtc 							break;
536a232aee2Slukem 						} else
53786a62b8dSjtc 							loc += SZ_PLAYERSTRUCT;
53886a62b8dSjtc 				}
53986a62b8dSjtc 			}
54086a62b8dSjtc 
54186a62b8dSjtc 		/* move grail to new location */
54286a62b8dSjtc 		Enrgyvoid.ev_active = TRUE;
54386a62b8dSjtc 		Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
54486a62b8dSjtc 		Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
54586a62b8dSjtc 		writevoid(&Enrgyvoid, 0L);
54686a62b8dSjtc 		break;
54786a62b8dSjtc 	}
54886a62b8dSjtc 	refresh();
54986a62b8dSjtc 	sleep(2);
55086a62b8dSjtc }
55186a62b8dSjtc 
552a232aee2Slukem void
userlist(phbool ingameflag)553c7a109ccSdholland userlist(phbool ingameflag)
55486a62b8dSjtc {
555a232aee2Slukem 	int     numusers = 0;	/* number of users on file */
55686a62b8dSjtc 
557a232aee2Slukem 	if (ingameflag && Player.p_blindness) {
55886a62b8dSjtc 		mvaddstr(8, 0, "You cannot see anyone.\n");
55986a62b8dSjtc 		return;
56086a62b8dSjtc 	}
5615fb18dd9Sjsm 	fseek(Playersfp, 0L, SEEK_SET);
56286a62b8dSjtc 	mvaddstr(8, 0,
56386a62b8dSjtc 	    "Name                         X         Y    Lvl Type Login    Status\n");
56486a62b8dSjtc 
565a232aee2Slukem 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
56686a62b8dSjtc 		if (Other.p_status == S_NOTUSED
56786a62b8dSjtc 		/* record is unused */
56886a62b8dSjtc 		    || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED))
56986a62b8dSjtc 			/* cloaked valar */
57086a62b8dSjtc 		{
57186a62b8dSjtc 			if (!Wizard)
57286a62b8dSjtc 				/* wizard can see everything on file */
57386a62b8dSjtc 				continue;
57486a62b8dSjtc 		}
57586a62b8dSjtc 		++numusers;
57686a62b8dSjtc 
57786a62b8dSjtc 		if (ingameflag &&
57886a62b8dSjtc 		/* must be playing for the rest of these conditions */
57986a62b8dSjtc 		    (Player.p_specialtype >= SC_KING
58086a62b8dSjtc 		/* kings and higher can see others */
58186a62b8dSjtc 			|| Other.p_specialtype >= SC_KING
58286a62b8dSjtc 		/* kings and higher can be seen by others */
58386a62b8dSjtc 			|| Circle >= CIRCLE(Other.p_x, Other.p_y)
58486a62b8dSjtc 		/* those nearer the origin can be seen */
58586a62b8dSjtc 			|| Player.p_palantir)
58686a62b8dSjtc 		/* palantir enables one to see others */
58786a62b8dSjtc 		    && (Other.p_status != S_CLOAKED
58886a62b8dSjtc 			|| (Player.p_specialtype == SC_VALAR && Player.p_palantir))
58986a62b8dSjtc 		/* not cloaked; valar can see through cloak with a palantir */
59086a62b8dSjtc 		    && Other.p_specialtype != SC_VALAR)
59186a62b8dSjtc 			/* not a valar */
59286a62b8dSjtc 			/* coordinates should be printed */
59386a62b8dSjtc 			printw("%-20s  %8.0f  %8.0f ",
59486a62b8dSjtc 			    Other.p_name, Other.p_x, Other.p_y);
59586a62b8dSjtc 		else
59686a62b8dSjtc 			/* cannot see player's coordinates */
59786a62b8dSjtc 			printw("%-20s %19.19s ",
59886a62b8dSjtc 			    Other.p_name, descrlocation(&Other, TRUE));
59986a62b8dSjtc 
60086a62b8dSjtc 		printw("%6.0f %s  %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE),
60186a62b8dSjtc 		    Other.p_login, descrstatus(&Other));
60286a62b8dSjtc 
603a232aee2Slukem 		if ((numusers % (LINES - 10)) == 0) {
60486a62b8dSjtc 			more(LINES - 1);
60586a62b8dSjtc 			move(9, 0);
60686a62b8dSjtc 			clrtobot();
60786a62b8dSjtc 		}
60886a62b8dSjtc 	}
60986a62b8dSjtc 
61086a62b8dSjtc 	printw("Total players on file = %d\n", numusers);
61186a62b8dSjtc 	refresh();
61286a62b8dSjtc }
61386a62b8dSjtc 
614a232aee2Slukem void
throneroom(void)615c7a109ccSdholland throneroom(void)
61686a62b8dSjtc {
61786a62b8dSjtc 	FILE   *fp;		/* to clear energy voids */
61886a62b8dSjtc 	long    loc = 0L;	/* location of old king in player file */
61986a62b8dSjtc 
62086a62b8dSjtc 	if (Player.p_specialtype < SC_KING)
62186a62b8dSjtc 		/* not already king -- assumes crown */
62286a62b8dSjtc 	{
6235fb18dd9Sjsm 		fseek(Playersfp, 0L, SEEK_SET);
62486a62b8dSjtc 		while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
62586a62b8dSjtc 			if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
62686a62b8dSjtc 				/* found old king */
62786a62b8dSjtc 			{
62886a62b8dSjtc 				if (Other.p_status != S_OFF)
62986a62b8dSjtc 					/* old king is playing */
63086a62b8dSjtc 				{
63186a62b8dSjtc 					mvaddstr(4, 0, "The king is playing, so you cannot steal his throne\n");
63286a62b8dSjtc 					altercoordinates(0.0, 0.0, A_NEAR);
63386a62b8dSjtc 					move(6, 0);
63486a62b8dSjtc 					return;
635a232aee2Slukem 				} else
636a232aee2Slukem 					/* old king is not playing - remove
637a232aee2Slukem 					 * him/her */
63886a62b8dSjtc 				{
63986a62b8dSjtc 					Other.p_specialtype = SC_NONE;
64086a62b8dSjtc 					if (Other.p_crowns)
64186a62b8dSjtc 						--Other.p_crowns;
64286a62b8dSjtc 					writerecord(&Other, loc);
64386a62b8dSjtc 					break;
64486a62b8dSjtc 				}
645a232aee2Slukem 			} else
64686a62b8dSjtc 				loc += SZ_PLAYERSTRUCT;
64786a62b8dSjtc 
64886a62b8dSjtc 		/* make player new king */
64986a62b8dSjtc 		Changed = TRUE;
65086a62b8dSjtc 		Player.p_specialtype = SC_KING;
65186a62b8dSjtc 		mvaddstr(4, 0, "You have become king!\n");
65286a62b8dSjtc 
65386a62b8dSjtc 		/* let everyone else know */
65486a62b8dSjtc 		fp = fopen(_PATH_MESS, "w");
65586a62b8dSjtc 		fprintf(fp, "All hail the new king!");
65686a62b8dSjtc 		fclose(fp);
65786a62b8dSjtc 
65886a62b8dSjtc 		/* clear all energy voids; retain location of holy grail */
6595fb18dd9Sjsm 		fseek(Energyvoidfp, 0L, SEEK_SET);
66086a62b8dSjtc 		fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
66186a62b8dSjtc 		fp = fopen(_PATH_VOID, "w");
66286a62b8dSjtc 		fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
66386a62b8dSjtc 		fclose(fp);
66486a62b8dSjtc 	}
66586a62b8dSjtc 	mvaddstr(6, 0, "0:Decree  ");
66686a62b8dSjtc }
66786a62b8dSjtc 
668a232aee2Slukem void
dotampered(void)669c7a109ccSdholland dotampered(void)
67086a62b8dSjtc {
67186a62b8dSjtc 	short   tamper;		/* value for tampering with other players */
672092d3130Sjsm 	const char   *option;		/* pointer to option description */
67386a62b8dSjtc 	double  temp1 = 0.0, temp2 = 0.0;	/* other tampering values */
67486a62b8dSjtc 	int     ch;		/* input */
67586a62b8dSjtc 	long    loc;		/* location in energy void file */
67686a62b8dSjtc 	FILE   *fp;		/* for opening gold file */
67786a62b8dSjtc 
67886a62b8dSjtc 	move(6, 0);
67986a62b8dSjtc 	clrtoeol();
68086a62b8dSjtc 	if (Player.p_specialtype < SC_COUNCIL && !Wizard)
68186a62b8dSjtc 		/* king options */
68286a62b8dSjtc 	{
68386a62b8dSjtc 		addstr("1:Transport  2:Curse  3:Energy Void  4:Bestow  5:Collect Taxes  ");
68486a62b8dSjtc 
68586a62b8dSjtc 		ch = getanswer(" ", TRUE);
68686a62b8dSjtc 		move(6, 0);
68786a62b8dSjtc 		clrtoeol();
68886a62b8dSjtc 		move(4, 0);
689a232aee2Slukem 		switch (ch) {
69086a62b8dSjtc 		case '1':	/* transport someone */
69186a62b8dSjtc 			tamper = T_TRANSPORT;
69286a62b8dSjtc 			option = "transport";
69386a62b8dSjtc 			break;
69486a62b8dSjtc 
69586a62b8dSjtc 		case '2':	/* curse another */
69686a62b8dSjtc 			tamper = T_CURSED;
69786a62b8dSjtc 			option = "curse";
69886a62b8dSjtc 			break;
69986a62b8dSjtc 
70086a62b8dSjtc 		case '3':	/* create energy void */
70120e33050Sjsm 			if ((loc = allocvoid()) > 20L * (long)SZ_VOIDSTRUCT)
70286a62b8dSjtc 				/* can only have 20 void active at once */
70386a62b8dSjtc 				mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
704a232aee2Slukem 			else {
70586a62b8dSjtc 				addstr("Enter the X Y coordinates of void ? ");
70686a62b8dSjtc 				getstring(Databuf, SZ_DATABUF);
70786a62b8dSjtc 				sscanf(Databuf, "%lf %lf", &temp1, &temp2);
70886a62b8dSjtc 				Enrgyvoid.ev_x = floor(temp1);
70986a62b8dSjtc 				Enrgyvoid.ev_y = floor(temp2);
71086a62b8dSjtc 				Enrgyvoid.ev_active = TRUE;
71186a62b8dSjtc 				writevoid(&Enrgyvoid, loc);
71286a62b8dSjtc 				mvaddstr(5, 0, "It is done.\n");
71386a62b8dSjtc 			}
71486a62b8dSjtc 			return;
71586a62b8dSjtc 
71686a62b8dSjtc 		case '4':	/* bestow gold to subject */
71786a62b8dSjtc 			tamper = T_BESTOW;
71886a62b8dSjtc 			addstr("How much gold to bestow ? ");
71986a62b8dSjtc 			temp1 = infloat();
720a232aee2Slukem 			if (temp1 > Player.p_gold || temp1 < 0) {
72186a62b8dSjtc 				mvaddstr(5, 0, "You don't have that !\n");
72286a62b8dSjtc 				return;
72386a62b8dSjtc 			}
724a232aee2Slukem 			/* adjust gold after we are sure it will be given to
725a232aee2Slukem 			 * someone */
72686a62b8dSjtc 			option = "give gold to";
72786a62b8dSjtc 			break;
72886a62b8dSjtc 
72986a62b8dSjtc 		case '5':	/* collect accumulated taxes */
73086a62b8dSjtc 			if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)
73186a62b8dSjtc 				/* collect taxes */
73286a62b8dSjtc 			{
73386a62b8dSjtc 				fread((char *) &temp1, sizeof(double), 1, fp);
7345fb18dd9Sjsm 				fseek(fp, 0L, SEEK_SET);
73586a62b8dSjtc 				/* clear out value */
73686a62b8dSjtc 				temp2 = 0.0;
73786a62b8dSjtc 				fwrite((char *) &temp2, sizeof(double), 1, fp);
73886a62b8dSjtc 				fclose(fp);
73986a62b8dSjtc 			}
74086a62b8dSjtc 			mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1);
74186a62b8dSjtc 			Player.p_gold += floor(temp1);
74286a62b8dSjtc 			return;
74386a62b8dSjtc 
74486a62b8dSjtc 		default:
74586a62b8dSjtc 			return;
74686a62b8dSjtc 		}
74786a62b8dSjtc 		/* end of king options */
748a232aee2Slukem 	} else
74986a62b8dSjtc 		/* council of wise, valar, wizard options */
75086a62b8dSjtc 	{
75186a62b8dSjtc 		addstr("1:Heal  ");
75286a62b8dSjtc 		if (Player.p_palantir || Wizard)
75386a62b8dSjtc 			addstr("2:Seek Grail  ");
75486a62b8dSjtc 		if (Player.p_specialtype == SC_VALAR || Wizard)
75586a62b8dSjtc 			addstr("3:Throw Monster  4:Relocate  5:Bless  ");
75686a62b8dSjtc 		if (Wizard)
75786a62b8dSjtc 			addstr("6:Vaporize  ");
75886a62b8dSjtc 
75986a62b8dSjtc 		ch = getanswer(" ", TRUE);
760a232aee2Slukem 		if (!Wizard) {
761a232aee2Slukem 			if (ch > '2' && Player.p_specialtype != SC_VALAR) {
76286a62b8dSjtc 				ILLCMD();
76386a62b8dSjtc 				return;
76486a62b8dSjtc 			}
765a232aee2Slukem 			if (Player.p_mana < MM_INTERVENE) {
76686a62b8dSjtc 				mvaddstr(5, 0, "No mana left.\n");
76786a62b8dSjtc 				return;
768a232aee2Slukem 			} else
76986a62b8dSjtc 				Player.p_mana -= MM_INTERVENE;
77086a62b8dSjtc 		}
771a232aee2Slukem 		switch (ch) {
77286a62b8dSjtc 		case '1':	/* heal another */
77386a62b8dSjtc 			tamper = T_HEAL;
77486a62b8dSjtc 			option = "heal";
77586a62b8dSjtc 			break;
77686a62b8dSjtc 
77786a62b8dSjtc 		case '2':	/* seek grail */
77886a62b8dSjtc 			if (Player.p_palantir)
77986a62b8dSjtc 				/* need a palantir to seek */
78086a62b8dSjtc 			{
7815fb18dd9Sjsm 				fseek(Energyvoidfp, 0L, SEEK_SET);
78286a62b8dSjtc 				fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
78386a62b8dSjtc 				temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y);
78486a62b8dSjtc 				temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0);	/* add some error */
78586a62b8dSjtc 				mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1);
786a232aee2Slukem 			} else
78786a62b8dSjtc 				/* no palantir */
78886a62b8dSjtc 				mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
78986a62b8dSjtc 			return;
79086a62b8dSjtc 
79186a62b8dSjtc 		case '3':	/* lob monster at someone */
79286a62b8dSjtc 			mvaddstr(4, 0, "Which monster [0-99] ? ");
79386a62b8dSjtc 			temp1 = infloat();
79486a62b8dSjtc 			temp1 = MAX(0.0, MIN(99.0, temp1));
79586a62b8dSjtc 			tamper = T_MONSTER;
79686a62b8dSjtc 			option = "throw a monster at";
79786a62b8dSjtc 			break;
79886a62b8dSjtc 
79986a62b8dSjtc 		case '4':	/* move another player */
80086a62b8dSjtc 			mvaddstr(4, 0, "New X Y coordinates ? ");
80186a62b8dSjtc 			getstring(Databuf, SZ_DATABUF);
80286a62b8dSjtc 			sscanf(Databuf, "%lf %lf", &temp1, &temp2);
80386a62b8dSjtc 			tamper = T_RELOCATE;
80486a62b8dSjtc 			option = "relocate";
80586a62b8dSjtc 			break;
80686a62b8dSjtc 
80786a62b8dSjtc 		case '5':	/* bless a player */
80886a62b8dSjtc 			tamper = T_BLESSED;
80986a62b8dSjtc 			option = "bless";
81086a62b8dSjtc 			break;
81186a62b8dSjtc 
81286a62b8dSjtc 		case '6':	/* kill off a player */
813a232aee2Slukem 			if (Wizard) {
81486a62b8dSjtc 				tamper = T_VAPORIZED;
81586a62b8dSjtc 				option = "vaporize";
81686a62b8dSjtc 				break;
817a232aee2Slukem 			} else
81886a62b8dSjtc 				return;
81986a62b8dSjtc 
82086a62b8dSjtc 		default:
82186a62b8dSjtc 			return;
82286a62b8dSjtc 		}
82386a62b8dSjtc 
82486a62b8dSjtc 		/* adjust age after we are sure intervention will be done */
82586a62b8dSjtc 		/* end of valar, etc. options */
82686a62b8dSjtc 	}
82786a62b8dSjtc 
82886a62b8dSjtc 	for (;;)
82986a62b8dSjtc 		/* prompt for player to affect */
83086a62b8dSjtc 	{
83186a62b8dSjtc 		mvprintw(4, 0, "Who do you want to %s ? ", option);
83286a62b8dSjtc 		getstring(Databuf, SZ_DATABUF);
83386a62b8dSjtc 		truncstring(Databuf);
83486a62b8dSjtc 
83586a62b8dSjtc 		if (Databuf[0] == '\0')
83686a62b8dSjtc 			userlist(TRUE);
83786a62b8dSjtc 		else
83886a62b8dSjtc 			break;
83986a62b8dSjtc 	}
84086a62b8dSjtc 
84186a62b8dSjtc 	if (strcmp(Player.p_name, Databuf) != 0)
84286a62b8dSjtc 		/* name other than self */
84386a62b8dSjtc 	{
844a232aee2Slukem 		if ((loc = findname(Databuf, &Other)) >= 0L) {
845a232aee2Slukem 			if (Other.p_tampered != T_OFF) {
84686a62b8dSjtc 				mvaddstr(5, 0, "That person has something pending already.\n");
84786a62b8dSjtc 				return;
848a232aee2Slukem 			} else {
84986a62b8dSjtc 				if (tamper == T_RELOCATE
85086a62b8dSjtc 				    && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y)
85186a62b8dSjtc 				    && !Wizard)
85286a62b8dSjtc 					mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
853a232aee2Slukem 				else {
854a232aee2Slukem 					if (tamper == T_BESTOW)
855a232aee2Slukem 						Player.p_gold -= floor(temp1);
85686a62b8dSjtc 					if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER ||
85786a62b8dSjtc 						tamper == T_RELOCATE || tamper == T_BLESSED))
85886a62b8dSjtc 						Player.p_age += N_AGE;	/* age penalty */
85986a62b8dSjtc 					Other.p_tampered = tamper;
86086a62b8dSjtc 					Other.p_1scratch = floor(temp1);
86186a62b8dSjtc 					Other.p_2scratch = floor(temp2);
86286a62b8dSjtc 					writerecord(&Other, loc);
86386a62b8dSjtc 					mvaddstr(5, 0, "It is done.\n");
86486a62b8dSjtc 				}
86586a62b8dSjtc 				return;
86686a62b8dSjtc 			}
867a232aee2Slukem 		} else
86886a62b8dSjtc 			/* player not found */
86986a62b8dSjtc 			mvaddstr(5, 0, "There is no one by that name.\n");
870a232aee2Slukem 	} else
87186a62b8dSjtc 		/* self */
87286a62b8dSjtc 		mvaddstr(5, 0, "You may not do it to yourself!\n");
87386a62b8dSjtc }
87486a62b8dSjtc 
875a232aee2Slukem void
writevoid(struct energyvoid * vp,long loc)876c7a109ccSdholland writevoid(struct energyvoid *vp, long loc)
87786a62b8dSjtc {
87886a62b8dSjtc 
8795fb18dd9Sjsm 	fseek(Energyvoidfp, loc, SEEK_SET);
88086a62b8dSjtc 	fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp);
88186a62b8dSjtc 	fflush(Energyvoidfp);
8825fb18dd9Sjsm 	fseek(Energyvoidfp, 0L, SEEK_SET);
88386a62b8dSjtc }
88486a62b8dSjtc 
8855305281bSdholland static long
allocvoid(void)886c7a109ccSdholland allocvoid(void)
88786a62b8dSjtc {
88886a62b8dSjtc 	long    loc = 0L;	/* location of new energy void */
88986a62b8dSjtc 
8905fb18dd9Sjsm 	fseek(Energyvoidfp, 0L, SEEK_SET);
89186a62b8dSjtc 	while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
89286a62b8dSjtc 		if (Enrgyvoid.ev_active)
89386a62b8dSjtc 			loc += SZ_VOIDSTRUCT;
89486a62b8dSjtc 		else
89586a62b8dSjtc 			break;
89686a62b8dSjtc 
89786a62b8dSjtc 	return (loc);
89886a62b8dSjtc }
899