Home | History | Annotate | Line # | Download | only in phantasia
interplayer.c revision 1.1
      1  1.1  jtc /*
      2  1.1  jtc  * interplayer.c - player to player routines for Phantasia
      3  1.1  jtc  */
      4  1.1  jtc 
      5  1.1  jtc #include "include.h"
      6  1.1  jtc 
      7  1.1  jtc /************************************************************************
      8  1.1  jtc /
      9  1.1  jtc / FUNCTION NAME: checkbattle()
     10  1.1  jtc /
     11  1.1  jtc / FUNCTION: check to see if current player should battle another
     12  1.1  jtc /
     13  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
     14  1.1  jtc /
     15  1.1  jtc / ARGUMENTS: none
     16  1.1  jtc /
     17  1.1  jtc / RETURN VALUE: none
     18  1.1  jtc /
     19  1.1  jtc / MODULES CALLED: battleplayer(), fread(), fseek()
     20  1.1  jtc /
     21  1.1  jtc / GLOBAL INPUTS: Other, Users, Player, Fileloc, *Playersfp
     22  1.1  jtc /
     23  1.1  jtc / GLOBAL OUTPUTS: Users
     24  1.1  jtc /
     25  1.1  jtc / DESCRIPTION:
     26  1.1  jtc /	Seach player file for a foe at the same coordinates as the
     27  1.1  jtc /	current player.
     28  1.1  jtc /	Also update user count.
     29  1.1  jtc /
     30  1.1  jtc /************************************************************************/
     31  1.1  jtc 
     32  1.1  jtc checkbattle()
     33  1.1  jtc {
     34  1.1  jtc long	foeloc = 0L;		/* location in file of person to fight */
     35  1.1  jtc 
     36  1.1  jtc     Users = 0;
     37  1.1  jtc     fseek(Playersfp, 0L, 0);
     38  1.1  jtc 
     39  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
     40  1.1  jtc 	{
     41  1.1  jtc 	if (Other.p_status != S_OFF
     42  1.1  jtc 	    && Other.p_status != S_NOTUSED
     43  1.1  jtc 	    && Other.p_status != S_HUNGUP
     44  1.1  jtc 	    && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR))
     45  1.1  jtc 	    /* player is on and not a cloaked valar */
     46  1.1  jtc 	    {
     47  1.1  jtc 	    ++Users;
     48  1.1  jtc 
     49  1.1  jtc 	    if (Player.p_x == Other.p_x
     50  1.1  jtc 		&& Player.p_y == Other.p_y
     51  1.1  jtc 		/* same coordinates */
     52  1.1  jtc 		&& foeloc != Fileloc
     53  1.1  jtc 		/* not self */
     54  1.1  jtc 		&& Player.p_status == S_PLAYING
     55  1.1  jtc 		&& (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE)
     56  1.1  jtc 		/* both are playing */
     57  1.1  jtc 		&& Other.p_specialtype != SC_VALAR
     58  1.1  jtc 		&& Player.p_specialtype != SC_VALAR)
     59  1.1  jtc 		/* neither is valar */
     60  1.1  jtc 		{
     61  1.1  jtc 		battleplayer(foeloc);
     62  1.1  jtc 		return;
     63  1.1  jtc 		}
     64  1.1  jtc 	    }
     65  1.1  jtc 	foeloc += SZ_PLAYERSTRUCT;
     66  1.1  jtc 	}
     67  1.1  jtc }
     68  1.1  jtc /**/
     70  1.1  jtc /************************************************************************
     71  1.1  jtc /
     72  1.1  jtc / FUNCTION NAME: battleplayer()
     73  1.1  jtc /
     74  1.1  jtc / FUNCTION: inter-terminal battle with another player
     75  1.1  jtc /
     76  1.1  jtc / AUTHOR: E. A. Estes, 2/15/86
     77  1.1  jtc /
     78  1.1  jtc / ARGUMENTS:
     79  1.1  jtc /	long foeplace - location in player file of person to battle
     80  1.1  jtc /
     81  1.1  jtc / RETURN VALUE: none
     82  1.1  jtc /
     83  1.1  jtc / MODULES CALLED: readrecord(), readmessage(), writerecord(), collecttaxes(),
     84  1.1  jtc /	displaystats(), fabs(), more(), death(), sleep(), wmove(), waddch(), printw(),
     85  1.1  jtc /	myturn(), altercoordinates(), waddstr(), wrefresh(), mvprintw(),
     86  1.1  jtc /	getanswer(), wclrtoeol(), wclrtobot()
     87  1.1  jtc /
     88  1.1  jtc / GLOBAL INPUTS: Foestrikes, LINES, Lines, Other, Shield, Player, *stdscr,
     89  1.1  jtc /	Fileloc, *Enemyname
     90  1.1  jtc /
     91  1.1  jtc / GLOBAL OUTPUTS: Foestrikes, Lines, Shield, Player, Luckout, *Enemyname
     92  1.1  jtc /
     93  1.1  jtc / DESCRIPTION:
     94  1.1  jtc /	Inter-terminal battle is a very fragile and slightly klugy thing.
     95  1.1  jtc /	At any time, one player is master and the other is slave.
     96  1.1  jtc /	We pick who is master first by speed and level.  After that,
     97  1.1  jtc /	the slave waits for the master to relinquish its turn, and
     98  1.1  jtc /	the slave becomes master, and so on.
     99  1.1  jtc /
    100  1.1  jtc /	The items in the player structure which control the handshake are:
    101  1.1  jtc /	    p_tampered:
    102  1.1  jtc /		master increments this to relinquish control
    103  1.1  jtc /	    p_istat:
    104  1.1  jtc /		master sets this to specify particular action
    105  1.1  jtc /	    p_1scratch:
    106  1.1  jtc /		set to total damage inflicted so far; changes to indicate action
    107  1.1  jtc /
    108  1.1  jtc /************************************************************************/
    109  1.1  jtc 
    110  1.1  jtc battleplayer(foeplace)
    111  1.1  jtc long	foeplace;
    112  1.1  jtc {
    113  1.1  jtc double	dtemp;		/* for temporary calculations */
    114  1.1  jtc double	oldhits = 0.0;	/* previous damage inflicted by foe */
    115  1.1  jtc register int	loop;	/* for timing out */
    116  1.1  jtc int	ch;		/* input */
    117  1.1  jtc short	oldtampered;	/* old value of foe's p_tampered */
    118  1.1  jtc 
    119  1.1  jtc     Lines = 8;
    120  1.1  jtc     Luckout = FALSE;
    121  1.1  jtc     mvaddstr(4, 0, "Preparing for battle!\n");
    122  1.1  jtc     refresh();
    123  1.1  jtc 
    124  1.1  jtc #ifdef SYS5
    125  1.1  jtc     flushinp();
    126  1.1  jtc #endif
    127  1.1  jtc 
    128  1.1  jtc     /* set up variables, file, etc. */
    129  1.1  jtc     Player.p_status = S_INBATTLE;
    130  1.1  jtc     Shield = Player.p_energy;
    131  1.1  jtc 
    132  1.1  jtc     /* if p_tampered is not 0, someone else may try to change it (king, etc.) */
    133  1.1  jtc     Player.p_tampered = oldtampered = 1;
    134  1.1  jtc     Player.p_1scratch = 0.0;
    135  1.1  jtc     Player.p_istat = I_OFF;
    136  1.1  jtc 
    137  1.1  jtc     readrecord(&Other, foeplace);
    138  1.1  jtc     if (fabs(Player.p_level - Other.p_level) > 20.0)
    139  1.1  jtc 	/* see if players are greatly mismatched */
    140  1.1  jtc 	{
    141  1.1  jtc 	dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level);
    142  1.1  jtc 	if (dtemp < -0.5)
    143  1.1  jtc 	    /* foe outweighs this one */
    144  1.1  jtc 	    Player.p_speed *= 2.0;
    145  1.1  jtc 	}
    146  1.1  jtc 
    147  1.1  jtc     writerecord(&Player, Fileloc);		/* write out all our info */
    148  1.1  jtc 
    149  1.1  jtc     if (Player.p_blindness)
    150  1.1  jtc 	Enemyname = "someone";
    151  1.1  jtc     else
    152  1.1  jtc 	Enemyname = Other.p_name;
    153  1.1  jtc 
    154  1.1  jtc     mvprintw(6, 0, "You have encountered %s   Level: %.0f\n", Enemyname, Other.p_level);
    155  1.1  jtc     refresh();
    156  1.1  jtc 
    157  1.1  jtc     for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop)
    158  1.1  jtc 	/* wait for foe to respond */
    159  1.1  jtc 	{
    160  1.1  jtc 	readrecord(&Other, foeplace);
    161  1.1  jtc 	sleep(1);
    162  1.1  jtc 	}
    163  1.1  jtc 
    164  1.1  jtc     if (Other.p_status != S_INBATTLE)
    165  1.1  jtc 	/* foe did not respond */
    166  1.1  jtc 	{
    167  1.1  jtc 	mvprintw(5, 0, "%s is not responding.\n", Enemyname);
    168  1.1  jtc 	goto LEAVE;
    169  1.1  jtc 	}
    170  1.1  jtc     /* else, we are ready to battle */
    171  1.1  jtc 
    172  1.1  jtc     move(4, 0);
    173  1.1  jtc     clrtoeol();
    174  1.1  jtc 
    175  1.1  jtc     /*
    176  1.1  jtc      * determine who is first master
    177  1.1  jtc      * if neither player is faster, check level
    178  1.1  jtc      * if neither level is greater, battle is not allowed
    179  1.1  jtc      * (this should never happen, but we have to handle it)
    180  1.1  jtc      */
    181  1.1  jtc     if (Player.p_speed > Other.p_speed)
    182  1.1  jtc 	Foestrikes = FALSE;
    183  1.1  jtc     else if (Other.p_speed > Player.p_speed)
    184  1.1  jtc 	Foestrikes = TRUE;
    185  1.1  jtc     else if (Player.p_level > Other.p_level)
    186  1.1  jtc 	Foestrikes = FALSE;
    187  1.1  jtc     else if (Other.p_level > Player.p_level)
    188  1.1  jtc 	Foestrikes = TRUE;
    189  1.1  jtc     else
    190  1.1  jtc 	/* no one is faster */
    191  1.1  jtc 	{
    192  1.1  jtc 	printw("You can't fight %s yet.", Enemyname);
    193  1.1  jtc 	goto LEAVE;
    194  1.1  jtc 	}
    195  1.1  jtc 
    196  1.1  jtc     for (;;)
    197  1.1  jtc 	{
    198  1.1  jtc 	displaystats();
    199  1.1  jtc 	readmessage();
    200  1.1  jtc 	mvprintw(1, 26, "%20.0f", Shield);	/* overprint energy */
    201  1.1  jtc 
    202  1.1  jtc 	if (!Foestrikes)
    203  1.1  jtc 	    /* take action against foe */
    204  1.1  jtc 	    myturn();
    205  1.1  jtc 	else
    206  1.1  jtc 	    /* wait for foe to take action */
    207  1.1  jtc 	    {
    208  1.1  jtc 	    mvaddstr(4, 0, "Waiting...\n");
    209  1.1  jtc 	    clrtoeol();
    210  1.1  jtc 	    refresh();
    211  1.1  jtc 
    212  1.1  jtc 	    for (loop = 0; loop < 20; ++loop)
    213  1.1  jtc 		/* wait for foe to act */
    214  1.1  jtc 		{
    215  1.1  jtc 		readrecord(&Other, foeplace);
    216  1.1  jtc 		if (Other.p_1scratch != oldhits)
    217  1.1  jtc 		    /* p_1scratch changes to indicate action */
    218  1.1  jtc 		    break;
    219  1.1  jtc 		else
    220  1.1  jtc 		    /* wait and try again */
    221  1.1  jtc 		    {
    222  1.1  jtc 		    sleep(1);
    223  1.1  jtc 		    addch('.');
    224  1.1  jtc 		    refresh();
    225  1.1  jtc 		    }
    226  1.1  jtc 		}
    227  1.1  jtc 
    228  1.1  jtc 	    if (Other.p_1scratch == oldhits)
    229  1.1  jtc 		{
    230  1.1  jtc 		/* timeout */
    231  1.1  jtc 		mvaddstr(22, 0, "Timeout: waiting for response.  Do you want to wait ? ");
    232  1.1  jtc 		ch = getanswer("NY", FALSE);
    233  1.1  jtc 		move(22, 0);
    234  1.1  jtc 		clrtobot();
    235  1.1  jtc 		if (ch == 'Y')
    236  1.1  jtc 		    continue;
    237  1.1  jtc 		else
    238  1.1  jtc 		    break;
    239  1.1  jtc 		}
    240  1.1  jtc 	    else
    241  1.1  jtc 		/* foe took action */
    242  1.1  jtc 		{
    243  1.1  jtc 		switch (Other.p_istat)
    244  1.1  jtc 		    {
    245  1.1  jtc 		    case I_RAN:		/* foe ran away */
    246  1.1  jtc 			mvprintw(Lines++, 0, "%s ran away!", Enemyname);
    247  1.1  jtc 			break;
    248  1.1  jtc 
    249  1.1  jtc 		    case I_STUCK:	/* foe tried to run, but couldn't */
    250  1.1  jtc 			mvprintw(Lines++, 0, "%s tried to run away.", Enemyname);
    251  1.1  jtc 			break;
    252  1.1  jtc 
    253  1.1  jtc 		    case I_BLEWIT:	/* foe tried to luckout, but didn't */
    254  1.1  jtc 			mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname);
    255  1.1  jtc 			break;
    256  1.1  jtc 
    257  1.1  jtc 		    default:
    258  1.1  jtc 			dtemp = Other.p_1scratch - oldhits;
    259  1.1  jtc 			mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp);
    260  1.1  jtc 			Shield -= dtemp;
    261  1.1  jtc 			break;
    262  1.1  jtc 		    }
    263  1.1  jtc 
    264  1.1  jtc 		oldhits = Other.p_1scratch;	/* keep track of old hits */
    265  1.1  jtc 
    266  1.1  jtc 		if (Other.p_tampered != oldtampered)
    267  1.1  jtc 		    /* p_tampered changes to relinquish turn */
    268  1.1  jtc 		    {
    269  1.1  jtc 		    oldtampered = Other.p_tampered;
    270  1.1  jtc 		    Foestrikes = FALSE;
    271  1.1  jtc 		    }
    272  1.1  jtc 		}
    273  1.1  jtc 	    }
    274  1.1  jtc 
    275  1.1  jtc 	/* decide what happens next */
    276  1.1  jtc 	refresh();
    277  1.1  jtc 	if (Lines > LINES - 2)
    278  1.1  jtc 	    {
    279  1.1  jtc 	    more(Lines);
    280  1.1  jtc 	    move(Lines = 8, 0);
    281  1.1  jtc 	    clrtobot();
    282  1.1  jtc 	    }
    283  1.1  jtc 
    284  1.1  jtc 	if (Other.p_istat == I_KILLED || Shield < 0.0)
    285  1.1  jtc 	    /* we died */
    286  1.1  jtc 	    {
    287  1.1  jtc 	    Shield = -2.0;		/* insure this value is negative */
    288  1.1  jtc 	    break;
    289  1.1  jtc 	    }
    290  1.1  jtc 
    291  1.1  jtc 	if (Player.p_istat == I_KILLED)
    292  1.1  jtc 	    /* we killed foe; award treasre */
    293  1.1  jtc 	    {
    294  1.1  jtc 	    mvprintw(Lines++, 0, "You killed %s!", Enemyname);
    295  1.1  jtc 	    Player.p_experience += Other.p_experience;
    296  1.1  jtc 	    Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0;
    297  1.1  jtc 	    Player.p_amulets += Other.p_amulets;
    298  1.1  jtc 	    Player.p_charms += Other.p_charms;
    299  1.1  jtc 	    collecttaxes(Other.p_gold, Other.p_gems);
    300  1.1  jtc 	    Player.p_sword = MAX(Player.p_sword, Other.p_sword);
    301  1.1  jtc 	    Player.p_shield = MAX(Player.p_shield, Other.p_shield);
    302  1.1  jtc 	    Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver);
    303  1.1  jtc 	    if (Other.p_virgin && !Player.p_virgin)
    304  1.1  jtc 		{
    305  1.1  jtc 		mvaddstr(Lines++, 0, "You have rescued a virgin.  Will you be honorable ? ");
    306  1.1  jtc 		if ((ch = getanswer("YN", FALSE)) == 'Y')
    307  1.1  jtc 		    Player.p_virgin = TRUE;
    308  1.1  jtc 		else
    309  1.1  jtc 		    {
    310  1.1  jtc 		    ++Player.p_sin;
    311  1.1  jtc 		    Player.p_experience += 8000.0;
    312  1.1  jtc 		    }
    313  1.1  jtc 		}
    314  1.1  jtc 	    sleep(3);     		/* give other person time to die */
    315  1.1  jtc 	    break;
    316  1.1  jtc 	    }
    317  1.1  jtc 	else if (Player.p_istat == I_RAN || Other.p_istat == I_RAN)
    318  1.1  jtc 	    /* either player ran away */
    319  1.1  jtc 	    break;
    320  1.1  jtc 	}
    321  1.1  jtc 
    322  1.1  jtc LEAVE:
    323  1.1  jtc     /* clean up things and leave */
    324  1.1  jtc     writerecord(&Player, Fileloc);	/* update a final time */
    325  1.1  jtc     altercoordinates(0.0, 0.0, A_NEAR);	/* move away from battle site */
    326  1.1  jtc     Player.p_energy = Shield;		/* set energy to actual value */
    327  1.1  jtc     Player.p_tampered = T_OFF;		/* clear p_tampered */
    328  1.1  jtc 
    329  1.1  jtc     more(Lines);			/* pause */
    330  1.1  jtc 
    331  1.1  jtc     move(4, 0);
    332  1.1  jtc     clrtobot();				/* clear bottom area of screen */
    333  1.1  jtc 
    334  1.1  jtc     if (Player.p_energy < 0.0)
    335  1.1  jtc 	/* we are dead */
    336  1.1  jtc 	death("Interterminal battle");
    337  1.1  jtc }
    338  1.1  jtc /**/
    340  1.1  jtc /************************************************************************
    341  1.1  jtc /
    342  1.1  jtc / FUNCTION NAME: myturn()
    343  1.1  jtc /
    344  1.1  jtc / FUNCTION: process players action against foe in battle
    345  1.1  jtc /
    346  1.1  jtc / AUTHOR: E. A. Estes, 2/7/86
    347  1.1  jtc /
    348  1.1  jtc / ARGUMENTS: none
    349  1.1  jtc /
    350  1.1  jtc / RETURN VALUE: none
    351  1.1  jtc /
    352  1.1  jtc / MODULES CALLED: writerecord(), inputoption(), floor(), wmove(), drandom(),
    353  1.1  jtc /	waddstr(), wrefresh(), mvprintw(), wclrtoeol(), wclrtobot()
    354  1.1  jtc /
    355  1.1  jtc / GLOBAL INPUTS: Lines, Other, Player, *stdscr, Fileloc, Luckout,
    356  1.1  jtc /	*Enemyname
    357  1.1  jtc /
    358  1.1  jtc / GLOBAL OUTPUTS: Foestrikes, Lines, Player, Luckout
    359  1.1  jtc /
    360  1.1  jtc / DESCRIPTION:
    361  1.1  jtc /	Take action action against foe, and decide who is master
    362  1.1  jtc /	for next iteration.
    363  1.1  jtc /
    364  1.1  jtc /************************************************************************/
    365  1.1  jtc 
    366  1.1  jtc myturn()
    367  1.1  jtc {
    368  1.1  jtc double	dtemp;		/* for temporary calculations */
    369  1.1  jtc int	ch;		/* input */
    370  1.1  jtc 
    371  1.1  jtc     mvaddstr(7, 0, "1:Fight  2:Run Away!  3:Power Blast  ");
    372  1.1  jtc     if (Luckout)
    373  1.1  jtc 	clrtoeol();
    374  1.1  jtc     else
    375  1.1  jtc 	addstr("4:Luckout  ");
    376  1.1  jtc 
    377  1.1  jtc     ch = inputoption();
    378  1.1  jtc     move(Lines = 8, 0);
    379  1.1  jtc     clrtobot();
    380  1.1  jtc 
    381  1.1  jtc     switch (ch)
    382  1.1  jtc 	{
    383  1.1  jtc 	default:	/* fight */
    384  1.1  jtc 	    dtemp = ROLL(2.0, Player.p_might);
    385  1.1  jtc HIT:
    386  1.1  jtc 	    mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp);
    387  1.1  jtc 	    Player.p_sin += 0.5;
    388  1.1  jtc 	    Player.p_1scratch += dtemp;
    389  1.1  jtc 	    Player.p_istat = I_OFF;
    390  1.1  jtc 	    break;
    391  1.1  jtc 
    392  1.1  jtc 	case '2':	/* run away */
    393  1.1  jtc 	    Player.p_1scratch -= 1.0;	/* change this to indicate action */
    394  1.1  jtc 	    if (drandom() > 0.25)
    395  1.1  jtc 		{
    396  1.1  jtc 		mvaddstr(Lines++, 0, "You got away!");
    397  1.1  jtc 		Player.p_istat = I_RAN;
    398  1.1  jtc 		}
    399  1.1  jtc 	    else
    400  1.1  jtc 		{
    401  1.1  jtc 		mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
    402  1.1  jtc 		Player.p_istat = I_STUCK;
    403  1.1  jtc 		}
    404  1.1  jtc 	    break;
    405  1.1  jtc 
    406  1.1  jtc 	case '3':	/* power blast */
    407  1.1  jtc 	    dtemp = MIN(Player.p_mana, Player.p_level * 5.0);
    408  1.1  jtc 	    Player.p_mana -= dtemp;
    409  1.1  jtc 	    dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0;
    410  1.1  jtc 	    mvprintw(Lines++, 0, "You blasted %s !", Enemyname);
    411  1.1  jtc 	    goto HIT;
    412  1.1  jtc 
    413  1.1  jtc 	case '4':	/* luckout */
    414  1.1  jtc 	    if (Luckout || drandom() > 0.1)
    415  1.1  jtc 		{
    416  1.1  jtc 		if (Luckout)
    417  1.1  jtc 		    mvaddstr(Lines++, 0, "You already tried that!");
    418  1.1  jtc 		else
    419  1.1  jtc 		    {
    420  1.1  jtc 		    mvaddstr(Lines++, 0, "Not this time . . .");
    421  1.1  jtc 		    Luckout = TRUE;
    422  1.1  jtc 		    }
    423  1.1  jtc 
    424  1.1  jtc 		Player.p_1scratch -= 1.0;
    425  1.1  jtc 		Player.p_istat = I_BLEWIT;
    426  1.1  jtc 		}
    427  1.1  jtc 	    else
    428  1.1  jtc 		{
    429  1.1  jtc 		mvaddstr(Lines++, 0, "You just lucked out!");
    430  1.1  jtc 		Player.p_1scratch = Other.p_energy * 1.1;
    431  1.1  jtc 		}
    432  1.1  jtc 	    break;
    433  1.1  jtc 	}
    434  1.1  jtc 
    435  1.1  jtc     refresh();
    436  1.1  jtc     Player.p_1scratch = floor(Player.p_1scratch);	/* clean up any mess */
    437  1.1  jtc 
    438  1.1  jtc     if (Player.p_1scratch > Other.p_energy)
    439  1.1  jtc 	Player.p_istat = I_KILLED;
    440  1.1  jtc     else if (drandom() * Player.p_speed < drandom() * Other.p_speed)
    441  1.1  jtc 	/* relinquish control */
    442  1.1  jtc 	{
    443  1.1  jtc 	++Player.p_tampered;
    444  1.1  jtc 	Foestrikes = TRUE;
    445  1.1  jtc 	}
    446  1.1  jtc 
    447  1.1  jtc     writerecord(&Player, Fileloc);			/* let foe know what we did */
    448  1.1  jtc }
    449  1.1  jtc /**/
    451  1.1  jtc /************************************************************************
    452  1.1  jtc /
    453  1.1  jtc / FUNCTION NAME: checktampered()
    454  1.1  jtc /
    455  1.1  jtc / FUNCTION: check if current player has been tampered with
    456  1.1  jtc /
    457  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    458  1.1  jtc /
    459  1.1  jtc / ARGUMENTS: none
    460  1.1  jtc /
    461  1.1  jtc / RETURN VALUE: none
    462  1.1  jtc /
    463  1.1  jtc / MODULES CALLED: readrecord(), fread(), fseek(), tampered(), writevoid()
    464  1.1  jtc /
    465  1.1  jtc / GLOBAL INPUTS: *Energyvoidfp, Other, Player, Fileloc, Enrgyvoid
    466  1.1  jtc /
    467  1.1  jtc / GLOBAL OUTPUTS: Enrgyvoid
    468  1.1  jtc /
    469  1.1  jtc / DESCRIPTION:
    470  1.1  jtc /	Check for energy voids, holy grail, and tampering by other
    471  1.1  jtc /	players.
    472  1.1  jtc /
    473  1.1  jtc /************************************************************************/
    474  1.1  jtc 
    475  1.1  jtc checktampered()
    476  1.1  jtc {
    477  1.1  jtc long	loc = 0L;		/* location in energy void file */
    478  1.1  jtc 
    479  1.1  jtc     /* first check for energy voids */
    480  1.1  jtc     fseek(Energyvoidfp, 0L, 0);
    481  1.1  jtc     while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
    482  1.1  jtc 	if (Enrgyvoid.ev_active
    483  1.1  jtc 	    && Enrgyvoid.ev_x == Player.p_x
    484  1.1  jtc 	    && Enrgyvoid.ev_y == Player.p_y)
    485  1.1  jtc 	    /* sitting on one */
    486  1.1  jtc 	    {
    487  1.1  jtc 	    if (loc > 0L)
    488  1.1  jtc 		/* not the holy grail; inactivate energy void */
    489  1.1  jtc 		{
    490  1.1  jtc 		Enrgyvoid.ev_active = FALSE;
    491  1.1  jtc 		writevoid(&Enrgyvoid, loc);
    492  1.1  jtc 		tampered(T_NRGVOID, 0.0, 0.0);
    493  1.1  jtc 		}
    494  1.1  jtc 	    else if (Player.p_status != S_CLOAKED)
    495  1.1  jtc 		/* holy grail */
    496  1.1  jtc 		tampered(T_GRAIL, 0.0, 0.0);
    497  1.1  jtc 	    break;
    498  1.1  jtc 	    }
    499  1.1  jtc 	else
    500  1.1  jtc 	    loc += SZ_VOIDSTRUCT;
    501  1.1  jtc 
    502  1.1  jtc     /* now check for other things */
    503  1.1  jtc     readrecord(&Other, Fileloc);
    504  1.1  jtc     if (Other.p_tampered != T_OFF)
    505  1.1  jtc 	tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch);
    506  1.1  jtc }
    507  1.1  jtc /**/
    509  1.1  jtc /************************************************************************
    510  1.1  jtc /
    511  1.1  jtc / FUNCTION NAME: tampered()
    512  1.1  jtc /
    513  1.1  jtc / FUNCTION: take care of tampering by other players
    514  1.1  jtc /
    515  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    516  1.1  jtc /
    517  1.1  jtc / ARGUMENTS:
    518  1.1  jtc /	int what - what type of tampering
    519  1.1  jtc /	double arg1, arg2 - rest of tampering info
    520  1.1  jtc /
    521  1.1  jtc / RETURN VALUE: none
    522  1.1  jtc /
    523  1.1  jtc / MODULES CALLED: writerecord(), more(), fread(), death(), fseek(), sleep(),
    524  1.1  jtc /	floor(), wmove(), waddch(), drandom(), printw(), altercoordinates(),
    525  1.1  jtc /	waddstr(), wrefresh(), encounter(), writevoid()
    526  1.1  jtc /
    527  1.1  jtc / GLOBAL INPUTS: Other, Player, *stdscr, Enrgyvoid, *Playersfp
    528  1.1  jtc /
    529  1.1  jtc / GLOBAL OUTPUTS: Other, Player, Changed, Enrgyvoid
    530  1.1  jtc /
    531  1.1  jtc / DESCRIPTION:
    532  1.1  jtc /	Take care of energy voids, holy grail, decree and intervention
    533  1.1  jtc /	action on current player.
    534  1.1  jtc /
    535  1.1  jtc /************************************************************************/
    536  1.1  jtc 
    537  1.1  jtc tampered(what, arg1, arg2)
    538  1.1  jtc int	what;
    539  1.1  jtc double	arg1;
    540  1.1  jtc double	arg2;
    541  1.1  jtc {
    542  1.1  jtc long	loc;			/* location in file of other players */
    543  1.1  jtc 
    544  1.1  jtc     Changed = TRUE;
    545  1.1  jtc     move(4,0);
    546  1.1  jtc 
    547  1.1  jtc     Player.p_tampered = T_OFF;	/* no longer tampered with */
    548  1.1  jtc 
    549  1.1  jtc     switch (what)
    550  1.1  jtc 	{
    551  1.1  jtc 	case T_NRGVOID:
    552  1.1  jtc 	    addstr("You've hit an energy void !\n");
    553  1.1  jtc 	    Player.p_mana /= 3.0;
    554  1.1  jtc 	    Player.p_energy /= 2.0;
    555  1.1  jtc 	    Player.p_gold = floor(Player.p_gold/1.25) + 0.1;
    556  1.1  jtc 	    altercoordinates(0.0, 0.0, A_NEAR);
    557  1.1  jtc 	    break;
    558  1.1  jtc 
    559  1.1  jtc 	case T_TRANSPORT:
    560  1.1  jtc 	    addstr("The king transported you !  ");
    561  1.1  jtc 	    if (Player.p_charms > 0)
    562  1.1  jtc 		{
    563  1.1  jtc 		addstr("But your charm saved you. . .\n");
    564  1.1  jtc 		--Player.p_charms;
    565  1.1  jtc 		}
    566  1.1  jtc 	    else
    567  1.1  jtc 		{
    568  1.1  jtc 		altercoordinates(0.0, 0.0, A_FAR);
    569  1.1  jtc 		addch('\n');
    570  1.1  jtc 		}
    571  1.1  jtc 	    break;
    572  1.1  jtc 
    573  1.1  jtc 	case T_BESTOW:
    574  1.1  jtc 	    printw("The king has bestowed %.0f gold pieces on you !\n", arg1);
    575  1.1  jtc 	    Player.p_gold += arg1;
    576  1.1  jtc 	    break;
    577  1.1  jtc 
    578  1.1  jtc 	case T_CURSED:
    579  1.1  jtc 	    addstr("You've been cursed !  ");
    580  1.1  jtc 	    if (Player.p_blessing)
    581  1.1  jtc 		{
    582  1.1  jtc 		addstr("But your blessing saved you. . .\n");
    583  1.1  jtc 		Player.p_blessing = FALSE;
    584  1.1  jtc 		}
    585  1.1  jtc 	    else
    586  1.1  jtc 		{
    587  1.1  jtc 		addch('\n');
    588  1.1  jtc 		Player.p_poison += 2.0;
    589  1.1  jtc 		Player.p_energy = 10.0;
    590  1.1  jtc 		Player.p_maxenergy  *= 0.95;
    591  1.1  jtc 		Player.p_status = S_PLAYING;	/* no longer cloaked */
    592  1.1  jtc 		}
    593  1.1  jtc 	    break;
    594  1.1  jtc 
    595  1.1  jtc 	case T_VAPORIZED:
    596  1.1  jtc 	    addstr("You have been vaporized!\n");
    597  1.1  jtc 	    more(7);
    598  1.1  jtc 	    death("Vaporization");
    599  1.1  jtc 	    break;
    600  1.1  jtc 
    601  1.1  jtc 	case T_MONSTER:
    602  1.1  jtc 	    addstr("The Valar zapped you with a monster!\n");
    603  1.1  jtc 	    more(7);
    604  1.1  jtc 	    encounter((int) arg1);
    605  1.1  jtc 	    return;
    606  1.1  jtc 
    607  1.1  jtc 	case T_BLESSED:
    608  1.1  jtc 	    addstr("The Valar has blessed you!\n");
    609  1.1  jtc 	    Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield;
    610  1.1  jtc 	    Player.p_mana += 500.0;
    611  1.1  jtc 	    Player.p_strength += 0.5;
    612  1.1  jtc 	    Player.p_brains += 0.5;
    613  1.1  jtc 	    Player.p_magiclvl += 0.5;
    614  1.1  jtc 	    Player.p_poison = MIN(0.5, Player.p_poison);
    615  1.1  jtc 	    break;
    616  1.1  jtc 
    617  1.1  jtc 	case T_RELOCATE:
    618  1.1  jtc 	    addstr("You've been relocated. . .\n");
    619  1.1  jtc 	    altercoordinates(arg1, arg2, A_FORCED);
    620  1.1  jtc 	    break;
    621  1.1  jtc 
    622  1.1  jtc 	case T_HEAL:
    623  1.1  jtc 	    addstr("You've been healed!\n");
    624  1.1  jtc 	    Player.p_poison -=  0.25;
    625  1.1  jtc 	    Player.p_energy = Player.p_maxenergy + Player.p_shield;
    626  1.1  jtc 	    break;
    627  1.1  jtc 
    628  1.1  jtc 	case T_EXVALAR:
    629  1.1  jtc 	    addstr("You are no longer Valar!\n");
    630  1.1  jtc 	    Player.p_specialtype = SC_COUNCIL;
    631  1.1  jtc 	    break;
    632  1.1  jtc 
    633  1.1  jtc 	case T_GRAIL:
    634  1.1  jtc 	    addstr("You have found The Holy Grail!!\n");
    635  1.1  jtc 	    if (Player.p_specialtype < SC_COUNCIL)
    636  1.1  jtc 		/* must be council of wise to behold grail */
    637  1.1  jtc 		{
    638  1.1  jtc 		addstr("However, you are not experienced enough to behold it.\n");
    639  1.1  jtc 		Player.p_sin *= Player.p_sin;
    640  1.1  jtc 		Player.p_mana +=  1000;
    641  1.1  jtc 		}
    642  1.1  jtc 	    else if (Player.p_specialtype == SC_VALAR
    643  1.1  jtc 		|| Player.p_specialtype == SC_EXVALAR)
    644  1.1  jtc 		{
    645  1.1  jtc 		addstr("You have made it to the position of Valar once already.\n");
    646  1.1  jtc 		addstr("The Grail is of no more use to you now.\n");
    647  1.1  jtc 		}
    648  1.1  jtc 	    else
    649  1.1  jtc 		{
    650  1.1  jtc 		addstr("It is now time to see if you are worthy to behold it. . .\n");
    651  1.1  jtc 		refresh();
    652  1.1  jtc 		sleep(4);
    653  1.1  jtc 
    654  1.1  jtc 		if (drandom() / 2.0 < Player.p_sin)
    655  1.1  jtc 		    {
    656  1.1  jtc 		    addstr("You have failed!\n");
    657  1.1  jtc 		    Player.p_strength =
    658  1.1  jtc 		    Player.p_mana =
    659  1.1  jtc 		    Player.p_energy =
    660  1.1  jtc 		    Player.p_maxenergy =
    661  1.1  jtc 		    Player.p_magiclvl =
    662  1.1  jtc 		    Player.p_brains =
    663  1.1  jtc 		    Player.p_experience =
    664  1.1  jtc 		    Player.p_quickness = 1.0;
    665  1.1  jtc 
    666  1.1  jtc 		    altercoordinates(1.0, 1.0, A_FORCED);
    667  1.1  jtc 		    Player.p_level = 0.0;
    668  1.1  jtc 		    }
    669  1.1  jtc 		else
    670  1.1  jtc 		    {
    671  1.1  jtc 		    addstr("You made to position of Valar!\n");
    672  1.1  jtc 		    Player.p_specialtype = SC_VALAR;
    673  1.1  jtc 		    Player.p_lives = 5;
    674  1.1  jtc 		    fseek(Playersfp, 0L, 0);
    675  1.1  jtc 		    loc = 0L;
    676  1.1  jtc 		    while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    677  1.1  jtc 			/* search for existing valar */
    678  1.1  jtc 			if (Other.p_specialtype == SC_VALAR
    679  1.1  jtc 			    && Other.p_status != S_NOTUSED)
    680  1.1  jtc 			    /* found old valar */
    681  1.1  jtc 			    {
    682  1.1  jtc 			    Other.p_tampered = T_EXVALAR;
    683  1.1  jtc 			    writerecord(&Other, loc);
    684  1.1  jtc 			    break;
    685  1.1  jtc 			    }
    686  1.1  jtc 			else
    687  1.1  jtc 			    loc += SZ_PLAYERSTRUCT;
    688  1.1  jtc 		    }
    689  1.1  jtc 		}
    690  1.1  jtc 
    691  1.1  jtc 	    /* move grail to new location */
    692  1.1  jtc 	    Enrgyvoid.ev_active = TRUE;
    693  1.1  jtc 	    Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
    694  1.1  jtc 	    Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
    695  1.1  jtc 	    writevoid(&Enrgyvoid, 0L);
    696  1.1  jtc 	    break;
    697  1.1  jtc 	}
    698  1.1  jtc     refresh();
    699  1.1  jtc     sleep(2);
    700  1.1  jtc }
    701  1.1  jtc /**/
    703  1.1  jtc /************************************************************************
    704  1.1  jtc /
    705  1.1  jtc / FUNCTION NAME: userlist()
    706  1.1  jtc /
    707  1.1  jtc / FUNCTION: print list of players and locations
    708  1.1  jtc /
    709  1.1  jtc / AUTHOR: E. A. Estes, 2/28/86
    710  1.1  jtc /
    711  1.1  jtc / ARGUMENTS:
    712  1.1  jtc /	bool ingameflag - set if called while playing
    713  1.1  jtc /
    714  1.1  jtc / RETURN VALUE: none
    715  1.1  jtc /
    716  1.1  jtc / MODULES CALLED: descrstatus(), descrlocation(), more(), fread(), fseek(),
    717  1.1  jtc /	floor(), wmove(), printw(), waddstr(), distance(), wrefresh(),
    718  1.1  jtc /	descrtype(), wclrtobot()
    719  1.1  jtc /
    720  1.1  jtc / GLOBAL INPUTS: LINES, Other, Circle, Wizard, Player, *stdscr, *Playersfp
    721  1.1  jtc /
    722  1.1  jtc / GLOBAL OUTPUTS: none
    723  1.1  jtc /
    724  1.1  jtc / DESCRIPTION:
    725  1.1  jtc /	We can only see the coordinate of those closer to the origin
    726  1.1  jtc /	from us.
    727  1.1  jtc /	Kings and council of the wise can see and can be seen by everyone.
    728  1.1  jtc /	Palantirs are good for seeing everyone; and the valar can use
    729  1.1  jtc /	one to see through a 'cloak' spell.
    730  1.1  jtc /	The valar has no coordinates, and is completely invisible if
    731  1.1  jtc /	cloaked.
    732  1.1  jtc /
    733  1.1  jtc /************************************************************************/
    734  1.1  jtc 
    735  1.1  jtc userlist(ingameflag)
    736  1.1  jtc bool	ingameflag;
    737  1.1  jtc {
    738  1.1  jtc register int	numusers = 0;	/* number of users on file */
    739  1.1  jtc 
    740  1.1  jtc     if (ingameflag && Player.p_blindness)
    741  1.1  jtc 	{
    742  1.1  jtc 	mvaddstr(8, 0, "You cannot see anyone.\n");
    743  1.1  jtc 	return;
    744  1.1  jtc 	}
    745  1.1  jtc 
    746  1.1  jtc     fseek(Playersfp, 0L, 0);
    747  1.1  jtc     mvaddstr(8, 0,
    748  1.1  jtc 	"Name                         X         Y    Lvl Type Login    Status\n");
    749  1.1  jtc 
    750  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    751  1.1  jtc 	{
    752  1.1  jtc 	if (Other.p_status == S_NOTUSED
    753  1.1  jtc 	    /* record is unused */
    754  1.1  jtc 	    || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED))
    755  1.1  jtc 	    /* cloaked valar */
    756  1.1  jtc 	    {
    757  1.1  jtc 	    if (!Wizard)
    758  1.1  jtc 		/* wizard can see everything on file */
    759  1.1  jtc 		continue;
    760  1.1  jtc 	    }
    761  1.1  jtc 
    762  1.1  jtc 	    ++numusers;
    763  1.1  jtc 
    764  1.1  jtc 	    if (ingameflag &&
    765  1.1  jtc 		/* must be playing for the rest of these conditions */
    766  1.1  jtc 		(Player.p_specialtype >= SC_KING
    767  1.1  jtc 		/* kings and higher can see others */
    768  1.1  jtc 		|| Other.p_specialtype >= SC_KING
    769  1.1  jtc 		/* kings and higher can be seen by others */
    770  1.1  jtc 		|| Circle >= CIRCLE(Other.p_x, Other.p_y)
    771  1.1  jtc 		/* those nearer the origin can be seen */
    772  1.1  jtc 		|| Player.p_palantir)
    773  1.1  jtc 		/* palantir enables one to see others */
    774  1.1  jtc 		&& (Other.p_status != S_CLOAKED
    775  1.1  jtc 		    || (Player.p_specialtype == SC_VALAR && Player.p_palantir))
    776  1.1  jtc 		/* not cloaked; valar can see through cloak with a palantir */
    777  1.1  jtc 		&& Other.p_specialtype != SC_VALAR)
    778  1.1  jtc 		/* not a valar */
    779  1.1  jtc 		/* coordinates should be printed */
    780  1.1  jtc 		printw("%-20s  %8.0f  %8.0f ",
    781  1.1  jtc 		    Other.p_name, Other.p_x, Other.p_y);
    782  1.1  jtc 	    else
    783  1.1  jtc 		/* cannot see player's coordinates */
    784  1.1  jtc 		printw("%-20s %19.19s ",
    785  1.1  jtc 		    Other.p_name, descrlocation(&Other, TRUE));
    786  1.1  jtc 
    787  1.1  jtc 	printw("%6.0f %s  %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE),
    788  1.1  jtc 	    Other.p_login, descrstatus(&Other));
    789  1.1  jtc 
    790  1.1  jtc 	if ((numusers % (LINES - 10)) == 0)
    791  1.1  jtc 	    {
    792  1.1  jtc 	    more(LINES - 1);
    793  1.1  jtc 	    move(9, 0);
    794  1.1  jtc 	    clrtobot();
    795  1.1  jtc 	    }
    796  1.1  jtc 	}
    797  1.1  jtc 
    798  1.1  jtc     printw("Total players on file = %d\n", numusers);
    799  1.1  jtc     refresh();
    800  1.1  jtc }
    801  1.1  jtc /**/
    803  1.1  jtc /************************************************************************
    804  1.1  jtc /
    805  1.1  jtc / FUNCTION NAME: throneroom()
    806  1.1  jtc /
    807  1.1  jtc / FUNCTION: king stuff upon entering throne
    808  1.1  jtc /
    809  1.1  jtc / AUTHOR: E. A. Estes, 12/16/85
    810  1.1  jtc /
    811  1.1  jtc / ARGUMENTS: none
    812  1.1  jtc /
    813  1.1  jtc / RETURN VALUE: none
    814  1.1  jtc /
    815  1.1  jtc / MODULES CALLED: writerecord(), fread(), fseek(), fopen(), wmove(), fclose(),
    816  1.1  jtc /	fwrite(), altercoordinates(), waddstr(), fprintf()
    817  1.1  jtc /
    818  1.1  jtc / GLOBAL INPUTS: *Energyvoidfp, Other, Player, *stdscr,
    819  1.1  jtc /	Enrgyvoid, *Playersfp
    820  1.1  jtc /
    821  1.1  jtc / GLOBAL OUTPUTS: Other, Player, Changed
    822  1.1  jtc /
    823  1.1  jtc / DESCRIPTION:
    824  1.1  jtc /	If player is not already king, make him/her so if the old king
    825  1.1  jtc /	is not playing.
    826  1.1  jtc /	Clear energy voids with new king.
    827  1.1  jtc /	Print 'decree' prompt.
    828  1.1  jtc /
    829  1.1  jtc /************************************************************************/
    830  1.1  jtc 
    831  1.1  jtc throneroom()
    832  1.1  jtc {
    833  1.1  jtc FILE	*fp;			/* to clear energy voids */
    834  1.1  jtc long	loc = 0L;		/* location of old king in player file */
    835  1.1  jtc 
    836  1.1  jtc     if (Player.p_specialtype < SC_KING)
    837  1.1  jtc 	/* not already king -- assumes crown */
    838  1.1  jtc 	{
    839  1.1  jtc 	fseek(Playersfp, 0L, 0);
    840  1.1  jtc 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    841  1.1  jtc 	    if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
    842  1.1  jtc 		/* found old king */
    843  1.1  jtc 		{
    844  1.1  jtc 		if (Other.p_status != S_OFF)
    845  1.1  jtc 		    /* old king is playing */
    846  1.1  jtc 		    {
    847  1.1  jtc 		    mvaddstr( 4, 0, "The king is playing, so you cannot steal his throne\n");
    848  1.1  jtc 		    altercoordinates(0.0, 0.0, A_NEAR);
    849  1.1  jtc 		    move(6, 0);
    850  1.1  jtc 		    return;
    851  1.1  jtc 		    }
    852  1.1  jtc 		else
    853  1.1  jtc 		    /* old king is not playing - remove him/her */
    854  1.1  jtc 		    {
    855  1.1  jtc 		    Other.p_specialtype = SC_NONE;
    856  1.1  jtc 		    if (Other.p_crowns)
    857  1.1  jtc 			--Other.p_crowns;
    858  1.1  jtc 		    writerecord(&Other, loc);
    859  1.1  jtc 		    break;
    860  1.1  jtc 		    }
    861  1.1  jtc 		}
    862  1.1  jtc 	    else
    863  1.1  jtc 		loc += SZ_PLAYERSTRUCT;
    864  1.1  jtc 
    865  1.1  jtc 	/* make player new king */
    866  1.1  jtc 	Changed = TRUE;
    867  1.1  jtc 	Player.p_specialtype = SC_KING;
    868  1.1  jtc 	mvaddstr(4, 0, "You have become king!\n");
    869  1.1  jtc 
    870  1.1  jtc 	/* let everyone else know */
    871  1.1  jtc 	fp = fopen(_PATH_MESS, "w");
    872  1.1  jtc 	fprintf(fp, "All hail the new king!");
    873  1.1  jtc 	fclose(fp);
    874  1.1  jtc 
    875  1.1  jtc 	/* clear all energy voids; retain location of holy grail */
    876  1.1  jtc 	fseek(Energyvoidfp, 0L, 0);
    877  1.1  jtc 	fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
    878  1.1  jtc 	fp = fopen(_PATH_VOID, "w");
    879  1.1  jtc 	fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
    880  1.1  jtc 	fclose(fp);
    881  1.1  jtc 	}
    882  1.1  jtc 
    883  1.1  jtc     mvaddstr(6, 0, "0:Decree  ");
    884  1.1  jtc }
    885  1.1  jtc /**/
    887  1.1  jtc /************************************************************************
    888  1.1  jtc /
    889  1.1  jtc / FUNCTION NAME: dotampered()
    890  1.1  jtc /
    891  1.1  jtc / FUNCTION: king and valar special options
    892  1.1  jtc /
    893  1.1  jtc / AUTHOR: E. A. Estes, 2/28/86
    894  1.1  jtc /
    895  1.1  jtc / ARGUMENTS: none
    896  1.1  jtc /
    897  1.1  jtc / RETURN VALUE: none
    898  1.1  jtc /
    899  1.1  jtc / MODULES CALLED: writerecord(), truncstring(), fread(), fseek(), fopen(),
    900  1.1  jtc /	floor(), wmove(), drandom(), fclose(), fwrite(), sscanf(), strcmp(),
    901  1.1  jtc /	infloat(), waddstr(), findname(), distance(), userlist(), mvprintw(),
    902  1.1  jtc /	allocvoid(), getanswer(), getstring(), wclrtoeol(), writevoid()
    903  1.1  jtc /
    904  1.1  jtc / GLOBAL INPUTS: *Energyvoidfp, Other, Illcmd[], Wizard, Player, *stdscr,
    905  1.1  jtc /	Databuf[], Enrgyvoid
    906  1.1  jtc /
    907  1.1  jtc / GLOBAL OUTPUTS: Other, Player, Enrgyvoid
    908  1.1  jtc /
    909  1.1  jtc / DESCRIPTION:
    910  1.1  jtc /	Tamper with other players.  Handle king/valar specific options.
    911  1.1  jtc /
    912  1.1  jtc /************************************************************************/
    913  1.1  jtc 
    914  1.1  jtc dotampered()
    915  1.1  jtc {
    916  1.1  jtc short	tamper;			/* value for tampering with other players */
    917  1.1  jtc char	*option;			/* pointer to option description */
    918  1.1  jtc double	temp1 = 0.0, temp2 = 0.0;	/* other tampering values */
    919  1.1  jtc int	ch;				/* input */
    920  1.1  jtc long	loc;				/* location in energy void file */
    921  1.1  jtc FILE	*fp;				/* for opening gold file */
    922  1.1  jtc 
    923  1.1  jtc     move(6, 0);
    924  1.1  jtc     clrtoeol();
    925  1.1  jtc     if (Player.p_specialtype < SC_COUNCIL && !Wizard)
    926  1.1  jtc 	/* king options */
    927  1.1  jtc 	{
    928  1.1  jtc 	addstr("1:Transport  2:Curse  3:Energy Void  4:Bestow  5:Collect Taxes  ");
    929  1.1  jtc 
    930  1.1  jtc 	ch = getanswer(" ", TRUE);
    931  1.1  jtc 	move(6, 0);
    932  1.1  jtc 	clrtoeol();
    933  1.1  jtc 	move(4, 0);
    934  1.1  jtc 	switch (ch)
    935  1.1  jtc 	    {
    936  1.1  jtc 	    case '1':	/* transport someone */
    937  1.1  jtc 		tamper = T_TRANSPORT;
    938  1.1  jtc 		option = "transport";
    939  1.1  jtc 		break;
    940  1.1  jtc 
    941  1.1  jtc 	    case '2':	/* curse another */
    942  1.1  jtc 		tamper = T_CURSED;
    943  1.1  jtc 		option = "curse";
    944  1.1  jtc 		break;
    945  1.1  jtc 
    946  1.1  jtc 	    case '3':	/* create energy void */
    947  1.1  jtc 		if ((loc = allocvoid()) > 20L * SZ_VOIDSTRUCT)
    948  1.1  jtc 		    /* can only have 20 void active at once */
    949  1.1  jtc 		    mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
    950  1.1  jtc 		else
    951  1.1  jtc 		    {
    952  1.1  jtc 		    addstr("Enter the X Y coordinates of void ? ");
    953  1.1  jtc 		    getstring(Databuf, SZ_DATABUF);
    954  1.1  jtc 		    sscanf(Databuf, "%lf %lf", &temp1, &temp2);
    955  1.1  jtc 		    Enrgyvoid.ev_x = floor(temp1);
    956  1.1  jtc 		    Enrgyvoid.ev_y = floor(temp2);
    957  1.1  jtc 		    Enrgyvoid.ev_active = TRUE;
    958  1.1  jtc 		    writevoid(&Enrgyvoid, loc);
    959  1.1  jtc 		    mvaddstr(5, 0, "It is done.\n");
    960  1.1  jtc 		    }
    961  1.1  jtc 		return;
    962  1.1  jtc 
    963  1.1  jtc 	    case '4':	/* bestow gold to subject */
    964  1.1  jtc 		tamper = T_BESTOW;
    965  1.1  jtc 		addstr("How much gold to bestow ? ");
    966  1.1  jtc 		temp1 = infloat();
    967  1.1  jtc 		if (temp1 > Player.p_gold || temp1 < 0)
    968  1.1  jtc 		    {
    969  1.1  jtc 		    mvaddstr(5, 0, "You don't have that !\n");
    970  1.1  jtc 		    return;
    971  1.1  jtc 		    }
    972  1.1  jtc 
    973  1.1  jtc 		/* adjust gold after we are sure it will be given to someone */
    974  1.1  jtc 		option = "give gold to";
    975  1.1  jtc 		break;
    976  1.1  jtc 
    977  1.1  jtc 	    case '5':	/* collect accumulated taxes */
    978  1.1  jtc 		if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)
    979  1.1  jtc 		    /* collect taxes */
    980  1.1  jtc 		    {
    981  1.1  jtc 		    fread((char *) &temp1, sizeof(double), 1, fp);
    982  1.1  jtc 		    fseek(fp, 0L, 0);
    983  1.1  jtc 		    /* clear out value */
    984  1.1  jtc 		    temp2 = 0.0;
    985  1.1  jtc 		    fwrite((char *) &temp2, sizeof(double), 1, fp);
    986  1.1  jtc 		    fclose(fp);
    987  1.1  jtc 		    }
    988  1.1  jtc 
    989  1.1  jtc 		mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1);
    990  1.1  jtc 		Player.p_gold += floor(temp1);
    991  1.1  jtc 		return;
    992  1.1  jtc 
    993  1.1  jtc 	    default:
    994  1.1  jtc 		return;
    995  1.1  jtc 	    }
    996  1.1  jtc 	/* end of king options */
    997  1.1  jtc 	}
    998  1.1  jtc     else
    999  1.1  jtc 	/* council of wise, valar, wizard options */
   1000  1.1  jtc 	{
   1001  1.1  jtc 	addstr("1:Heal  ");
   1002  1.1  jtc 	if (Player.p_palantir || Wizard)
   1003  1.1  jtc 	    addstr("2:Seek Grail  ");
   1004  1.1  jtc 	if (Player.p_specialtype == SC_VALAR || Wizard)
   1005  1.1  jtc 	    addstr("3:Throw Monster  4:Relocate  5:Bless  ");
   1006  1.1  jtc 	if (Wizard)
   1007  1.1  jtc 	    addstr("6:Vaporize  ");
   1008  1.1  jtc 
   1009  1.1  jtc 	ch = getanswer(" ", TRUE);
   1010  1.1  jtc 	if (!Wizard)
   1011  1.1  jtc 	    {
   1012  1.1  jtc 	    if (ch > '2' && Player.p_specialtype != SC_VALAR)
   1013  1.1  jtc 		{
   1014  1.1  jtc 		ILLCMD();
   1015  1.1  jtc 		return;
   1016  1.1  jtc 		}
   1017  1.1  jtc 
   1018  1.1  jtc 	    if (Player.p_mana < MM_INTERVENE)
   1019  1.1  jtc 		{
   1020  1.1  jtc 		mvaddstr(5, 0, "No mana left.\n");
   1021  1.1  jtc 		return;
   1022  1.1  jtc 		}
   1023  1.1  jtc 	    else
   1024  1.1  jtc 		Player.p_mana -= MM_INTERVENE;
   1025  1.1  jtc 	    }
   1026  1.1  jtc 
   1027  1.1  jtc 	switch (ch)
   1028  1.1  jtc 	    {
   1029  1.1  jtc 	    case '1':	/* heal another */
   1030  1.1  jtc 		tamper = T_HEAL;
   1031  1.1  jtc 		option = "heal";
   1032  1.1  jtc 		break;
   1033  1.1  jtc 
   1034  1.1  jtc 	    case '2':	/* seek grail */
   1035  1.1  jtc 		if (Player.p_palantir)
   1036  1.1  jtc 		    /* need a palantir to seek */
   1037  1.1  jtc 		    {
   1038  1.1  jtc 		    fseek(Energyvoidfp, 0L, 0);
   1039  1.1  jtc 		    fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
   1040  1.1  jtc 		    temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y);
   1041  1.1  jtc 		    temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0);	/* add some error */
   1042  1.1  jtc 		    mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1);
   1043  1.1  jtc 		    }
   1044  1.1  jtc 		else
   1045  1.1  jtc 		    /* no palantir */
   1046  1.1  jtc 		    mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
   1047  1.1  jtc 		return;
   1048  1.1  jtc 
   1049  1.1  jtc 	    case '3':	/* lob monster at someone */
   1050  1.1  jtc 		mvaddstr(4, 0, "Which monster [0-99] ? ");
   1051  1.1  jtc 		temp1 = infloat();
   1052  1.1  jtc 		temp1 = MAX(0.0, MIN(99.0, temp1));
   1053  1.1  jtc 		tamper = T_MONSTER;
   1054  1.1  jtc 		option = "throw a monster at";
   1055  1.1  jtc 		break;
   1056  1.1  jtc 
   1057  1.1  jtc 	    case '4':	/* move another player */
   1058  1.1  jtc 		mvaddstr(4, 0, "New X Y coordinates ? ");
   1059  1.1  jtc 		getstring(Databuf, SZ_DATABUF);
   1060  1.1  jtc 		sscanf(Databuf, "%lf %lf", &temp1, &temp2);
   1061  1.1  jtc 		tamper = T_RELOCATE;
   1062  1.1  jtc 		option = "relocate";
   1063  1.1  jtc 		break;
   1064  1.1  jtc 
   1065  1.1  jtc 	    case '5':	/* bless a player */
   1066  1.1  jtc 		tamper = T_BLESSED;
   1067  1.1  jtc 		option = "bless";
   1068  1.1  jtc 		break;
   1069  1.1  jtc 
   1070  1.1  jtc 	    case '6':	/* kill off a player */
   1071  1.1  jtc 		if (Wizard)
   1072  1.1  jtc 		    {
   1073  1.1  jtc 		    tamper = T_VAPORIZED;
   1074  1.1  jtc 		    option = "vaporize";
   1075  1.1  jtc 		    break;
   1076  1.1  jtc 		    }
   1077  1.1  jtc 		else
   1078  1.1  jtc 		    return;
   1079  1.1  jtc 
   1080  1.1  jtc 	    default:
   1081  1.1  jtc 		return;
   1082  1.1  jtc 	    }
   1083  1.1  jtc 
   1084  1.1  jtc 	/* adjust age after we are sure intervention will be done */
   1085  1.1  jtc 	/* end of valar, etc. options */
   1086  1.1  jtc 	}
   1087  1.1  jtc 
   1088  1.1  jtc     for (;;)
   1089  1.1  jtc 	/* prompt for player to affect */
   1090  1.1  jtc 	{
   1091  1.1  jtc 	mvprintw(4, 0, "Who do you want to %s ? ", option);
   1092  1.1  jtc 	getstring(Databuf, SZ_DATABUF);
   1093  1.1  jtc 	truncstring(Databuf);
   1094  1.1  jtc 
   1095  1.1  jtc 	if (Databuf[0] == '\0')
   1096  1.1  jtc 	    userlist(TRUE);
   1097  1.1  jtc 	else
   1098  1.1  jtc 	    break;
   1099  1.1  jtc 	}
   1100  1.1  jtc 
   1101  1.1  jtc     if (strcmp(Player.p_name, Databuf) != 0)
   1102  1.1  jtc 	/* name other than self */
   1103  1.1  jtc 	{
   1104  1.1  jtc 	if ((loc = findname(Databuf, &Other)) >= 0L)
   1105  1.1  jtc 	    {
   1106  1.1  jtc 	    if (Other.p_tampered != T_OFF)
   1107  1.1  jtc 		{
   1108  1.1  jtc 		mvaddstr(5, 0, "That person has something pending already.\n");
   1109  1.1  jtc 		return;
   1110  1.1  jtc 		}
   1111  1.1  jtc 	    else
   1112  1.1  jtc 		{
   1113  1.1  jtc 		if (tamper == T_RELOCATE
   1114  1.1  jtc 		    && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y)
   1115  1.1  jtc 		    && !Wizard)
   1116  1.1  jtc 		    mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
   1117  1.1  jtc 		else
   1118  1.1  jtc 		    {
   1119  1.1  jtc 		    if (tamper == T_BESTOW) Player.p_gold -= floor(temp1);
   1120  1.1  jtc 		    if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER ||
   1121  1.1  jtc 			tamper == T_RELOCATE || tamper == T_BLESSED))
   1122  1.1  jtc 	    			Player.p_age += N_AGE;	/* age penalty */
   1123  1.1  jtc 		    Other.p_tampered = tamper;
   1124  1.1  jtc 		    Other.p_1scratch = floor(temp1);
   1125  1.1  jtc 		    Other.p_2scratch = floor(temp2);
   1126  1.1  jtc 		    writerecord(&Other, loc);
   1127  1.1  jtc 		    mvaddstr(5, 0, "It is done.\n");
   1128  1.1  jtc 		    }
   1129  1.1  jtc 		return;
   1130  1.1  jtc 		}
   1131  1.1  jtc 	    }
   1132  1.1  jtc 	else
   1133  1.1  jtc 	    /* player not found */
   1134  1.1  jtc 	    mvaddstr(5, 0, "There is no one by that name.\n");
   1135  1.1  jtc 	}
   1136  1.1  jtc     else
   1137  1.1  jtc 	/* self */
   1138  1.1  jtc 	mvaddstr(5, 0, "You may not do it to yourself!\n");
   1139  1.1  jtc }
   1140  1.1  jtc /**/
   1142  1.1  jtc /************************************************************************
   1143  1.1  jtc /
   1144  1.1  jtc / FUNCTION NAME: writevoid()
   1145  1.1  jtc /
   1146  1.1  jtc / FUNCTION: update energy void entry in energy void file
   1147  1.1  jtc /
   1148  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
   1149  1.1  jtc /
   1150  1.1  jtc / ARGUMENTS:
   1151  1.1  jtc /	struct energyvoid *vp - pointer to structure to write to file
   1152  1.1  jtc /	long loc - location in file to update
   1153  1.1  jtc /
   1154  1.1  jtc / RETURN VALUE: none
   1155  1.1  jtc /
   1156  1.1  jtc / MODULES CALLED: fseek(), fwrite(), fflush()
   1157  1.1  jtc /
   1158  1.1  jtc / GLOBAL INPUTS: *Energyvoidfp
   1159  1.1  jtc /
   1160  1.1  jtc / GLOBAL OUTPUTS: none
   1161  1.1  jtc /
   1162  1.1  jtc / DESCRIPTION:
   1163  1.1  jtc /	Write out energy void structure at specified location.
   1164  1.1  jtc /
   1165  1.1  jtc /************************************************************************/
   1166  1.1  jtc 
   1167  1.1  jtc writevoid(vp, loc)
   1168  1.1  jtc register struct energyvoid	*vp;
   1169  1.1  jtc long	loc;
   1170  1.1  jtc {
   1171  1.1  jtc 
   1172  1.1  jtc     fseek(Energyvoidfp, loc, 0);
   1173  1.1  jtc     fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp);
   1174  1.1  jtc     fflush(Energyvoidfp);
   1175  1.1  jtc     fseek(Energyvoidfp, 0L, 0);
   1176  1.1  jtc }
   1177  1.1  jtc /**/
   1179  1.1  jtc /************************************************************************
   1180  1.1  jtc /
   1181  1.1  jtc / FUNCTION NAME: allocvoid()
   1182  1.1  jtc /
   1183  1.1  jtc / FUNCTION: allocate space for a new energy void
   1184  1.1  jtc /
   1185  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
   1186  1.1  jtc /
   1187  1.1  jtc / ARGUMENTS: none
   1188  1.1  jtc /
   1189  1.1  jtc / RETURN VALUE: location of new energy void space
   1190  1.1  jtc /
   1191  1.1  jtc / MODULES CALLED: fread(), fseek()
   1192  1.1  jtc /
   1193  1.1  jtc / GLOBAL INPUTS: *Energyvoidfp, Enrgyvoid
   1194  1.1  jtc /
   1195  1.1  jtc / GLOBAL OUTPUTS: none
   1196  1.1  jtc /
   1197  1.1  jtc / DESCRIPTION:
   1198  1.1  jtc /	Search energy void file for an inactive entry and return its
   1199  1.1  jtc /	location.
   1200  1.1  jtc /	If no inactive ones are found, return one more than last location.
   1201  1.1  jtc /
   1202  1.1  jtc /************************************************************************/
   1203  1.1  jtc 
   1204  1.1  jtc long
   1205  1.1  jtc allocvoid()
   1206  1.1  jtc {
   1207  1.1  jtc long	loc = 0L;		/* location of new energy void */
   1208  1.1  jtc 
   1209               fseek(Energyvoidfp, 0L, 0);
   1210               while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
   1211           	if (Enrgyvoid.ev_active)
   1212           	    loc += SZ_VOIDSTRUCT;
   1213           	else
   1214           	    break;
   1215           
   1216               return(loc);
   1217           }
   1218