Home | History | Annotate | Line # | Download | only in phantasia
main.c revision 1.1
      1  1.1  jtc /*
      2  1.1  jtc  * Phantasia 3.3.2 -- Interterminal fantasy game
      3  1.1  jtc  *
      4  1.1  jtc  * Edward A. Estes
      5  1.1  jtc  * AT&T, March 12, 1986
      6  1.1  jtc  */
      7  1.1  jtc 
      8  1.1  jtc /* DISCLAIMER:
      9  1.1  jtc  *
     10  1.1  jtc  * This game is distributed for free as is.  It is not guaranteed to work
     11  1.1  jtc  * in every conceivable environment.  It is not even guaranteed to work
     12  1.1  jtc  * in ANY environment.
     13  1.1  jtc  *
     14  1.1  jtc  * This game is distributed without notice of copyright, therefore it
     15  1.1  jtc  * may be used in any manner the recipient sees fit.  However, the
     16  1.1  jtc  * author assumes no responsibility for maintaining or revising this
     17  1.1  jtc  * game, in its original form, or any derivitives thereof.
     18  1.1  jtc  *
     19  1.1  jtc  * The author shall not be responsible for any loss, cost, or damage,
     20  1.1  jtc  * including consequential damage, caused by reliance on this material.
     21  1.1  jtc  *
     22  1.1  jtc  * The author makes no warranties, express or implied, including warranties
     23  1.1  jtc  * of merchantability or fitness for a particular purpose or use.
     24  1.1  jtc  *
     25  1.1  jtc  * AT&T is in no way connected with this game.
     26  1.1  jtc  */
     27  1.1  jtc 
     28  1.1  jtc #include <sys/types.h>
     29  1.1  jtc #include <pwd.h>
     30  1.1  jtc 
     31  1.1  jtc /*
     32  1.1  jtc  * The program allocates as much file space as it needs to store characters,
     33  1.1  jtc  * so the possibility exists for the character file to grow without bound.
     34  1.1  jtc  * The file is purged upon normal entry to try to avoid that problem.
     35  1.1  jtc  * A similar problem exists for energy voids.  To alleviate the problem here,
     36  1.1  jtc  * the void file is cleared with every new king, and a limit is placed
     37  1.1  jtc  * on the size of the energy void file.
     38  1.1  jtc  */
     39  1.1  jtc 
     40  1.1  jtc /*
     41  1.1  jtc  * Put one line of text into the file 'motd' for announcements, etc.
     42  1.1  jtc  */
     43  1.1  jtc 
     44  1.1  jtc /*
     45  1.1  jtc  * The scoreboard file is updated when someone dies, and keeps track
     46  1.1  jtc  * of the highest character to date for that login.
     47  1.1  jtc  * Being purged from the character file does not cause the scoreboard
     48  1.1  jtc  * to be updated.
     49  1.1  jtc  */
     50  1.1  jtc 
     51  1.1  jtc /*
     52  1.1  jtc  * All source files are set up for 'vi' with shiftwidth=4, tabstop=8.
     53  1.1  jtc  */
     54  1.1  jtc 
     55  1.1  jtc /**/
     57  1.1  jtc 
     58  1.1  jtc /*
     59  1.1  jtc  * main.c	Main routines for Phantasia
     60  1.1  jtc  */
     61  1.1  jtc 
     62  1.1  jtc #include "include.h"
     63  1.1  jtc 
     64  1.1  jtc /***************************************************************************
     65  1.1  jtc / FUNCTION NAME: main()
     66  1.1  jtc /
     67  1.1  jtc / FUNCTION: initialize state, and call main process
     68  1.1  jtc /
     69  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
     70  1.1  jtc /
     71  1.1  jtc / ARGUMENTS:
     72  1.1  jtc /	int	argc - argument count
     73  1.1  jtc /	char	**argv - argument vector
     74  1.1  jtc /
     75  1.1  jtc / RETURN VALUE: none
     76  1.1  jtc /
     77  1.1  jtc / MODULES CALLED: monstlist(), checkenemy(), activelist(),
     78  1.1  jtc /	throneroom(), checkbattle(), readmessage(), changestats(), writerecord(),
     79  1.1  jtc /	tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(),
     80  1.1  jtc /	fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(),
     81  1.1  jtc /	signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(),
     82  1.1  jtc /	strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(),
     83  1.1  jtc /	playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(),
     84  1.1  jtc /	scorelist(), titlelist()
     85  1.1  jtc /
     86  1.1  jtc / GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
     87  1.1  jtc /	Fileloc, Stattable[]
     88  1.1  jtc /
     89  1.1  jtc / GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
     90  1.1  jtc /
     91  1.1  jtc / DESCRIPTION:
     92  1.1  jtc /	Process arguments, initialize program, and loop forever processing
     93  1.1  jtc /	player input.
     94  1.1  jtc /
     95  1.1  jtc /***************************************************************************/
     96  1.1  jtc 
     97  1.1  jtc main(argc, argv)
     98  1.1  jtc int	argc;
     99  1.1  jtc char	**argv;
    100  1.1  jtc {
    101  1.1  jtc bool	noheader = FALSE;	/* set if don't want header */
    102  1.1  jtc bool	headeronly = FALSE;	/* set if only want header */
    103  1.1  jtc bool	examine = FALSE;	/* set if examine a character */
    104  1.1  jtc long	seconds;		/* for time of day */
    105  1.1  jtc double	dtemp;			/* for temporary calculations */
    106  1.1  jtc 
    107  1.1  jtc     initialstate();		/* init globals */
    108  1.1  jtc 
    109  1.1  jtc     /* process arguments */
    110  1.1  jtc     while (--argc && (*++argv)[0] == '-')
    111  1.1  jtc 	switch ((*argv)[1])
    112  1.1  jtc 	    {
    113  1.1  jtc 	    case 's':	/* short */
    114  1.1  jtc 		noheader = TRUE;
    115  1.1  jtc 		break;
    116  1.1  jtc 
    117  1.1  jtc 	    case 'H':	/* Header */
    118  1.1  jtc 		headeronly = TRUE;
    119  1.1  jtc 		break;
    120  1.1  jtc 
    121  1.1  jtc 	    case 'a':	/* all users */
    122  1.1  jtc 		activelist();
    123  1.1  jtc 		cleanup(TRUE);
    124  1.1  jtc 		/*NOTREACHED*/
    125  1.1  jtc 
    126  1.1  jtc 	    case 'p':	/* purge old players */
    127  1.1  jtc 		purgeoldplayers();
    128  1.1  jtc 		cleanup(TRUE);
    129  1.1  jtc 		/*NOTREACHED*/
    130  1.1  jtc 
    131  1.1  jtc 	    case 'S':	/* set 'Wizard' */
    132  1.1  jtc 		Wizard = !getuid();
    133  1.1  jtc 		break;
    134  1.1  jtc 
    135  1.1  jtc 	    case 'x':	/* examine */
    136  1.1  jtc 		examine = TRUE;
    137  1.1  jtc 		break;
    138  1.1  jtc 
    139  1.1  jtc 	    case 'm':	/* monsters */
    140  1.1  jtc 		monstlist();
    141  1.1  jtc 		cleanup(TRUE);
    142  1.1  jtc 		/*NOTREACHED*/
    143  1.1  jtc 
    144  1.1  jtc 	    case 'b':	/* scoreboard */
    145  1.1  jtc 		scorelist();
    146  1.1  jtc 		cleanup(TRUE);
    147  1.1  jtc 		/*NOTREACHED*/
    148  1.1  jtc 		}
    149  1.1  jtc 
    150  1.1  jtc     if (!isatty(0))		/* don't let non-tty's play */
    151  1.1  jtc 	cleanup(TRUE);
    152  1.1  jtc 	/*NOTREACHED*/
    153  1.1  jtc 
    154  1.1  jtc     playinit();			/* set up to catch signals, init curses */
    155  1.1  jtc 
    156  1.1  jtc     if (examine)
    157  1.1  jtc 	{
    158  1.1  jtc 	changestats(FALSE);
    159  1.1  jtc 	cleanup(TRUE);
    160  1.1  jtc 	/*NOTREACHED*/
    161  1.1  jtc 	}
    162  1.1  jtc 
    163  1.1  jtc     if (!noheader)
    164  1.1  jtc 	{
    165  1.1  jtc 	titlelist();
    166  1.1  jtc 	purgeoldplayers();    /* clean up old characters */
    167  1.1  jtc 	}
    168  1.1  jtc 
    169  1.1  jtc     if (headeronly)
    170  1.1  jtc 	cleanup(TRUE);
    171  1.1  jtc 	/*NOTREACHED*/
    172  1.1  jtc 
    173  1.1  jtc     do
    174  1.1  jtc 	/* get the player structure filled */
    175  1.1  jtc 	{
    176  1.1  jtc 	Fileloc = -1L;
    177  1.1  jtc 
    178  1.1  jtc 	mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
    179  1.1  jtc 
    180  1.1  jtc 	switch (getanswer("NYQ", FALSE))
    181  1.1  jtc 	    {
    182  1.1  jtc 	    case 'Y':
    183  1.1  jtc 		Fileloc = recallplayer();
    184  1.1  jtc 		break;
    185  1.1  jtc 
    186  1.1  jtc 	    case 'Q':
    187  1.1  jtc 		cleanup(TRUE);
    188  1.1  jtc 		/*NOTREACHED*/
    189  1.1  jtc 
    190  1.1  jtc 	    default:
    191  1.1  jtc 		Fileloc = rollnewplayer();
    192  1.1  jtc 		break;
    193  1.1  jtc 	    }
    194  1.1  jtc 	clear();
    195  1.1  jtc 	}
    196  1.1  jtc     while (Fileloc < 0L);
    197  1.1  jtc 
    198  1.1  jtc     if (Player.p_level > 5.0)
    199  1.1  jtc 	/* low level players have long timeout */
    200  1.1  jtc 	Timeout = TRUE;
    201  1.1  jtc 
    202  1.1  jtc     /* update some important player statistics */
    203  1.1  jtc     strcpy(Player.p_login, Login);
    204  1.1  jtc     time(&seconds);
    205  1.1  jtc     Player.p_lastused = localtime(&seconds)->tm_yday;
    206  1.1  jtc     Player.p_status = S_PLAYING;
    207  1.1  jtc     writerecord(&Player, Fileloc);
    208  1.1  jtc 
    209  1.1  jtc     Statptr = &Stattable[Player.p_type];	/* initialize pointer */
    210  1.1  jtc 
    211  1.1  jtc     /* catch interrupts */
    212  1.1  jtc #ifdef	BSD41
    213  1.1  jtc     sigset(SIGINT, interrupt);
    214  1.1  jtc #endif
    215  1.1  jtc #ifdef	BSD42
    216  1.1  jtc     signal(SIGINT, interrupt);
    217  1.1  jtc #endif
    218  1.1  jtc #ifdef	SYS3
    219  1.1  jtc     signal(SIGINT, interrupt);
    220  1.1  jtc #endif
    221  1.1  jtc #ifdef	SYS5
    222  1.1  jtc     signal(SIGINT, interrupt);
    223  1.1  jtc #endif
    224  1.1  jtc 
    225  1.1  jtc     altercoordinates(Player.p_x, Player.p_y, A_FORCED);	/* set some flags */
    226  1.1  jtc 
    227  1.1  jtc     clear();
    228  1.1  jtc 
    229  1.1  jtc     for (;;)
    230  1.1  jtc 	/* loop forever, processing input */
    231  1.1  jtc 	{
    232  1.1  jtc 
    233  1.1  jtc 	adjuststats();		/* cleanup stats */
    234  1.1  jtc 
    235  1.1  jtc 	if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING)
    236  1.1  jtc 	    /* not allowed on throne -- move */
    237  1.1  jtc 	    {
    238  1.1  jtc 	    mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n");
    239  1.1  jtc 	    altercoordinates(0.0, 0.0, A_NEAR);
    240  1.1  jtc 	    }
    241  1.1  jtc 
    242  1.1  jtc 	checktampered();	/* check for energy voids, etc. */
    243  1.1  jtc 
    244  1.1  jtc 	if (Player.p_status != S_CLOAKED
    245  1.1  jtc 	    /* not cloaked */
    246  1.1  jtc 	    && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y)
    247  1.1  jtc 	    /* |x| = |y| */
    248  1.1  jtc 	    && !Throne)
    249  1.1  jtc 	    /* not on throne */
    250  1.1  jtc 	    {
    251  1.1  jtc 	    dtemp = sqrt(dtemp / 100.0);
    252  1.1  jtc 	    if (floor(dtemp) == dtemp)
    253  1.1  jtc 		/* |x| / 100 == n*n; at a trading post */
    254  1.1  jtc 		{
    255  1.1  jtc 		tradingpost();
    256  1.1  jtc 		clear();
    257  1.1  jtc 		}
    258  1.1  jtc 	    }
    259  1.1  jtc 
    260  1.1  jtc 	checkbattle();		/* check for player to player battle */
    261  1.1  jtc 	neatstuff();		/* gurus, medics, etc. */
    262  1.1  jtc 
    263  1.1  jtc 	if (Player.p_status == S_CLOAKED)
    264  1.1  jtc 	    /* costs 3 mana per turn to be cloaked */
    265  1.1  jtc 	    if (Player.p_mana > 3.0)
    266  1.1  jtc 		Player.p_mana -= 3.0;
    267  1.1  jtc 	    else
    268  1.1  jtc 		/* ran out of mana, uncloak */
    269  1.1  jtc 		{
    270  1.1  jtc 		Player.p_status = S_PLAYING;
    271  1.1  jtc 		Changed = TRUE;
    272  1.1  jtc 		}
    273  1.1  jtc 
    274  1.1  jtc 	if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED)
    275  1.1  jtc 	    /* change status back to S_PLAYING */
    276  1.1  jtc 	    {
    277  1.1  jtc 	    Player.p_status = S_PLAYING;
    278  1.1  jtc 	    Changed = TRUE;
    279  1.1  jtc 	    }
    280  1.1  jtc 
    281  1.1  jtc 	if (Changed)
    282  1.1  jtc 	    /* update file only if important stuff has changed */
    283  1.1  jtc 	    {
    284  1.1  jtc 	    writerecord(&Player, Fileloc);
    285  1.1  jtc 	    Changed = FALSE;
    286  1.1  jtc 	    continue;
    287  1.1  jtc 	    }
    288  1.1  jtc 
    289  1.1  jtc 	readmessage();			/* read message, if any */
    290  1.1  jtc 
    291  1.1  jtc 	displaystats();			/* print statistics */
    292  1.1  jtc 
    293  1.1  jtc 	move(6, 0);
    294  1.1  jtc 
    295  1.1  jtc 	if (Throne)
    296  1.1  jtc 	    /* maybe make king, print prompt, etc. */
    297  1.1  jtc 	    throneroom();
    298  1.1  jtc 
    299  1.1  jtc 	/* print status line */
    300  1.1  jtc 	addstr("1:Move  2:Players  3:Talk  4:Stats  5:Quit  ");
    301  1.1  jtc 	if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK)
    302  1.1  jtc 	    addstr("6:Cloak  ");
    303  1.1  jtc 	if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT)
    304  1.1  jtc 	    addstr("7:Teleport  ");
    305  1.1  jtc 	if (Player.p_specialtype >= SC_COUNCIL || Wizard)
    306  1.1  jtc 	    addstr("8:Intervene  ");
    307  1.1  jtc 
    308  1.1  jtc 	procmain();			/* process input */
    309  1.1  jtc 	}
    310  1.1  jtc }
    311  1.1  jtc /**/
    313  1.1  jtc /************************************************************************
    314  1.1  jtc /
    315  1.1  jtc / FUNCTION NAME: initialstate()
    316  1.1  jtc /
    317  1.1  jtc / FUNCTION: initialize some important global variable
    318  1.1  jtc /
    319  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    320  1.1  jtc /
    321  1.1  jtc / ARGUMENTS: none
    322  1.1  jtc /
    323  1.1  jtc / RETURN VALUE: none
    324  1.1  jtc /
    325  1.1  jtc / MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(),
    326  1.1  jtc /	getpwuid()
    327  1.1  jtc /
    328  1.1  jtc / GLOBAL INPUTS:
    329  1.1  jtc /
    330  1.1  jtc / GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
    331  1.1  jtc /	Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
    332  1.1  jtc /	*Playersfp
    333  1.1  jtc /
    334  1.1  jtc / DESCRIPTION:
    335  1.1  jtc /	Set global flags, and open files which remain open.
    336  1.1  jtc /
    337  1.1  jtc /************************************************************************/
    338  1.1  jtc 
    339  1.1  jtc initialstate()
    340  1.1  jtc {
    341  1.1  jtc     Beyond = FALSE;
    342  1.1  jtc     Marsh = FALSE;
    343  1.1  jtc     Throne = FALSE;
    344  1.1  jtc     Changed = FALSE;
    345  1.1  jtc     Wizard = FALSE;
    346  1.1  jtc     Timeout = FALSE;
    347  1.1  jtc     Users = 0;
    348  1.1  jtc     Windows = FALSE;
    349  1.1  jtc     Echo = TRUE;
    350  1.1  jtc 
    351  1.1  jtc     /* setup login name */
    352  1.1  jtc     if ((Login = getlogin()) == NULL)
    353  1.1  jtc 	Login = getpwuid(getuid())->pw_name;
    354  1.1  jtc 
    355  1.1  jtc     /* open some files */
    356  1.1  jtc     if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
    357  1.1  jtc 	error(_PATH_PEOPLE);
    358  1.1  jtc 	/*NOTREACHED*/
    359  1.1  jtc 
    360  1.1  jtc     if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL)
    361  1.1  jtc 	error(_PATH_MONST);
    362  1.1  jtc 	/*NOTREACHED*/
    363  1.1  jtc 
    364  1.1  jtc     if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL)
    365  1.1  jtc 	error(_PATH_MESS);
    366  1.1  jtc 	/*NOTREACHED*/
    367  1.1  jtc 
    368  1.1  jtc     if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL)
    369  1.1  jtc 	error(_PATH_VOID);
    370  1.1  jtc 	/*NOTREACHED*/
    371  1.1  jtc 
    372  1.1  jtc     srandom((unsigned) time((long *) NULL));	/* prime random numbers */
    373  1.1  jtc }
    374  1.1  jtc /**/
    376  1.1  jtc /************************************************************************
    377  1.1  jtc /
    378  1.1  jtc / FUNCTION NAME: rollnewplayer()
    379  1.1  jtc /
    380  1.1  jtc / FUNCTION: roll up a new character
    381  1.1  jtc /
    382  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    383  1.1  jtc /
    384  1.1  jtc / ARGUMENTS: none
    385  1.1  jtc /
    386  1.1  jtc / RETURN VALUE: none
    387  1.1  jtc /
    388  1.1  jtc / MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(),
    389  1.1  jtc /	wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(),
    390  1.1  jtc /	getanswer(), getstring()
    391  1.1  jtc /
    392  1.1  jtc / GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
    393  1.1  jtc /
    394  1.1  jtc / GLOBAL OUTPUTS: Echo
    395  1.1  jtc /
    396  1.1  jtc / DESCRIPTION:
    397  1.1  jtc /	Prompt player, and roll up new character.
    398  1.1  jtc /
    399  1.1  jtc /************************************************************************/
    400  1.1  jtc 
    401  1.1  jtc long
    402  1.1  jtc rollnewplayer()
    403  1.1  jtc {
    404  1.1  jtc int	chartype;	/* character type */
    405  1.1  jtc int	ch;		/* input */
    406  1.1  jtc 
    407  1.1  jtc     initplayer(&Player);		/* initialize player structure */
    408  1.1  jtc 
    409  1.1  jtc     clear();
    410  1.1  jtc     mvaddstr(4, 21, "Which type of character do you want:");
    411  1.1  jtc     mvaddstr(8, 4, "1:Magic User  2:Fighter  3:Elf  4:Dwarf  5:Halfling  6:Experimento  ");
    412  1.1  jtc     if (Wizard) {
    413  1.1  jtc 	addstr("7:Super  ? ");
    414  1.1  jtc 	chartype = getanswer("1234567", FALSE);
    415  1.1  jtc 	}
    416  1.1  jtc     else {
    417  1.1  jtc 	addstr("?  ");
    418  1.1  jtc 	chartype = getanswer("123456", FALSE);
    419  1.1  jtc 	}
    420  1.1  jtc 
    421  1.1  jtc     do
    422  1.1  jtc 	{
    423  1.1  jtc 	genchar(chartype);		/* roll up a character */
    424  1.1  jtc 
    425  1.1  jtc 	/* print out results */
    426  1.1  jtc 	mvprintw(12, 14,
    427  1.1  jtc 	    "Strength    :  %2.0f  Quickness:  %2.0f  Mana       :  %2.0f\n",
    428  1.1  jtc 	    Player.p_strength, Player.p_quickness, Player.p_mana);
    429  1.1  jtc 	mvprintw(13, 14,
    430  1.1  jtc 	    "Energy Level:  %2.0f  Brains   :  %2.0f  Magic Level:  %2.0f\n",
    431  1.1  jtc 	    Player.p_energy, Player.p_brains, Player.p_magiclvl);
    432  1.1  jtc 
    433  1.1  jtc 	if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
    434  1.1  jtc 	    break;
    435  1.1  jtc 
    436  1.1  jtc 	mvaddstr(14, 14, "Type '1' to keep >");
    437  1.1  jtc 	ch = getanswer(" ", TRUE);
    438  1.1  jtc 	}
    439  1.1  jtc     while (ch != '1');
    440  1.1  jtc 
    441  1.1  jtc     if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
    442  1.1  jtc 	/* get coordinates for experimento */
    443  1.1  jtc 	for (;;)
    444  1.1  jtc 	    {
    445  1.1  jtc 	    mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
    446  1.1  jtc 	    getstring(Databuf, SZ_DATABUF);
    447  1.1  jtc 	    sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y);
    448  1.1  jtc 
    449  1.1  jtc 	    if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER)
    450  1.1  jtc 		mvaddstr(17, 0, "Invalid coordinates.  Try again.\n");
    451  1.1  jtc 	    else
    452  1.1  jtc 		break;
    453  1.1  jtc 	    }
    454  1.1  jtc 
    455  1.1  jtc     for (;;)
    456  1.1  jtc 	/* name the new character */
    457  1.1  jtc 	{
    458  1.1  jtc 	mvprintw(18, 0,
    459  1.1  jtc 	    "Give your character a name [up to %d characters] ?  ", SZ_NAME - 1);
    460  1.1  jtc 	getstring(Player.p_name, SZ_NAME);
    461  1.1  jtc 	truncstring(Player.p_name);		/* remove trailing blanks */
    462  1.1  jtc 
    463  1.1  jtc 	if (Player.p_name[0] == '\0')
    464  1.1  jtc 	    /* no null names */
    465  1.1  jtc 	    mvaddstr(19, 0, "Invalid name.");
    466  1.1  jtc 	else if (findname(Player.p_name, &Other) >= 0L)
    467  1.1  jtc 	    /* cannot have duplicate names */
    468  1.1  jtc 	    mvaddstr(19, 0, "Name already in use.");
    469  1.1  jtc 	else
    470  1.1  jtc 	    /* name is acceptable */
    471  1.1  jtc 	    break;
    472  1.1  jtc 
    473  1.1  jtc 	addstr("  Pick another.\n");
    474  1.1  jtc 	}
    475  1.1  jtc 
    476  1.1  jtc     /* get a password for character */
    477  1.1  jtc     Echo = FALSE;
    478  1.1  jtc 
    479  1.1  jtc     do
    480  1.1  jtc 	{
    481  1.1  jtc 	mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
    482  1.1  jtc 	getstring(Player.p_password, SZ_PASSWORD);
    483  1.1  jtc 	mvaddstr(21, 0, "One more time to verify ? ");
    484  1.1  jtc 	getstring(Databuf, SZ_PASSWORD);
    485  1.1  jtc 	}
    486  1.1  jtc     while (strcmp(Player.p_password, Databuf) != 0);
    487  1.1  jtc 
    488  1.1  jtc     Echo = TRUE;
    489  1.1  jtc 
    490  1.1  jtc     return(allocrecord());
    491  1.1  jtc }
    492  1.1  jtc /**/
    494  1.1  jtc /************************************************************************
    495  1.1  jtc /
    496  1.1  jtc / FUNCTION NAME: procmain()
    497  1.1  jtc /
    498  1.1  jtc / FUNCTION: process input from player
    499  1.1  jtc /
    500  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    501  1.1  jtc /
    502  1.1  jtc / ARGUMENTS: none
    503  1.1  jtc /
    504  1.1  jtc / RETURN VALUE: none
    505  1.1  jtc /
    506  1.1  jtc / MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(),
    507  1.1  jtc /	fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(),
    508  1.1  jtc /	waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(),
    509  1.1  jtc /	getstring(), wclrtobot()
    510  1.1  jtc /
    511  1.1  jtc / GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
    512  1.1  jtc /	Databuf[], Illmove[]
    513  1.1  jtc /
    514  1.1  jtc / GLOBAL OUTPUTS: Player, Changed
    515  1.1  jtc /
    516  1.1  jtc / DESCRIPTION:
    517  1.1  jtc /	Process main menu options.
    518  1.1  jtc /
    519  1.1  jtc /************************************************************************/
    520  1.1  jtc 
    521  1.1  jtc procmain()
    522  1.1  jtc {
    523  1.1  jtc int	ch;			/* input */
    524  1.1  jtc double	x;			/* desired new x coordinate */
    525  1.1  jtc double	y;			/* desired new y coordinate */
    526  1.1  jtc double	temp;			/* for temporary calculations */
    527  1.1  jtc FILE	*fp;			/* for opening files */
    528  1.1  jtc register int	loop;		/* a loop counter */
    529  1.1  jtc bool	hasmoved = FALSE;	/* set if player has moved */
    530  1.1  jtc 
    531  1.1  jtc     ch = inputoption();
    532  1.1  jtc     mvaddstr(4, 0, "\n\n");		/* clear status area */
    533  1.1  jtc 
    534  1.1  jtc     move(7, 0);
    535  1.1  jtc     clrtobot();			/* clear data on bottom area of screen */
    536  1.1  jtc 
    537  1.1  jtc     if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7'))
    538  1.1  jtc 	/* valar cannot move */
    539  1.1  jtc 	ch = ' ';
    540  1.1  jtc 
    541  1.1  jtc     switch (ch)
    542  1.1  jtc 	{
    543  1.1  jtc 	case 'K':		/* move up/north */
    544  1.1  jtc 	case 'N':
    545  1.1  jtc 	    x = Player.p_x;
    546  1.1  jtc 	    y = Player.p_y + MAXMOVE();
    547  1.1  jtc 	    hasmoved = TRUE;
    548  1.1  jtc 	    break;
    549  1.1  jtc 
    550  1.1  jtc 	case 'J':		/* move down/south */
    551  1.1  jtc 	case 'S':
    552  1.1  jtc 	    x = Player.p_x;
    553  1.1  jtc 	    y = Player.p_y - MAXMOVE();
    554  1.1  jtc 	    hasmoved = TRUE;
    555  1.1  jtc 	    break;
    556  1.1  jtc 
    557  1.1  jtc 	case 'L':		/* move right/east */
    558  1.1  jtc 	case 'E':
    559  1.1  jtc 	    x = Player.p_x + MAXMOVE();
    560  1.1  jtc 	    y = Player.p_y;
    561  1.1  jtc 	    hasmoved = TRUE;
    562  1.1  jtc 	    break;
    563  1.1  jtc 
    564  1.1  jtc 	case 'H':		/* move left/west */
    565  1.1  jtc 	case 'W':
    566  1.1  jtc 	    x = Player.p_x - MAXMOVE();
    567  1.1  jtc 	    y = Player.p_y;
    568  1.1  jtc 	    hasmoved = TRUE;
    569  1.1  jtc 	    break;
    570  1.1  jtc 
    571  1.1  jtc 	default:    /* rest */
    572  1.1  jtc 	    Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0
    573  1.1  jtc 		+ Player.p_level / 3.0 + 2.0;
    574  1.1  jtc 	    Player.p_energy =
    575  1.1  jtc 		MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield);
    576  1.1  jtc 
    577  1.1  jtc 	    if (Player.p_status != S_CLOAKED)
    578  1.1  jtc 		/* cannot find mana if cloaked */
    579  1.1  jtc 		{
    580  1.1  jtc 		Player.p_mana += (Circle + Player.p_level) / 4.0;
    581  1.1  jtc 
    582  1.1  jtc 		if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
    583  1.1  jtc 		    /* wandering monster */
    584  1.1  jtc 		    encounter(-1);
    585  1.1  jtc 		}
    586  1.1  jtc 	    break;
    587  1.1  jtc 
    588  1.1  jtc 	case 'X':		/* change/examine a character */
    589  1.1  jtc 	    changestats(TRUE);
    590  1.1  jtc 	    break;
    591  1.1  jtc 
    592  1.1  jtc 	case '1':		/* move */
    593  1.1  jtc 	    for (loop = 3; loop; --loop)
    594  1.1  jtc 		{
    595  1.1  jtc 		mvaddstr(4, 0, "X Y Coordinates ? ");
    596  1.1  jtc 		getstring(Databuf, SZ_DATABUF);
    597  1.1  jtc 
    598  1.1  jtc 		if (sscanf(Databuf, "%lf %lf", &x, &y) != 2)
    599  1.1  jtc 		    mvaddstr(5, 0, "Try again\n");
    600  1.1  jtc 		else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE())
    601  1.1  jtc 		    ILLMOVE();
    602  1.1  jtc 		else
    603  1.1  jtc 		    {
    604  1.1  jtc 		    hasmoved = TRUE;
    605  1.1  jtc 		    break;
    606  1.1  jtc 		    }
    607  1.1  jtc 		}
    608  1.1  jtc 	    break;
    609  1.1  jtc 
    610  1.1  jtc 	case '2':		/* players */
    611  1.1  jtc 	    userlist(TRUE);
    612  1.1  jtc 	    break;
    613  1.1  jtc 
    614  1.1  jtc 	case '3':		/* message */
    615  1.1  jtc 	    mvaddstr(4, 0, "Message ? ");
    616  1.1  jtc 	    getstring(Databuf, SZ_DATABUF);
    617  1.1  jtc 	    /* we open the file for writing to erase any data which is already there */
    618  1.1  jtc 	    fp = fopen(_PATH_MESS, "w");
    619  1.1  jtc 	    if (Databuf[0] != '\0')
    620  1.1  jtc 		fprintf(fp, "%s: %s", Player.p_name, Databuf);
    621  1.1  jtc 	    fclose(fp);
    622  1.1  jtc 	    break;
    623  1.1  jtc 
    624  1.1  jtc 	case '4':		/* stats */
    625  1.1  jtc 	    allstatslist();
    626  1.1  jtc 	    break;
    627  1.1  jtc 
    628  1.1  jtc 	case '5':		/* good-bye */
    629  1.1  jtc 	    leavegame();
    630  1.1  jtc 	    /*NOTREACHED*/
    631  1.1  jtc 
    632  1.1  jtc 	case '6':		/* cloak */
    633  1.1  jtc 	    if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK)
    634  1.1  jtc 		ILLCMD();
    635  1.1  jtc 	    else if (Player.p_status == S_CLOAKED)
    636  1.1  jtc 		Player.p_status = S_PLAYING;
    637  1.1  jtc 	    else if (Player.p_mana < MM_CLOAK)
    638  1.1  jtc 		mvaddstr(5, 0, "No mana left.\n");
    639  1.1  jtc 	    else
    640  1.1  jtc 		{
    641  1.1  jtc 		Changed = TRUE;
    642  1.1  jtc 		Player.p_mana -= MM_CLOAK;
    643  1.1  jtc 		Player.p_status = S_CLOAKED;
    644  1.1  jtc 		}
    645  1.1  jtc 	    break;
    646  1.1  jtc 
    647  1.1  jtc 	case '7':	/* teleport */
    648  1.1  jtc 	    /*
    649  1.1  jtc 	     * conditions for teleport
    650  1.1  jtc 	     *	- 20 per (level plus magic level)
    651  1.1  jtc 	     *	- OR council of the wise or valar or ex-valar
    652  1.1  jtc 	     *	- OR transport from throne
    653  1.1  jtc 	     * transports from throne cost no mana
    654  1.1  jtc 	     */
    655  1.1  jtc 	    if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT)
    656  1.1  jtc 		ILLCMD();
    657  1.1  jtc 	    else
    658  1.1  jtc 		for (loop = 3; loop; --loop)
    659  1.1  jtc 		    {
    660  1.1  jtc 		    mvaddstr(4, 0, "X Y Coordinates ? ");
    661  1.1  jtc 		    getstring(Databuf, SZ_DATABUF);
    662  1.1  jtc 
    663  1.1  jtc 		    if (sscanf(Databuf, "%lf %lf", &x, &y) == 2)
    664  1.1  jtc 			{
    665  1.1  jtc 			temp = distance(Player.p_x, x, Player.p_y, y);
    666  1.1  jtc 			if (!Throne
    667  1.1  jtc 			    /* can transport anywhere from throne */
    668  1.1  jtc 			    && Player.p_specialtype <= SC_COUNCIL
    669  1.1  jtc 			    /* council, valar can transport anywhere */
    670  1.1  jtc 			    && temp > (Player.p_level + Player.p_magiclvl) * 20.0)
    671  1.1  jtc 			    /* can only move 20 per exp. level + mag. level */
    672  1.1  jtc 			    ILLMOVE();
    673  1.1  jtc 			else
    674  1.1  jtc 			    {
    675  1.1  jtc 			    temp = (temp / 75.0 + 1.0) * 20.0;	/* mana used */
    676  1.1  jtc 
    677  1.1  jtc 			    if (!Throne && temp > Player.p_mana)
    678  1.1  jtc 				mvaddstr(5, 0, "Not enough power for that distance.\n");
    679  1.1  jtc 			    else
    680  1.1  jtc 				{
    681  1.1  jtc 				if (!Throne)
    682  1.1  jtc 				    Player.p_mana -= temp;
    683  1.1  jtc 				hasmoved = TRUE;
    684  1.1  jtc 				break;
    685  1.1  jtc 				}
    686  1.1  jtc 			    }
    687  1.1  jtc 			}
    688  1.1  jtc 		    }
    689  1.1  jtc 	    break;
    690  1.1  jtc 
    691  1.1  jtc 	case 'C':
    692  1.1  jtc 	case '9':		/* monster */
    693  1.1  jtc 	    if (Throne)
    694  1.1  jtc 		/* no monsters while on throne */
    695  1.1  jtc 		mvaddstr(5, 0, "No monsters in the chamber!\n");
    696  1.1  jtc 	    else if (Player.p_specialtype != SC_VALAR)
    697  1.1  jtc 		/* the valar cannot call monsters */
    698  1.1  jtc 		{
    699  1.1  jtc 		Player.p_sin += 1e-6;
    700  1.1  jtc 		encounter(-1);
    701  1.1  jtc 		}
    702  1.1  jtc 	    break;
    703  1.1  jtc 
    704  1.1  jtc 	case '0':		/* decree */
    705  1.1  jtc 	    if (Wizard || Player.p_specialtype == SC_KING && Throne)
    706  1.1  jtc 		/* kings must be on throne to decree */
    707  1.1  jtc 		dotampered();
    708  1.1  jtc 	    else
    709  1.1  jtc 		ILLCMD();
    710  1.1  jtc 	    break;
    711  1.1  jtc 
    712  1.1  jtc 	case '8':		/* intervention */
    713  1.1  jtc 	    if (Wizard || Player.p_specialtype >= SC_COUNCIL)
    714  1.1  jtc 		dotampered();
    715  1.1  jtc 	    else
    716  1.1  jtc 		ILLCMD();
    717  1.1  jtc 	    break;
    718  1.1  jtc 	}
    719  1.1  jtc 
    720  1.1  jtc     if (hasmoved)
    721  1.1  jtc 	/* player has moved -- alter coordinates, and do random monster */
    722  1.1  jtc 	{
    723  1.1  jtc 	altercoordinates(x, y, A_SPECIFIC);
    724  1.1  jtc 
    725  1.1  jtc 	if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
    726  1.1  jtc 	    encounter(-1);
    727  1.1  jtc 	}
    728  1.1  jtc }
    729  1.1  jtc /**/
    731  1.1  jtc /************************************************************************
    732  1.1  jtc /
    733  1.1  jtc / FUNCTION NAME: titlelist()
    734  1.1  jtc /
    735  1.1  jtc / FUNCTION: print title page
    736  1.1  jtc /
    737  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    738  1.1  jtc /
    739  1.1  jtc / ARGUMENTS: none
    740  1.1  jtc /
    741  1.1  jtc / RETURN VALUE: none
    742  1.1  jtc /
    743  1.1  jtc / MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(),
    744  1.1  jtc /	fclose(), strlen(), waddstr(), sprintf(), wrefresh()
    745  1.1  jtc /
    746  1.1  jtc / GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
    747  1.1  jtc /
    748  1.1  jtc / GLOBAL OUTPUTS: Lines
    749  1.1  jtc /
    750  1.1  jtc / DESCRIPTION:
    751  1.1  jtc /	Print important information about game, players, etc.
    752  1.1  jtc /
    753  1.1  jtc /************************************************************************/
    754  1.1  jtc 
    755  1.1  jtc titlelist()
    756  1.1  jtc {
    757  1.1  jtc register FILE	*fp;		/* used for opening various files */
    758  1.1  jtc bool	councilfound = FALSE;	/* set if we find a member of the council */
    759  1.1  jtc bool	kingfound = FALSE;	/* set if we find a king */
    760  1.1  jtc double	hiexp, nxtexp;		/* used for finding the two highest players */
    761  1.1  jtc double	hilvl, nxtlvl;		/* used for finding the two highest players */
    762  1.1  jtc char	hiname[21], nxtname[21];/* used for finding the two highest players */
    763  1.1  jtc 
    764  1.1  jtc     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)!");
    765  1.1  jtc 
    766  1.1  jtc     /* print message of the day */
    767  1.1  jtc     if ((fp = fopen(_PATH_MOTD, "r")) != NULL
    768  1.1  jtc 	&& fgets(Databuf, SZ_DATABUF, fp) != NULL)
    769  1.1  jtc 	{
    770  1.1  jtc 	mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf);
    771  1.1  jtc 	fclose(fp);
    772  1.1  jtc 	}
    773  1.1  jtc 
    774  1.1  jtc     /* search for king */
    775  1.1  jtc     fseek(Playersfp, 0L, 0);
    776  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    777  1.1  jtc 	if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
    778  1.1  jtc 	    /* found the king */
    779  1.1  jtc 	    {
    780  1.1  jtc 	    sprintf(Databuf, "The present ruler is %s  Level:%.0f",
    781  1.1  jtc 		Other.p_name, Other.p_level);
    782  1.1  jtc 	    mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf);
    783  1.1  jtc 	    kingfound = TRUE;
    784  1.1  jtc 	    break;
    785  1.1  jtc 	    }
    786  1.1  jtc 
    787  1.1  jtc     if (!kingfound)
    788  1.1  jtc 	mvaddstr(4, 24, "There is no ruler at this time.");
    789  1.1  jtc 
    790  1.1  jtc     /* search for valar */
    791  1.1  jtc     fseek(Playersfp, 0L, 0);
    792  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    793  1.1  jtc 	if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
    794  1.1  jtc 	    /* found the valar */
    795  1.1  jtc 	    {
    796  1.1  jtc 	    sprintf(Databuf, "The Valar is %s   Login:  %s", Other.p_name, Other.p_login);
    797  1.1  jtc 	    mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf);
    798  1.1  jtc 	    break;
    799  1.1  jtc 	    }
    800  1.1  jtc 
    801  1.1  jtc     /* search for council of the wise */
    802  1.1  jtc     fseek(Playersfp, 0L, 0);
    803  1.1  jtc     Lines = 10;
    804  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    805  1.1  jtc 	if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED)
    806  1.1  jtc 	    /* found a member of the council */
    807  1.1  jtc 	    {
    808  1.1  jtc 	    if (!councilfound)
    809  1.1  jtc 		{
    810  1.1  jtc 		mvaddstr(8, 30, "Council of the Wise:");
    811  1.1  jtc 		councilfound = TRUE;
    812  1.1  jtc 		}
    813  1.1  jtc 
    814  1.1  jtc 	    /* This assumes a finite (<=5) number of C.O.W.: */
    815  1.1  jtc 	    sprintf(Databuf, "%s   Login:  %s", Other.p_name, Other.p_login);
    816  1.1  jtc 	    mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf);
    817  1.1  jtc 	    }
    818  1.1  jtc 
    819  1.1  jtc     /* search for the two highest players */
    820  1.1  jtc     nxtname[0] = hiname[0] = '\0';
    821  1.1  jtc     hiexp = 0.0;
    822  1.1  jtc     nxtlvl = hilvl = 0;
    823  1.1  jtc 
    824  1.1  jtc     fseek(Playersfp, 0L, 0);
    825  1.1  jtc     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
    826  1.1  jtc 	if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED)
    827  1.1  jtc 	    /* highest found so far */
    828  1.1  jtc 	    {
    829  1.1  jtc 	    nxtexp = hiexp;
    830  1.1  jtc 	    hiexp = Other.p_experience;
    831  1.1  jtc 	    nxtlvl = hilvl;
    832  1.1  jtc 	    hilvl = Other.p_level;
    833  1.1  jtc 	    strcpy(nxtname, hiname);
    834  1.1  jtc 	    strcpy(hiname, Other.p_name);
    835  1.1  jtc 	    }
    836  1.1  jtc 	else if (Other.p_experience > nxtexp
    837  1.1  jtc 	    && Other.p_specialtype <= SC_KING
    838  1.1  jtc 	    && Other.p_status != S_NOTUSED)
    839  1.1  jtc 	    /* next highest found so far */
    840  1.1  jtc 	    {
    841  1.1  jtc 	    nxtexp = Other.p_experience;
    842  1.1  jtc 	    nxtlvl = Other.p_level;
    843  1.1  jtc 	    strcpy(nxtname, Other.p_name);
    844  1.1  jtc 	    }
    845  1.1  jtc 
    846  1.1  jtc     mvaddstr(15, 28, "Highest characters are:");
    847  1.1  jtc     sprintf(Databuf, "%s  Level:%.0f   and   %s  Level:%.0f",
    848  1.1  jtc 	hiname, hilvl, nxtname, nxtlvl);
    849  1.1  jtc     mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf);
    850  1.1  jtc 
    851  1.1  jtc     /* print last to die */
    852  1.1  jtc     if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL
    853  1.1  jtc 	&& fgets(Databuf, SZ_DATABUF, fp) != NULL)
    854  1.1  jtc 	{
    855  1.1  jtc 	mvaddstr(19, 25, "The last character to die was:");
    856  1.1  jtc 	mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf);
    857  1.1  jtc 	fclose(fp);
    858  1.1  jtc 	}
    859  1.1  jtc 
    860  1.1  jtc     refresh();
    861  1.1  jtc }
    862  1.1  jtc /**/
    864  1.1  jtc /************************************************************************
    865  1.1  jtc /
    866  1.1  jtc / FUNCTION NAME: recallplayer()
    867  1.1  jtc /
    868  1.1  jtc / FUNCTION: find a character on file
    869  1.1  jtc /
    870  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
    871  1.1  jtc /
    872  1.1  jtc / ARGUMENTS: none
    873  1.1  jtc /
    874  1.1  jtc / RETURN VALUE: none
    875  1.1  jtc /
    876  1.1  jtc / MODULES CALLED: writerecord(), truncstring(), more(), death(), wmove(),
    877  1.1  jtc /	wclear(), strcmp(), printw(), cleanup(), waddstr(), findname(), mvprintw(),
    878  1.1  jtc /	getanswer(), getstring()
    879  1.1  jtc /
    880  1.1  jtc / GLOBAL INPUTS: Player, *stdscr, Databuf[]
    881  1.1  jtc /
    882  1.1  jtc / GLOBAL OUTPUTS: Echo, Player
    883  1.1  jtc /
    884  1.1  jtc / DESCRIPTION:
    885  1.1  jtc /	Search for a character of a certain name, and check password.
    886  1.1  jtc /
    887  1.1  jtc /************************************************************************/
    888  1.1  jtc 
    889  1.1  jtc long
    890  1.1  jtc recallplayer()
    891  1.1  jtc {
    892  1.1  jtc long	loc = 0L;		/* location in player file */
    893  1.1  jtc register int	loop;		/* loop counter */
    894  1.1  jtc int	ch;			/* input */
    895  1.1  jtc 
    896  1.1  jtc     clear();
    897  1.1  jtc     mvprintw(10, 0, "What was your character's name ? ");
    898  1.1  jtc     getstring(Databuf, SZ_NAME);
    899  1.1  jtc     truncstring(Databuf);
    900  1.1  jtc 
    901  1.1  jtc     if ((loc = findname(Databuf, &Player)) >= 0L)
    902  1.1  jtc 	/* found character */
    903  1.1  jtc 	{
    904  1.1  jtc 	Echo = FALSE;
    905  1.1  jtc 
    906  1.1  jtc 	for (loop = 0; loop < 2; ++loop)
    907  1.1  jtc 	    {
    908  1.1  jtc 	    /* prompt for password */
    909  1.1  jtc 	    mvaddstr(11, 0, "Password ? ");
    910  1.1  jtc 	    getstring(Databuf, SZ_PASSWORD);
    911  1.1  jtc 	    if (strcmp(Databuf, Player.p_password) == 0)
    912  1.1  jtc 		/* password good */
    913  1.1  jtc 		{
    914  1.1  jtc 		Echo = TRUE;
    915  1.1  jtc 
    916  1.1  jtc 		if (Player.p_status != S_OFF)
    917  1.1  jtc 		    /* player did not exit normally last time */
    918  1.1  jtc 		    {
    919  1.1  jtc 		    clear();
    920  1.1  jtc 		    addstr("Your character did not exit normally last time.\n");
    921  1.1  jtc 		    addstr("If you think you have good cause to have your character saved,\n");
    922  1.1  jtc 		    printw("you may quit and mail your reason to 'root'.\n");
    923  1.1  jtc 		    addstr("Otherwise, continuing spells certain death.\n");
    924  1.1  jtc 		    addstr("Do you want to quit ? ");
    925  1.1  jtc 		    ch = getanswer("YN", FALSE);
    926  1.1  jtc 		    if (ch == 'Y')
    927  1.1  jtc 			{
    928  1.1  jtc 			Player.p_status = S_HUNGUP;
    929  1.1  jtc 			writerecord(&Player, loc);
    930  1.1  jtc 			cleanup(TRUE);
    931  1.1  jtc 			/*NOTREACHED*/
    932  1.1  jtc 			}
    933  1.1  jtc 		    death("Stupidity");
    934  1.1  jtc 		    /*NOTREACHED*/
    935  1.1  jtc 		    }
    936  1.1  jtc 		return(loc);
    937  1.1  jtc 		}
    938  1.1  jtc 	    else
    939  1.1  jtc 		mvaddstr(12, 0, "No good.\n");
    940  1.1  jtc 	    }
    941  1.1  jtc 
    942  1.1  jtc 	Echo = TRUE;
    943  1.1  jtc 	}
    944  1.1  jtc     else
    945  1.1  jtc 	mvaddstr(11, 0, "Not found.\n");
    946  1.1  jtc 
    947  1.1  jtc     more(13);
    948  1.1  jtc     return(-1L);
    949  1.1  jtc }
    950  1.1  jtc /**/
    952  1.1  jtc /************************************************************************
    953  1.1  jtc /
    954  1.1  jtc / FUNCTION NAME: neatstuff()
    955  1.1  jtc /
    956  1.1  jtc / FUNCTION: do random stuff
    957  1.1  jtc /
    958  1.1  jtc / AUTHOR: E. A. Estes, 3/3/86
    959  1.1  jtc /
    960  1.1  jtc / ARGUMENTS: none
    961  1.1  jtc /
    962  1.1  jtc / RETURN VALUE: none
    963  1.1  jtc /
    964  1.1  jtc / MODULES CALLED: collecttaxes(), floor(), wmove(), drandom(), infloat(),
    965  1.1  jtc /	waddstr(), mvprintw(), getanswer()
    966  1.1  jtc /
    967  1.1  jtc / GLOBAL INPUTS: Player, *stdscr, *Statptr
    968  1.1  jtc /
    969  1.1  jtc / GLOBAL OUTPUTS: Player
    970  1.1  jtc /
    971  1.1  jtc / DESCRIPTION:
    972  1.1  jtc /	Handle gurus, medics, etc.
    973  1.1  jtc /
    974  1.1  jtc /************************************************************************/
    975  1.1  jtc 
    976  1.1  jtc neatstuff()
    977  1.1  jtc {
    978  1.1  jtc double	temp;	/* for temporary calculations */
    979  1.1  jtc int	ch;	/* input */
    980  1.1  jtc 
    981  1.1  jtc     switch ((int) ROLL(0.0, 100.0))
    982  1.1  jtc 	{
    983  1.1  jtc 	case 1:
    984  1.1  jtc 	case 2:
    985  1.1  jtc 	    if (Player.p_poison > 0.0)
    986  1.1  jtc 		{
    987  1.1  jtc 		mvaddstr(4, 0, "You've found a medic!  How much will you offer to be cured ? ");
    988  1.1  jtc 		temp = floor(infloat());
    989  1.1  jtc 		if (temp < 0.0 || temp > Player.p_gold)
    990  1.1  jtc 		    /* negative gold, or more than available */
    991  1.1  jtc 		    {
    992  1.1  jtc 		    mvaddstr(6, 0, "He was not amused, and made you worse.\n");
    993  1.1  jtc 		    Player.p_poison += 1.0;
    994  1.1  jtc 		    }
    995  1.1  jtc 		else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1))
    996  1.1  jtc 		    /* medic wants 1/2 of available gold */
    997  1.1  jtc 		    mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
    998  1.1  jtc 		else
    999  1.1  jtc 		    {
   1000  1.1  jtc 		    mvaddstr(5, 0, "He accepted.");
   1001  1.1  jtc 		    Player.p_poison = MAX(0.0, Player.p_poison - 1.0);
   1002  1.1  jtc 		    Player.p_gold -= temp;
   1003  1.1  jtc 		    }
   1004  1.1  jtc 		}
   1005  1.1  jtc 	    break;
   1006  1.1  jtc 
   1007  1.1  jtc 	case 3:
   1008  1.1  jtc 	    mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
   1009  1.1  jtc 	    Player.p_experience += 4000.0;
   1010  1.1  jtc 	    Player.p_sin += 0.5;
   1011  1.1  jtc 	    break;
   1012  1.1  jtc 
   1013  1.1  jtc 	case 4:
   1014  1.1  jtc 	    temp = ROLL(10.0, 75.0);
   1015  1.1  jtc 	    mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp);
   1016  1.1  jtc 	    ch = getanswer("NY", FALSE);
   1017  1.1  jtc 
   1018  1.1  jtc 	    if (ch == 'Y')
   1019  1.1  jtc 		collecttaxes(temp, 0.0);
   1020  1.1  jtc 	    break;
   1021  1.1  jtc 
   1022  1.1  jtc 	case 5:
   1023  1.1  jtc 	    if (Player.p_sin > 1.0)
   1024  1.1  jtc 		{
   1025  1.1  jtc 		mvaddstr(4, 0, "You've found a Holy Orb!\n");
   1026  1.1  jtc 		Player.p_sin -= 0.25;
   1027  1.1  jtc 		}
   1028  1.1  jtc 	    break;
   1029  1.1  jtc 
   1030  1.1  jtc 	case 6:
   1031  1.1  jtc 	    if (Player.p_poison < 1.0)
   1032  1.1  jtc 		{
   1033  1.1  jtc 		mvaddstr(4, 0, "You've been hit with a plague!\n");
   1034  1.1  jtc 		Player.p_poison += 1.0;
   1035  1.1  jtc 		}
   1036  1.1  jtc 	    break;
   1037  1.1  jtc 
   1038  1.1  jtc 	case 7:
   1039  1.1  jtc 	    mvaddstr(4, 0, "You've found some holy water.\n");
   1040  1.1  jtc 	    ++Player.p_holywater;
   1041  1.1  jtc 	    break;
   1042  1.1  jtc 
   1043  1.1  jtc 	case 8:
   1044  1.1  jtc 	    mvaddstr(4, 0, "You've met a Guru. . .");
   1045  1.1  jtc 	    if (drandom() * Player.p_sin > 1.0)
   1046  1.1  jtc 		addstr("You disgusted him with your sins!\n");
   1047  1.1  jtc 	    else if (Player.p_poison > 0.0)
   1048  1.1  jtc 		{
   1049  1.1  jtc 		addstr("He looked kindly upon you, and cured you.\n");
   1050  1.1  jtc 		Player.p_poison = 0.0;
   1051  1.1  jtc 		}
   1052  1.1  jtc 	    else
   1053  1.1  jtc 		{
   1054  1.1  jtc 		addstr("He rewarded you for your virtue.\n");
   1055  1.1  jtc 		Player.p_mana += 50.0;
   1056  1.1  jtc 		Player.p_shield += 2.0;
   1057  1.1  jtc 		}
   1058  1.1  jtc 	    break;
   1059  1.1  jtc 
   1060  1.1  jtc 	case 9:
   1061  1.1  jtc 	    mvaddstr(4, 0, "You've found an amulet.\n");
   1062  1.1  jtc 	    ++Player.p_amulets;
   1063  1.1  jtc 	    break;
   1064  1.1  jtc 
   1065  1.1  jtc 	case 10:
   1066  1.1  jtc 	    if (Player.p_blindness)
   1067  1.1  jtc 		{
   1068  1.1  jtc 		mvaddstr(4, 0, "You've regained your sight!\n");
   1069  1.1  jtc 		Player.p_blindness = FALSE;
   1070  1.1  jtc 		}
   1071  1.1  jtc 	    break;
   1072  1.1  jtc 
   1073  1.1  jtc 	default:	/* deal with poison */
   1074  1.1  jtc 	    if (Player.p_poison > 0.0)
   1075  1.1  jtc 		{
   1076  1.1  jtc 		temp = Player.p_poison * Statptr->c_weakness
   1077  1.1  jtc 		    * Player.p_maxenergy / 600.0;
   1078  1.1  jtc 		if (Player.p_energy > Player.p_maxenergy / 10.0
   1079  1.1  jtc 		    && temp + 5.0 < Player.p_energy)
   1080  1.1  jtc 		    Player.p_energy -= temp;
   1081  1.1  jtc 		}
   1082  1.1  jtc 	    break;
   1083  1.1  jtc 	}
   1084  1.1  jtc }
   1085  1.1  jtc /**/
   1087  1.1  jtc /************************************************************************
   1088  1.1  jtc /
   1089  1.1  jtc / FUNCTION NAME: genchar()
   1090  1.1  jtc /
   1091  1.1  jtc / FUNCTION: generate a random character
   1092  1.1  jtc /
   1093  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
   1094  1.1  jtc /
   1095  1.1  jtc / ARGUMENTS:
   1096  1.1  jtc /	int type - ASCII value of character type to generate
   1097  1.1  jtc /
   1098  1.1  jtc / RETURN VALUE: none
   1099  1.1  jtc /
   1100  1.1  jtc / MODULES CALLED: floor(), drandom()
   1101  1.1  jtc /
   1102  1.1  jtc / GLOBAL INPUTS: Wizard, Player, Stattable[]
   1103  1.1  jtc /
   1104  1.1  jtc / GLOBAL OUTPUTS: Player
   1105  1.1  jtc /
   1106  1.1  jtc / DESCRIPTION:
   1107  1.1  jtc /	Use the lookup table for rolling stats.
   1108  1.1  jtc /
   1109  1.1  jtc /************************************************************************/
   1110  1.1  jtc 
   1111  1.1  jtc genchar(type)
   1112  1.1  jtc int	type;
   1113  1.1  jtc {
   1114  1.1  jtc register int	subscript;		/* used for subscripting into Stattable */
   1115  1.1  jtc register struct charstats	*statptr;/* for pointing into Stattable */
   1116  1.1  jtc 
   1117  1.1  jtc     subscript = type - '1';
   1118  1.1  jtc 
   1119  1.1  jtc     if (subscript < C_MAGIC || subscript > C_EXPER)
   1120  1.1  jtc 	if (subscript != C_SUPER || !Wizard)
   1121  1.1  jtc 	    /* fighter is default */
   1122  1.1  jtc 	    subscript = C_FIGHTER;
   1123  1.1  jtc 
   1124  1.1  jtc     statptr = &Stattable[subscript];
   1125  1.1  jtc 
   1126  1.1  jtc     Player.p_quickness =
   1127  1.1  jtc 	ROLL(statptr->c_quickness.base, statptr->c_quickness.interval);
   1128  1.1  jtc     Player.p_strength =
   1129  1.1  jtc 	ROLL(statptr->c_strength.base, statptr->c_strength.interval);
   1130  1.1  jtc     Player.p_mana =
   1131  1.1  jtc 	ROLL(statptr->c_mana.base, statptr->c_mana.interval);
   1132  1.1  jtc     Player.p_maxenergy =
   1133  1.1  jtc     Player.p_energy =
   1134  1.1  jtc 	ROLL(statptr->c_energy.base, statptr->c_energy.interval);
   1135  1.1  jtc     Player.p_brains =
   1136  1.1  jtc 	ROLL(statptr->c_brains.base, statptr->c_brains.interval);
   1137  1.1  jtc     Player.p_magiclvl =
   1138  1.1  jtc 	ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval);
   1139  1.1  jtc 
   1140  1.1  jtc     Player.p_type = subscript;
   1141  1.1  jtc 
   1142  1.1  jtc     if (Player.p_type == C_HALFLING)
   1143  1.1  jtc 	/* give halfling some experience */
   1144  1.1  jtc 	Player.p_experience = ROLL(600.0, 200.0);
   1145  1.1  jtc }
   1146  1.1  jtc /**/
   1148  1.1  jtc /************************************************************************
   1149  1.1  jtc /
   1150  1.1  jtc / FUNCTION NAME: playinit()
   1151  1.1  jtc /
   1152  1.1  jtc / FUNCTION: initialize for playing game
   1153  1.1  jtc /
   1154  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
   1155  1.1  jtc /
   1156  1.1  jtc / ARGUMENTS: none
   1157  1.1  jtc /
   1158  1.1  jtc / RETURN VALUE: none
   1159  1.1  jtc /
   1160  1.1  jtc / MODULES CALLED: signal(), wclear(), noecho(), crmode(), initscr(),
   1161  1.1  jtc /	wrefresh()
   1162  1.1  jtc /
   1163  1.1  jtc / GLOBAL INPUTS: *stdscr, ill_sig()
   1164  1.1  jtc /
   1165  1.1  jtc / GLOBAL OUTPUTS: Windows
   1166  1.1  jtc /
   1167  1.1  jtc / DESCRIPTION:
   1168  1.1  jtc /	Catch a bunch of signals, and turn on curses stuff.
   1169  1.1  jtc /
   1170  1.1  jtc /************************************************************************/
   1171  1.1  jtc 
   1172  1.1  jtc playinit()
   1173  1.1  jtc {
   1174  1.1  jtc     /* catch/ingnore signals */
   1175  1.1  jtc 
   1176  1.1  jtc #ifdef	BSD41
   1177  1.1  jtc     sigignore(SIGQUIT);
   1178  1.1  jtc     sigignore(SIGALRM);
   1179  1.1  jtc     sigignore(SIGTERM);
   1180  1.1  jtc     sigignore(SIGTSTP);
   1181  1.1  jtc     sigignore(SIGTTIN);
   1182  1.1  jtc     sigignore(SIGTTOU);
   1183  1.1  jtc     sighold(SIGINT);
   1184  1.1  jtc     sigset(SIGHUP, ill_sig);
   1185  1.1  jtc     sigset(SIGTRAP, ill_sig);
   1186  1.1  jtc     sigset(SIGIOT, ill_sig);
   1187  1.1  jtc     sigset(SIGEMT, ill_sig);
   1188  1.1  jtc     sigset(SIGFPE, ill_sig);
   1189  1.1  jtc     sigset(SIGBUS, ill_sig);
   1190  1.1  jtc     sigset(SIGSEGV, ill_sig);
   1191  1.1  jtc     sigset(SIGSYS, ill_sig);
   1192  1.1  jtc     sigset(SIGPIPE, ill_sig);
   1193  1.1  jtc #endif
   1194  1.1  jtc #ifdef	BSD42
   1195  1.1  jtc     signal(SIGQUIT, ill_sig);
   1196  1.1  jtc     signal(SIGALRM, SIG_IGN);
   1197  1.1  jtc     signal(SIGTERM, SIG_IGN);
   1198  1.1  jtc     signal(SIGTSTP, SIG_IGN);
   1199  1.1  jtc     signal(SIGTTIN, SIG_IGN);
   1200  1.1  jtc     signal(SIGTTOU, SIG_IGN);
   1201  1.1  jtc     signal(SIGINT, ill_sig);
   1202  1.1  jtc     signal(SIGHUP, SIG_DFL);
   1203  1.1  jtc     signal(SIGTRAP, ill_sig);
   1204  1.1  jtc     signal(SIGIOT, ill_sig);
   1205  1.1  jtc     signal(SIGEMT, ill_sig);
   1206  1.1  jtc     signal(SIGFPE, ill_sig);
   1207  1.1  jtc     signal(SIGBUS, ill_sig);
   1208  1.1  jtc     signal(SIGSEGV, ill_sig);
   1209  1.1  jtc     signal(SIGSYS, ill_sig);
   1210  1.1  jtc     signal(SIGPIPE, ill_sig);
   1211  1.1  jtc #endif
   1212  1.1  jtc #ifdef	SYS3
   1213  1.1  jtc     signal(SIGINT, SIG_IGN);
   1214  1.1  jtc     signal(SIGQUIT, SIG_IGN);
   1215  1.1  jtc     signal(SIGTERM, SIG_IGN);
   1216  1.1  jtc     signal(SIGALRM, SIG_IGN);
   1217  1.1  jtc     signal(SIGHUP, ill_sig);
   1218  1.1  jtc     signal(SIGTRAP, ill_sig);
   1219  1.1  jtc     signal(SIGIOT, ill_sig);
   1220  1.1  jtc     signal(SIGEMT, ill_sig);
   1221  1.1  jtc     signal(SIGFPE, ill_sig);
   1222  1.1  jtc     signal(SIGBUS, ill_sig);
   1223  1.1  jtc     signal(SIGSEGV, ill_sig);
   1224  1.1  jtc     signal(SIGSYS, ill_sig);
   1225  1.1  jtc     signal(SIGPIPE, ill_sig);
   1226  1.1  jtc #endif
   1227  1.1  jtc #ifdef	SYS5
   1228  1.1  jtc     signal(SIGINT, SIG_IGN);
   1229  1.1  jtc     signal(SIGQUIT, SIG_IGN);
   1230  1.1  jtc     signal(SIGTERM, SIG_IGN);
   1231  1.1  jtc     signal(SIGALRM, SIG_IGN);
   1232  1.1  jtc     signal(SIGHUP, ill_sig);
   1233  1.1  jtc     signal(SIGTRAP, ill_sig);
   1234  1.1  jtc     signal(SIGIOT, ill_sig);
   1235  1.1  jtc     signal(SIGEMT, ill_sig);
   1236  1.1  jtc     signal(SIGFPE, ill_sig);
   1237  1.1  jtc     signal(SIGBUS, ill_sig);
   1238  1.1  jtc     signal(SIGSEGV, ill_sig);
   1239  1.1  jtc     signal(SIGSYS, ill_sig);
   1240  1.1  jtc     signal(SIGPIPE, ill_sig);
   1241  1.1  jtc #endif
   1242  1.1  jtc 
   1243  1.1  jtc     initscr();		/* turn on curses */
   1244  1.1  jtc     noecho();		/* do not echo input */
   1245  1.1  jtc     crmode();		/* do not process erase, kill */
   1246  1.1  jtc     clear();
   1247  1.1  jtc     refresh();
   1248  1.1  jtc     Windows = TRUE;	/* mark the state */
   1249  1.1  jtc }
   1250  1.1  jtc 
   1251  1.1  jtc /**/
   1253  1.1  jtc /************************************************************************
   1254  1.1  jtc /
   1255  1.1  jtc / FUNCTION NAME: cleanup()
   1256  1.1  jtc /
   1257  1.1  jtc / FUNCTION: close some files, and maybe exit
   1258  1.1  jtc /
   1259  1.1  jtc / AUTHOR: E. A. Estes, 12/4/85
   1260  1.1  jtc /
   1261  1.1  jtc / ARGUMENTS:
   1262  1.1  jtc /	bool doexit - exit flag
   1263  1.1  jtc /
   1264  1.1  jtc / RETURN VALUE: none
   1265  1.1  jtc /
   1266  1.1  jtc / MODULES CALLED: exit(), wmove(), fclose(), endwin(), nocrmode(), wrefresh()
   1267  1.1  jtc /
   1268  1.1  jtc / GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
   1269  1.1  jtc /	*Messagefp, *Playersfp
   1270  1.1  jtc /
   1271  1.1  jtc / GLOBAL OUTPUTS: none
   1272  1.1  jtc /
   1273  1.1  jtc / DESCRIPTION:
   1274  1.1  jtc /	Close all open files.  If we are "in curses" terminate curses.
   1275  1.1  jtc /	If 'doexit' is set, exit, otherwise return.
   1276  1.1  jtc /
   1277  1.1  jtc /************************************************************************/
   1278  1.1  jtc 
   1279  1.1  jtc cleanup(doexit)
   1280  1.1  jtc bool	doexit;
   1281  1.1  jtc {
   1282  1.1  jtc     if (Windows)
   1283  1.1  jtc 	{
   1284  1.1  jtc 	move(LINES - 2, 0);
   1285  1.1  jtc 	refresh();
   1286  1.1  jtc 	nocrmode();
   1287  1.1  jtc 	endwin();
   1288  1.1  jtc 	}
   1289           
   1290               fclose(Playersfp);
   1291               fclose(Monstfp);
   1292               fclose(Messagefp);
   1293               fclose(Energyvoidfp);
   1294           
   1295               if (doexit)
   1296           	exit(0);
   1297           	/*NOTREACHED*/
   1298           }
   1299