134598Sbostic /*
234598Sbostic  * interplayer.c - player to player routines for Phantasia
334598Sbostic  */
434598Sbostic 
534598Sbostic #include "include.h"
634598Sbostic 
734598Sbostic /************************************************************************
834598Sbostic /
934598Sbostic / FUNCTION NAME: checkbattle()
1034598Sbostic /
1134598Sbostic / FUNCTION: check to see if current player should battle another
1234598Sbostic /
1334598Sbostic / AUTHOR: E. A. Estes, 12/4/85
1434598Sbostic /
1534598Sbostic / ARGUMENTS: none
1634598Sbostic /
1734598Sbostic / RETURN VALUE: none
1834598Sbostic /
1934598Sbostic / MODULES CALLED: battleplayer(), fread(), fseek()
2034598Sbostic /
2134598Sbostic / GLOBAL INPUTS: Other, Users, Player, Fileloc, *Playersfp
2234598Sbostic /
2334598Sbostic / GLOBAL OUTPUTS: Users
2434598Sbostic /
2534598Sbostic / DESCRIPTION:
2634598Sbostic /	Seach player file for a foe at the same coordinates as the
2734598Sbostic /	current player.
2834598Sbostic /	Also update user count.
2934598Sbostic /
3034598Sbostic /************************************************************************/
3134598Sbostic 
checkbattle()3234598Sbostic checkbattle()
3334598Sbostic {
3434598Sbostic long	foeloc = 0L;		/* location in file of person to fight */
3534598Sbostic 
3634598Sbostic     Users = 0;
3734598Sbostic     fseek(Playersfp, 0L, 0);
3834598Sbostic 
3934598Sbostic     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
4034598Sbostic 	{
4134598Sbostic 	if (Other.p_status != S_OFF
4234598Sbostic 	    && Other.p_status != S_NOTUSED
4334598Sbostic 	    && Other.p_status != S_HUNGUP
4434598Sbostic 	    && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR))
4534598Sbostic 	    /* player is on and not a cloaked valar */
4634598Sbostic 	    {
4734598Sbostic 	    ++Users;
4834598Sbostic 
4934598Sbostic 	    if (Player.p_x == Other.p_x
5034598Sbostic 		&& Player.p_y == Other.p_y
5134598Sbostic 		/* same coordinates */
5234598Sbostic 		&& foeloc != Fileloc
5334598Sbostic 		/* not self */
5434598Sbostic 		&& Player.p_status == S_PLAYING
5534598Sbostic 		&& (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE)
5634598Sbostic 		/* both are playing */
5734598Sbostic 		&& Other.p_specialtype != SC_VALAR
5834598Sbostic 		&& Player.p_specialtype != SC_VALAR)
5934598Sbostic 		/* neither is valar */
6034598Sbostic 		{
6134598Sbostic 		battleplayer(foeloc);
6234598Sbostic 		return;
6334598Sbostic 		}
6434598Sbostic 	    }
6534598Sbostic 	foeloc += SZ_PLAYERSTRUCT;
6634598Sbostic 	}
6734598Sbostic }
6834598Sbostic /**/
6934598Sbostic /************************************************************************
7034598Sbostic /
7134598Sbostic / FUNCTION NAME: battleplayer()
7234598Sbostic /
7334598Sbostic / FUNCTION: inter-terminal battle with another player
7434598Sbostic /
7534598Sbostic / AUTHOR: E. A. Estes, 2/15/86
7634598Sbostic /
7734598Sbostic / ARGUMENTS:
7834598Sbostic /	long foeplace - location in player file of person to battle
7934598Sbostic /
8034598Sbostic / RETURN VALUE: none
8134598Sbostic /
8234598Sbostic / MODULES CALLED: readrecord(), readmessage(), writerecord(), collecttaxes(),
8334598Sbostic /	displaystats(), fabs(), more(), death(), sleep(), wmove(), waddch(), printw(),
8434598Sbostic /	myturn(), altercoordinates(), waddstr(), wrefresh(), mvprintw(),
8534598Sbostic /	getanswer(), wclrtoeol(), wclrtobot()
8634598Sbostic /
8734598Sbostic / GLOBAL INPUTS: Foestrikes, LINES, Lines, Other, Shield, Player, *stdscr,
8834598Sbostic /	Fileloc, *Enemyname
8934598Sbostic /
9034598Sbostic / GLOBAL OUTPUTS: Foestrikes, Lines, Shield, Player, Luckout, *Enemyname
9134598Sbostic /
9234598Sbostic / DESCRIPTION:
9334598Sbostic /	Inter-terminal battle is a very fragile and slightly klugy thing.
9434598Sbostic /	At any time, one player is master and the other is slave.
9534598Sbostic /	We pick who is master first by speed and level.  After that,
9634598Sbostic /	the slave waits for the master to relinquish its turn, and
9734598Sbostic /	the slave becomes master, and so on.
9834598Sbostic /
9934598Sbostic /	The items in the player structure which control the handshake are:
10034598Sbostic /	    p_tampered:
10134598Sbostic /		master increments this to relinquish control
10234598Sbostic /	    p_istat:
10334598Sbostic /		master sets this to specify particular action
10434598Sbostic /	    p_1scratch:
10534598Sbostic /		set to total damage inflicted so far; changes to indicate action
10634598Sbostic /
10734598Sbostic /************************************************************************/
10834598Sbostic 
battleplayer(foeplace)10934598Sbostic battleplayer(foeplace)
11034598Sbostic long	foeplace;
11134598Sbostic {
11234598Sbostic double	dtemp;		/* for temporary calculations */
11334598Sbostic double	oldhits = 0.0;	/* previous damage inflicted by foe */
11434598Sbostic register int	loop;	/* for timing out */
11534598Sbostic int	ch;		/* input */
11634598Sbostic short	oldtampered;	/* old value of foe's p_tampered */
11734598Sbostic 
11834598Sbostic     Lines = 8;
11934598Sbostic     Luckout = FALSE;
12034598Sbostic     mvaddstr(4, 0, "Preparing for battle!\n");
12134598Sbostic     refresh();
12234598Sbostic 
12334598Sbostic #ifdef SYS5
12434598Sbostic     flushinp();
12534598Sbostic #endif
12634598Sbostic 
12734598Sbostic     /* set up variables, file, etc. */
12834598Sbostic     Player.p_status = S_INBATTLE;
12934598Sbostic     Shield = Player.p_energy;
13034598Sbostic 
13134598Sbostic     /* if p_tampered is not 0, someone else may try to change it (king, etc.) */
13234598Sbostic     Player.p_tampered = oldtampered = 1;
13334598Sbostic     Player.p_1scratch = 0.0;
13434598Sbostic     Player.p_istat = I_OFF;
13534598Sbostic 
13634598Sbostic     readrecord(&Other, foeplace);
13734598Sbostic     if (fabs(Player.p_level - Other.p_level) > 20.0)
13834598Sbostic 	/* see if players are greatly mismatched */
13934598Sbostic 	{
14034598Sbostic 	dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level);
14134598Sbostic 	if (dtemp < -0.5)
14234598Sbostic 	    /* foe outweighs this one */
14334598Sbostic 	    Player.p_speed *= 2.0;
14434598Sbostic 	}
14534598Sbostic 
14634598Sbostic     writerecord(&Player, Fileloc);		/* write out all our info */
14734598Sbostic 
14834598Sbostic     if (Player.p_blindness)
14934598Sbostic 	Enemyname = "someone";
15034598Sbostic     else
15134598Sbostic 	Enemyname = Other.p_name;
15234598Sbostic 
15334598Sbostic     mvprintw(6, 0, "You have encountered %s   Level: %.0f\n", Enemyname, Other.p_level);
15434598Sbostic     refresh();
15534598Sbostic 
15634598Sbostic     for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop)
15734598Sbostic 	/* wait for foe to respond */
15834598Sbostic 	{
15934598Sbostic 	readrecord(&Other, foeplace);
16034598Sbostic 	sleep(1);
16134598Sbostic 	}
16234598Sbostic 
16334598Sbostic     if (Other.p_status != S_INBATTLE)
16434598Sbostic 	/* foe did not respond */
16534598Sbostic 	{
16634598Sbostic 	mvprintw(5, 0, "%s is not responding.\n", Enemyname);
16734598Sbostic 	goto LEAVE;
16834598Sbostic 	}
16934598Sbostic     /* else, we are ready to battle */
17034598Sbostic 
17134598Sbostic     move(4, 0);
17234598Sbostic     clrtoeol();
17334598Sbostic 
17434598Sbostic     /*
17534598Sbostic      * determine who is first master
17634598Sbostic      * if neither player is faster, check level
17734598Sbostic      * if neither level is greater, battle is not allowed
17834598Sbostic      * (this should never happen, but we have to handle it)
17934598Sbostic      */
18034598Sbostic     if (Player.p_speed > Other.p_speed)
18134598Sbostic 	Foestrikes = FALSE;
18234598Sbostic     else if (Other.p_speed > Player.p_speed)
18334598Sbostic 	Foestrikes = TRUE;
18434598Sbostic     else if (Player.p_level > Other.p_level)
18534598Sbostic 	Foestrikes = FALSE;
18634598Sbostic     else if (Other.p_level > Player.p_level)
18734598Sbostic 	Foestrikes = TRUE;
18834598Sbostic     else
18934598Sbostic 	/* no one is faster */
19034598Sbostic 	{
19134598Sbostic 	printw("You can't fight %s yet.", Enemyname);
19234598Sbostic 	goto LEAVE;
19334598Sbostic 	}
19434598Sbostic 
19534598Sbostic     for (;;)
19634598Sbostic 	{
19734598Sbostic 	displaystats();
19834598Sbostic 	readmessage();
19934598Sbostic 	mvprintw(1, 26, "%20.0f", Shield);	/* overprint energy */
20034598Sbostic 
20134598Sbostic 	if (!Foestrikes)
20234598Sbostic 	    /* take action against foe */
20334598Sbostic 	    myturn();
20434598Sbostic 	else
20534598Sbostic 	    /* wait for foe to take action */
20634598Sbostic 	    {
20734598Sbostic 	    mvaddstr(4, 0, "Waiting...\n");
20834598Sbostic 	    clrtoeol();
20934598Sbostic 	    refresh();
21034598Sbostic 
21134598Sbostic 	    for (loop = 0; loop < 20; ++loop)
21234598Sbostic 		/* wait for foe to act */
21334598Sbostic 		{
21434598Sbostic 		readrecord(&Other, foeplace);
21534598Sbostic 		if (Other.p_1scratch != oldhits)
21634598Sbostic 		    /* p_1scratch changes to indicate action */
21734598Sbostic 		    break;
21834598Sbostic 		else
21934598Sbostic 		    /* wait and try again */
22034598Sbostic 		    {
22134598Sbostic 		    sleep(1);
22234598Sbostic 		    addch('.');
22334598Sbostic 		    refresh();
22434598Sbostic 		    }
22534598Sbostic 		}
22634598Sbostic 
22734598Sbostic 	    if (Other.p_1scratch == oldhits)
22834598Sbostic 		{
22934598Sbostic 		/* timeout */
23034598Sbostic 		mvaddstr(22, 0, "Timeout: waiting for response.  Do you want to wait ? ");
23134598Sbostic 		ch = getanswer("NY", FALSE);
23234598Sbostic 		move(22, 0);
23334598Sbostic 		clrtobot();
23434598Sbostic 		if (ch == 'Y')
23534598Sbostic 		    continue;
23634598Sbostic 		else
23734598Sbostic 		    break;
23834598Sbostic 		}
23934598Sbostic 	    else
24034598Sbostic 		/* foe took action */
24134598Sbostic 		{
24234598Sbostic 		switch (Other.p_istat)
24334598Sbostic 		    {
24434598Sbostic 		    case I_RAN:		/* foe ran away */
24534598Sbostic 			mvprintw(Lines++, 0, "%s ran away!", Enemyname);
24634598Sbostic 			break;
24734598Sbostic 
24834598Sbostic 		    case I_STUCK:	/* foe tried to run, but couldn't */
24934598Sbostic 			mvprintw(Lines++, 0, "%s tried to run away.", Enemyname);
25034598Sbostic 			break;
25134598Sbostic 
25234598Sbostic 		    case I_BLEWIT:	/* foe tried to luckout, but didn't */
25334598Sbostic 			mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname);
25434598Sbostic 			break;
25534598Sbostic 
25634598Sbostic 		    default:
25734598Sbostic 			dtemp = Other.p_1scratch - oldhits;
25834598Sbostic 			mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp);
25934598Sbostic 			Shield -= dtemp;
26034598Sbostic 			break;
26134598Sbostic 		    }
26234598Sbostic 
26334598Sbostic 		oldhits = Other.p_1scratch;	/* keep track of old hits */
26434598Sbostic 
26534598Sbostic 		if (Other.p_tampered != oldtampered)
26634598Sbostic 		    /* p_tampered changes to relinquish turn */
26734598Sbostic 		    {
26834598Sbostic 		    oldtampered = Other.p_tampered;
26934598Sbostic 		    Foestrikes = FALSE;
27034598Sbostic 		    }
27134598Sbostic 		}
27234598Sbostic 	    }
27334598Sbostic 
27434598Sbostic 	/* decide what happens next */
27534598Sbostic 	refresh();
27634598Sbostic 	if (Lines > LINES - 2)
27734598Sbostic 	    {
27834598Sbostic 	    more(Lines);
27934598Sbostic 	    move(Lines = 8, 0);
28034598Sbostic 	    clrtobot();
28134598Sbostic 	    }
28234598Sbostic 
28334598Sbostic 	if (Other.p_istat == I_KILLED || Shield < 0.0)
28434598Sbostic 	    /* we died */
28534598Sbostic 	    {
28634598Sbostic 	    Shield = -2.0;		/* insure this value is negative */
28734598Sbostic 	    break;
28834598Sbostic 	    }
28934598Sbostic 
29034598Sbostic 	if (Player.p_istat == I_KILLED)
29134598Sbostic 	    /* we killed foe; award treasre */
29234598Sbostic 	    {
29334598Sbostic 	    mvprintw(Lines++, 0, "You killed %s!", Enemyname);
29434598Sbostic 	    Player.p_experience += Other.p_experience;
29534598Sbostic 	    Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0;
29634598Sbostic 	    Player.p_amulets += Other.p_amulets;
29734598Sbostic 	    Player.p_charms += Other.p_charms;
29834598Sbostic 	    collecttaxes(Other.p_gold, Other.p_gems);
29934598Sbostic 	    Player.p_sword = MAX(Player.p_sword, Other.p_sword);
30034598Sbostic 	    Player.p_shield = MAX(Player.p_shield, Other.p_shield);
30134598Sbostic 	    Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver);
30234598Sbostic 	    if (Other.p_virgin && !Player.p_virgin)
30334598Sbostic 		{
30434598Sbostic 		mvaddstr(Lines++, 0, "You have rescued a virgin.  Will you be honorable ? ");
30534598Sbostic 		if ((ch = getanswer("YN", FALSE)) == 'Y')
30634598Sbostic 		    Player.p_virgin = TRUE;
30734598Sbostic 		else
30834598Sbostic 		    {
30934598Sbostic 		    ++Player.p_sin;
31034598Sbostic 		    Player.p_experience += 8000.0;
31134598Sbostic 		    }
31234598Sbostic 		}
31334598Sbostic 	    sleep(3);     		/* give other person time to die */
31434598Sbostic 	    break;
31534598Sbostic 	    }
31634598Sbostic 	else if (Player.p_istat == I_RAN || Other.p_istat == I_RAN)
31734598Sbostic 	    /* either player ran away */
31834598Sbostic 	    break;
31934598Sbostic 	}
32034598Sbostic 
32134598Sbostic LEAVE:
32234598Sbostic     /* clean up things and leave */
32334598Sbostic     writerecord(&Player, Fileloc);	/* update a final time */
32434598Sbostic     altercoordinates(0.0, 0.0, A_NEAR);	/* move away from battle site */
32534598Sbostic     Player.p_energy = Shield;		/* set energy to actual value */
32634598Sbostic     Player.p_tampered = T_OFF;		/* clear p_tampered */
32734598Sbostic 
32834598Sbostic     more(Lines);			/* pause */
32934598Sbostic 
33034598Sbostic     move(4, 0);
33134598Sbostic     clrtobot();				/* clear bottom area of screen */
33234598Sbostic 
33334598Sbostic     if (Player.p_energy < 0.0)
33434598Sbostic 	/* we are dead */
33534598Sbostic 	death("Interterminal battle");
33634598Sbostic }
33734598Sbostic /**/
33834598Sbostic /************************************************************************
33934598Sbostic /
34034598Sbostic / FUNCTION NAME: myturn()
34134598Sbostic /
34234598Sbostic / FUNCTION: process players action against foe in battle
34334598Sbostic /
34434598Sbostic / AUTHOR: E. A. Estes, 2/7/86
34534598Sbostic /
34634598Sbostic / ARGUMENTS: none
34734598Sbostic /
34834598Sbostic / RETURN VALUE: none
34934598Sbostic /
35034598Sbostic / MODULES CALLED: writerecord(), inputoption(), floor(), wmove(), drandom(),
35134598Sbostic /	waddstr(), wrefresh(), mvprintw(), wclrtoeol(), wclrtobot()
35234598Sbostic /
35334598Sbostic / GLOBAL INPUTS: Lines, Other, Player, *stdscr, Fileloc, Luckout,
35434598Sbostic /	*Enemyname
35534598Sbostic /
35634598Sbostic / GLOBAL OUTPUTS: Foestrikes, Lines, Player, Luckout
35734598Sbostic /
35834598Sbostic / DESCRIPTION:
35934598Sbostic /	Take action action against foe, and decide who is master
36034598Sbostic /	for next iteration.
36134598Sbostic /
36234598Sbostic /************************************************************************/
36334598Sbostic 
myturn()36434598Sbostic myturn()
36534598Sbostic {
36634598Sbostic double	dtemp;		/* for temporary calculations */
36734598Sbostic int	ch;		/* input */
36834598Sbostic 
36934598Sbostic     mvaddstr(7, 0, "1:Fight  2:Run Away!  3:Power Blast  ");
37034598Sbostic     if (Luckout)
37134598Sbostic 	clrtoeol();
37234598Sbostic     else
37334598Sbostic 	addstr("4:Luckout  ");
37434598Sbostic 
37534598Sbostic     ch = inputoption();
37634598Sbostic     move(Lines = 8, 0);
37734598Sbostic     clrtobot();
37834598Sbostic 
37934598Sbostic     switch (ch)
38034598Sbostic 	{
38134598Sbostic 	default:	/* fight */
38234598Sbostic 	    dtemp = ROLL(2.0, Player.p_might);
38334598Sbostic HIT:
38434598Sbostic 	    mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp);
38534598Sbostic 	    Player.p_sin += 0.5;
38634598Sbostic 	    Player.p_1scratch += dtemp;
38734598Sbostic 	    Player.p_istat = I_OFF;
38834598Sbostic 	    break;
38934598Sbostic 
39034598Sbostic 	case '2':	/* run away */
39134598Sbostic 	    Player.p_1scratch -= 1.0;	/* change this to indicate action */
39234598Sbostic 	    if (drandom() > 0.25)
39334598Sbostic 		{
39434598Sbostic 		mvaddstr(Lines++, 0, "You got away!");
39534598Sbostic 		Player.p_istat = I_RAN;
39634598Sbostic 		}
39734598Sbostic 	    else
39834598Sbostic 		{
39934598Sbostic 		mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
40034598Sbostic 		Player.p_istat = I_STUCK;
40134598Sbostic 		}
40234598Sbostic 	    break;
40334598Sbostic 
40434598Sbostic 	case '3':	/* power blast */
40534598Sbostic 	    dtemp = MIN(Player.p_mana, Player.p_level * 5.0);
40634598Sbostic 	    Player.p_mana -= dtemp;
40734598Sbostic 	    dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0;
40834598Sbostic 	    mvprintw(Lines++, 0, "You blasted %s !", Enemyname);
40934598Sbostic 	    goto HIT;
41034598Sbostic 
41134598Sbostic 	case '4':	/* luckout */
41234598Sbostic 	    if (Luckout || drandom() > 0.1)
41334598Sbostic 		{
41434598Sbostic 		if (Luckout)
41534598Sbostic 		    mvaddstr(Lines++, 0, "You already tried that!");
41634598Sbostic 		else
41734598Sbostic 		    {
41834598Sbostic 		    mvaddstr(Lines++, 0, "Not this time . . .");
41934598Sbostic 		    Luckout = TRUE;
42034598Sbostic 		    }
42134598Sbostic 
42234598Sbostic 		Player.p_1scratch -= 1.0;
42334598Sbostic 		Player.p_istat = I_BLEWIT;
42434598Sbostic 		}
42534598Sbostic 	    else
42634598Sbostic 		{
42734598Sbostic 		mvaddstr(Lines++, 0, "You just lucked out!");
42834598Sbostic 		Player.p_1scratch = Other.p_energy * 1.1;
42934598Sbostic 		}
43034598Sbostic 	    break;
43134598Sbostic 	}
43234598Sbostic 
43334598Sbostic     refresh();
43434598Sbostic     Player.p_1scratch = floor(Player.p_1scratch);	/* clean up any mess */
43534598Sbostic 
43634598Sbostic     if (Player.p_1scratch > Other.p_energy)
43734598Sbostic 	Player.p_istat = I_KILLED;
43834598Sbostic     else if (drandom() * Player.p_speed < drandom() * Other.p_speed)
43934598Sbostic 	/* relinquish control */
44034598Sbostic 	{
44134598Sbostic 	++Player.p_tampered;
44234598Sbostic 	Foestrikes = TRUE;
44334598Sbostic 	}
44434598Sbostic 
44534598Sbostic     writerecord(&Player, Fileloc);			/* let foe know what we did */
44634598Sbostic }
44734598Sbostic /**/
44834598Sbostic /************************************************************************
44934598Sbostic /
45034598Sbostic / FUNCTION NAME: checktampered()
45134598Sbostic /
45234598Sbostic / FUNCTION: check if current player has been tampered with
45334598Sbostic /
45434598Sbostic / AUTHOR: E. A. Estes, 12/4/85
45534598Sbostic /
45634598Sbostic / ARGUMENTS: none
45734598Sbostic /
45834598Sbostic / RETURN VALUE: none
45934598Sbostic /
46034598Sbostic / MODULES CALLED: readrecord(), fread(), fseek(), tampered(), writevoid()
46134598Sbostic /
46234598Sbostic / GLOBAL INPUTS: *Energyvoidfp, Other, Player, Fileloc, Enrgyvoid
46334598Sbostic /
46434598Sbostic / GLOBAL OUTPUTS: Enrgyvoid
46534598Sbostic /
46634598Sbostic / DESCRIPTION:
46734598Sbostic /	Check for energy voids, holy grail, and tampering by other
46834598Sbostic /	players.
46934598Sbostic /
47034598Sbostic /************************************************************************/
47134598Sbostic 
checktampered()47234598Sbostic checktampered()
47334598Sbostic {
47434598Sbostic long	loc = 0L;		/* location in energy void file */
47534598Sbostic 
47634598Sbostic     /* first check for energy voids */
47734598Sbostic     fseek(Energyvoidfp, 0L, 0);
47834598Sbostic     while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
47934598Sbostic 	if (Enrgyvoid.ev_active
48034598Sbostic 	    && Enrgyvoid.ev_x == Player.p_x
48134598Sbostic 	    && Enrgyvoid.ev_y == Player.p_y)
48234598Sbostic 	    /* sitting on one */
48334598Sbostic 	    {
48434598Sbostic 	    if (loc > 0L)
48534598Sbostic 		/* not the holy grail; inactivate energy void */
48634598Sbostic 		{
48734598Sbostic 		Enrgyvoid.ev_active = FALSE;
48834598Sbostic 		writevoid(&Enrgyvoid, loc);
48934598Sbostic 		tampered(T_NRGVOID, 0.0, 0.0);
49034598Sbostic 		}
49134598Sbostic 	    else if (Player.p_status != S_CLOAKED)
49234598Sbostic 		/* holy grail */
49334598Sbostic 		tampered(T_GRAIL, 0.0, 0.0);
49434598Sbostic 	    break;
49534598Sbostic 	    }
49634598Sbostic 	else
49734598Sbostic 	    loc += SZ_VOIDSTRUCT;
49834598Sbostic 
49934598Sbostic     /* now check for other things */
50034598Sbostic     readrecord(&Other, Fileloc);
50134598Sbostic     if (Other.p_tampered != T_OFF)
50234598Sbostic 	tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch);
50334598Sbostic }
50434598Sbostic /**/
50534598Sbostic /************************************************************************
50634598Sbostic /
50734598Sbostic / FUNCTION NAME: tampered()
50834598Sbostic /
50934598Sbostic / FUNCTION: take care of tampering by other players
51034598Sbostic /
51134598Sbostic / AUTHOR: E. A. Estes, 12/4/85
51234598Sbostic /
51334598Sbostic / ARGUMENTS:
51434598Sbostic /	int what - what type of tampering
51534598Sbostic /	double arg1, arg2 - rest of tampering info
51634598Sbostic /
51734598Sbostic / RETURN VALUE: none
51834598Sbostic /
51934598Sbostic / MODULES CALLED: writerecord(), more(), fread(), death(), fseek(), sleep(),
52034598Sbostic /	floor(), wmove(), waddch(), drandom(), printw(), altercoordinates(),
52134598Sbostic /	waddstr(), wrefresh(), encounter(), writevoid()
52234598Sbostic /
52334598Sbostic / GLOBAL INPUTS: Other, Player, *stdscr, Enrgyvoid, *Playersfp
52434598Sbostic /
52534598Sbostic / GLOBAL OUTPUTS: Other, Player, Changed, Enrgyvoid
52634598Sbostic /
52734598Sbostic / DESCRIPTION:
52834598Sbostic /	Take care of energy voids, holy grail, decree and intervention
52934598Sbostic /	action on current player.
53034598Sbostic /
53134598Sbostic /************************************************************************/
53234598Sbostic 
tampered(what,arg1,arg2)53334598Sbostic tampered(what, arg1, arg2)
53434598Sbostic int	what;
53534598Sbostic double	arg1;
53634598Sbostic double	arg2;
53734598Sbostic {
53834598Sbostic long	loc;			/* location in file of other players */
53934598Sbostic 
54034598Sbostic     Changed = TRUE;
54134598Sbostic     move(4,0);
54234598Sbostic 
54334598Sbostic     Player.p_tampered = T_OFF;	/* no longer tampered with */
54434598Sbostic 
54534598Sbostic     switch (what)
54634598Sbostic 	{
54734598Sbostic 	case T_NRGVOID:
54834598Sbostic 	    addstr("You've hit an energy void !\n");
54934598Sbostic 	    Player.p_mana /= 3.0;
55034598Sbostic 	    Player.p_energy /= 2.0;
55134598Sbostic 	    Player.p_gold = floor(Player.p_gold/1.25) + 0.1;
55234598Sbostic 	    altercoordinates(0.0, 0.0, A_NEAR);
55334598Sbostic 	    break;
55434598Sbostic 
55534598Sbostic 	case T_TRANSPORT:
55634598Sbostic 	    addstr("The king transported you !  ");
55734598Sbostic 	    if (Player.p_charms > 0)
55834598Sbostic 		{
55934598Sbostic 		addstr("But your charm saved you. . .\n");
56034598Sbostic 		--Player.p_charms;
56134598Sbostic 		}
56234598Sbostic 	    else
56334598Sbostic 		{
56434598Sbostic 		altercoordinates(0.0, 0.0, A_FAR);
56534598Sbostic 		addch('\n');
56634598Sbostic 		}
56734598Sbostic 	    break;
56834598Sbostic 
56934598Sbostic 	case T_BESTOW:
57034598Sbostic 	    printw("The king has bestowed %.0f gold pieces on you !\n", arg1);
57134598Sbostic 	    Player.p_gold += arg1;
57234598Sbostic 	    break;
57334598Sbostic 
57434598Sbostic 	case T_CURSED:
57534598Sbostic 	    addstr("You've been cursed !  ");
57634598Sbostic 	    if (Player.p_blessing)
57734598Sbostic 		{
57834598Sbostic 		addstr("But your blessing saved you. . .\n");
57934598Sbostic 		Player.p_blessing = FALSE;
58034598Sbostic 		}
58134598Sbostic 	    else
58234598Sbostic 		{
58334598Sbostic 		addch('\n');
58434598Sbostic 		Player.p_poison += 2.0;
58534598Sbostic 		Player.p_energy = 10.0;
58634598Sbostic 		Player.p_maxenergy  *= 0.95;
58734598Sbostic 		Player.p_status = S_PLAYING;	/* no longer cloaked */
58834598Sbostic 		}
58934598Sbostic 	    break;
59034598Sbostic 
59134598Sbostic 	case T_VAPORIZED:
59234598Sbostic 	    addstr("You have been vaporized!\n");
59334598Sbostic 	    more(7);
59434598Sbostic 	    death("Vaporization");
59534598Sbostic 	    break;
59634598Sbostic 
59734598Sbostic 	case T_MONSTER:
59834598Sbostic 	    addstr("The Valar zapped you with a monster!\n");
59934598Sbostic 	    more(7);
60034598Sbostic 	    encounter((int) arg1);
60134598Sbostic 	    return;
60234598Sbostic 
60334598Sbostic 	case T_BLESSED:
60434598Sbostic 	    addstr("The Valar has blessed you!\n");
60534598Sbostic 	    Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield;
60634598Sbostic 	    Player.p_mana += 500.0;
60734598Sbostic 	    Player.p_strength += 0.5;
60834598Sbostic 	    Player.p_brains += 0.5;
60934598Sbostic 	    Player.p_magiclvl += 0.5;
61034598Sbostic 	    Player.p_poison = MIN(0.5, Player.p_poison);
61134598Sbostic 	    break;
61234598Sbostic 
61334598Sbostic 	case T_RELOCATE:
61434598Sbostic 	    addstr("You've been relocated. . .\n");
61534598Sbostic 	    altercoordinates(arg1, arg2, A_FORCED);
61634598Sbostic 	    break;
61734598Sbostic 
61834598Sbostic 	case T_HEAL:
61934598Sbostic 	    addstr("You've been healed!\n");
62034598Sbostic 	    Player.p_poison -=  0.25;
62134598Sbostic 	    Player.p_energy = Player.p_maxenergy + Player.p_shield;
62234598Sbostic 	    break;
62334598Sbostic 
62434598Sbostic 	case T_EXVALAR:
62534598Sbostic 	    addstr("You are no longer Valar!\n");
62634598Sbostic 	    Player.p_specialtype = SC_COUNCIL;
62734598Sbostic 	    break;
62834598Sbostic 
62934598Sbostic 	case T_GRAIL:
63034598Sbostic 	    addstr("You have found The Holy Grail!!\n");
63134598Sbostic 	    if (Player.p_specialtype < SC_COUNCIL)
63234598Sbostic 		/* must be council of wise to behold grail */
63334598Sbostic 		{
63434598Sbostic 		addstr("However, you are not experienced enough to behold it.\n");
63534598Sbostic 		Player.p_sin *= Player.p_sin;
63634598Sbostic 		Player.p_mana +=  1000;
63734598Sbostic 		}
63834598Sbostic 	    else if (Player.p_specialtype == SC_VALAR
63934598Sbostic 		|| Player.p_specialtype == SC_EXVALAR)
64034598Sbostic 		{
64134598Sbostic 		addstr("You have made it to the position of Valar once already.\n");
64234598Sbostic 		addstr("The Grail is of no more use to you now.\n");
64334598Sbostic 		}
64434598Sbostic 	    else
64534598Sbostic 		{
64634598Sbostic 		addstr("It is now time to see if you are worthy to behold it. . .\n");
64734598Sbostic 		refresh();
64834598Sbostic 		sleep(4);
64934598Sbostic 
65034598Sbostic 		if (drandom() / 2.0 < Player.p_sin)
65134598Sbostic 		    {
65234598Sbostic 		    addstr("You have failed!\n");
65334598Sbostic 		    Player.p_strength =
65434598Sbostic 		    Player.p_mana =
65534598Sbostic 		    Player.p_energy =
65634598Sbostic 		    Player.p_maxenergy =
65734598Sbostic 		    Player.p_magiclvl =
65834598Sbostic 		    Player.p_brains =
65934598Sbostic 		    Player.p_experience =
66034598Sbostic 		    Player.p_quickness = 1.0;
66134598Sbostic 
66234598Sbostic 		    altercoordinates(1.0, 1.0, A_FORCED);
66334598Sbostic 		    Player.p_level = 0.0;
66434598Sbostic 		    }
66534598Sbostic 		else
66634598Sbostic 		    {
66734598Sbostic 		    addstr("You made to position of Valar!\n");
66834598Sbostic 		    Player.p_specialtype = SC_VALAR;
66934598Sbostic 		    Player.p_lives = 5;
67034598Sbostic 		    fseek(Playersfp, 0L, 0);
67134598Sbostic 		    loc = 0L;
67234598Sbostic 		    while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
67334598Sbostic 			/* search for existing valar */
67434598Sbostic 			if (Other.p_specialtype == SC_VALAR
67534598Sbostic 			    && Other.p_status != S_NOTUSED)
67634598Sbostic 			    /* found old valar */
67734598Sbostic 			    {
67834598Sbostic 			    Other.p_tampered = T_EXVALAR;
67934598Sbostic 			    writerecord(&Other, loc);
68034598Sbostic 			    break;
68134598Sbostic 			    }
68234598Sbostic 			else
68334598Sbostic 			    loc += SZ_PLAYERSTRUCT;
68434598Sbostic 		    }
68534598Sbostic 		}
68634598Sbostic 
68734598Sbostic 	    /* move grail to new location */
68834598Sbostic 	    Enrgyvoid.ev_active = TRUE;
68934598Sbostic 	    Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
69034598Sbostic 	    Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
69134598Sbostic 	    writevoid(&Enrgyvoid, 0L);
69234598Sbostic 	    break;
69334598Sbostic 	}
69434598Sbostic     refresh();
69534598Sbostic     sleep(2);
69634598Sbostic }
69734598Sbostic /**/
69834598Sbostic /************************************************************************
69934598Sbostic /
70034598Sbostic / FUNCTION NAME: userlist()
70134598Sbostic /
70234598Sbostic / FUNCTION: print list of players and locations
70334598Sbostic /
70434598Sbostic / AUTHOR: E. A. Estes, 2/28/86
70534598Sbostic /
70634598Sbostic / ARGUMENTS:
70734598Sbostic /	bool ingameflag - set if called while playing
70834598Sbostic /
70934598Sbostic / RETURN VALUE: none
71034598Sbostic /
71134598Sbostic / MODULES CALLED: descrstatus(), descrlocation(), more(), fread(), fseek(),
71234598Sbostic /	floor(), wmove(), printw(), waddstr(), distance(), wrefresh(),
71334598Sbostic /	descrtype(), wclrtobot()
71434598Sbostic /
71534598Sbostic / GLOBAL INPUTS: LINES, Other, Circle, Wizard, Player, *stdscr, *Playersfp
71634598Sbostic /
71734598Sbostic / GLOBAL OUTPUTS: none
71834598Sbostic /
71934598Sbostic / DESCRIPTION:
72034598Sbostic /	We can only see the coordinate of those closer to the origin
72134598Sbostic /	from us.
72234598Sbostic /	Kings and council of the wise can see and can be seen by everyone.
72334598Sbostic /	Palantirs are good for seeing everyone; and the valar can use
72434598Sbostic /	one to see through a 'cloak' spell.
72534598Sbostic /	The valar has no coordinates, and is completely invisible if
72634598Sbostic /	cloaked.
72734598Sbostic /
72834598Sbostic /************************************************************************/
72934598Sbostic 
userlist(ingameflag)73034598Sbostic userlist(ingameflag)
73134598Sbostic bool	ingameflag;
73234598Sbostic {
73334598Sbostic register int	numusers = 0;	/* number of users on file */
73434598Sbostic 
73534598Sbostic     if (ingameflag && Player.p_blindness)
73634598Sbostic 	{
73734598Sbostic 	mvaddstr(8, 0, "You cannot see anyone.\n");
73834598Sbostic 	return;
73934598Sbostic 	}
74034598Sbostic 
74134598Sbostic     fseek(Playersfp, 0L, 0);
74234598Sbostic     mvaddstr(8, 0,
74334598Sbostic 	"Name                         X         Y    Lvl Type Login    Status\n");
74434598Sbostic 
74534598Sbostic     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
74634598Sbostic 	{
74734598Sbostic 	if (Other.p_status == S_NOTUSED
74834598Sbostic 	    /* record is unused */
74934598Sbostic 	    || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED))
75034598Sbostic 	    /* cloaked valar */
75134598Sbostic 	    {
75234598Sbostic 	    if (!Wizard)
75334598Sbostic 		/* wizard can see everything on file */
75434598Sbostic 		continue;
75534598Sbostic 	    }
75634598Sbostic 
75734598Sbostic 	    ++numusers;
75834598Sbostic 
75934598Sbostic 	    if (ingameflag &&
76034598Sbostic 		/* must be playing for the rest of these conditions */
76134598Sbostic 		(Player.p_specialtype >= SC_KING
76234598Sbostic 		/* kings and higher can see others */
76334598Sbostic 		|| Other.p_specialtype >= SC_KING
76434598Sbostic 		/* kings and higher can be seen by others */
76534598Sbostic 		|| Circle >= CIRCLE(Other.p_x, Other.p_y)
76634598Sbostic 		/* those nearer the origin can be seen */
76734598Sbostic 		|| Player.p_palantir)
76834598Sbostic 		/* palantir enables one to see others */
76934598Sbostic 		&& (Other.p_status != S_CLOAKED
77034598Sbostic 		    || (Player.p_specialtype == SC_VALAR && Player.p_palantir))
77134598Sbostic 		/* not cloaked; valar can see through cloak with a palantir */
77234598Sbostic 		&& Other.p_specialtype != SC_VALAR)
77334598Sbostic 		/* not a valar */
77434598Sbostic 		/* coordinates should be printed */
77534598Sbostic 		printw("%-20s  %8.0f  %8.0f ",
77634598Sbostic 		    Other.p_name, Other.p_x, Other.p_y);
77734598Sbostic 	    else
77834598Sbostic 		/* cannot see player's coordinates */
77934598Sbostic 		printw("%-20s %19.19s ",
78034598Sbostic 		    Other.p_name, descrlocation(&Other, TRUE));
78134598Sbostic 
78234598Sbostic 	printw("%6.0f %s  %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE),
78334598Sbostic 	    Other.p_login, descrstatus(&Other));
78434598Sbostic 
78534598Sbostic 	if ((numusers % (LINES - 10)) == 0)
78634598Sbostic 	    {
78734598Sbostic 	    more(LINES - 1);
78834598Sbostic 	    move(9, 0);
78934598Sbostic 	    clrtobot();
79034598Sbostic 	    }
79134598Sbostic 	}
79234598Sbostic 
79334598Sbostic     printw("Total players on file = %d\n", numusers);
79434598Sbostic     refresh();
79534598Sbostic }
79634598Sbostic /**/
79734598Sbostic /************************************************************************
79834598Sbostic /
79934598Sbostic / FUNCTION NAME: throneroom()
80034598Sbostic /
80134598Sbostic / FUNCTION: king stuff upon entering throne
80234598Sbostic /
80334598Sbostic / AUTHOR: E. A. Estes, 12/16/85
80434598Sbostic /
80534598Sbostic / ARGUMENTS: none
80634598Sbostic /
80734598Sbostic / RETURN VALUE: none
80834598Sbostic /
80934598Sbostic / MODULES CALLED: writerecord(), fread(), fseek(), fopen(), wmove(), fclose(),
81034598Sbostic /	fwrite(), altercoordinates(), waddstr(), fprintf()
81134598Sbostic /
812*40279Sbostic / GLOBAL INPUTS: *Energyvoidfp, Other, Player, *stdscr,
813*40279Sbostic /	Enrgyvoid, *Playersfp
81434598Sbostic /
81534598Sbostic / GLOBAL OUTPUTS: Other, Player, Changed
81634598Sbostic /
81734598Sbostic / DESCRIPTION:
81834598Sbostic /	If player is not already king, make him/her so if the old king
81934598Sbostic /	is not playing.
82034598Sbostic /	Clear energy voids with new king.
82134598Sbostic /	Print 'decree' prompt.
82234598Sbostic /
82334598Sbostic /************************************************************************/
82434598Sbostic 
throneroom()82534598Sbostic throneroom()
82634598Sbostic {
82734598Sbostic FILE	*fp;			/* to clear energy voids */
82834598Sbostic long	loc = 0L;		/* location of old king in player file */
82934598Sbostic 
83034598Sbostic     if (Player.p_specialtype < SC_KING)
83134598Sbostic 	/* not already king -- assumes crown */
83234598Sbostic 	{
83334598Sbostic 	fseek(Playersfp, 0L, 0);
83434598Sbostic 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
83534598Sbostic 	    if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
83634598Sbostic 		/* found old king */
83734598Sbostic 		{
83834598Sbostic 		if (Other.p_status != S_OFF)
83934598Sbostic 		    /* old king is playing */
84034598Sbostic 		    {
84134598Sbostic 		    mvaddstr( 4, 0, "The king is playing, so you cannot steal his throne\n");
84234598Sbostic 		    altercoordinates(0.0, 0.0, A_NEAR);
84334598Sbostic 		    move(6, 0);
84434598Sbostic 		    return;
84534598Sbostic 		    }
84634598Sbostic 		else
84734598Sbostic 		    /* old king is not playing - remove him/her */
84834598Sbostic 		    {
84934598Sbostic 		    Other.p_specialtype = SC_NONE;
85034598Sbostic 		    if (Other.p_crowns)
85134598Sbostic 			--Other.p_crowns;
85234598Sbostic 		    writerecord(&Other, loc);
85334598Sbostic 		    break;
85434598Sbostic 		    }
85534598Sbostic 		}
85634598Sbostic 	    else
85734598Sbostic 		loc += SZ_PLAYERSTRUCT;
85834598Sbostic 
85934598Sbostic 	/* make player new king */
86034598Sbostic 	Changed = TRUE;
86134598Sbostic 	Player.p_specialtype = SC_KING;
86234598Sbostic 	mvaddstr(4, 0, "You have become king!\n");
86334598Sbostic 
86434598Sbostic 	/* let everyone else know */
865*40279Sbostic 	fp = fopen(_PATH_MESS, "w");
86634598Sbostic 	fprintf(fp, "All hail the new king!");
86734598Sbostic 	fclose(fp);
86834598Sbostic 
86934598Sbostic 	/* clear all energy voids; retain location of holy grail */
87034598Sbostic 	fseek(Energyvoidfp, 0L, 0);
87134598Sbostic 	fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
872*40279Sbostic 	fp = fopen(_PATH_VOID, "w");
87334598Sbostic 	fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
87434598Sbostic 	fclose(fp);
87534598Sbostic 	}
87634598Sbostic 
87734598Sbostic     mvaddstr(6, 0, "0:Decree  ");
87834598Sbostic }
87934598Sbostic /**/
88034598Sbostic /************************************************************************
88134598Sbostic /
88234598Sbostic / FUNCTION NAME: dotampered()
88334598Sbostic /
88434598Sbostic / FUNCTION: king and valar special options
88534598Sbostic /
88634598Sbostic / AUTHOR: E. A. Estes, 2/28/86
88734598Sbostic /
88834598Sbostic / ARGUMENTS: none
88934598Sbostic /
89034598Sbostic / RETURN VALUE: none
89134598Sbostic /
89234598Sbostic / MODULES CALLED: writerecord(), truncstring(), fread(), fseek(), fopen(),
89334598Sbostic /	floor(), wmove(), drandom(), fclose(), fwrite(), sscanf(), strcmp(),
89434598Sbostic /	infloat(), waddstr(), findname(), distance(), userlist(), mvprintw(),
89534598Sbostic /	allocvoid(), getanswer(), getstring(), wclrtoeol(), writevoid()
89634598Sbostic /
89734598Sbostic / GLOBAL INPUTS: *Energyvoidfp, Other, Illcmd[], Wizard, Player, *stdscr,
898*40279Sbostic /	Databuf[], Enrgyvoid
89934598Sbostic /
90034598Sbostic / GLOBAL OUTPUTS: Other, Player, Enrgyvoid
90134598Sbostic /
90234598Sbostic / DESCRIPTION:
90334598Sbostic /	Tamper with other players.  Handle king/valar specific options.
90434598Sbostic /
90534598Sbostic /************************************************************************/
90634598Sbostic 
dotampered()90734598Sbostic dotampered()
90834598Sbostic {
90934598Sbostic short	tamper;			/* value for tampering with other players */
91034598Sbostic char	*option;			/* pointer to option description */
91134598Sbostic double	temp1 = 0.0, temp2 = 0.0;	/* other tampering values */
91234598Sbostic int	ch;				/* input */
91334598Sbostic long	loc;				/* location in energy void file */
91434598Sbostic FILE	*fp;				/* for opening gold file */
91534598Sbostic 
91634598Sbostic     move(6, 0);
91734598Sbostic     clrtoeol();
91834598Sbostic     if (Player.p_specialtype < SC_COUNCIL && !Wizard)
91934598Sbostic 	/* king options */
92034598Sbostic 	{
92134598Sbostic 	addstr("1:Transport  2:Curse  3:Energy Void  4:Bestow  5:Collect Taxes  ");
92234598Sbostic 
92334598Sbostic 	ch = getanswer(" ", TRUE);
92434598Sbostic 	move(6, 0);
92534598Sbostic 	clrtoeol();
92634598Sbostic 	move(4, 0);
92734598Sbostic 	switch (ch)
92834598Sbostic 	    {
92934598Sbostic 	    case '1':	/* transport someone */
93034598Sbostic 		tamper = T_TRANSPORT;
93134598Sbostic 		option = "transport";
93234598Sbostic 		break;
93334598Sbostic 
93434598Sbostic 	    case '2':	/* curse another */
93534598Sbostic 		tamper = T_CURSED;
93634598Sbostic 		option = "curse";
93734598Sbostic 		break;
93834598Sbostic 
93934598Sbostic 	    case '3':	/* create energy void */
94034598Sbostic 		if ((loc = allocvoid()) > 20L * SZ_VOIDSTRUCT)
94134598Sbostic 		    /* can only have 20 void active at once */
94234598Sbostic 		    mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
94334598Sbostic 		else
94434598Sbostic 		    {
94534598Sbostic 		    addstr("Enter the X Y coordinates of void ? ");
94634598Sbostic 		    getstring(Databuf, SZ_DATABUF);
94734613Sbostic 		    sscanf(Databuf, "%lf %lf", &temp1, &temp2);
94834598Sbostic 		    Enrgyvoid.ev_x = floor(temp1);
94934598Sbostic 		    Enrgyvoid.ev_y = floor(temp2);
95034598Sbostic 		    Enrgyvoid.ev_active = TRUE;
95134598Sbostic 		    writevoid(&Enrgyvoid, loc);
95234598Sbostic 		    mvaddstr(5, 0, "It is done.\n");
95334598Sbostic 		    }
95434598Sbostic 		return;
95534598Sbostic 
95634598Sbostic 	    case '4':	/* bestow gold to subject */
95734598Sbostic 		tamper = T_BESTOW;
95834598Sbostic 		addstr("How much gold to bestow ? ");
95934598Sbostic 		temp1 = infloat();
96034598Sbostic 		if (temp1 > Player.p_gold || temp1 < 0)
96134598Sbostic 		    {
96234598Sbostic 		    mvaddstr(5, 0, "You don't have that !\n");
96334598Sbostic 		    return;
96434598Sbostic 		    }
96534598Sbostic 
96634598Sbostic 		/* adjust gold after we are sure it will be given to someone */
96734598Sbostic 		option = "give gold to";
96834598Sbostic 		break;
96934598Sbostic 
97034598Sbostic 	    case '5':	/* collect accumulated taxes */
971*40279Sbostic 		if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)
97234598Sbostic 		    /* collect taxes */
97334598Sbostic 		    {
97434598Sbostic 		    fread((char *) &temp1, sizeof(double), 1, fp);
97534598Sbostic 		    fseek(fp, 0L, 0);
97634598Sbostic 		    /* clear out value */
97734598Sbostic 		    temp2 = 0.0;
97834598Sbostic 		    fwrite((char *) &temp2, sizeof(double), 1, fp);
97934598Sbostic 		    fclose(fp);
98034598Sbostic 		    }
98134598Sbostic 
98234598Sbostic 		mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1);
98334598Sbostic 		Player.p_gold += floor(temp1);
98434598Sbostic 		return;
98534598Sbostic 
98634598Sbostic 	    default:
98734598Sbostic 		return;
98834598Sbostic 	    }
98934598Sbostic 	/* end of king options */
99034598Sbostic 	}
99134598Sbostic     else
99234598Sbostic 	/* council of wise, valar, wizard options */
99334598Sbostic 	{
99434598Sbostic 	addstr("1:Heal  ");
99534598Sbostic 	if (Player.p_palantir || Wizard)
99634598Sbostic 	    addstr("2:Seek Grail  ");
99734598Sbostic 	if (Player.p_specialtype == SC_VALAR || Wizard)
99834598Sbostic 	    addstr("3:Throw Monster  4:Relocate  5:Bless  ");
99934598Sbostic 	if (Wizard)
100034598Sbostic 	    addstr("6:Vaporize  ");
100134598Sbostic 
100234598Sbostic 	ch = getanswer(" ", TRUE);
100334598Sbostic 	if (!Wizard)
100434598Sbostic 	    {
100534598Sbostic 	    if (ch > '2' && Player.p_specialtype != SC_VALAR)
100634598Sbostic 		{
100734598Sbostic 		ILLCMD();
100834598Sbostic 		return;
100934598Sbostic 		}
101034598Sbostic 
101134598Sbostic 	    if (Player.p_mana < MM_INTERVENE)
101234598Sbostic 		{
101334598Sbostic 		mvaddstr(5, 0, "No mana left.\n");
101434598Sbostic 		return;
101534598Sbostic 		}
101634598Sbostic 	    else
101734598Sbostic 		Player.p_mana -= MM_INTERVENE;
101834598Sbostic 	    }
101934598Sbostic 
102034598Sbostic 	switch (ch)
102134598Sbostic 	    {
102234598Sbostic 	    case '1':	/* heal another */
102334598Sbostic 		tamper = T_HEAL;
102434598Sbostic 		option = "heal";
102534598Sbostic 		break;
102634598Sbostic 
102734598Sbostic 	    case '2':	/* seek grail */
102834598Sbostic 		if (Player.p_palantir)
102934598Sbostic 		    /* need a palantir to seek */
103034598Sbostic 		    {
103134598Sbostic 		    fseek(Energyvoidfp, 0L, 0);
103234598Sbostic 		    fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
103334598Sbostic 		    temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y);
103434598Sbostic 		    temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0);	/* add some error */
103534598Sbostic 		    mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1);
103634598Sbostic 		    }
103734598Sbostic 		else
103834598Sbostic 		    /* no palantir */
103934598Sbostic 		    mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
104034598Sbostic 		return;
104134598Sbostic 
104234598Sbostic 	    case '3':	/* lob monster at someone */
104334598Sbostic 		mvaddstr(4, 0, "Which monster [0-99] ? ");
104434598Sbostic 		temp1 = infloat();
104534598Sbostic 		temp1 = MAX(0.0, MIN(99.0, temp1));
104634598Sbostic 		tamper = T_MONSTER;
104734598Sbostic 		option = "throw a monster at";
104834598Sbostic 		break;
104934598Sbostic 
105034598Sbostic 	    case '4':	/* move another player */
105134598Sbostic 		mvaddstr(4, 0, "New X Y coordinates ? ");
105234598Sbostic 		getstring(Databuf, SZ_DATABUF);
105334613Sbostic 		sscanf(Databuf, "%lf %lf", &temp1, &temp2);
105434598Sbostic 		tamper = T_RELOCATE;
105534598Sbostic 		option = "relocate";
105634598Sbostic 		break;
105734598Sbostic 
105834598Sbostic 	    case '5':	/* bless a player */
105934598Sbostic 		tamper = T_BLESSED;
106034598Sbostic 		option = "bless";
106134598Sbostic 		break;
106234598Sbostic 
106334598Sbostic 	    case '6':	/* kill off a player */
106434598Sbostic 		if (Wizard)
106534598Sbostic 		    {
106634598Sbostic 		    tamper = T_VAPORIZED;
106734598Sbostic 		    option = "vaporize";
106834598Sbostic 		    break;
106934598Sbostic 		    }
107034598Sbostic 		else
107134598Sbostic 		    return;
107234598Sbostic 
107334598Sbostic 	    default:
107434598Sbostic 		return;
107534598Sbostic 	    }
107634598Sbostic 
107734598Sbostic 	/* adjust age after we are sure intervention will be done */
107834598Sbostic 	/* end of valar, etc. options */
107934598Sbostic 	}
108034598Sbostic 
108134598Sbostic     for (;;)
108234598Sbostic 	/* prompt for player to affect */
108334598Sbostic 	{
108434598Sbostic 	mvprintw(4, 0, "Who do you want to %s ? ", option);
108534598Sbostic 	getstring(Databuf, SZ_DATABUF);
108634598Sbostic 	truncstring(Databuf);
108734598Sbostic 
108834598Sbostic 	if (Databuf[0] == '\0')
108934598Sbostic 	    userlist(TRUE);
109034598Sbostic 	else
109134598Sbostic 	    break;
109234598Sbostic 	}
109334598Sbostic 
109434598Sbostic     if (strcmp(Player.p_name, Databuf) != 0)
109534598Sbostic 	/* name other than self */
109634598Sbostic 	{
109734598Sbostic 	if ((loc = findname(Databuf, &Other)) >= 0L)
109834598Sbostic 	    {
109934598Sbostic 	    if (Other.p_tampered != T_OFF)
110034598Sbostic 		{
110134598Sbostic 		mvaddstr(5, 0, "That person has something pending already.\n");
110234598Sbostic 		return;
110334598Sbostic 		}
110434598Sbostic 	    else
110534598Sbostic 		{
110634598Sbostic 		if (tamper == T_RELOCATE
110734598Sbostic 		    && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y)
110834598Sbostic 		    && !Wizard)
110934598Sbostic 		    mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
111034598Sbostic 		else
111134598Sbostic 		    {
111234598Sbostic 		    if (tamper == T_BESTOW) Player.p_gold -= floor(temp1);
111334598Sbostic 		    if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER ||
111434598Sbostic 			tamper == T_RELOCATE || tamper == T_BLESSED))
111534598Sbostic 	    			Player.p_age += N_AGE;	/* age penalty */
111634598Sbostic 		    Other.p_tampered = tamper;
111734598Sbostic 		    Other.p_1scratch = floor(temp1);
111834598Sbostic 		    Other.p_2scratch = floor(temp2);
111934598Sbostic 		    writerecord(&Other, loc);
112034598Sbostic 		    mvaddstr(5, 0, "It is done.\n");
112134598Sbostic 		    }
112234598Sbostic 		return;
112334598Sbostic 		}
112434598Sbostic 	    }
112534598Sbostic 	else
112634598Sbostic 	    /* player not found */
112734598Sbostic 	    mvaddstr(5, 0, "There is no one by that name.\n");
112834598Sbostic 	}
112934598Sbostic     else
113034598Sbostic 	/* self */
113134598Sbostic 	mvaddstr(5, 0, "You may not do it to yourself!\n");
113234598Sbostic }
113334598Sbostic /**/
113434598Sbostic /************************************************************************
113534598Sbostic /
113634598Sbostic / FUNCTION NAME: writevoid()
113734598Sbostic /
113834598Sbostic / FUNCTION: update energy void entry in energy void file
113934598Sbostic /
114034598Sbostic / AUTHOR: E. A. Estes, 12/4/85
114134598Sbostic /
114234598Sbostic / ARGUMENTS:
114334598Sbostic /	struct energyvoid *vp - pointer to structure to write to file
114434598Sbostic /	long loc - location in file to update
114534598Sbostic /
114634598Sbostic / RETURN VALUE: none
114734598Sbostic /
114834598Sbostic / MODULES CALLED: fseek(), fwrite(), fflush()
114934598Sbostic /
115034598Sbostic / GLOBAL INPUTS: *Energyvoidfp
115134598Sbostic /
115234598Sbostic / GLOBAL OUTPUTS: none
115334598Sbostic /
115434598Sbostic / DESCRIPTION:
115534598Sbostic /	Write out energy void structure at specified location.
115634598Sbostic /
115734598Sbostic /************************************************************************/
115834598Sbostic 
writevoid(vp,loc)115934598Sbostic writevoid(vp, loc)
116034598Sbostic register struct energyvoid	*vp;
116134598Sbostic long	loc;
116234598Sbostic {
116334598Sbostic 
116434598Sbostic     fseek(Energyvoidfp, loc, 0);
116534598Sbostic     fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp);
116634598Sbostic     fflush(Energyvoidfp);
116734598Sbostic     fseek(Energyvoidfp, 0L, 0);
116834598Sbostic }
116934598Sbostic /**/
117034598Sbostic /************************************************************************
117134598Sbostic /
117234598Sbostic / FUNCTION NAME: allocvoid()
117334598Sbostic /
117434598Sbostic / FUNCTION: allocate space for a new energy void
117534598Sbostic /
117634598Sbostic / AUTHOR: E. A. Estes, 12/4/85
117734598Sbostic /
117834598Sbostic / ARGUMENTS: none
117934598Sbostic /
118034598Sbostic / RETURN VALUE: location of new energy void space
118134598Sbostic /
118234598Sbostic / MODULES CALLED: fread(), fseek()
118334598Sbostic /
118434598Sbostic / GLOBAL INPUTS: *Energyvoidfp, Enrgyvoid
118534598Sbostic /
118634598Sbostic / GLOBAL OUTPUTS: none
118734598Sbostic /
118834598Sbostic / DESCRIPTION:
118934598Sbostic /	Search energy void file for an inactive entry and return its
119034598Sbostic /	location.
119134598Sbostic /	If no inactive ones are found, return one more than last location.
119234598Sbostic /
119334598Sbostic /************************************************************************/
119434598Sbostic 
119534598Sbostic long
allocvoid()119634598Sbostic allocvoid()
119734598Sbostic {
119834598Sbostic long	loc = 0L;		/* location of new energy void */
119934598Sbostic 
120034598Sbostic     fseek(Energyvoidfp, 0L, 0);
120134598Sbostic     while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
120234598Sbostic 	if (Enrgyvoid.ev_active)
120334598Sbostic 	    loc += SZ_VOIDSTRUCT;
120434598Sbostic 	else
120534598Sbostic 	    break;
120634598Sbostic 
120734598Sbostic     return(loc);
120834598Sbostic }
1209