xref: /netbsd-src/games/phantasia/gamesupport.c (revision e28fc9086cd7f59ab0a7363c8a37303b5a0d04a0)
1*e28fc908Sdholland /*	$NetBSD: gamesupport.c,v 1.11 2009/08/31 08:27:16 dholland Exp $	*/
2dcfebd78Scgd 
386a62b8dSjtc /*
486a62b8dSjtc  * gamesupport.c - auxiliary routines for support of Phantasia
586a62b8dSjtc  */
686a62b8dSjtc 
7*e28fc908Sdholland #include <setjmp.h>
8*e28fc908Sdholland #include <stdio.h>
9*e28fc908Sdholland #include <string.h>
10*e28fc908Sdholland #include <time.h>
11*e28fc908Sdholland 
12*e28fc908Sdholland #include "phantdefs.h"
13*e28fc908Sdholland #include "phantstruct.h"
14*e28fc908Sdholland #include "phantglobs.h"
15*e28fc908Sdholland #include "pathnames.h"
16*e28fc908Sdholland 
179b1375acShe #undef bool
189209ce5aSross #include <curses.h>
1986a62b8dSjtc 
20a232aee2Slukem void
changestats(phbool ingameflag)21c7a109ccSdholland changestats(phbool ingameflag)
2286a62b8dSjtc {
2386a62b8dSjtc 	static char flag[2] =	/* for printing values of bools */
2486a62b8dSjtc 	{'F', 'T'};
25a232aee2Slukem 	struct player *playerp;	/* pointer to structure to alter */
26092d3130Sjsm 	const char   *prompt;		/* pointer to prompt string */
2786a62b8dSjtc 	int     c;		/* input */
2886a62b8dSjtc 	int     today;		/* day of year of today */
2986a62b8dSjtc 	int     temp;		/* temporary variable */
3086a62b8dSjtc 	long    loc;		/* location in player file */
31c4816c32Scgd 	time_t  now;		/* time now */
3286a62b8dSjtc 	double  dtemp;		/* temporary variable */
3358b3287bSjsm 	phbool *bptr;		/* pointer to bool item to change */
3486a62b8dSjtc 	double *dptr;		/* pointer to double item to change */
3586a62b8dSjtc 	short  *sptr;		/* pointer to short item to change */
3686a62b8dSjtc 
3786a62b8dSjtc 	clear();
3886a62b8dSjtc 
3986a62b8dSjtc 	for (;;)
4086a62b8dSjtc 		/* get name of player to examine/alter */
4186a62b8dSjtc 	{
4286a62b8dSjtc 		mvaddstr(5, 0, "Which character do you want to look at ? ");
4386a62b8dSjtc 		getstring(Databuf, SZ_DATABUF);
4486a62b8dSjtc 		truncstring(Databuf);
4586a62b8dSjtc 
4686a62b8dSjtc 		if (Databuf[0] == '\0')
4786a62b8dSjtc 			userlist(ingameflag);
4886a62b8dSjtc 		else
4986a62b8dSjtc 			break;
5086a62b8dSjtc 	}
5186a62b8dSjtc 
5286a62b8dSjtc 	loc = -1L;
5386a62b8dSjtc 
5486a62b8dSjtc 	if (!ingameflag)
5586a62b8dSjtc 		/* use 'Player' structure */
5686a62b8dSjtc 		playerp = &Player;
57a232aee2Slukem 	else
58a232aee2Slukem 		if (strcmp(Databuf, Player.p_name) == 0)
5986a62b8dSjtc 			/* alter/examine current player */
6086a62b8dSjtc 		{
6186a62b8dSjtc 			playerp = &Player;
6286a62b8dSjtc 			loc = Fileloc;
63a232aee2Slukem 		} else
6486a62b8dSjtc 			/* use 'Other' structure */
6586a62b8dSjtc 			playerp = &Other;
6686a62b8dSjtc 
6786a62b8dSjtc 	/* find player on file */
6886a62b8dSjtc 	if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
6986a62b8dSjtc 		/* didn't find player */
7086a62b8dSjtc 	{
7186a62b8dSjtc 		clear();
7286a62b8dSjtc 		mvaddstr(11, 0, "Not found.");
7386a62b8dSjtc 		return;
7486a62b8dSjtc 	}
7586a62b8dSjtc 	time(&now);
7686a62b8dSjtc 	today = localtime(&now)->tm_yday;
7786a62b8dSjtc 
7886a62b8dSjtc 	clear();
7986a62b8dSjtc 
8086a62b8dSjtc 	for (;;)
8186a62b8dSjtc 		/* print player structure, and prompt for action */
8286a62b8dSjtc 	{
8386a62b8dSjtc 		mvprintw(0, 0, "A:Name         %s\n", playerp->p_name);
8486a62b8dSjtc 
8586a62b8dSjtc 		if (Wizard)
8686a62b8dSjtc 			printw("B:Password     %s\n", playerp->p_password);
8786a62b8dSjtc 		else
8886a62b8dSjtc 			addstr("B:Password     XXXXXXXX\n");
8986a62b8dSjtc 
9086a62b8dSjtc 		printw(" :Login        %s\n", playerp->p_login);
9186a62b8dSjtc 
9286a62b8dSjtc 		printw("C:Experience   %.0f\n", playerp->p_experience);
9386a62b8dSjtc 		printw("D:Level        %.0f\n", playerp->p_level);
9486a62b8dSjtc 		printw("E:Strength     %.0f\n", playerp->p_strength);
9586a62b8dSjtc 		printw("F:Sword        %.0f\n", playerp->p_sword);
9686a62b8dSjtc 		printw(" :Might        %.0f\n", playerp->p_might);
9786a62b8dSjtc 		printw("G:Energy       %.0f\n", playerp->p_energy);
9886a62b8dSjtc 		printw("H:Max-Energy   %.0f\n", playerp->p_maxenergy);
9986a62b8dSjtc 		printw("I:Shield       %.0f\n", playerp->p_shield);
10086a62b8dSjtc 		printw("J:Quickness    %.0f\n", playerp->p_quickness);
10186a62b8dSjtc 		printw("K:Quicksilver  %.0f\n", playerp->p_quksilver);
10286a62b8dSjtc 		printw(" :Speed        %.0f\n", playerp->p_speed);
10386a62b8dSjtc 		printw("L:Magic Level  %.0f\n", playerp->p_magiclvl);
10486a62b8dSjtc 		printw("M:Mana         %.0f\n", playerp->p_mana);
10586a62b8dSjtc 		printw("N:Brains       %.0f\n", playerp->p_brains);
10686a62b8dSjtc 
10786a62b8dSjtc 		if (Wizard || playerp->p_specialtype != SC_VALAR)
10886a62b8dSjtc 			mvaddstr(0, 40, descrstatus(playerp));
10986a62b8dSjtc 
11086a62b8dSjtc 		mvprintw(1, 40, "O:Poison       %0.3f\n", playerp->p_poison);
11186a62b8dSjtc 		mvprintw(2, 40, "P:Gold         %.0f\n", playerp->p_gold);
11286a62b8dSjtc 		mvprintw(3, 40, "Q:Gem          %.0f\n", playerp->p_gems);
11386a62b8dSjtc 		mvprintw(4, 40, "R:Sin          %0.3f\n", playerp->p_sin);
114a232aee2Slukem 		if (Wizard) {
11586a62b8dSjtc 			mvprintw(5, 40, "S:X-coord      %.0f\n", playerp->p_x);
11686a62b8dSjtc 			mvprintw(6, 40, "T:Y-coord      %.0f\n", playerp->p_y);
117a232aee2Slukem 		} else {
11886a62b8dSjtc 			mvaddstr(5, 40, "S:X-coord      ?\n");
11986a62b8dSjtc 			mvaddstr(6, 40, "T:Y-coord      ?\n");
12086a62b8dSjtc 		}
12186a62b8dSjtc 
12286a62b8dSjtc 		mvprintw(7, 40, "U:Age          %ld\n", playerp->p_age);
12386a62b8dSjtc 		mvprintw(8, 40, "V:Degenerated  %d\n", playerp->p_degenerated);
12486a62b8dSjtc 
12586a62b8dSjtc 		mvprintw(9, 40, "W:Type         %d (%s)\n",
12686a62b8dSjtc 		    playerp->p_type, descrtype(playerp, FALSE) + 1);
12786a62b8dSjtc 		mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
12886a62b8dSjtc 		mvprintw(11, 40, "Y:Lives        %d\n", playerp->p_lives);
12986a62b8dSjtc 		mvprintw(12, 40, "Z:Crowns       %d\n", playerp->p_crowns);
13086a62b8dSjtc 		mvprintw(13, 40, "0:Charms       %d\n", playerp->p_charms);
13186a62b8dSjtc 		mvprintw(14, 40, "1:Amulets      %d\n", playerp->p_amulets);
13286a62b8dSjtc 		mvprintw(15, 40, "2:Holy Water   %d\n", playerp->p_holywater);
13386a62b8dSjtc 
13486a62b8dSjtc 		temp = today - playerp->p_lastused;
13586a62b8dSjtc 		if (temp < 0)
13686a62b8dSjtc 			/* last year */
13786a62b8dSjtc 			temp += 365;
13886a62b8dSjtc 		mvprintw(16, 40, "3:Lastused     %d  (%d)\n", playerp->p_lastused, temp);
13986a62b8dSjtc 
14086a62b8dSjtc 		mvprintw(18, 8, "4:Palantir %c  5:Blessing %c  6:Virgin %c  7:Blind %c",
141a232aee2Slukem 		    flag[(int)playerp->p_palantir],
142a232aee2Slukem 		    flag[(int)playerp->p_blessing],
143a232aee2Slukem 		    flag[(int)playerp->p_virgin],
144a232aee2Slukem 		    flag[(int)playerp->p_blindness]);
14586a62b8dSjtc 
14686a62b8dSjtc 		if (!Wizard)
14786a62b8dSjtc 			mvprintw(19, 8, "8:Ring    %c",
14886a62b8dSjtc 			    flag[playerp->p_ring.ring_type != R_NONE]);
14986a62b8dSjtc 		else
15086a62b8dSjtc 			mvprintw(19, 8, "8:Ring    %d  9:Duration %d",
15186a62b8dSjtc 			    playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
15286a62b8dSjtc 
15386a62b8dSjtc 		if (!Wizard
15486a62b8dSjtc 		/* not wizard */
15586a62b8dSjtc 		    && (ingameflag || strcmp(Login, playerp->p_login) != 0))
15686a62b8dSjtc 			/* in game or not examining own character */
15786a62b8dSjtc 		{
158a232aee2Slukem 			if (ingameflag) {
15986a62b8dSjtc 				more(LINES - 1);
16086a62b8dSjtc 				clear();
16186a62b8dSjtc 				return;
162a232aee2Slukem 			} else
16386a62b8dSjtc 				cleanup(TRUE);
16486a62b8dSjtc 			/* NOTREACHED */
16586a62b8dSjtc 		}
16686a62b8dSjtc 		mvaddstr(20, 0, "!:Quit       ?:Delete");
16786a62b8dSjtc 		mvaddstr(21, 0, "What would you like to change ? ");
16886a62b8dSjtc 
16986a62b8dSjtc 		if (Wizard)
17086a62b8dSjtc 			c = getanswer(" ", TRUE);
17186a62b8dSjtc 		else
172a232aee2Slukem 			/* examining own player; allow to change name and
173a232aee2Slukem 			 * password */
17486a62b8dSjtc 			c = getanswer("!BA", FALSE);
17586a62b8dSjtc 
176a232aee2Slukem 		switch (c) {
17786a62b8dSjtc 		case 'A':	/* change name */
17886a62b8dSjtc 		case 'B':	/* change password */
17986a62b8dSjtc 			if (!Wizard)
18086a62b8dSjtc 				/* prompt for password */
18186a62b8dSjtc 			{
18286a62b8dSjtc 				mvaddstr(23, 0, "Password ? ");
18386a62b8dSjtc 				Echo = FALSE;
18486a62b8dSjtc 				getstring(Databuf, 9);
18586a62b8dSjtc 				Echo = TRUE;
18686a62b8dSjtc 				if (strcmp(Databuf, playerp->p_password) != 0)
18786a62b8dSjtc 					continue;
18886a62b8dSjtc 			}
18986a62b8dSjtc 			if (c == 'A')
19086a62b8dSjtc 				/* get new name */
19186a62b8dSjtc 			{
19286a62b8dSjtc 				mvaddstr(23, 0, "New name: ");
19386a62b8dSjtc 				getstring(Databuf, SZ_NAME);
19486a62b8dSjtc 				truncstring(Databuf);
19586a62b8dSjtc 				if (Databuf[0] != '\0')
19686a62b8dSjtc 					if (Wizard || findname(Databuf, &Other) < 0L)
19786a62b8dSjtc 						strcpy(playerp->p_name, Databuf);
198a232aee2Slukem 			} else
19986a62b8dSjtc 				/* get new password */
20086a62b8dSjtc 			{
20186a62b8dSjtc 				if (!Wizard)
20286a62b8dSjtc 					Echo = FALSE;
20386a62b8dSjtc 
20486a62b8dSjtc 				do
205a232aee2Slukem 					/* get two copies of new password
206a232aee2Slukem 					 * until they match */
20786a62b8dSjtc 				{
20886a62b8dSjtc 					/* get first copy */
20986a62b8dSjtc 					mvaddstr(23, 0, "New password ? ");
21086a62b8dSjtc 					getstring(Databuf, SZ_PASSWORD);
21186a62b8dSjtc 					if (Databuf[0] == '\0')
21286a62b8dSjtc 						break;
21386a62b8dSjtc 
21486a62b8dSjtc 					/* get second copy */
21586a62b8dSjtc 					mvaddstr(23, 0, "One more time ? ");
21686a62b8dSjtc 					getstring(playerp->p_password, SZ_PASSWORD);
21786a62b8dSjtc 				}
21886a62b8dSjtc 				while (strcmp(playerp->p_password, Databuf) != 0);
21986a62b8dSjtc 
22086a62b8dSjtc 				Echo = TRUE;
22186a62b8dSjtc 			}
22286a62b8dSjtc 
22386a62b8dSjtc 			continue;
22486a62b8dSjtc 
22586a62b8dSjtc 		case 'C':	/* change experience */
22686a62b8dSjtc 			prompt = "experience";
22786a62b8dSjtc 			dptr = &playerp->p_experience;
22886a62b8dSjtc 			goto DALTER;
22986a62b8dSjtc 
23086a62b8dSjtc 		case 'D':	/* change level */
23186a62b8dSjtc 			prompt = "level";
23286a62b8dSjtc 			dptr = &playerp->p_level;
23386a62b8dSjtc 			goto DALTER;
23486a62b8dSjtc 
23586a62b8dSjtc 		case 'E':	/* change strength */
23686a62b8dSjtc 			prompt = "strength";
23786a62b8dSjtc 			dptr = &playerp->p_strength;
23886a62b8dSjtc 			goto DALTER;
23986a62b8dSjtc 
24086a62b8dSjtc 		case 'F':	/* change swords */
24186a62b8dSjtc 			prompt = "sword";
24286a62b8dSjtc 			dptr = &playerp->p_sword;
24386a62b8dSjtc 			goto DALTER;
24486a62b8dSjtc 
24586a62b8dSjtc 		case 'G':	/* change energy */
24686a62b8dSjtc 			prompt = "energy";
24786a62b8dSjtc 			dptr = &playerp->p_energy;
24886a62b8dSjtc 			goto DALTER;
24986a62b8dSjtc 
25086a62b8dSjtc 		case 'H':	/* change maximum energy */
25186a62b8dSjtc 			prompt = "max energy";
25286a62b8dSjtc 			dptr = &playerp->p_maxenergy;
25386a62b8dSjtc 			goto DALTER;
25486a62b8dSjtc 
25586a62b8dSjtc 		case 'I':	/* change shields */
25686a62b8dSjtc 			prompt = "shield";
25786a62b8dSjtc 			dptr = &playerp->p_shield;
25886a62b8dSjtc 			goto DALTER;
25986a62b8dSjtc 
26086a62b8dSjtc 		case 'J':	/* change quickness */
26186a62b8dSjtc 			prompt = "quickness";
26286a62b8dSjtc 			dptr = &playerp->p_quickness;
26386a62b8dSjtc 			goto DALTER;
26486a62b8dSjtc 
26586a62b8dSjtc 		case 'K':	/* change quicksilver */
26686a62b8dSjtc 			prompt = "quicksilver";
26786a62b8dSjtc 			dptr = &playerp->p_quksilver;
26886a62b8dSjtc 			goto DALTER;
26986a62b8dSjtc 
27086a62b8dSjtc 		case 'L':	/* change magic */
27186a62b8dSjtc 			prompt = "magic level";
27286a62b8dSjtc 			dptr = &playerp->p_magiclvl;
27386a62b8dSjtc 			goto DALTER;
27486a62b8dSjtc 
27586a62b8dSjtc 		case 'M':	/* change mana */
27686a62b8dSjtc 			prompt = "mana";
27786a62b8dSjtc 			dptr = &playerp->p_mana;
27886a62b8dSjtc 			goto DALTER;
27986a62b8dSjtc 
28086a62b8dSjtc 		case 'N':	/* change brains */
28186a62b8dSjtc 			prompt = "brains";
28286a62b8dSjtc 			dptr = &playerp->p_brains;
28386a62b8dSjtc 			goto DALTER;
28486a62b8dSjtc 
28586a62b8dSjtc 		case 'O':	/* change poison */
28686a62b8dSjtc 			prompt = "poison";
28786a62b8dSjtc 			dptr = &playerp->p_poison;
28886a62b8dSjtc 			goto DALTER;
28986a62b8dSjtc 
29086a62b8dSjtc 		case 'P':	/* change gold */
29186a62b8dSjtc 			prompt = "gold";
29286a62b8dSjtc 			dptr = &playerp->p_gold;
29386a62b8dSjtc 			goto DALTER;
29486a62b8dSjtc 
29586a62b8dSjtc 		case 'Q':	/* change gems */
29686a62b8dSjtc 			prompt = "gems";
29786a62b8dSjtc 			dptr = &playerp->p_gems;
29886a62b8dSjtc 			goto DALTER;
29986a62b8dSjtc 
30086a62b8dSjtc 		case 'R':	/* change sin */
30186a62b8dSjtc 			prompt = "sin";
30286a62b8dSjtc 			dptr = &playerp->p_sin;
30386a62b8dSjtc 			goto DALTER;
30486a62b8dSjtc 
30586a62b8dSjtc 		case 'S':	/* change x coord */
30686a62b8dSjtc 			prompt = "x";
30786a62b8dSjtc 			dptr = &playerp->p_x;
30886a62b8dSjtc 			goto DALTER;
30986a62b8dSjtc 
31086a62b8dSjtc 		case 'T':	/* change y coord */
31186a62b8dSjtc 			prompt = "y";
31286a62b8dSjtc 			dptr = &playerp->p_y;
31386a62b8dSjtc 			goto DALTER;
31486a62b8dSjtc 
31586a62b8dSjtc 		case 'U':	/* change age */
31686a62b8dSjtc 			mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
31786a62b8dSjtc 			dtemp = infloat();
31886a62b8dSjtc 			if (dtemp != 0.0)
31986a62b8dSjtc 				playerp->p_age = (long) dtemp;
32086a62b8dSjtc 			continue;
32186a62b8dSjtc 
32286a62b8dSjtc 		case 'V':	/* change degen */
32386a62b8dSjtc 			mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
32486a62b8dSjtc 			dtemp = infloat();
32586a62b8dSjtc 			if (dtemp != 0.0)
32686a62b8dSjtc 				playerp->p_degenerated = (int) dtemp;
32786a62b8dSjtc 			continue;
32886a62b8dSjtc 
32986a62b8dSjtc 		case 'W':	/* change type */
33086a62b8dSjtc 			prompt = "type";
33186a62b8dSjtc 			sptr = &playerp->p_type;
33286a62b8dSjtc 			goto SALTER;
33386a62b8dSjtc 
33486a62b8dSjtc 		case 'X':	/* change special type */
33586a62b8dSjtc 			prompt = "special type";
33686a62b8dSjtc 			sptr = &playerp->p_specialtype;
33786a62b8dSjtc 			goto SALTER;
33886a62b8dSjtc 
33986a62b8dSjtc 		case 'Y':	/* change lives */
34086a62b8dSjtc 			prompt = "lives";
34186a62b8dSjtc 			sptr = &playerp->p_lives;
34286a62b8dSjtc 			goto SALTER;
34386a62b8dSjtc 
34486a62b8dSjtc 		case 'Z':	/* change crowns */
34586a62b8dSjtc 			prompt = "crowns";
34686a62b8dSjtc 			sptr = &playerp->p_crowns;
34786a62b8dSjtc 			goto SALTER;
34886a62b8dSjtc 
34986a62b8dSjtc 		case '0':	/* change charms */
35086a62b8dSjtc 			prompt = "charm";
35186a62b8dSjtc 			sptr = &playerp->p_charms;
35286a62b8dSjtc 			goto SALTER;
35386a62b8dSjtc 
35486a62b8dSjtc 		case '1':	/* change amulet */
35586a62b8dSjtc 			prompt = "amulet";
35686a62b8dSjtc 			sptr = &playerp->p_amulets;
35786a62b8dSjtc 			goto SALTER;
35886a62b8dSjtc 
35986a62b8dSjtc 		case '2':	/* change holy water */
36086a62b8dSjtc 			prompt = "holy water";
36186a62b8dSjtc 			sptr = &playerp->p_holywater;
36286a62b8dSjtc 			goto SALTER;
36386a62b8dSjtc 
36486a62b8dSjtc 		case '3':	/* change last-used */
36586a62b8dSjtc 			prompt = "last-used";
36686a62b8dSjtc 			sptr = &playerp->p_lastused;
36786a62b8dSjtc 			goto SALTER;
36886a62b8dSjtc 
36986a62b8dSjtc 		case '4':	/* change palantir */
37086a62b8dSjtc 			prompt = "palantir";
37186a62b8dSjtc 			bptr = &playerp->p_palantir;
37286a62b8dSjtc 			goto BALTER;
37386a62b8dSjtc 
37486a62b8dSjtc 		case '5':	/* change blessing */
37586a62b8dSjtc 			prompt = "blessing";
37686a62b8dSjtc 			bptr = &playerp->p_blessing;
37786a62b8dSjtc 			goto BALTER;
37886a62b8dSjtc 
37986a62b8dSjtc 		case '6':	/* change virgin */
38086a62b8dSjtc 			prompt = "virgin";
38186a62b8dSjtc 			bptr = &playerp->p_virgin;
38286a62b8dSjtc 			goto BALTER;
38386a62b8dSjtc 
38486a62b8dSjtc 		case '7':	/* change blindness */
38586a62b8dSjtc 			prompt = "blindness";
38686a62b8dSjtc 			bptr = &playerp->p_blindness;
38786a62b8dSjtc 			goto BALTER;
38886a62b8dSjtc 
38986a62b8dSjtc 		case '8':	/* change ring type */
39086a62b8dSjtc 			prompt = "ring-type";
39186a62b8dSjtc 			sptr = &playerp->p_ring.ring_type;
39286a62b8dSjtc 			goto SALTER;
39386a62b8dSjtc 
39486a62b8dSjtc 		case '9':	/* change ring duration */
39586a62b8dSjtc 			prompt = "ring-duration";
39686a62b8dSjtc 			sptr = &playerp->p_ring.ring_duration;
39786a62b8dSjtc 			goto SALTER;
39886a62b8dSjtc 
39986a62b8dSjtc 		case '!':	/* quit, update */
40086a62b8dSjtc 			if (Wizard &&
40186a62b8dSjtc 			    (!ingameflag || playerp != &Player))
40286a62b8dSjtc 				/* turn off status if not modifying self */
40386a62b8dSjtc 			{
40486a62b8dSjtc 				playerp->p_status = S_OFF;
40586a62b8dSjtc 				playerp->p_tampered = T_OFF;
40686a62b8dSjtc 			}
40786a62b8dSjtc 			writerecord(playerp, loc);
40886a62b8dSjtc 			clear();
40986a62b8dSjtc 			return;
41086a62b8dSjtc 
41186a62b8dSjtc 		case '?':	/* delete player */
41286a62b8dSjtc 			if (ingameflag && playerp == &Player)
41386a62b8dSjtc 				/* cannot delete self */
41486a62b8dSjtc 				continue;
41586a62b8dSjtc 
41686a62b8dSjtc 			freerecord(playerp, loc);
41786a62b8dSjtc 			clear();
41886a62b8dSjtc 			return;
41986a62b8dSjtc 
42086a62b8dSjtc 		default:
42186a62b8dSjtc 			continue;
42286a62b8dSjtc 		}
42386a62b8dSjtc DALTER:
42486a62b8dSjtc 		mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
42586a62b8dSjtc 		dtemp = infloat();
42686a62b8dSjtc 		if (dtemp != 0.0)
42786a62b8dSjtc 			*dptr = dtemp;
42886a62b8dSjtc 		continue;
42986a62b8dSjtc 
43086a62b8dSjtc SALTER:
43186a62b8dSjtc 		mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
43286a62b8dSjtc 		dtemp = infloat();
43386a62b8dSjtc 		if (dtemp != 0.0)
43486a62b8dSjtc 			*sptr = (short) dtemp;
43586a62b8dSjtc 		continue;
43686a62b8dSjtc 
43786a62b8dSjtc BALTER:
438a232aee2Slukem 		mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[(int)*bptr],
439a232aee2Slukem 		    prompt);
44086a62b8dSjtc 		c = getanswer("\nTF", TRUE);
44186a62b8dSjtc 		if (c == 'T')
44286a62b8dSjtc 			*bptr = TRUE;
443a232aee2Slukem 		else
444a232aee2Slukem 			if (c == 'F')
44586a62b8dSjtc 				*bptr = FALSE;
44686a62b8dSjtc 		continue;
44786a62b8dSjtc 	}
44886a62b8dSjtc }
44986a62b8dSjtc 
450a232aee2Slukem void
monstlist(void)451c7a109ccSdholland monstlist(void)
45286a62b8dSjtc {
453a232aee2Slukem 	int     count = 0;	/* count in file */
45486a62b8dSjtc 
45586a62b8dSjtc 	puts(" #)  Name                 Str  Brain  Quick  Energy  Exper  Treas  Type  Flock%\n");
4565fb18dd9Sjsm 	fseek(Monstfp, 0L, SEEK_SET);
45786a62b8dSjtc 	while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
45886a62b8dSjtc 		printf("%2d)  %-20.20s%4.0f   %4.0f     %2.0f   %5.0f  %5.0f     %2d    %2d     %3.0f\n", count++,
45986a62b8dSjtc 		    Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
46086a62b8dSjtc 		    Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
46186a62b8dSjtc 		    Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
46286a62b8dSjtc }
46386a62b8dSjtc 
464a232aee2Slukem void
scorelist(void)465c7a109ccSdholland scorelist(void)
46686a62b8dSjtc {
46786a62b8dSjtc 	struct scoreboard sbuf;	/* for reading entries */
468a232aee2Slukem 	FILE   *fp;		/* to open the file */
46986a62b8dSjtc 
470a232aee2Slukem 	if ((fp = fopen(_PATH_SCORE, "r")) != NULL) {
47186a62b8dSjtc 		while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
47286a62b8dSjtc 			printf("%-20s   (%-9s)  Level: %6.0f  Type: %s\n",
47386a62b8dSjtc 			    sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
47486a62b8dSjtc 		fclose(fp);
47586a62b8dSjtc 	}
47686a62b8dSjtc }
47786a62b8dSjtc 
478a232aee2Slukem void
activelist(void)479c7a109ccSdholland activelist(void)
48086a62b8dSjtc {
4815fb18dd9Sjsm 	fseek(Playersfp, 0L, SEEK_SET);
48286a62b8dSjtc 	printf("Current characters on file are:\n\n");
48386a62b8dSjtc 
48486a62b8dSjtc 	while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
48586a62b8dSjtc 		if (Other.p_status != S_NOTUSED)
48686a62b8dSjtc 			printf("%-20s   (%-9s)  Level: %6.0f  %s  (%s)\n",
48786a62b8dSjtc 			    Other.p_name, Other.p_login, Other.p_level,
48886a62b8dSjtc 			    descrtype(&Other, FALSE), descrstatus(&Other));
48986a62b8dSjtc 
49086a62b8dSjtc }
49186a62b8dSjtc 
492a232aee2Slukem void
purgeoldplayers(void)493c7a109ccSdholland purgeoldplayers(void)
49486a62b8dSjtc {
49586a62b8dSjtc 	int     today;		/* day of year for today */
496a232aee2Slukem 	int     daysold;	/* how many days since the character has been
497a232aee2Slukem 				 * used */
498c4816c32Scgd 	time_t  ltime;		/* time in seconds */
49986a62b8dSjtc 	long    loc = 0L;	/* location in file */
50086a62b8dSjtc 
50186a62b8dSjtc 	time(&ltime);
50286a62b8dSjtc 	today = localtime(&ltime)->tm_yday;
50386a62b8dSjtc 
504a232aee2Slukem 	for (;;) {
5055fb18dd9Sjsm 		fseek(Playersfp, loc, SEEK_SET);
50686a62b8dSjtc 		if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
50786a62b8dSjtc 			break;
50886a62b8dSjtc 
50986a62b8dSjtc 		daysold = today - Other.p_lastused;
51086a62b8dSjtc 		if (daysold < 0)
51186a62b8dSjtc 			daysold += 365;
51286a62b8dSjtc 
51386a62b8dSjtc 		if (daysold > N_DAYSOLD)
51486a62b8dSjtc 			/* player hasn't been used in a while; delete */
51586a62b8dSjtc 			freerecord(&Other, loc);
51686a62b8dSjtc 
51786a62b8dSjtc 		loc += SZ_PLAYERSTRUCT;
51886a62b8dSjtc 	}
51986a62b8dSjtc }
52086a62b8dSjtc 
521a232aee2Slukem void
enterscore(void)522c7a109ccSdholland enterscore(void)
52386a62b8dSjtc {
52486a62b8dSjtc 	struct scoreboard sbuf;	/* buffer to read in scoreboard entries */
52586a62b8dSjtc 	FILE   *fp;		/* to open scoreboard file */
52686a62b8dSjtc 	long    loc = 0L;	/* location in scoreboard file */
52786a62b8dSjtc 	bool    found = FALSE;	/* set if we found an entry for this login */
52886a62b8dSjtc 
529a232aee2Slukem 	if ((fp = fopen(_PATH_SCORE, "r+")) != NULL) {
53086a62b8dSjtc 		while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
531a232aee2Slukem 			if (strcmp(Player.p_login, sbuf.sb_login) == 0) {
53286a62b8dSjtc 				found = TRUE;
53386a62b8dSjtc 				break;
534a232aee2Slukem 			} else
53586a62b8dSjtc 				loc += SZ_SCORESTRUCT;
536a232aee2Slukem 	} else {
53786a62b8dSjtc 		error(_PATH_SCORE);
53886a62b8dSjtc 		/* NOTREACHED */
53986a62b8dSjtc 	}
54086a62b8dSjtc 
54186a62b8dSjtc 	/*
54286a62b8dSjtc          * At this point, 'loc' will either indicate a point beyond
54386a62b8dSjtc          * the end of file, or the place where the previous entry
54486a62b8dSjtc          * was found.
54586a62b8dSjtc          */
54686a62b8dSjtc 
54786a62b8dSjtc 	if ((!found) || Player.p_level > sbuf.sb_level)
54886a62b8dSjtc 		/* put new entry in for this login */
54986a62b8dSjtc 	{
55086a62b8dSjtc 		strcpy(sbuf.sb_login, Player.p_login);
55186a62b8dSjtc 		strcpy(sbuf.sb_name, Player.p_name);
55286a62b8dSjtc 		sbuf.sb_level = Player.p_level;
55386a62b8dSjtc 		strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
55486a62b8dSjtc 	}
55586a62b8dSjtc 	/* update entry */
5565fb18dd9Sjsm 	fseek(fp, loc, SEEK_SET);
55786a62b8dSjtc 	fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
55886a62b8dSjtc 	fclose(fp);
55986a62b8dSjtc }
560