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