Home | History | Annotate | Line # | Download | only in phantasia
gamesupport.c revision 1.2
      1  1.2  cgd /*	$NetBSD: gamesupport.c,v 1.2 1995/03/24 03:58:43 cgd Exp $	*/
      2  1.2  cgd 
      3  1.1  jtc /*
      4  1.1  jtc  * gamesupport.c - auxiliary routines for support of Phantasia
      5  1.1  jtc  */
      6  1.1  jtc 
      7  1.1  jtc #include "include.h"
      8  1.1  jtc 
      9  1.1  jtc /************************************************************************
     10  1.1  jtc /
     11  1.1  jtc / FUNCTION NAME: changestats()
     12  1.1  jtc /
     13  1.1  jtc / FUNCTION: examine/change statistics for a player
     14  1.1  jtc /
     15  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
     16  1.1  jtc /
     17  1.1  jtc / ARGUMENTS:
     18  1.1  jtc /	bool ingameflag - set if called while playing game (Wizard only)
     19  1.1  jtc /
     20  1.1  jtc / RETURN VALUE: none
     21  1.1  jtc /
     22  1.1  jtc / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
     23  1.1  jtc /	time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
     24  1.1  jtc /	infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
     25  1.1  jtc /	localtime(), getanswer(), descrtype(), getstring()
     26  1.1  jtc /
     27  1.1  jtc / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
     28  1.1  jtc /	Fileloc
     29  1.1  jtc /
     30  1.1  jtc / GLOBAL OUTPUTS: Echo
     31  1.1  jtc /
     32  1.1  jtc / DESCRIPTION:
     33  1.1  jtc /	Prompt for player name to examine/change.
     34  1.1  jtc /	If the name is NULL, print a list of all players.
     35  1.1  jtc /	If we are called from within the game, check for the
     36  1.1  jtc /	desired name being the same as the current player's name.
     37  1.1  jtc /	Only the 'Wizard' may alter players.
     38  1.1  jtc /	Items are changed only if a non-zero value is specified.
     39  1.1  jtc /	To change an item to 0, use 0.1; it will be truncated later.
     40  1.1  jtc /
     41  1.1  jtc /	Players may alter their names and passwords, if the following
     42  1.1  jtc /	are true:
     43  1.1  jtc /	    - current login matches the character's logins
     44  1.1  jtc /	    - the password is known
     45  1.1  jtc /	    - the player is not in the middle of the game (ingameflag == FALSE)
     46  1.1  jtc /
     47  1.1  jtc /	The last condition is imposed for two reasons:
     48  1.1  jtc /	    - the game could possibly get a bit hectic if a player were
     49  1.1  jtc /	      continually changing his/her name
     50  1.1  jtc /	    - another player structure would be necessary to check for names
     51  1.1  jtc /	      already in use
     52  1.1  jtc /
     53  1.1  jtc /************************************************************************/
     54  1.1  jtc 
     55  1.1  jtc changestats(ingameflag)
     56  1.1  jtc bool	ingameflag;
     57  1.1  jtc {
     58  1.1  jtc static char	flag[2] = /* for printing values of bools */
     59  1.1  jtc 	{'F', 'T'};
     60  1.1  jtc register struct player	*playerp;/* pointer to structure to alter */
     61  1.1  jtc register char	*prompt;	/* pointer to prompt string */
     62  1.1  jtc int	c;			/* input */
     63  1.1  jtc int	today;			/* day of year of today */
     64  1.1  jtc int	temp;			/* temporary variable */
     65  1.1  jtc long	loc;			/* location in player file */
     66  1.1  jtc long	now;			/* time now */
     67  1.1  jtc double	dtemp;			/* temporary variable */
     68  1.1  jtc bool	*bptr;			/* pointer to bool item to change */
     69  1.1  jtc double	*dptr;			/* pointer to double item to change */
     70  1.1  jtc short	*sptr;			/* pointer to short item to change */
     71  1.1  jtc 
     72  1.1  jtc     clear();
     73  1.1  jtc 
     74  1.1  jtc     for (;;)
     75  1.1  jtc 	/* get name of player to examine/alter */
     76  1.1  jtc 	{
     77  1.1  jtc 	mvaddstr(5, 0, "Which character do you want to look at ? ");
     78  1.1  jtc 	getstring(Databuf, SZ_DATABUF);
     79  1.1  jtc 	truncstring(Databuf);
     80  1.1  jtc 
     81  1.1  jtc 	if (Databuf[0] == '\0')
     82  1.1  jtc 	    userlist(ingameflag);
     83  1.1  jtc 	else
     84  1.1  jtc 	    break;
     85  1.1  jtc 	}
     86  1.1  jtc 
     87  1.1  jtc     loc = -1L;
     88  1.1  jtc 
     89  1.1  jtc     if (!ingameflag)
     90  1.1  jtc 	/* use 'Player' structure */
     91  1.1  jtc 	playerp = &Player;
     92  1.1  jtc     else if (strcmp(Databuf, Player.p_name) == 0)
     93  1.1  jtc 	/* alter/examine current player */
     94  1.1  jtc 	{
     95  1.1  jtc 	playerp = &Player;
     96  1.1  jtc 	loc = Fileloc;
     97  1.1  jtc 	}
     98  1.1  jtc     else
     99  1.1  jtc 	/* use 'Other' structure */
    100  1.1  jtc 	playerp = &Other;
    101  1.1  jtc 
    102  1.1  jtc     /* find player on file */
    103  1.1  jtc     if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
    104  1.1  jtc 	/* didn't find player */
    105  1.1  jtc 	{
    106  1.1  jtc 	clear();
    107  1.1  jtc 	mvaddstr(11, 0, "Not found.");
    108  1.1  jtc 	return;
    109  1.1  jtc 	}
    110  1.1  jtc 
    111  1.1  jtc     time(&now);
    112  1.1  jtc     today = localtime(&now)->tm_yday;
    113  1.1  jtc 
    114  1.1  jtc     clear();
    115  1.1  jtc 
    116  1.1  jtc     for (;;)
    117  1.1  jtc 	/* print player structure, and prompt for action */
    118  1.1  jtc 	{
    119  1.1  jtc 	mvprintw(0, 0,"A:Name         %s\n", playerp->p_name);
    120  1.1  jtc 
    121  1.1  jtc 	if (Wizard)
    122  1.1  jtc 	    printw("B:Password     %s\n", playerp->p_password);
    123  1.1  jtc 	else
    124  1.1  jtc 	    addstr("B:Password     XXXXXXXX\n");
    125  1.1  jtc 
    126  1.1  jtc 	printw(" :Login        %s\n", playerp->p_login);
    127  1.1  jtc 
    128  1.1  jtc 	printw("C:Experience   %.0f\n", playerp->p_experience);
    129  1.1  jtc 	printw("D:Level        %.0f\n", playerp->p_level);
    130  1.1  jtc 	printw("E:Strength     %.0f\n", playerp->p_strength);
    131  1.1  jtc 	printw("F:Sword        %.0f\n", playerp->p_sword);
    132  1.1  jtc 	printw(" :Might        %.0f\n", playerp->p_might);
    133  1.1  jtc 	printw("G:Energy       %.0f\n", playerp->p_energy);
    134  1.1  jtc 	printw("H:Max-Energy   %.0f\n", playerp->p_maxenergy);
    135  1.1  jtc 	printw("I:Shield       %.0f\n", playerp->p_shield);
    136  1.1  jtc 	printw("J:Quickness    %.0f\n", playerp->p_quickness);
    137  1.1  jtc 	printw("K:Quicksilver  %.0f\n", playerp->p_quksilver);
    138  1.1  jtc 	printw(" :Speed        %.0f\n", playerp->p_speed);
    139  1.1  jtc 	printw("L:Magic Level  %.0f\n", playerp->p_magiclvl);
    140  1.1  jtc 	printw("M:Mana         %.0f\n", playerp->p_mana);
    141  1.1  jtc 	printw("N:Brains       %.0f\n", playerp->p_brains);
    142  1.1  jtc 
    143  1.1  jtc 	if (Wizard || playerp->p_specialtype != SC_VALAR)
    144  1.1  jtc 	    mvaddstr(0, 40, descrstatus(playerp));
    145  1.1  jtc 
    146  1.1  jtc 	mvprintw(1, 40, "O:Poison       %0.3f\n", playerp->p_poison);
    147  1.1  jtc 	mvprintw(2, 40, "P:Gold         %.0f\n", playerp->p_gold);
    148  1.1  jtc 	mvprintw(3, 40, "Q:Gem          %.0f\n", playerp->p_gems);
    149  1.1  jtc 	mvprintw(4, 40, "R:Sin          %0.3f\n", playerp->p_sin);
    150  1.1  jtc 	if (Wizard)
    151  1.1  jtc 	    {
    152  1.1  jtc 	    mvprintw(5, 40, "S:X-coord      %.0f\n", playerp->p_x);
    153  1.1  jtc 	    mvprintw(6, 40, "T:Y-coord      %.0f\n", playerp->p_y);
    154  1.1  jtc 	    }
    155  1.1  jtc 	else
    156  1.1  jtc 	    {
    157  1.1  jtc 	    mvaddstr(5, 40, "S:X-coord      ?\n");
    158  1.1  jtc 	    mvaddstr(6, 40, "T:Y-coord      ?\n");
    159  1.1  jtc 	    }
    160  1.1  jtc 
    161  1.1  jtc 	mvprintw(7, 40, "U:Age          %ld\n", playerp->p_age);
    162  1.1  jtc 	mvprintw(8, 40, "V:Degenerated  %d\n", playerp->p_degenerated);
    163  1.1  jtc 
    164  1.1  jtc 	mvprintw(9, 40, "W:Type         %d (%s)\n",
    165  1.1  jtc 	    playerp->p_type, descrtype(playerp, FALSE) + 1);
    166  1.1  jtc 	mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
    167  1.1  jtc 	mvprintw(11, 40, "Y:Lives        %d\n", playerp->p_lives);
    168  1.1  jtc 	mvprintw(12, 40, "Z:Crowns       %d\n", playerp->p_crowns);
    169  1.1  jtc 	mvprintw(13, 40, "0:Charms       %d\n", playerp->p_charms);
    170  1.1  jtc 	mvprintw(14, 40, "1:Amulets      %d\n", playerp->p_amulets);
    171  1.1  jtc 	mvprintw(15, 40, "2:Holy Water   %d\n", playerp->p_holywater);
    172  1.1  jtc 
    173  1.1  jtc 	temp = today - playerp->p_lastused;
    174  1.1  jtc 	if (temp < 0)
    175  1.1  jtc 	    /* last year */
    176  1.1  jtc 	    temp += 365;
    177  1.1  jtc 	mvprintw(16, 40, "3:Lastused     %d  (%d)\n", playerp->p_lastused,  temp);
    178  1.1  jtc 
    179  1.1  jtc 	mvprintw(18, 8, "4:Palantir %c  5:Blessing %c  6:Virgin %c  7:Blind %c",
    180  1.1  jtc 	    flag[playerp->p_palantir],
    181  1.1  jtc 	    flag[playerp->p_blessing],
    182  1.1  jtc 	    flag[playerp->p_virgin],
    183  1.1  jtc 	    flag[playerp->p_blindness]);
    184  1.1  jtc 
    185  1.1  jtc 	if (!Wizard)
    186  1.1  jtc 	    mvprintw(19, 8, "8:Ring    %c",
    187  1.1  jtc 		flag[playerp->p_ring.ring_type != R_NONE]);
    188  1.1  jtc 	else
    189  1.1  jtc 	    mvprintw(19, 8, "8:Ring    %d  9:Duration %d",
    190  1.1  jtc 		playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
    191  1.1  jtc 
    192  1.1  jtc 	if (!Wizard
    193  1.1  jtc 	    /* not wizard */
    194  1.1  jtc 	    && (ingameflag || strcmp(Login, playerp->p_login) != 0))
    195  1.1  jtc 	    /* in game or not examining own character */
    196  1.1  jtc 	    {
    197  1.1  jtc 	    if (ingameflag)
    198  1.1  jtc 		{
    199  1.1  jtc 		more(LINES - 1);
    200  1.1  jtc 		clear();
    201  1.1  jtc 		return;
    202  1.1  jtc 		}
    203  1.1  jtc 	    else
    204  1.1  jtc 		cleanup(TRUE);
    205  1.1  jtc 		/*NOTREACHED*/
    206  1.1  jtc 	    }
    207  1.1  jtc 
    208  1.1  jtc 	mvaddstr(20, 0, "!:Quit       ?:Delete");
    209  1.1  jtc 	mvaddstr(21, 0, "What would you like to change ? ");
    210  1.1  jtc 
    211  1.1  jtc 	if (Wizard)
    212  1.1  jtc 	    c = getanswer(" ", TRUE);
    213  1.1  jtc 	else
    214  1.1  jtc 	    /* examining own player; allow to change name and password */
    215  1.1  jtc 	    c = getanswer("!BA", FALSE);
    216  1.1  jtc 
    217  1.1  jtc 	switch (c)
    218  1.1  jtc 	    {
    219  1.1  jtc 	    case 'A':	/* change name */
    220  1.1  jtc 	    case 'B':	/* change password */
    221  1.1  jtc 		if (!Wizard)
    222  1.1  jtc 		    /* prompt for password */
    223  1.1  jtc 		    {
    224  1.1  jtc 		    mvaddstr(23, 0, "Password ? ");
    225  1.1  jtc 		    Echo = FALSE;
    226  1.1  jtc 		    getstring(Databuf, 9);
    227  1.1  jtc 		    Echo = TRUE;
    228  1.1  jtc 		    if (strcmp(Databuf, playerp->p_password) != 0)
    229  1.1  jtc 			continue;
    230  1.1  jtc 		    }
    231  1.1  jtc 
    232  1.1  jtc 		if (c == 'A')
    233  1.1  jtc 		    /* get new name */
    234  1.1  jtc 		    {
    235  1.1  jtc 		    mvaddstr(23, 0, "New name: ");
    236  1.1  jtc 		    getstring(Databuf, SZ_NAME);
    237  1.1  jtc 		    truncstring(Databuf);
    238  1.1  jtc 		    if (Databuf[0] != '\0')
    239  1.1  jtc 			if (Wizard || findname(Databuf, &Other) < 0L)
    240  1.1  jtc 			    strcpy(playerp->p_name, Databuf);
    241  1.1  jtc 		    }
    242  1.1  jtc 		else
    243  1.1  jtc 		    /* get new password */
    244  1.1  jtc 		    {
    245  1.1  jtc 		    if (!Wizard)
    246  1.1  jtc 			Echo = FALSE;
    247  1.1  jtc 
    248  1.1  jtc 		    do
    249  1.1  jtc 			/* get two copies of new password until they match */
    250  1.1  jtc 			{
    251  1.1  jtc 			/* get first copy */
    252  1.1  jtc 			mvaddstr(23, 0, "New password ? ");
    253  1.1  jtc 			getstring(Databuf, SZ_PASSWORD);
    254  1.1  jtc 			if (Databuf[0] == '\0')
    255  1.1  jtc 			    break;
    256  1.1  jtc 
    257  1.1  jtc 			/* get second copy */
    258  1.1  jtc 			mvaddstr(23, 0, "One more time ? ");
    259  1.1  jtc 			getstring(playerp->p_password, SZ_PASSWORD);
    260  1.1  jtc 			}
    261  1.1  jtc 		    while (strcmp(playerp->p_password, Databuf) != 0);
    262  1.1  jtc 
    263  1.1  jtc 		    Echo = TRUE;
    264  1.1  jtc 		    }
    265  1.1  jtc 
    266  1.1  jtc 		continue;
    267  1.1  jtc 
    268  1.1  jtc 	    case 'C':	/* change experience */
    269  1.1  jtc 		prompt = "experience";
    270  1.1  jtc 		dptr = &playerp->p_experience;
    271  1.1  jtc 		goto DALTER;
    272  1.1  jtc 
    273  1.1  jtc 	    case 'D':	/* change level */
    274  1.1  jtc 		prompt = "level";
    275  1.1  jtc 		dptr = &playerp->p_level;
    276  1.1  jtc 		goto DALTER;
    277  1.1  jtc 
    278  1.1  jtc 	    case 'E':	/* change strength */
    279  1.1  jtc 		prompt = "strength";
    280  1.1  jtc 		dptr = &playerp->p_strength;
    281  1.1  jtc 		goto DALTER;
    282  1.1  jtc 
    283  1.1  jtc 	    case 'F':	/* change swords */
    284  1.1  jtc 		prompt = "sword";
    285  1.1  jtc 		dptr = &playerp->p_sword;
    286  1.1  jtc 		goto DALTER;
    287  1.1  jtc 
    288  1.1  jtc 	    case 'G':	/* change energy */
    289  1.1  jtc 		prompt = "energy";
    290  1.1  jtc 		dptr = &playerp->p_energy;
    291  1.1  jtc 		goto DALTER;
    292  1.1  jtc 
    293  1.1  jtc 	    case 'H':	/* change maximum energy */
    294  1.1  jtc 		prompt = "max energy";
    295  1.1  jtc 		dptr = &playerp->p_maxenergy;
    296  1.1  jtc 		goto DALTER;
    297  1.1  jtc 
    298  1.1  jtc 	    case 'I':	/* change shields */
    299  1.1  jtc 		prompt = "shield";
    300  1.1  jtc 		dptr = &playerp->p_shield;
    301  1.1  jtc 		goto DALTER;
    302  1.1  jtc 
    303  1.1  jtc 	    case 'J':	/* change quickness */
    304  1.1  jtc 		prompt = "quickness";
    305  1.1  jtc 		dptr = &playerp->p_quickness;
    306  1.1  jtc 		goto DALTER;
    307  1.1  jtc 
    308  1.1  jtc 	    case 'K':	/* change quicksilver */
    309  1.1  jtc 		prompt = "quicksilver";
    310  1.1  jtc 		dptr = &playerp->p_quksilver;
    311  1.1  jtc 		goto DALTER;
    312  1.1  jtc 
    313  1.1  jtc 	    case 'L':	/* change magic */
    314  1.1  jtc 		prompt = "magic level";
    315  1.1  jtc 		dptr = &playerp->p_magiclvl;
    316  1.1  jtc 		goto DALTER;
    317  1.1  jtc 
    318  1.1  jtc 	    case 'M':	/* change mana */
    319  1.1  jtc 		prompt = "mana";
    320  1.1  jtc 		dptr = &playerp->p_mana;
    321  1.1  jtc 		goto DALTER;
    322  1.1  jtc 
    323  1.1  jtc 	    case 'N':	/* change brains */
    324  1.1  jtc 		prompt = "brains";
    325  1.1  jtc 		dptr = &playerp->p_brains;
    326  1.1  jtc 		goto DALTER;
    327  1.1  jtc 
    328  1.1  jtc 	    case 'O':	/* change poison */
    329  1.1  jtc 		prompt = "poison";
    330  1.1  jtc 		dptr = &playerp->p_poison;
    331  1.1  jtc 		goto DALTER;
    332  1.1  jtc 
    333  1.1  jtc 	    case 'P':	/* change gold */
    334  1.1  jtc 		prompt = "gold";
    335  1.1  jtc 		dptr = &playerp->p_gold;
    336  1.1  jtc 		goto DALTER;
    337  1.1  jtc 
    338  1.1  jtc 	    case 'Q':	/* change gems */
    339  1.1  jtc 		prompt = "gems";
    340  1.1  jtc 		dptr = &playerp->p_gems;
    341  1.1  jtc 		goto DALTER;
    342  1.1  jtc 
    343  1.1  jtc 	    case 'R':	/* change sin */
    344  1.1  jtc 		prompt = "sin";
    345  1.1  jtc 		dptr = &playerp->p_sin;
    346  1.1  jtc 		goto DALTER;
    347  1.1  jtc 
    348  1.1  jtc 	    case 'S':	/* change x coord */
    349  1.1  jtc 		prompt = "x";
    350  1.1  jtc 		dptr = &playerp->p_x;
    351  1.1  jtc 		goto DALTER;
    352  1.1  jtc 
    353  1.1  jtc 	    case 'T':	/* change y coord */
    354  1.1  jtc 		prompt = "y";
    355  1.1  jtc 		dptr = &playerp->p_y;
    356  1.1  jtc 		goto DALTER;
    357  1.1  jtc 
    358  1.1  jtc 	    case 'U':	/* change age */
    359  1.1  jtc 		mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
    360  1.1  jtc 		dtemp = infloat();
    361  1.1  jtc 		if (dtemp != 0.0)
    362  1.1  jtc 		    playerp->p_age = (long) dtemp;
    363  1.1  jtc 		continue;
    364  1.1  jtc 
    365  1.1  jtc 	    case 'V':	/* change degen */
    366  1.1  jtc 		mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
    367  1.1  jtc 		dtemp = infloat();
    368  1.1  jtc 		if (dtemp != 0.0)
    369  1.1  jtc 		    playerp->p_degenerated = (int) dtemp;
    370  1.1  jtc 		continue;
    371  1.1  jtc 
    372  1.1  jtc 	    case 'W':	/* change type */
    373  1.1  jtc 		prompt = "type";
    374  1.1  jtc 		sptr = &playerp->p_type;
    375  1.1  jtc 		goto SALTER;
    376  1.1  jtc 
    377  1.1  jtc 	    case 'X':	/* change special type */
    378  1.1  jtc 		prompt = "special type";
    379  1.1  jtc 		sptr = &playerp->p_specialtype;
    380  1.1  jtc 		goto SALTER;
    381  1.1  jtc 
    382  1.1  jtc 	    case 'Y':	/* change lives */
    383  1.1  jtc 		prompt = "lives";
    384  1.1  jtc 		sptr = &playerp->p_lives;
    385  1.1  jtc 		goto SALTER;
    386  1.1  jtc 
    387  1.1  jtc 	    case 'Z':	/* change crowns */
    388  1.1  jtc 		prompt = "crowns";
    389  1.1  jtc 		sptr = &playerp->p_crowns;
    390  1.1  jtc 		goto SALTER;
    391  1.1  jtc 
    392  1.1  jtc 	    case '0':	/* change charms */
    393  1.1  jtc 		prompt = "charm";
    394  1.1  jtc 		sptr = &playerp->p_charms;
    395  1.1  jtc 		goto SALTER;
    396  1.1  jtc 
    397  1.1  jtc 	    case '1':	/* change amulet */
    398  1.1  jtc 		prompt = "amulet";
    399  1.1  jtc 		sptr = &playerp->p_amulets;
    400  1.1  jtc 		goto SALTER;
    401  1.1  jtc 
    402  1.1  jtc 	    case '2':	/* change holy water */
    403  1.1  jtc 		prompt = "holy water";
    404  1.1  jtc 		sptr = &playerp->p_holywater;
    405  1.1  jtc 		goto SALTER;
    406  1.1  jtc 
    407  1.1  jtc 	    case '3':	/* change last-used */
    408  1.1  jtc 		prompt = "last-used";
    409  1.1  jtc 		sptr = &playerp->p_lastused;
    410  1.1  jtc 		goto SALTER;
    411  1.1  jtc 
    412  1.1  jtc 	    case '4':	/* change palantir */
    413  1.1  jtc 		prompt = "palantir";
    414  1.1  jtc 		bptr = &playerp->p_palantir;
    415  1.1  jtc 		goto BALTER;
    416  1.1  jtc 
    417  1.1  jtc 	    case '5':	/* change blessing */
    418  1.1  jtc 		prompt = "blessing";
    419  1.1  jtc 		bptr = &playerp->p_blessing;
    420  1.1  jtc 		goto BALTER;
    421  1.1  jtc 
    422  1.1  jtc 	    case '6':	/* change virgin */
    423  1.1  jtc 		prompt = "virgin";
    424  1.1  jtc 		bptr = &playerp->p_virgin;
    425  1.1  jtc 		goto BALTER;
    426  1.1  jtc 
    427  1.1  jtc 	    case '7':	/* change blindness */
    428  1.1  jtc 		prompt = "blindness";
    429  1.1  jtc 		bptr = &playerp->p_blindness;
    430  1.1  jtc 		goto BALTER;
    431  1.1  jtc 
    432  1.1  jtc 	    case '8':	/* change ring type */
    433  1.1  jtc 		prompt = "ring-type";
    434  1.1  jtc 		sptr = &playerp->p_ring.ring_type;
    435  1.1  jtc 		goto SALTER;
    436  1.1  jtc 
    437  1.1  jtc 	    case '9':	/* change ring duration */
    438  1.1  jtc 		prompt = "ring-duration";
    439  1.1  jtc 		sptr = &playerp->p_ring.ring_duration;
    440  1.1  jtc 		goto SALTER;
    441  1.1  jtc 
    442  1.1  jtc 	    case '!':	/* quit, update */
    443  1.1  jtc 		if (Wizard &&
    444  1.1  jtc 		    (!ingameflag || playerp != &Player))
    445  1.1  jtc 		    /* turn off status if not modifying self */
    446  1.1  jtc 		    {
    447  1.1  jtc 		    playerp->p_status = S_OFF;
    448  1.1  jtc 		    playerp->p_tampered = T_OFF;
    449  1.1  jtc 		    }
    450  1.1  jtc 
    451  1.1  jtc 		writerecord(playerp, loc);
    452  1.1  jtc 		clear();
    453  1.1  jtc 		return;
    454  1.1  jtc 
    455  1.1  jtc 	    case '?':	/* delete player */
    456  1.1  jtc 		if (ingameflag && playerp == &Player)
    457  1.1  jtc 		    /* cannot delete self */
    458  1.1  jtc 		    continue;
    459  1.1  jtc 
    460  1.1  jtc 		freerecord(playerp, loc);
    461  1.1  jtc 		clear();
    462  1.1  jtc 		return;
    463  1.1  jtc 
    464  1.1  jtc 	    default:
    465  1.1  jtc 		continue;
    466  1.1  jtc 	    }
    467  1.1  jtc DALTER:
    468  1.1  jtc 	mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
    469  1.1  jtc 	dtemp = infloat();
    470  1.1  jtc 	if (dtemp != 0.0)
    471  1.1  jtc 	    *dptr = dtemp;
    472  1.1  jtc 	continue;
    473  1.1  jtc 
    474  1.1  jtc SALTER:
    475  1.1  jtc 	mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
    476  1.1  jtc 	dtemp = infloat();
    477  1.1  jtc 	if (dtemp != 0.0)
    478  1.1  jtc 	    *sptr = (short) dtemp;
    479  1.1  jtc 	continue;
    480  1.1  jtc 
    481  1.1  jtc BALTER:
    482  1.1  jtc 	mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt);
    483  1.1  jtc 	c = getanswer("\nTF", TRUE);
    484  1.1  jtc 	if (c == 'T')
    485  1.1  jtc 	    *bptr = TRUE;
    486  1.1  jtc 	else if (c == 'F')
    487  1.1  jtc 	    *bptr = FALSE;
    488  1.1  jtc 	continue;
    489  1.1  jtc 	}
    490  1.1  jtc }
    491  1.1  jtc /**/
    493  1.1  jtc /************************************************************************
    494  1.1  jtc /
    495  1.1  jtc / FUNCTION NAME: monstlist()
    496  1.1  jtc /
    497  1.1  jtc / FUNCTION: print a monster listing
    498  1.1  jtc /
    499  1.1  jtc / AUTHOR: E. A. Estes, 2/27/86
    500  1.1  jtc /
    501  1.1  jtc / ARGUMENTS: none
    502  1.1  jtc /
    503  1.1  jtc / RETURN VALUE: none
    504  1.1  jtc /
    505  1.1  jtc / MODULES CALLED: puts(), fread(), fseek(), printf()
    506  1.1  jtc /
    507  1.1  jtc / GLOBAL INPUTS: Curmonster, *Monstfp
    508  1.1  jtc /
    509  1.1  jtc / GLOBAL OUTPUTS: none
    510  1.1  jtc /
    511  1.1  jtc / DESCRIPTION:
    512  1.1  jtc /	Read monster file, and print a monster listing on standard output.
    513  1.1  jtc /
    514  1.1  jtc /************************************************************************/
    515  1.1  jtc 
    516  1.1  jtc monstlist()
    517  1.1  jtc {
    518  1.1  jtc register int 	count = 0;		/* count in file */
    519  1.1  jtc 
    520  1.1  jtc     puts(" #)  Name                 Str  Brain  Quick  Energy  Exper  Treas  Type  Flock%\n");
    521  1.1  jtc     fseek(Monstfp, 0L, 0);
    522  1.1  jtc     while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
    523  1.1  jtc 	printf("%2d)  %-20.20s%4.0f   %4.0f     %2.0f   %5.0f  %5.0f     %2d    %2d     %3.0f\n", count++,
    524  1.1  jtc 	    Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
    525  1.1  jtc 	    Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
    526  1.1  jtc 	    Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
    527  1.1  jtc }
    528  1.1  jtc /**/
    530  1.1  jtc /************************************************************************
    531  1.1  jtc /
    532  1.1  jtc / FUNCTION NAME: scorelist()
    533  1.1  jtc /
    534  1.1  jtc / FUNCTION: print player score board
    535  1.1  jtc /
    536  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    537  1.1  jtc /
    538  1.1  jtc / ARGUMENTS: none
    539  1.1  jtc /
    540  1.1  jtc / RETURN VALUE: none
    541  1.1  jtc /
    542  1.1  jtc / MODULES CALLED: fread(), fopen(), printf(), fclose()
    543  1.1  jtc /
    544  1.1  jtc / GLOBAL INPUTS:
    545  1.1  jtc /
    546  1.1  jtc / GLOBAL OUTPUTS: none
    547  1.1  jtc /
    548  1.1  jtc / DESCRIPTION:
    549  1.1  jtc /	Read the scoreboard file and print the contents.
    550  1.1  jtc /
    551  1.1  jtc /************************************************************************/
    552  1.1  jtc 
    553  1.1  jtc scorelist()
    554  1.1  jtc {
    555  1.1  jtc struct	scoreboard	sbuf;	/* for reading entries */
    556  1.1  jtc register FILE	*fp;		/* to open the file */
    557  1.1  jtc 
    558  1.1  jtc     if ((fp = fopen(_PATH_SCORE, "r")) != NULL)
    559  1.1  jtc 	{
    560  1.1  jtc 	while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
    561  1.1  jtc 	    printf("%-20s   (%-9s)  Level: %6.0f  Type: %s\n",
    562  1.1  jtc 		sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
    563  1.1  jtc 	fclose(fp);
    564  1.1  jtc 	}
    565  1.1  jtc }
    566  1.1  jtc /**/
    568  1.1  jtc /************************************************************************
    569  1.1  jtc /
    570  1.1  jtc / FUNCTION NAME: activelist()
    571  1.1  jtc /
    572  1.1  jtc / FUNCTION: print list of active players to standard output
    573  1.1  jtc /
    574  1.1  jtc / AUTHOR: E. A. Estes, 3/7/86
    575  1.1  jtc /
    576  1.1  jtc / ARGUMENTS: none
    577  1.1  jtc /
    578  1.1  jtc / RETURN VALUE: none
    579  1.1  jtc /
    580  1.1  jtc / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
    581  1.1  jtc /
    582  1.1  jtc / GLOBAL INPUTS: Other, *Playersfp
    583  1.1  jtc /
    584  1.1  jtc / GLOBAL OUTPUTS: none
    585  1.1  jtc /
    586  1.1  jtc / DESCRIPTION:
    587  1.1  jtc /	Read player file, and print list of active records to standard output.
    588  1.1  jtc /
    589  1.1  jtc /************************************************************************/
    590  1.1  jtc 
    591  1.1  jtc activelist()
    592  1.1  jtc {
    593  1.1  jtc     fseek(Playersfp, 0L, 0);
    594  1.1  jtc     printf("Current characters on file are:\n\n");
    595  1.1  jtc 
    596  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    597  1.1  jtc 	if (Other.p_status != S_NOTUSED)
    598  1.1  jtc 	    printf("%-20s   (%-9s)  Level: %6.0f  %s  (%s)\n",
    599  1.1  jtc 		Other.p_name, Other.p_login, Other.p_level,
    600  1.1  jtc 		descrtype(&Other, FALSE), descrstatus(&Other));
    601  1.1  jtc 
    602  1.1  jtc }
    603  1.1  jtc /**/
    605  1.1  jtc /************************************************************************
    606  1.1  jtc /
    607  1.1  jtc / FUNCTION NAME: purgeoldplayers()
    608  1.1  jtc /
    609  1.1  jtc / FUNCTION: purge inactive players from player file
    610  1.1  jtc /
    611  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    612  1.1  jtc /
    613  1.1  jtc / ARGUMENTS: none
    614  1.1  jtc /
    615  1.1  jtc / RETURN VALUE: none
    616  1.1  jtc /
    617  1.1  jtc / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
    618  1.1  jtc /
    619  1.1  jtc / GLOBAL INPUTS: Other, *Playersfp
    620  1.1  jtc /
    621  1.1  jtc / GLOBAL OUTPUTS: none
    622  1.1  jtc /
    623  1.1  jtc / DESCRIPTION:
    624  1.1  jtc /	Delete characters which have not been used with the last
    625  1.1  jtc /	three weeks.
    626  1.1  jtc /
    627  1.1  jtc /************************************************************************/
    628  1.1  jtc 
    629  1.1  jtc purgeoldplayers()
    630  1.1  jtc {
    631  1.1  jtc int	today;		/* day of year for today */
    632  1.1  jtc int	daysold;	/* how many days since the character has been used */
    633  1.1  jtc long	ltime;		/* time in seconds */
    634  1.1  jtc long	loc = 0L;	/* location in file */
    635  1.1  jtc 
    636  1.1  jtc     time(&ltime);
    637  1.1  jtc     today = localtime(&ltime)->tm_yday;
    638  1.1  jtc 
    639  1.1  jtc     for (;;)
    640  1.1  jtc 	{
    641  1.1  jtc 	fseek(Playersfp, loc, 0);
    642  1.1  jtc 	if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
    643  1.1  jtc 	    break;
    644  1.1  jtc 
    645  1.1  jtc 	daysold = today - Other.p_lastused;
    646  1.1  jtc 	if (daysold < 0)
    647  1.1  jtc 	    daysold += 365;
    648  1.1  jtc 
    649  1.1  jtc 	if (daysold > N_DAYSOLD)
    650  1.1  jtc 	    /* player hasn't been used in a while; delete */
    651  1.1  jtc 	    freerecord(&Other, loc);
    652  1.1  jtc 
    653  1.1  jtc 	loc += SZ_PLAYERSTRUCT;
    654  1.1  jtc 	}
    655  1.1  jtc }
    656  1.1  jtc /**/
    658  1.1  jtc /************************************************************************
    659  1.1  jtc /
    660  1.1  jtc / FUNCTION NAME: enterscore()
    661  1.1  jtc /
    662  1.1  jtc / FUNCTION: enter player into scoreboard
    663  1.1  jtc /
    664  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    665  1.1  jtc /
    666  1.1  jtc / ARGUMENTS: none
    667  1.1  jtc /
    668  1.1  jtc / RETURN VALUE: none
    669  1.1  jtc /
    670  1.1  jtc / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
    671  1.1  jtc /	strcpy(), fwrite(), descrtype()
    672  1.1  jtc /
    673  1.1  jtc / GLOBAL INPUTS: Player
    674  1.1  jtc /
    675  1.1  jtc / GLOBAL OUTPUTS: none
    676  1.1  jtc /
    677  1.1  jtc / DESCRIPTION:
    678  1.1  jtc /	The scoreboard keeps track of the highest character on a
    679  1.1  jtc /	per-login basis.
    680  1.1  jtc /	Search the scoreboard for an entry for the current login,
    681  1.1  jtc /	if an entry is found, and it is lower than the current player,
    682  1.1  jtc /	replace it, otherwise create an entry.
    683  1.1  jtc /
    684  1.1  jtc /************************************************************************/
    685  1.1  jtc 
    686  1.1  jtc enterscore()
    687  1.1  jtc {
    688  1.1  jtc struct	scoreboard sbuf;		/* buffer to read in scoreboard entries */
    689  1.1  jtc FILE	*fp;				/* to open scoreboard file */
    690  1.1  jtc long	loc = 0L;			/* location in scoreboard file */
    691  1.1  jtc bool	found = FALSE;			/* set if we found an entry for this login */
    692  1.1  jtc 
    693  1.1  jtc     if ((fp = fopen(_PATH_SCORE, "r+")) != NULL)
    694  1.1  jtc 	{
    695  1.1  jtc 	while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
    696  1.1  jtc 	    if (strcmp(Player.p_login, sbuf.sb_login) == 0)
    697  1.1  jtc 		{
    698  1.1  jtc 		found = TRUE;
    699  1.1  jtc 		break;
    700  1.1  jtc 		}
    701  1.1  jtc 	    else
    702  1.1  jtc 		loc += SZ_SCORESTRUCT;
    703  1.1  jtc 	}
    704  1.1  jtc     else
    705  1.1  jtc 	{
    706  1.1  jtc 	error(_PATH_SCORE);
    707  1.1  jtc 	/*NOTREACHED*/
    708  1.1  jtc 	}
    709  1.1  jtc 
    710  1.1  jtc     /*
    711  1.1  jtc      * At this point, 'loc' will either indicate a point beyond
    712  1.1  jtc      * the end of file, or the place where the previous entry
    713  1.1  jtc      * was found.
    714  1.1  jtc      */
    715  1.1  jtc 
    716  1.1  jtc     if ((!found) || Player.p_level > sbuf.sb_level)
    717  1.1  jtc 	/* put new entry in for this login */
    718  1.1  jtc 	{
    719  1.1  jtc 	strcpy(sbuf.sb_login, Player.p_login);
    720  1.1  jtc 	strcpy(sbuf.sb_name, Player.p_name);
    721  1.1  jtc 	sbuf.sb_level = Player.p_level;
    722  1.1  jtc 	strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
    723  1.1  jtc 	}
    724  1.1  jtc 
    725               /* update entry */
    726               fseek(fp, loc, 0);
    727               fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
    728               fclose(fp);
    729           }
    730