xref: /csrg-svn/games/phantasia/main.c (revision 41319)
134600Sbostic /*
234600Sbostic  * Phantasia 3.3.2 -- Interterminal fantasy game
334600Sbostic  *
434600Sbostic  * Edward A. Estes
534600Sbostic  * AT&T, March 12, 1986
634600Sbostic  */
734600Sbostic 
834600Sbostic /* DISCLAIMER:
934600Sbostic  *
1034600Sbostic  * This game is distributed for free as is.  It is not guaranteed to work
1134600Sbostic  * in every conceivable environment.  It is not even guaranteed to work
1234600Sbostic  * in ANY environment.
1334600Sbostic  *
1434600Sbostic  * This game is distributed without notice of copyright, therefore it
1534600Sbostic  * may be used in any manner the recipient sees fit.  However, the
1634600Sbostic  * author assumes no responsibility for maintaining or revising this
1734600Sbostic  * game, in its original form, or any derivitives thereof.
1834600Sbostic  *
1934600Sbostic  * The author shall not be responsible for any loss, cost, or damage,
2034600Sbostic  * including consequential damage, caused by reliance on this material.
2134600Sbostic  *
2234600Sbostic  * The author makes no warranties, express or implied, including warranties
2334600Sbostic  * of merchantability or fitness for a particular purpose or use.
2434600Sbostic  *
2534600Sbostic  * AT&T is in no way connected with this game.
2634600Sbostic  */
2734600Sbostic 
2837051Sbostic #include <sys/types.h>
2937051Sbostic #include <pwd.h>
3037051Sbostic 
3134600Sbostic /*
3234600Sbostic  * The program allocates as much file space as it needs to store characters,
3334600Sbostic  * so the possibility exists for the character file to grow without bound.
3434600Sbostic  * The file is purged upon normal entry to try to avoid that problem.
3534600Sbostic  * A similar problem exists for energy voids.  To alleviate the problem here,
3634600Sbostic  * the void file is cleared with every new king, and a limit is placed
3734600Sbostic  * on the size of the energy void file.
3834600Sbostic  */
3934600Sbostic 
4034600Sbostic /*
4134600Sbostic  * Put one line of text into the file 'motd' for announcements, etc.
4234600Sbostic  */
4334600Sbostic 
4434600Sbostic /*
4534600Sbostic  * The scoreboard file is updated when someone dies, and keeps track
4634600Sbostic  * of the highest character to date for that login.
4734600Sbostic  * Being purged from the character file does not cause the scoreboard
4834600Sbostic  * to be updated.
4934600Sbostic  */
5034600Sbostic 
5134600Sbostic /*
5234600Sbostic  * All source files are set up for 'vi' with shiftwidth=4, tabstop=8.
5334600Sbostic  */
5434600Sbostic 
5534600Sbostic /**/
5634600Sbostic 
5734600Sbostic /*
5834600Sbostic  * main.c	Main routines for Phantasia
5934600Sbostic  */
6034600Sbostic 
6134600Sbostic #include "include.h"
6234600Sbostic 
6334600Sbostic /***************************************************************************
6434600Sbostic / FUNCTION NAME: main()
6534600Sbostic /
6634600Sbostic / FUNCTION: initialize state, and call main process
6734600Sbostic /
6834600Sbostic / AUTHOR: E. A. Estes, 12/4/85
6934600Sbostic /
7034600Sbostic / ARGUMENTS:
7134600Sbostic /	int	argc - argument count
7234600Sbostic /	char	**argv - argument vector
7334600Sbostic /
7434600Sbostic / RETURN VALUE: none
7534600Sbostic /
7641316Sbostic / MODULES CALLED: monstlist(), checkenemy(), activelist(),
7734600Sbostic /	throneroom(), checkbattle(), readmessage(), changestats(), writerecord(),
7834600Sbostic /	tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(),
7934600Sbostic /	fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(),
8034600Sbostic /	signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(),
8134600Sbostic /	strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(),
8234600Sbostic /	playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(),
8334600Sbostic /	scorelist(), titlelist()
8434600Sbostic /
8534600Sbostic / GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
8640279Sbostic /	Fileloc, Stattable[]
8734600Sbostic /
8834600Sbostic / GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
8934600Sbostic /
9034600Sbostic / DESCRIPTION:
9134600Sbostic /	Process arguments, initialize program, and loop forever processing
9234600Sbostic /	player input.
9334600Sbostic /
9434600Sbostic /***************************************************************************/
9534600Sbostic 
main(argc,argv)9634600Sbostic main(argc, argv)
9734600Sbostic int	argc;
9834600Sbostic char	**argv;
9934600Sbostic {
10034600Sbostic bool	noheader = FALSE;	/* set if don't want header */
10134600Sbostic bool	headeronly = FALSE;	/* set if only want header */
10234600Sbostic bool	examine = FALSE;	/* set if examine a character */
10334600Sbostic long	seconds;		/* for time of day */
10434600Sbostic double	dtemp;			/* for temporary calculations */
10534600Sbostic 
10634600Sbostic     initialstate();		/* init globals */
10734600Sbostic 
10834600Sbostic     /* process arguments */
10934600Sbostic     while (--argc && (*++argv)[0] == '-')
11034600Sbostic 	switch ((*argv)[1])
11134600Sbostic 	    {
11234600Sbostic 	    case 's':	/* short */
11334600Sbostic 		noheader = TRUE;
11434600Sbostic 		break;
11534600Sbostic 
11634600Sbostic 	    case 'H':	/* Header */
11734600Sbostic 		headeronly = TRUE;
11834600Sbostic 		break;
11934600Sbostic 
12034600Sbostic 	    case 'a':	/* all users */
12134600Sbostic 		activelist();
12234600Sbostic 		cleanup(TRUE);
12334600Sbostic 		/*NOTREACHED*/
12434600Sbostic 
12534600Sbostic 	    case 'p':	/* purge old players */
12634600Sbostic 		purgeoldplayers();
12734600Sbostic 		cleanup(TRUE);
12834600Sbostic 		/*NOTREACHED*/
12934600Sbostic 
13034600Sbostic 	    case 'S':	/* set 'Wizard' */
131*41319Sbostic 		Wizard = !getuid();
13234600Sbostic 		break;
13334600Sbostic 
13434600Sbostic 	    case 'x':	/* examine */
13534600Sbostic 		examine = TRUE;
13634600Sbostic 		break;
13734600Sbostic 
13834600Sbostic 	    case 'm':	/* monsters */
13934600Sbostic 		monstlist();
14034600Sbostic 		cleanup(TRUE);
14134600Sbostic 		/*NOTREACHED*/
14234600Sbostic 
14334600Sbostic 	    case 'b':	/* scoreboard */
14434600Sbostic 		scorelist();
14534600Sbostic 		cleanup(TRUE);
14634600Sbostic 		/*NOTREACHED*/
14734600Sbostic 		}
14834600Sbostic 
14934600Sbostic     if (!isatty(0))		/* don't let non-tty's play */
15034600Sbostic 	cleanup(TRUE);
15134600Sbostic 	/*NOTREACHED*/
15234600Sbostic 
15334600Sbostic     playinit();			/* set up to catch signals, init curses */
15434600Sbostic 
15534600Sbostic     if (examine)
15634600Sbostic 	{
15734600Sbostic 	changestats(FALSE);
15834600Sbostic 	cleanup(TRUE);
15934600Sbostic 	/*NOTREACHED*/
16034600Sbostic 	}
16134600Sbostic 
16234600Sbostic     if (!noheader)
16334600Sbostic 	{
16434600Sbostic 	titlelist();
16534600Sbostic 	purgeoldplayers();    /* clean up old characters */
16634600Sbostic 	}
16734600Sbostic 
16834600Sbostic     if (headeronly)
16934600Sbostic 	cleanup(TRUE);
17034600Sbostic 	/*NOTREACHED*/
17134600Sbostic 
17234600Sbostic     do
17334600Sbostic 	/* get the player structure filled */
17434600Sbostic 	{
17534600Sbostic 	Fileloc = -1L;
17634600Sbostic 
17734600Sbostic 	mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
17834600Sbostic 
17934600Sbostic 	switch (getanswer("NYQ", FALSE))
18034600Sbostic 	    {
18134600Sbostic 	    case 'Y':
18234600Sbostic 		Fileloc = recallplayer();
18334600Sbostic 		break;
18434600Sbostic 
18534600Sbostic 	    case 'Q':
18634600Sbostic 		cleanup(TRUE);
18734600Sbostic 		/*NOTREACHED*/
18834600Sbostic 
18934600Sbostic 	    default:
19034600Sbostic 		Fileloc = rollnewplayer();
19134600Sbostic 		break;
19234600Sbostic 	    }
19334600Sbostic 	clear();
19434600Sbostic 	}
19534600Sbostic     while (Fileloc < 0L);
19634600Sbostic 
19734600Sbostic     if (Player.p_level > 5.0)
19834600Sbostic 	/* low level players have long timeout */
19934600Sbostic 	Timeout = TRUE;
20034600Sbostic 
20134600Sbostic     /* update some important player statistics */
20234600Sbostic     strcpy(Player.p_login, Login);
20334600Sbostic     time(&seconds);
20434600Sbostic     Player.p_lastused = localtime(&seconds)->tm_yday;
20534600Sbostic     Player.p_status = S_PLAYING;
20634600Sbostic     writerecord(&Player, Fileloc);
20734600Sbostic 
20834600Sbostic     Statptr = &Stattable[Player.p_type];	/* initialize pointer */
20934600Sbostic 
21034600Sbostic     /* catch interrupts */
21134600Sbostic #ifdef	BSD41
21234600Sbostic     sigset(SIGINT, interrupt);
21334600Sbostic #endif
21434600Sbostic #ifdef	BSD42
21534600Sbostic     signal(SIGINT, interrupt);
21634600Sbostic #endif
21734600Sbostic #ifdef	SYS3
21834600Sbostic     signal(SIGINT, interrupt);
21934600Sbostic #endif
22034600Sbostic #ifdef	SYS5
22134600Sbostic     signal(SIGINT, interrupt);
22234600Sbostic #endif
22334600Sbostic 
22434600Sbostic     altercoordinates(Player.p_x, Player.p_y, A_FORCED);	/* set some flags */
22534600Sbostic 
22634600Sbostic     clear();
22734600Sbostic 
22834600Sbostic     for (;;)
22934600Sbostic 	/* loop forever, processing input */
23034600Sbostic 	{
23134600Sbostic 
23234600Sbostic 	adjuststats();		/* cleanup stats */
23334600Sbostic 
23434600Sbostic 	if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING)
23534600Sbostic 	    /* not allowed on throne -- move */
23634600Sbostic 	    {
23734600Sbostic 	    mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n");
23834600Sbostic 	    altercoordinates(0.0, 0.0, A_NEAR);
23934600Sbostic 	    }
24034600Sbostic 
24134600Sbostic 	checktampered();	/* check for energy voids, etc. */
24234600Sbostic 
24334600Sbostic 	if (Player.p_status != S_CLOAKED
24434600Sbostic 	    /* not cloaked */
24534600Sbostic 	    && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y)
24634600Sbostic 	    /* |x| = |y| */
24734600Sbostic 	    && !Throne)
24834600Sbostic 	    /* not on throne */
24934600Sbostic 	    {
25034600Sbostic 	    dtemp = sqrt(dtemp / 100.0);
25134600Sbostic 	    if (floor(dtemp) == dtemp)
25234600Sbostic 		/* |x| / 100 == n*n; at a trading post */
25334600Sbostic 		{
25434600Sbostic 		tradingpost();
25534600Sbostic 		clear();
25634600Sbostic 		}
25734600Sbostic 	    }
25834600Sbostic 
25934600Sbostic 	checkbattle();		/* check for player to player battle */
26034600Sbostic 	neatstuff();		/* gurus, medics, etc. */
26134600Sbostic 
26234600Sbostic 	if (Player.p_status == S_CLOAKED)
26334600Sbostic 	    /* costs 3 mana per turn to be cloaked */
26434600Sbostic 	    if (Player.p_mana > 3.0)
26534600Sbostic 		Player.p_mana -= 3.0;
26634600Sbostic 	    else
26734600Sbostic 		/* ran out of mana, uncloak */
26834600Sbostic 		{
26934600Sbostic 		Player.p_status = S_PLAYING;
27034600Sbostic 		Changed = TRUE;
27134600Sbostic 		}
27234600Sbostic 
27334600Sbostic 	if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED)
27434600Sbostic 	    /* change status back to S_PLAYING */
27534600Sbostic 	    {
27634600Sbostic 	    Player.p_status = S_PLAYING;
27734600Sbostic 	    Changed = TRUE;
27834600Sbostic 	    }
27934600Sbostic 
28034600Sbostic 	if (Changed)
28134600Sbostic 	    /* update file only if important stuff has changed */
28234600Sbostic 	    {
28334600Sbostic 	    writerecord(&Player, Fileloc);
28434600Sbostic 	    Changed = FALSE;
28534600Sbostic 	    continue;
28634600Sbostic 	    }
28734600Sbostic 
28834600Sbostic 	readmessage();			/* read message, if any */
28934600Sbostic 
29034600Sbostic 	displaystats();			/* print statistics */
29134600Sbostic 
29234600Sbostic 	move(6, 0);
29334600Sbostic 
29434600Sbostic 	if (Throne)
29534600Sbostic 	    /* maybe make king, print prompt, etc. */
29634600Sbostic 	    throneroom();
29734600Sbostic 
29834600Sbostic 	/* print status line */
29934600Sbostic 	addstr("1:Move  2:Players  3:Talk  4:Stats  5:Quit  ");
30034600Sbostic 	if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK)
30134600Sbostic 	    addstr("6:Cloak  ");
30234600Sbostic 	if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT)
30334600Sbostic 	    addstr("7:Teleport  ");
30434600Sbostic 	if (Player.p_specialtype >= SC_COUNCIL || Wizard)
30534600Sbostic 	    addstr("8:Intervene  ");
30634600Sbostic 
30734600Sbostic 	procmain();			/* process input */
30834600Sbostic 	}
30934600Sbostic }
31034600Sbostic /**/
31134600Sbostic /************************************************************************
31234600Sbostic /
31334600Sbostic / FUNCTION NAME: initialstate()
31434600Sbostic /
31534600Sbostic / FUNCTION: initialize some important global variable
31634600Sbostic /
31734600Sbostic / AUTHOR: E. A. Estes, 12/4/85
31834600Sbostic /
31934600Sbostic / ARGUMENTS: none
32034600Sbostic /
32134600Sbostic / RETURN VALUE: none
32234600Sbostic /
32334600Sbostic / MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(),
32434600Sbostic /	getpwuid()
32534600Sbostic /
32640279Sbostic / GLOBAL INPUTS:
32734600Sbostic /
32834600Sbostic / GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
32934600Sbostic /	Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
33034600Sbostic /	*Playersfp
33134600Sbostic /
33234600Sbostic / DESCRIPTION:
33334600Sbostic /	Set global flags, and open files which remain open.
33434600Sbostic /
33534600Sbostic /************************************************************************/
33634600Sbostic 
initialstate()33734600Sbostic initialstate()
33834600Sbostic {
33934600Sbostic     Beyond = FALSE;
34034600Sbostic     Marsh = FALSE;
34134600Sbostic     Throne = FALSE;
34234600Sbostic     Changed = FALSE;
34334600Sbostic     Wizard = FALSE;
34434600Sbostic     Timeout = FALSE;
34534600Sbostic     Users = 0;
34634600Sbostic     Windows = FALSE;
34734600Sbostic     Echo = TRUE;
34834600Sbostic 
34934600Sbostic     /* setup login name */
35034600Sbostic     if ((Login = getlogin()) == NULL)
35134600Sbostic 	Login = getpwuid(getuid())->pw_name;
35234600Sbostic 
35334600Sbostic     /* open some files */
35440279Sbostic     if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
35540279Sbostic 	error(_PATH_PEOPLE);
35634600Sbostic 	/*NOTREACHED*/
35734600Sbostic 
35840279Sbostic     if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL)
35940279Sbostic 	error(_PATH_MONST);
36034600Sbostic 	/*NOTREACHED*/
36134600Sbostic 
36240279Sbostic     if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL)
36340279Sbostic 	error(_PATH_MESS);
36434600Sbostic 	/*NOTREACHED*/
36534600Sbostic 
36640279Sbostic     if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL)
36740279Sbostic 	error(_PATH_VOID);
36834600Sbostic 	/*NOTREACHED*/
36934600Sbostic 
37034600Sbostic     srandom((unsigned) time((long *) NULL));	/* prime random numbers */
37134600Sbostic }
37234600Sbostic /**/
37334600Sbostic /************************************************************************
37434600Sbostic /
37534600Sbostic / FUNCTION NAME: rollnewplayer()
37634600Sbostic /
37734600Sbostic / FUNCTION: roll up a new character
37834600Sbostic /
37934600Sbostic / AUTHOR: E. A. Estes, 12/4/85
38034600Sbostic /
38134600Sbostic / ARGUMENTS: none
38234600Sbostic /
38334600Sbostic / RETURN VALUE: none
38434600Sbostic /
38534600Sbostic / MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(),
38634600Sbostic /	wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(),
38734600Sbostic /	getanswer(), getstring()
38834600Sbostic /
38934600Sbostic / GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
39034600Sbostic /
39134600Sbostic / GLOBAL OUTPUTS: Echo
39234600Sbostic /
39334600Sbostic / DESCRIPTION:
39434600Sbostic /	Prompt player, and roll up new character.
39534600Sbostic /
39634600Sbostic /************************************************************************/
39734600Sbostic 
39834600Sbostic long
rollnewplayer()39934600Sbostic rollnewplayer()
40034600Sbostic {
40134600Sbostic int	chartype;	/* character type */
40234600Sbostic int	ch;		/* input */
40334600Sbostic 
40434600Sbostic     initplayer(&Player);		/* initialize player structure */
40534600Sbostic 
40634600Sbostic     clear();
40734600Sbostic     mvaddstr(4, 21, "Which type of character do you want:");
40834600Sbostic     mvaddstr(8, 4, "1:Magic User  2:Fighter  3:Elf  4:Dwarf  5:Halfling  6:Experimento  ");
40934600Sbostic     if (Wizard) {
41034600Sbostic 	addstr("7:Super  ? ");
41134600Sbostic 	chartype = getanswer("1234567", FALSE);
41234600Sbostic 	}
41334600Sbostic     else {
41434600Sbostic 	addstr("?  ");
41534600Sbostic 	chartype = getanswer("123456", FALSE);
41634600Sbostic 	}
41734600Sbostic 
41834600Sbostic     do
41934600Sbostic 	{
42034600Sbostic 	genchar(chartype);		/* roll up a character */
42134600Sbostic 
42234600Sbostic 	/* print out results */
42334600Sbostic 	mvprintw(12, 14,
42434600Sbostic 	    "Strength    :  %2.0f  Quickness:  %2.0f  Mana       :  %2.0f\n",
42534600Sbostic 	    Player.p_strength, Player.p_quickness, Player.p_mana);
42634600Sbostic 	mvprintw(13, 14,
42734600Sbostic 	    "Energy Level:  %2.0f  Brains   :  %2.0f  Magic Level:  %2.0f\n",
42834600Sbostic 	    Player.p_energy, Player.p_brains, Player.p_magiclvl);
42934600Sbostic 
43034600Sbostic 	if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
43134600Sbostic 	    break;
43234600Sbostic 
43334600Sbostic 	mvaddstr(14, 14, "Type '1' to keep >");
43434600Sbostic 	ch = getanswer(" ", TRUE);
43534600Sbostic 	}
43634600Sbostic     while (ch != '1');
43734600Sbostic 
43834600Sbostic     if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
43934600Sbostic 	/* get coordinates for experimento */
44034600Sbostic 	for (;;)
44134600Sbostic 	    {
44234600Sbostic 	    mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
44334600Sbostic 	    getstring(Databuf, SZ_DATABUF);
44434613Sbostic 	    sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y);
44534600Sbostic 
44634600Sbostic 	    if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER)
44734600Sbostic 		mvaddstr(17, 0, "Invalid coordinates.  Try again.\n");
44834600Sbostic 	    else
44934600Sbostic 		break;
45034600Sbostic 	    }
45134600Sbostic 
45234600Sbostic     for (;;)
45334600Sbostic 	/* name the new character */
45434600Sbostic 	{
45534600Sbostic 	mvprintw(18, 0,
45634600Sbostic 	    "Give your character a name [up to %d characters] ?  ", SZ_NAME - 1);
45734600Sbostic 	getstring(Player.p_name, SZ_NAME);
45834600Sbostic 	truncstring(Player.p_name);		/* remove trailing blanks */
45934600Sbostic 
46034600Sbostic 	if (Player.p_name[0] == '\0')
46134600Sbostic 	    /* no null names */
46234600Sbostic 	    mvaddstr(19, 0, "Invalid name.");
46334600Sbostic 	else if (findname(Player.p_name, &Other) >= 0L)
46434600Sbostic 	    /* cannot have duplicate names */
46534600Sbostic 	    mvaddstr(19, 0, "Name already in use.");
46634600Sbostic 	else
46734600Sbostic 	    /* name is acceptable */
46834600Sbostic 	    break;
46934600Sbostic 
47034600Sbostic 	addstr("  Pick another.\n");
47134600Sbostic 	}
47234600Sbostic 
47334600Sbostic     /* get a password for character */
47434600Sbostic     Echo = FALSE;
47534600Sbostic 
47634600Sbostic     do
47734600Sbostic 	{
47834600Sbostic 	mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
47934600Sbostic 	getstring(Player.p_password, SZ_PASSWORD);
48034600Sbostic 	mvaddstr(21, 0, "One more time to verify ? ");
48134600Sbostic 	getstring(Databuf, SZ_PASSWORD);
48234600Sbostic 	}
48334600Sbostic     while (strcmp(Player.p_password, Databuf) != 0);
48434600Sbostic 
48534600Sbostic     Echo = TRUE;
48634600Sbostic 
48734600Sbostic     return(allocrecord());
48834600Sbostic }
48934600Sbostic /**/
49034600Sbostic /************************************************************************
49134600Sbostic /
49234600Sbostic / FUNCTION NAME: procmain()
49334600Sbostic /
49434600Sbostic / FUNCTION: process input from player
49534600Sbostic /
49634600Sbostic / AUTHOR: E. A. Estes, 12/4/85
49734600Sbostic /
49834600Sbostic / ARGUMENTS: none
49934600Sbostic /
50034600Sbostic / RETURN VALUE: none
50134600Sbostic /
50234600Sbostic / MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(),
50334600Sbostic /	fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(),
50434600Sbostic /	waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(),
50534600Sbostic /	getstring(), wclrtobot()
50634600Sbostic /
50734600Sbostic / GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
50840279Sbostic /	Databuf[], Illmove[]
50934600Sbostic /
51034600Sbostic / GLOBAL OUTPUTS: Player, Changed
51134600Sbostic /
51234600Sbostic / DESCRIPTION:
51334600Sbostic /	Process main menu options.
51434600Sbostic /
51534600Sbostic /************************************************************************/
51634600Sbostic 
procmain()51734600Sbostic procmain()
51834600Sbostic {
51934600Sbostic int	ch;			/* input */
52034600Sbostic double	x;			/* desired new x coordinate */
52134600Sbostic double	y;			/* desired new y coordinate */
52234600Sbostic double	temp;			/* for temporary calculations */
52334600Sbostic FILE	*fp;			/* for opening files */
52434600Sbostic register int	loop;		/* a loop counter */
52534600Sbostic bool	hasmoved = FALSE;	/* set if player has moved */
52634600Sbostic 
52734600Sbostic     ch = inputoption();
52834600Sbostic     mvaddstr(4, 0, "\n\n");		/* clear status area */
52934600Sbostic 
53034600Sbostic     move(7, 0);
53134600Sbostic     clrtobot();			/* clear data on bottom area of screen */
53234600Sbostic 
53334600Sbostic     if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7'))
53434600Sbostic 	/* valar cannot move */
53534600Sbostic 	ch = ' ';
53634600Sbostic 
53734600Sbostic     switch (ch)
53834600Sbostic 	{
53934600Sbostic 	case 'K':		/* move up/north */
54034600Sbostic 	case 'N':
54134600Sbostic 	    x = Player.p_x;
54234600Sbostic 	    y = Player.p_y + MAXMOVE();
54334600Sbostic 	    hasmoved = TRUE;
54434600Sbostic 	    break;
54534600Sbostic 
54634600Sbostic 	case 'J':		/* move down/south */
54734600Sbostic 	case 'S':
54834600Sbostic 	    x = Player.p_x;
54934600Sbostic 	    y = Player.p_y - MAXMOVE();
55034600Sbostic 	    hasmoved = TRUE;
55134600Sbostic 	    break;
55234600Sbostic 
55334600Sbostic 	case 'L':		/* move right/east */
55434600Sbostic 	case 'E':
55534600Sbostic 	    x = Player.p_x + MAXMOVE();
55634600Sbostic 	    y = Player.p_y;
55734600Sbostic 	    hasmoved = TRUE;
55834600Sbostic 	    break;
55934600Sbostic 
56034600Sbostic 	case 'H':		/* move left/west */
56134600Sbostic 	case 'W':
56234600Sbostic 	    x = Player.p_x - MAXMOVE();
56334600Sbostic 	    y = Player.p_y;
56434600Sbostic 	    hasmoved = TRUE;
56534600Sbostic 	    break;
56634600Sbostic 
56734600Sbostic 	default:    /* rest */
56834600Sbostic 	    Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0
56934600Sbostic 		+ Player.p_level / 3.0 + 2.0;
57034600Sbostic 	    Player.p_energy =
57134600Sbostic 		MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield);
57234600Sbostic 
57334600Sbostic 	    if (Player.p_status != S_CLOAKED)
57434600Sbostic 		/* cannot find mana if cloaked */
57534600Sbostic 		{
57634600Sbostic 		Player.p_mana += (Circle + Player.p_level) / 4.0;
57734600Sbostic 
57834600Sbostic 		if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
57934600Sbostic 		    /* wandering monster */
58034600Sbostic 		    encounter(-1);
58134600Sbostic 		}
58234600Sbostic 	    break;
58334600Sbostic 
58434600Sbostic 	case 'X':		/* change/examine a character */
58534600Sbostic 	    changestats(TRUE);
58634600Sbostic 	    break;
58734600Sbostic 
58834600Sbostic 	case '1':		/* move */
58934600Sbostic 	    for (loop = 3; loop; --loop)
59034600Sbostic 		{
59134600Sbostic 		mvaddstr(4, 0, "X Y Coordinates ? ");
59234600Sbostic 		getstring(Databuf, SZ_DATABUF);
59334600Sbostic 
59434613Sbostic 		if (sscanf(Databuf, "%lf %lf", &x, &y) != 2)
59534600Sbostic 		    mvaddstr(5, 0, "Try again\n");
59634600Sbostic 		else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE())
59734600Sbostic 		    ILLMOVE();
59834600Sbostic 		else
59934600Sbostic 		    {
60034600Sbostic 		    hasmoved = TRUE;
60134600Sbostic 		    break;
60234600Sbostic 		    }
60334600Sbostic 		}
60434600Sbostic 	    break;
60534600Sbostic 
60634600Sbostic 	case '2':		/* players */
60734600Sbostic 	    userlist(TRUE);
60834600Sbostic 	    break;
60934600Sbostic 
61034600Sbostic 	case '3':		/* message */
61134600Sbostic 	    mvaddstr(4, 0, "Message ? ");
61234600Sbostic 	    getstring(Databuf, SZ_DATABUF);
61334600Sbostic 	    /* we open the file for writing to erase any data which is already there */
61440279Sbostic 	    fp = fopen(_PATH_MESS, "w");
61534600Sbostic 	    if (Databuf[0] != '\0')
61634600Sbostic 		fprintf(fp, "%s: %s", Player.p_name, Databuf);
61734600Sbostic 	    fclose(fp);
61834600Sbostic 	    break;
61934600Sbostic 
62034600Sbostic 	case '4':		/* stats */
62134600Sbostic 	    allstatslist();
62234600Sbostic 	    break;
62334600Sbostic 
62434600Sbostic 	case '5':		/* good-bye */
62534600Sbostic 	    leavegame();
62634600Sbostic 	    /*NOTREACHED*/
62734600Sbostic 
62834600Sbostic 	case '6':		/* cloak */
62934600Sbostic 	    if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK)
63034600Sbostic 		ILLCMD();
63134600Sbostic 	    else if (Player.p_status == S_CLOAKED)
63234600Sbostic 		Player.p_status = S_PLAYING;
63334600Sbostic 	    else if (Player.p_mana < MM_CLOAK)
63434600Sbostic 		mvaddstr(5, 0, "No mana left.\n");
63534600Sbostic 	    else
63634600Sbostic 		{
63734600Sbostic 		Changed = TRUE;
63834600Sbostic 		Player.p_mana -= MM_CLOAK;
63934600Sbostic 		Player.p_status = S_CLOAKED;
64034600Sbostic 		}
64134600Sbostic 	    break;
64234600Sbostic 
64334600Sbostic 	case '7':	/* teleport */
64434600Sbostic 	    /*
64534600Sbostic 	     * conditions for teleport
64634600Sbostic 	     *	- 20 per (level plus magic level)
64734600Sbostic 	     *	- OR council of the wise or valar or ex-valar
64834600Sbostic 	     *	- OR transport from throne
64934600Sbostic 	     * transports from throne cost no mana
65034600Sbostic 	     */
65134600Sbostic 	    if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT)
65234600Sbostic 		ILLCMD();
65334600Sbostic 	    else
65434600Sbostic 		for (loop = 3; loop; --loop)
65534600Sbostic 		    {
65634600Sbostic 		    mvaddstr(4, 0, "X Y Coordinates ? ");
65734600Sbostic 		    getstring(Databuf, SZ_DATABUF);
65834600Sbostic 
65934613Sbostic 		    if (sscanf(Databuf, "%lf %lf", &x, &y) == 2)
66034600Sbostic 			{
66134600Sbostic 			temp = distance(Player.p_x, x, Player.p_y, y);
66234600Sbostic 			if (!Throne
66334600Sbostic 			    /* can transport anywhere from throne */
66434600Sbostic 			    && Player.p_specialtype <= SC_COUNCIL
66534600Sbostic 			    /* council, valar can transport anywhere */
66634600Sbostic 			    && temp > (Player.p_level + Player.p_magiclvl) * 20.0)
66734600Sbostic 			    /* can only move 20 per exp. level + mag. level */
66834600Sbostic 			    ILLMOVE();
66934600Sbostic 			else
67034600Sbostic 			    {
67134600Sbostic 			    temp = (temp / 75.0 + 1.0) * 20.0;	/* mana used */
67234600Sbostic 
67334600Sbostic 			    if (!Throne && temp > Player.p_mana)
67434600Sbostic 				mvaddstr(5, 0, "Not enough power for that distance.\n");
67534600Sbostic 			    else
67634600Sbostic 				{
67734600Sbostic 				if (!Throne)
67834600Sbostic 				    Player.p_mana -= temp;
67934600Sbostic 				hasmoved = TRUE;
68034600Sbostic 				break;
68134600Sbostic 				}
68234600Sbostic 			    }
68334600Sbostic 			}
68434600Sbostic 		    }
68534600Sbostic 	    break;
68634600Sbostic 
68734600Sbostic 	case 'C':
68834600Sbostic 	case '9':		/* monster */
68934600Sbostic 	    if (Throne)
69034600Sbostic 		/* no monsters while on throne */
69134600Sbostic 		mvaddstr(5, 0, "No monsters in the chamber!\n");
69234600Sbostic 	    else if (Player.p_specialtype != SC_VALAR)
69334600Sbostic 		/* the valar cannot call monsters */
69434600Sbostic 		{
69534600Sbostic 		Player.p_sin += 1e-6;
69634600Sbostic 		encounter(-1);
69734600Sbostic 		}
69834600Sbostic 	    break;
69934600Sbostic 
70034600Sbostic 	case '0':		/* decree */
70134600Sbostic 	    if (Wizard || Player.p_specialtype == SC_KING && Throne)
70234600Sbostic 		/* kings must be on throne to decree */
70334600Sbostic 		dotampered();
70434600Sbostic 	    else
70534600Sbostic 		ILLCMD();
70634600Sbostic 	    break;
70734600Sbostic 
70834600Sbostic 	case '8':		/* intervention */
70934600Sbostic 	    if (Wizard || Player.p_specialtype >= SC_COUNCIL)
71034600Sbostic 		dotampered();
71134600Sbostic 	    else
71234600Sbostic 		ILLCMD();
71334600Sbostic 	    break;
71434600Sbostic 	}
71534600Sbostic 
71634600Sbostic     if (hasmoved)
71734600Sbostic 	/* player has moved -- alter coordinates, and do random monster */
71834600Sbostic 	{
71934600Sbostic 	altercoordinates(x, y, A_SPECIFIC);
72034600Sbostic 
72134600Sbostic 	if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
72234600Sbostic 	    encounter(-1);
72334600Sbostic 	}
72434600Sbostic }
72534600Sbostic /**/
72634600Sbostic /************************************************************************
72734600Sbostic /
72834600Sbostic / FUNCTION NAME: titlelist()
72934600Sbostic /
73034600Sbostic / FUNCTION: print title page
73134600Sbostic /
73234600Sbostic / AUTHOR: E. A. Estes, 12/4/85
73334600Sbostic /
73434600Sbostic / ARGUMENTS: none
73534600Sbostic /
73634600Sbostic / RETURN VALUE: none
73734600Sbostic /
73834600Sbostic / MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(),
73934600Sbostic /	fclose(), strlen(), waddstr(), sprintf(), wrefresh()
74034600Sbostic /
74140279Sbostic / GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
74234600Sbostic /
74334600Sbostic / GLOBAL OUTPUTS: Lines
74434600Sbostic /
74534600Sbostic / DESCRIPTION:
74634600Sbostic /	Print important information about game, players, etc.
74734600Sbostic /
74834600Sbostic /************************************************************************/
74934600Sbostic 
titlelist()75034600Sbostic titlelist()
75134600Sbostic {
75234600Sbostic register FILE	*fp;		/* used for opening various files */
75334600Sbostic bool	councilfound = FALSE;	/* set if we find a member of the council */
75434600Sbostic bool	kingfound = FALSE;	/* set if we find a king */
75534600Sbostic double	hiexp, nxtexp;		/* used for finding the two highest players */
75634600Sbostic double	hilvl, nxtlvl;		/* used for finding the two highest players */
75734600Sbostic char	hiname[21], nxtname[21];/* used for finding the two highest players */
75834600Sbostic 
75934600Sbostic     mvaddstr(0, 14, "W e l c o m e   t o   P h a n t a s i a (vers. 3.3.2)!");
76034600Sbostic 
76134600Sbostic     /* print message of the day */
76240279Sbostic     if ((fp = fopen(_PATH_MOTD, "r")) != NULL
76334600Sbostic 	&& fgets(Databuf, SZ_DATABUF, fp) != NULL)
76434600Sbostic 	{
76534600Sbostic 	mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf);
76634600Sbostic 	fclose(fp);
76734600Sbostic 	}
76834600Sbostic 
76934600Sbostic     /* search for king */
77034600Sbostic     fseek(Playersfp, 0L, 0);
77134600Sbostic     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
77234600Sbostic 	if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
77334600Sbostic 	    /* found the king */
77434600Sbostic 	    {
77534600Sbostic 	    sprintf(Databuf, "The present ruler is %s  Level:%.0f",
77634600Sbostic 		Other.p_name, Other.p_level);
77734600Sbostic 	    mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf);
77834600Sbostic 	    kingfound = TRUE;
77934600Sbostic 	    break;
78034600Sbostic 	    }
78134600Sbostic 
78234600Sbostic     if (!kingfound)
78334600Sbostic 	mvaddstr(4, 24, "There is no ruler at this time.");
78434600Sbostic 
78534600Sbostic     /* search for valar */
78634600Sbostic     fseek(Playersfp, 0L, 0);
78734600Sbostic     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
78834600Sbostic 	if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
78934600Sbostic 	    /* found the valar */
79034600Sbostic 	    {
79134600Sbostic 	    sprintf(Databuf, "The Valar is %s   Login:  %s", Other.p_name, Other.p_login);
79234600Sbostic 	    mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf);
79334600Sbostic 	    break;
79434600Sbostic 	    }
79534600Sbostic 
79634600Sbostic     /* search for council of the wise */
79734600Sbostic     fseek(Playersfp, 0L, 0);
79834600Sbostic     Lines = 10;
79934600Sbostic     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
80034600Sbostic 	if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED)
80134600Sbostic 	    /* found a member of the council */
80234600Sbostic 	    {
80334600Sbostic 	    if (!councilfound)
80434600Sbostic 		{
80534600Sbostic 		mvaddstr(8, 30, "Council of the Wise:");
80634600Sbostic 		councilfound = TRUE;
80734600Sbostic 		}
80834600Sbostic 
80934600Sbostic 	    /* This assumes a finite (<=5) number of C.O.W.: */
81034600Sbostic 	    sprintf(Databuf, "%s   Login:  %s", Other.p_name, Other.p_login);
81134600Sbostic 	    mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf);
81234600Sbostic 	    }
81334600Sbostic 
81434600Sbostic     /* search for the two highest players */
81534600Sbostic     nxtname[0] = hiname[0] = '\0';
81634600Sbostic     hiexp = 0.0;
81734600Sbostic     nxtlvl = hilvl = 0;
81834600Sbostic 
81934600Sbostic     fseek(Playersfp, 0L, 0);
82034600Sbostic     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
82134600Sbostic 	if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED)
82234600Sbostic 	    /* highest found so far */
82334600Sbostic 	    {
82434600Sbostic 	    nxtexp = hiexp;
82534600Sbostic 	    hiexp = Other.p_experience;
82634600Sbostic 	    nxtlvl = hilvl;
82734600Sbostic 	    hilvl = Other.p_level;
82834600Sbostic 	    strcpy(nxtname, hiname);
82934600Sbostic 	    strcpy(hiname, Other.p_name);
83034600Sbostic 	    }
83134600Sbostic 	else if (Other.p_experience > nxtexp
83234600Sbostic 	    && Other.p_specialtype <= SC_KING
83334600Sbostic 	    && Other.p_status != S_NOTUSED)
83434600Sbostic 	    /* next highest found so far */
83534600Sbostic 	    {
83634600Sbostic 	    nxtexp = Other.p_experience;
83734600Sbostic 	    nxtlvl = Other.p_level;
83834600Sbostic 	    strcpy(nxtname, Other.p_name);
83934600Sbostic 	    }
84034600Sbostic 
84134600Sbostic     mvaddstr(15, 28, "Highest characters are:");
84234600Sbostic     sprintf(Databuf, "%s  Level:%.0f   and   %s  Level:%.0f",
84334600Sbostic 	hiname, hilvl, nxtname, nxtlvl);
84434600Sbostic     mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf);
84534600Sbostic 
84634600Sbostic     /* print last to die */
84740279Sbostic     if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL
84834600Sbostic 	&& fgets(Databuf, SZ_DATABUF, fp) != NULL)
84934600Sbostic 	{
85034600Sbostic 	mvaddstr(19, 25, "The last character to die was:");
85134600Sbostic 	mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf);
85234600Sbostic 	fclose(fp);
85334600Sbostic 	}
85434600Sbostic 
85534600Sbostic     refresh();
85634600Sbostic }
85734600Sbostic /**/
85834600Sbostic /************************************************************************
85934600Sbostic /
86034600Sbostic / FUNCTION NAME: recallplayer()
86134600Sbostic /
86234600Sbostic / FUNCTION: find a character on file
86334600Sbostic /
86434600Sbostic / AUTHOR: E. A. Estes, 12/4/85
86534600Sbostic /
86634600Sbostic / ARGUMENTS: none
86734600Sbostic /
86834600Sbostic / RETURN VALUE: none
86934600Sbostic /
87034600Sbostic / MODULES CALLED: writerecord(), truncstring(), more(), death(), wmove(),
87134600Sbostic /	wclear(), strcmp(), printw(), cleanup(), waddstr(), findname(), mvprintw(),
87234600Sbostic /	getanswer(), getstring()
87334600Sbostic /
87434600Sbostic / GLOBAL INPUTS: Player, *stdscr, Databuf[]
87534600Sbostic /
87634600Sbostic / GLOBAL OUTPUTS: Echo, Player
87734600Sbostic /
87834600Sbostic / DESCRIPTION:
87934600Sbostic /	Search for a character of a certain name, and check password.
88034600Sbostic /
88134600Sbostic /************************************************************************/
88234600Sbostic 
88334600Sbostic long
recallplayer()88434600Sbostic recallplayer()
88534600Sbostic {
88634600Sbostic long	loc = 0L;		/* location in player file */
88734600Sbostic register int	loop;		/* loop counter */
88834600Sbostic int	ch;			/* input */
88934600Sbostic 
89034600Sbostic     clear();
89134600Sbostic     mvprintw(10, 0, "What was your character's name ? ");
89234600Sbostic     getstring(Databuf, SZ_NAME);
89334600Sbostic     truncstring(Databuf);
89434600Sbostic 
89534600Sbostic     if ((loc = findname(Databuf, &Player)) >= 0L)
89634600Sbostic 	/* found character */
89734600Sbostic 	{
89834600Sbostic 	Echo = FALSE;
89934600Sbostic 
90034600Sbostic 	for (loop = 0; loop < 2; ++loop)
90134600Sbostic 	    {
90234600Sbostic 	    /* prompt for password */
90334600Sbostic 	    mvaddstr(11, 0, "Password ? ");
90434600Sbostic 	    getstring(Databuf, SZ_PASSWORD);
90534600Sbostic 	    if (strcmp(Databuf, Player.p_password) == 0)
90634600Sbostic 		/* password good */
90734600Sbostic 		{
90834600Sbostic 		Echo = TRUE;
90934600Sbostic 
91034600Sbostic 		if (Player.p_status != S_OFF)
91134600Sbostic 		    /* player did not exit normally last time */
91234600Sbostic 		    {
91334600Sbostic 		    clear();
91434600Sbostic 		    addstr("Your character did not exit normally last time.\n");
91534600Sbostic 		    addstr("If you think you have good cause to have your character saved,\n");
916*41319Sbostic 		    printw("you may quit and mail your reason to 'root'.\n");
91734600Sbostic 		    addstr("Otherwise, continuing spells certain death.\n");
91834600Sbostic 		    addstr("Do you want to quit ? ");
91934600Sbostic 		    ch = getanswer("YN", FALSE);
92034600Sbostic 		    if (ch == 'Y')
92134600Sbostic 			{
92234600Sbostic 			Player.p_status = S_HUNGUP;
92334600Sbostic 			writerecord(&Player, loc);
92434600Sbostic 			cleanup(TRUE);
92534600Sbostic 			/*NOTREACHED*/
92634600Sbostic 			}
92734600Sbostic 		    death("Stupidity");
92834600Sbostic 		    /*NOTREACHED*/
92934600Sbostic 		    }
93034600Sbostic 		return(loc);
93134600Sbostic 		}
93234600Sbostic 	    else
93334600Sbostic 		mvaddstr(12, 0, "No good.\n");
93434600Sbostic 	    }
93534600Sbostic 
93634600Sbostic 	Echo = TRUE;
93734600Sbostic 	}
93834600Sbostic     else
93934600Sbostic 	mvaddstr(11, 0, "Not found.\n");
94034600Sbostic 
94134600Sbostic     more(13);
94234600Sbostic     return(-1L);
94334600Sbostic }
94434600Sbostic /**/
94534600Sbostic /************************************************************************
94634600Sbostic /
94734600Sbostic / FUNCTION NAME: neatstuff()
94834600Sbostic /
94934600Sbostic / FUNCTION: do random stuff
95034600Sbostic /
95134600Sbostic / AUTHOR: E. A. Estes, 3/3/86
95234600Sbostic /
95334600Sbostic / ARGUMENTS: none
95434600Sbostic /
95534600Sbostic / RETURN VALUE: none
95634600Sbostic /
95734600Sbostic / MODULES CALLED: collecttaxes(), floor(), wmove(), drandom(), infloat(),
95834600Sbostic /	waddstr(), mvprintw(), getanswer()
95934600Sbostic /
96034600Sbostic / GLOBAL INPUTS: Player, *stdscr, *Statptr
96134600Sbostic /
96234600Sbostic / GLOBAL OUTPUTS: Player
96334600Sbostic /
96434600Sbostic / DESCRIPTION:
96534600Sbostic /	Handle gurus, medics, etc.
96634600Sbostic /
96734600Sbostic /************************************************************************/
96834600Sbostic 
neatstuff()96934600Sbostic neatstuff()
97034600Sbostic {
97134600Sbostic double	temp;	/* for temporary calculations */
97234600Sbostic int	ch;	/* input */
97334600Sbostic 
97434600Sbostic     switch ((int) ROLL(0.0, 100.0))
97534600Sbostic 	{
97634600Sbostic 	case 1:
97734600Sbostic 	case 2:
97834600Sbostic 	    if (Player.p_poison > 0.0)
97934600Sbostic 		{
98034600Sbostic 		mvaddstr(4, 0, "You've found a medic!  How much will you offer to be cured ? ");
98134600Sbostic 		temp = floor(infloat());
98234600Sbostic 		if (temp < 0.0 || temp > Player.p_gold)
98334600Sbostic 		    /* negative gold, or more than available */
98434600Sbostic 		    {
98534600Sbostic 		    mvaddstr(6, 0, "He was not amused, and made you worse.\n");
98634600Sbostic 		    Player.p_poison += 1.0;
98734600Sbostic 		    }
98834600Sbostic 		else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1))
98934600Sbostic 		    /* medic wants 1/2 of available gold */
99034600Sbostic 		    mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
99134600Sbostic 		else
99234600Sbostic 		    {
99334600Sbostic 		    mvaddstr(5, 0, "He accepted.");
99434600Sbostic 		    Player.p_poison = MAX(0.0, Player.p_poison - 1.0);
99534600Sbostic 		    Player.p_gold -= temp;
99634600Sbostic 		    }
99734600Sbostic 		}
99834600Sbostic 	    break;
99934600Sbostic 
100034600Sbostic 	case 3:
100134600Sbostic 	    mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
100234600Sbostic 	    Player.p_experience += 4000.0;
100334600Sbostic 	    Player.p_sin += 0.5;
100434600Sbostic 	    break;
100534600Sbostic 
100634600Sbostic 	case 4:
100734600Sbostic 	    temp = ROLL(10.0, 75.0);
100834600Sbostic 	    mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp);
100934600Sbostic 	    ch = getanswer("NY", FALSE);
101034600Sbostic 
101134600Sbostic 	    if (ch == 'Y')
101234600Sbostic 		collecttaxes(temp, 0.0);
101334600Sbostic 	    break;
101434600Sbostic 
101534600Sbostic 	case 5:
101634600Sbostic 	    if (Player.p_sin > 1.0)
101734600Sbostic 		{
101834600Sbostic 		mvaddstr(4, 0, "You've found a Holy Orb!\n");
101934600Sbostic 		Player.p_sin -= 0.25;
102034600Sbostic 		}
102134600Sbostic 	    break;
102234600Sbostic 
102334600Sbostic 	case 6:
102434600Sbostic 	    if (Player.p_poison < 1.0)
102534600Sbostic 		{
102634600Sbostic 		mvaddstr(4, 0, "You've been hit with a plague!\n");
102734600Sbostic 		Player.p_poison += 1.0;
102834600Sbostic 		}
102934600Sbostic 	    break;
103034600Sbostic 
103134600Sbostic 	case 7:
103234600Sbostic 	    mvaddstr(4, 0, "You've found some holy water.\n");
103334600Sbostic 	    ++Player.p_holywater;
103434600Sbostic 	    break;
103534600Sbostic 
103634600Sbostic 	case 8:
103734600Sbostic 	    mvaddstr(4, 0, "You've met a Guru. . .");
103834600Sbostic 	    if (drandom() * Player.p_sin > 1.0)
103934600Sbostic 		addstr("You disgusted him with your sins!\n");
104034600Sbostic 	    else if (Player.p_poison > 0.0)
104134600Sbostic 		{
104234600Sbostic 		addstr("He looked kindly upon you, and cured you.\n");
104334600Sbostic 		Player.p_poison = 0.0;
104434600Sbostic 		}
104534600Sbostic 	    else
104634600Sbostic 		{
104734600Sbostic 		addstr("He rewarded you for your virtue.\n");
104834600Sbostic 		Player.p_mana += 50.0;
104934600Sbostic 		Player.p_shield += 2.0;
105034600Sbostic 		}
105134600Sbostic 	    break;
105234600Sbostic 
105334600Sbostic 	case 9:
105434600Sbostic 	    mvaddstr(4, 0, "You've found an amulet.\n");
105534600Sbostic 	    ++Player.p_amulets;
105634600Sbostic 	    break;
105734600Sbostic 
105834600Sbostic 	case 10:
105934600Sbostic 	    if (Player.p_blindness)
106034600Sbostic 		{
106134600Sbostic 		mvaddstr(4, 0, "You've regained your sight!\n");
106234600Sbostic 		Player.p_blindness = FALSE;
106334600Sbostic 		}
106434600Sbostic 	    break;
106534600Sbostic 
106634600Sbostic 	default:	/* deal with poison */
106734600Sbostic 	    if (Player.p_poison > 0.0)
106834600Sbostic 		{
106934600Sbostic 		temp = Player.p_poison * Statptr->c_weakness
107034600Sbostic 		    * Player.p_maxenergy / 600.0;
107134600Sbostic 		if (Player.p_energy > Player.p_maxenergy / 10.0
107234600Sbostic 		    && temp + 5.0 < Player.p_energy)
107334600Sbostic 		    Player.p_energy -= temp;
107434600Sbostic 		}
107534600Sbostic 	    break;
107634600Sbostic 	}
107734600Sbostic }
107834600Sbostic /**/
107934600Sbostic /************************************************************************
108034600Sbostic /
108134600Sbostic / FUNCTION NAME: genchar()
108234600Sbostic /
108334600Sbostic / FUNCTION: generate a random character
108434600Sbostic /
108534600Sbostic / AUTHOR: E. A. Estes, 12/4/85
108634600Sbostic /
108734600Sbostic / ARGUMENTS:
108834600Sbostic /	int type - ASCII value of character type to generate
108934600Sbostic /
109034600Sbostic / RETURN VALUE: none
109134600Sbostic /
109234600Sbostic / MODULES CALLED: floor(), drandom()
109334600Sbostic /
109434600Sbostic / GLOBAL INPUTS: Wizard, Player, Stattable[]
109534600Sbostic /
109634600Sbostic / GLOBAL OUTPUTS: Player
109734600Sbostic /
109834600Sbostic / DESCRIPTION:
109934600Sbostic /	Use the lookup table for rolling stats.
110034600Sbostic /
110134600Sbostic /************************************************************************/
110234600Sbostic 
genchar(type)110334600Sbostic genchar(type)
110434600Sbostic int	type;
110534600Sbostic {
110634600Sbostic register int	subscript;		/* used for subscripting into Stattable */
110734600Sbostic register struct charstats	*statptr;/* for pointing into Stattable */
110834600Sbostic 
110934600Sbostic     subscript = type - '1';
111034600Sbostic 
111134600Sbostic     if (subscript < C_MAGIC || subscript > C_EXPER)
111234600Sbostic 	if (subscript != C_SUPER || !Wizard)
111334600Sbostic 	    /* fighter is default */
111434600Sbostic 	    subscript = C_FIGHTER;
111534600Sbostic 
111634600Sbostic     statptr = &Stattable[subscript];
111734600Sbostic 
111834600Sbostic     Player.p_quickness =
111934600Sbostic 	ROLL(statptr->c_quickness.base, statptr->c_quickness.interval);
112034600Sbostic     Player.p_strength =
112134600Sbostic 	ROLL(statptr->c_strength.base, statptr->c_strength.interval);
112234600Sbostic     Player.p_mana =
112334600Sbostic 	ROLL(statptr->c_mana.base, statptr->c_mana.interval);
112434600Sbostic     Player.p_maxenergy =
112534600Sbostic     Player.p_energy =
112634600Sbostic 	ROLL(statptr->c_energy.base, statptr->c_energy.interval);
112734600Sbostic     Player.p_brains =
112834600Sbostic 	ROLL(statptr->c_brains.base, statptr->c_brains.interval);
112934600Sbostic     Player.p_magiclvl =
113034600Sbostic 	ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval);
113134600Sbostic 
113234600Sbostic     Player.p_type = subscript;
113334600Sbostic 
113434600Sbostic     if (Player.p_type == C_HALFLING)
113534600Sbostic 	/* give halfling some experience */
113634600Sbostic 	Player.p_experience = ROLL(600.0, 200.0);
113734600Sbostic }
113834600Sbostic /**/
113934600Sbostic /************************************************************************
114034600Sbostic /
114134600Sbostic / FUNCTION NAME: playinit()
114234600Sbostic /
114334600Sbostic / FUNCTION: initialize for playing game
114434600Sbostic /
114534600Sbostic / AUTHOR: E. A. Estes, 12/4/85
114634600Sbostic /
114734600Sbostic / ARGUMENTS: none
114834600Sbostic /
114934600Sbostic / RETURN VALUE: none
115034600Sbostic /
115134600Sbostic / MODULES CALLED: signal(), wclear(), noecho(), crmode(), initscr(),
115234600Sbostic /	wrefresh()
115334600Sbostic /
115434600Sbostic / GLOBAL INPUTS: *stdscr, ill_sig()
115534600Sbostic /
115634600Sbostic / GLOBAL OUTPUTS: Windows
115734600Sbostic /
115834600Sbostic / DESCRIPTION:
115934600Sbostic /	Catch a bunch of signals, and turn on curses stuff.
116034600Sbostic /
116134600Sbostic /************************************************************************/
116234600Sbostic 
playinit()116334600Sbostic playinit()
116434600Sbostic {
116534600Sbostic     /* catch/ingnore signals */
116634600Sbostic 
116734600Sbostic #ifdef	BSD41
116834600Sbostic     sigignore(SIGQUIT);
116934600Sbostic     sigignore(SIGALRM);
117034600Sbostic     sigignore(SIGTERM);
117134600Sbostic     sigignore(SIGTSTP);
117234600Sbostic     sigignore(SIGTTIN);
117334600Sbostic     sigignore(SIGTTOU);
117434600Sbostic     sighold(SIGINT);
117534600Sbostic     sigset(SIGHUP, ill_sig);
117634600Sbostic     sigset(SIGTRAP, ill_sig);
117734600Sbostic     sigset(SIGIOT, ill_sig);
117834600Sbostic     sigset(SIGEMT, ill_sig);
117934600Sbostic     sigset(SIGFPE, ill_sig);
118034600Sbostic     sigset(SIGBUS, ill_sig);
118134600Sbostic     sigset(SIGSEGV, ill_sig);
118234600Sbostic     sigset(SIGSYS, ill_sig);
118334600Sbostic     sigset(SIGPIPE, ill_sig);
118434600Sbostic #endif
118534600Sbostic #ifdef	BSD42
118634600Sbostic     signal(SIGQUIT, ill_sig);
118734600Sbostic     signal(SIGALRM, SIG_IGN);
118834600Sbostic     signal(SIGTERM, SIG_IGN);
118934600Sbostic     signal(SIGTSTP, SIG_IGN);
119034600Sbostic     signal(SIGTTIN, SIG_IGN);
119134600Sbostic     signal(SIGTTOU, SIG_IGN);
119234600Sbostic     signal(SIGINT, ill_sig);
119334600Sbostic     signal(SIGHUP, SIG_DFL);
119434600Sbostic     signal(SIGTRAP, ill_sig);
119534600Sbostic     signal(SIGIOT, ill_sig);
119634600Sbostic     signal(SIGEMT, ill_sig);
119734600Sbostic     signal(SIGFPE, ill_sig);
119834600Sbostic     signal(SIGBUS, ill_sig);
119934600Sbostic     signal(SIGSEGV, ill_sig);
120034600Sbostic     signal(SIGSYS, ill_sig);
120134600Sbostic     signal(SIGPIPE, ill_sig);
120234600Sbostic #endif
120334600Sbostic #ifdef	SYS3
120434600Sbostic     signal(SIGINT, SIG_IGN);
120534600Sbostic     signal(SIGQUIT, SIG_IGN);
120634600Sbostic     signal(SIGTERM, SIG_IGN);
120734600Sbostic     signal(SIGALRM, SIG_IGN);
120834600Sbostic     signal(SIGHUP, ill_sig);
120934600Sbostic     signal(SIGTRAP, ill_sig);
121034600Sbostic     signal(SIGIOT, ill_sig);
121134600Sbostic     signal(SIGEMT, ill_sig);
121234600Sbostic     signal(SIGFPE, ill_sig);
121334600Sbostic     signal(SIGBUS, ill_sig);
121434600Sbostic     signal(SIGSEGV, ill_sig);
121534600Sbostic     signal(SIGSYS, ill_sig);
121634600Sbostic     signal(SIGPIPE, ill_sig);
121734600Sbostic #endif
121834600Sbostic #ifdef	SYS5
121934600Sbostic     signal(SIGINT, SIG_IGN);
122034600Sbostic     signal(SIGQUIT, SIG_IGN);
122134600Sbostic     signal(SIGTERM, SIG_IGN);
122234600Sbostic     signal(SIGALRM, SIG_IGN);
122334600Sbostic     signal(SIGHUP, ill_sig);
122434600Sbostic     signal(SIGTRAP, ill_sig);
122534600Sbostic     signal(SIGIOT, ill_sig);
122634600Sbostic     signal(SIGEMT, ill_sig);
122734600Sbostic     signal(SIGFPE, ill_sig);
122834600Sbostic     signal(SIGBUS, ill_sig);
122934600Sbostic     signal(SIGSEGV, ill_sig);
123034600Sbostic     signal(SIGSYS, ill_sig);
123134600Sbostic     signal(SIGPIPE, ill_sig);
123234600Sbostic #endif
123334600Sbostic 
123434600Sbostic     initscr();		/* turn on curses */
123534600Sbostic     noecho();		/* do not echo input */
123634600Sbostic     crmode();		/* do not process erase, kill */
123734600Sbostic     clear();
123834600Sbostic     refresh();
123934600Sbostic     Windows = TRUE;	/* mark the state */
124034600Sbostic }
124134600Sbostic 
124234600Sbostic /**/
124334600Sbostic /************************************************************************
124434600Sbostic /
124534600Sbostic / FUNCTION NAME: cleanup()
124634600Sbostic /
124734600Sbostic / FUNCTION: close some files, and maybe exit
124834600Sbostic /
124934600Sbostic / AUTHOR: E. A. Estes, 12/4/85
125034600Sbostic /
125134600Sbostic / ARGUMENTS:
125234600Sbostic /	bool doexit - exit flag
125334600Sbostic /
125434600Sbostic / RETURN VALUE: none
125534600Sbostic /
125634600Sbostic / MODULES CALLED: exit(), wmove(), fclose(), endwin(), nocrmode(), wrefresh()
125734600Sbostic /
125834600Sbostic / GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
125934600Sbostic /	*Messagefp, *Playersfp
126034600Sbostic /
126134600Sbostic / GLOBAL OUTPUTS: none
126234600Sbostic /
126334600Sbostic / DESCRIPTION:
126434600Sbostic /	Close all open files.  If we are "in curses" terminate curses.
126534600Sbostic /	If 'doexit' is set, exit, otherwise return.
126634600Sbostic /
126734600Sbostic /************************************************************************/
126834600Sbostic 
cleanup(doexit)126934600Sbostic cleanup(doexit)
127034600Sbostic bool	doexit;
127134600Sbostic {
127234600Sbostic     if (Windows)
127334600Sbostic 	{
127434600Sbostic 	move(LINES - 2, 0);
127534600Sbostic 	refresh();
127634600Sbostic 	nocrmode();
127734600Sbostic 	endwin();
127834600Sbostic 	}
127934600Sbostic 
128034600Sbostic     fclose(Playersfp);
128134600Sbostic     fclose(Monstfp);
128234600Sbostic     fclose(Messagefp);
128334600Sbostic     fclose(Energyvoidfp);
128434600Sbostic 
128534600Sbostic     if (doexit)
128634600Sbostic 	exit(0);
128734600Sbostic 	/*NOTREACHED*/
128834600Sbostic }
1289