2 * Phantasia 3.3.2 -- Interterminal fantasy game
7 * $FreeBSD: src/games/phantasia/main.c,v 1.8 1999/11/16 02:57:34 billf Exp $
12 * This game is distributed for free as is. It is not guaranteed to work
13 * in every conceivable environment. It is not even guaranteed to work
16 * This game is distributed without notice of copyright, therefore it
17 * may be used in any manner the recipient sees fit. However, the
18 * author assumes no responsibility for maintaining or revising this
19 * game, in its original form, or any derivitives thereof.
21 * The author shall not be responsible for any loss, cost, or damage,
22 * including consequential damage, caused by reliance on this material.
24 * The author makes no warranties, express or implied, including warranties
25 * of merchantability or fitness for a particular purpose or use.
27 * AT&T is in no way connected with this game.
30 #include <sys/types.h>
35 * The program allocates as much file space as it needs to store characters,
36 * so the possibility exists for the character file to grow without bound.
37 * The file is purged upon normal entry to try to avoid that problem.
38 * A similar problem exists for energy voids. To alleviate the problem here,
39 * the void file is cleared with every new king, and a limit is placed
40 * on the size of the energy void file.
44 * Put one line of text into the file 'motd' for announcements, etc.
48 * The scoreboard file is updated when someone dies, and keeps track
49 * of the highest character to date for that login.
50 * Being purged from the character file does not cause the scoreboard
55 * All source files are set up for 'vi' with shiftwidth=4, tabstop=8.
61 * main.c Main routines for Phantasia
66 /***************************************************************************
67 / FUNCTION NAME: main()
69 / FUNCTION: initialize state, and call main process
71 / AUTHOR: E. A. Estes, 12/4/85
74 / int argc - argument count
75 / char **argv - argument vector
79 / MODULES CALLED: monstlist(), checkenemy(), activelist(),
80 / throneroom(), checkbattle(), readmessage(), changestats(), writerecord(),
81 / tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(),
82 / fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(),
83 / signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(),
84 / strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(),
85 / playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(),
86 / scorelist(), titlelist()
88 / GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
89 / Fileloc, Stattable[]
91 / GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
94 / Process arguments, initialize program, and loop forever processing
97 ****************************************************************************/
103 bool noheader = FALSE; /* set if don't want header */
104 bool headeronly = FALSE; /* set if only want header */
105 bool examine = FALSE; /* set if examine a character */
106 time_t seconds; /* for time of day */
107 double dtemp; /* for temporary calculations */
109 initialstate(); /* init globals */
111 /* process arguments */
112 while (--argc && (*++argv)[0] == '-')
115 case 's': /* short */
119 case 'H': /* Header */
123 case 'a': /* all users */
128 case 'p': /* purge old players */
133 case 'S': /* set 'Wizard' */
137 case 'x': /* examine */
141 case 'm': /* monsters */
146 case 'b': /* scoreboard */
152 if (!isatty(0)) /* don't let non-tty's play */
156 playinit(); /* set up to catch signals, init curses */
168 purgeoldplayers(); /* clean up old characters */
176 /* get the player structure filled */
180 mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
182 switch (getanswer("NYQ", FALSE))
185 Fileloc = recallplayer();
193 Fileloc = rollnewplayer();
198 while (Fileloc < 0L);
200 if (Player.p_level > 5.0)
201 /* low level players have long timeout */
204 /* update some important player statistics */
205 strcpy(Player.p_login, Login);
207 Player.p_lastused = localtime(&seconds)->tm_yday;
208 Player.p_status = S_PLAYING;
209 writerecord(&Player, Fileloc);
211 Statptr = &Stattable[Player.p_type]; /* initialize pointer */
213 /* catch interrupts */
215 sigset(SIGINT, interrupt);
218 signal(SIGINT, interrupt);
221 signal(SIGINT, interrupt);
224 signal(SIGINT, interrupt);
227 altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */
232 /* loop forever, processing input */
235 adjuststats(); /* cleanup stats */
237 if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING)
238 /* not allowed on throne -- move */
240 mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n");
241 altercoordinates(0.0, 0.0, A_NEAR);
244 checktampered(); /* check for energy voids, etc. */
246 if (Player.p_status != S_CLOAKED
248 && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y)
253 dtemp = sqrt(dtemp / 100.0);
254 if (floor(dtemp) == dtemp)
255 /* |x| / 100 == n*n; at a trading post */
262 checkbattle(); /* check for player to player battle */
263 neatstuff(); /* gurus, medics, etc. */
265 if (Player.p_status == S_CLOAKED)
266 /* costs 3 mana per turn to be cloaked */
267 if (Player.p_mana > 3.0)
268 Player.p_mana -= 3.0;
270 /* ran out of mana, uncloak */
272 Player.p_status = S_PLAYING;
276 if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED)
277 /* change status back to S_PLAYING */
279 Player.p_status = S_PLAYING;
284 /* update file only if important stuff has changed */
286 writerecord(&Player, Fileloc);
291 readmessage(); /* read message, if any */
293 displaystats(); /* print statistics */
298 /* maybe make king, print prompt, etc. */
301 /* print status line */
302 addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit ");
303 if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK)
305 if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT)
306 addstr("7:Teleport ");
307 if (Player.p_specialtype >= SC_COUNCIL || Wizard)
308 addstr("8:Intervene ");
310 procmain(); /* process input */
314 /************************************************************************
316 / FUNCTION NAME: initialstate()
318 / FUNCTION: initialize some important global variable
320 / AUTHOR: E. A. Estes, 12/4/85
326 / MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(),
331 / GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
332 / Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
336 / Set global flags, and open files which remain open.
338 *************************************************************************/
352 /* setup login name */
353 if ((Login = getlogin()) == NULL)
354 Login = getpwuid(getuid())->pw_name;
356 /* open some files */
357 if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
361 if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL)
365 if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL)
369 if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL)
376 /************************************************************************
378 / FUNCTION NAME: rollnewplayer()
380 / FUNCTION: roll up a new character
382 / AUTHOR: E. A. Estes, 12/4/85
388 / MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(),
389 / wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(),
390 / getanswer(), getstring()
392 / GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
394 / GLOBAL OUTPUTS: Echo
397 / Prompt player, and roll up new character.
399 *************************************************************************/
404 int chartype; /* character type */
407 initplayer(&Player); /* initialize player structure */
410 mvaddstr(4, 21, "Which type of character do you want:");
411 mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento ");
413 addstr("7:Super ? ");
414 chartype = getanswer("1234567", FALSE);
418 chartype = getanswer("123456", FALSE);
423 genchar(chartype); /* roll up a character */
425 /* print out results */
427 "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n",
428 Player.p_strength, Player.p_quickness, Player.p_mana);
430 "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n",
431 Player.p_energy, Player.p_brains, Player.p_magiclvl);
433 if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
436 mvaddstr(14, 14, "Type '1' to keep >");
437 ch = getanswer(" ", TRUE);
441 if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
442 /* get coordinates for experimento */
445 mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
446 getstring(Databuf, SZ_DATABUF);
447 sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y);
449 if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER)
450 mvaddstr(17, 0, "Invalid coordinates. Try again.\n");
456 /* name the new character */
459 "Give your character a name [up to %d characters] ? ", SZ_NAME - 1);
460 getstring(Player.p_name, SZ_NAME);
461 truncstring(Player.p_name); /* remove trailing blanks */
463 if (Player.p_name[0] == '\0')
465 mvaddstr(19, 0, "Invalid name.");
466 else if (findname(Player.p_name, &Other) >= 0L)
467 /* cannot have duplicate names */
468 mvaddstr(19, 0, "Name already in use.");
470 /* name is acceptable */
473 addstr(" Pick another.\n");
476 /* get a password for character */
481 mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
482 getstring(Player.p_password, SZ_PASSWORD);
483 mvaddstr(21, 0, "One more time to verify ? ");
484 getstring(Databuf, SZ_PASSWORD);
486 while (strcmp(Player.p_password, Databuf) != 0);
490 return(allocrecord());
493 /************************************************************************
495 / FUNCTION NAME: procmain()
497 / FUNCTION: process input from player
499 / AUTHOR: E. A. Estes, 12/4/85
505 / MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(),
506 / fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(),
507 / waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(),
508 / getstring(), wclrtobot()
510 / GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
511 / Databuf[], Illmove[]
513 / GLOBAL OUTPUTS: Player, Changed
516 / Process main menu options.
518 *************************************************************************/
523 double x; /* desired new x coordinate */
524 double y; /* desired new y coordinate */
525 double temp; /* for temporary calculations */
526 FILE *fp; /* for opening files */
527 int loop; /* a loop counter */
528 bool hasmoved = FALSE; /* set if player has moved */
531 mvaddstr(4, 0, "\n\n"); /* clear status area */
534 clrtobot(); /* clear data on bottom area of screen */
536 if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7'))
537 /* valar cannot move */
542 case 'K': /* move up/north */
545 y = Player.p_y + MAXMOVE();
549 case 'J': /* move down/south */
552 y = Player.p_y - MAXMOVE();
556 case 'L': /* move right/east */
558 x = Player.p_x + MAXMOVE();
563 case 'H': /* move left/west */
565 x = Player.p_x - MAXMOVE();
571 Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0
572 + Player.p_level / 3.0 + 2.0;
574 MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield);
576 if (Player.p_status != S_CLOAKED)
577 /* cannot find mana if cloaked */
579 Player.p_mana += (Circle + Player.p_level) / 4.0;
581 if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
582 /* wandering monster */
587 case 'X': /* change/examine a character */
592 for (loop = 3; loop; --loop)
594 mvaddstr(4, 0, "X Y Coordinates ? ");
595 getstring(Databuf, SZ_DATABUF);
597 if (sscanf(Databuf, "%lf %lf", &x, &y) != 2)
598 mvaddstr(5, 0, "Try again\n");
599 else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE())
609 case '2': /* players */
613 case '3': /* message */
614 mvaddstr(4, 0, "Message ? ");
615 getstring(Databuf, SZ_DATABUF);
616 /* we open the file for writing to erase any data which is already there */
617 fp = fopen(_PATH_MESS, "w");
618 if (Databuf[0] != '\0')
619 fprintf(fp, "%s: %s", Player.p_name, Databuf);
623 case '4': /* stats */
627 case '5': /* good-bye */
631 case '6': /* cloak */
632 if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK)
634 else if (Player.p_status == S_CLOAKED)
635 Player.p_status = S_PLAYING;
636 else if (Player.p_mana < MM_CLOAK)
637 mvaddstr(5, 0, "No mana left.\n");
641 Player.p_mana -= MM_CLOAK;
642 Player.p_status = S_CLOAKED;
646 case '7': /* teleport */
648 * conditions for teleport
649 * - 20 per (level plus magic level)
650 * - OR council of the wise or valar or ex-valar
651 * - OR transport from throne
652 * transports from throne cost no mana
654 if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT)
657 for (loop = 3; loop; --loop)
659 mvaddstr(4, 0, "X Y Coordinates ? ");
660 getstring(Databuf, SZ_DATABUF);
662 if (sscanf(Databuf, "%lf %lf", &x, &y) == 2)
664 temp = distance(Player.p_x, x, Player.p_y, y);
666 /* can transport anywhere from throne */
667 && Player.p_specialtype <= SC_COUNCIL
668 /* council, valar can transport anywhere */
669 && temp > (Player.p_level + Player.p_magiclvl) * 20.0)
670 /* can only move 20 per exp. level + mag. level */
674 temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */
676 if (!Throne && temp > Player.p_mana)
677 mvaddstr(5, 0, "Not enough power for that distance.\n");
681 Player.p_mana -= temp;
691 case '9': /* monster */
693 /* no monsters while on throne */
694 mvaddstr(5, 0, "No monsters in the chamber!\n");
695 else if (Player.p_specialtype != SC_VALAR)
696 /* the valar cannot call monsters */
698 Player.p_sin += 1e-6;
703 case '0': /* decree */
704 if (Wizard || Player.p_specialtype == SC_KING && Throne)
705 /* kings must be on throne to decree */
711 case '8': /* intervention */
712 if (Wizard || Player.p_specialtype >= SC_COUNCIL)
720 /* player has moved -- alter coordinates, and do random monster */
722 altercoordinates(x, y, A_SPECIFIC);
724 if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
729 /************************************************************************
731 / FUNCTION NAME: titlelist()
733 / FUNCTION: print title page
735 / AUTHOR: E. A. Estes, 12/4/85
741 / MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(),
742 / fclose(), strlen(), waddstr(), sprintf(), wrefresh()
744 / GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
746 / GLOBAL OUTPUTS: Lines
749 / Print important information about game, players, etc.
751 *************************************************************************/
755 FILE *fp; /* used for opening various files */
756 bool councilfound = FALSE; /* set if we find a member of the council */
757 bool kingfound = FALSE; /* set if we find a king */
758 double hiexp, nxtexp; /* used for finding the two highest players */
759 double hilvl, nxtlvl; /* used for finding the two highest players */
760 char hiname[21], nxtname[21];/* used for finding the two highest players */
762 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)!");
764 /* print message of the day */
765 if ((fp = fopen(_PATH_MOTD, "r")) != NULL
766 && fgets(Databuf, SZ_DATABUF, fp) != NULL)
768 mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf);
772 /* search for king */
773 fseek(Playersfp, 0L, 0);
774 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
775 if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
778 sprintf(Databuf, "The present ruler is %s Level:%.0f",
779 Other.p_name, Other.p_level);
780 mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf);
786 mvaddstr(4, 24, "There is no ruler at this time.");
788 /* search for valar */
789 fseek(Playersfp, 0L, 0);
790 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
791 if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
792 /* found the valar */
794 sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login);
795 mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf);
799 /* search for council of the wise */
800 fseek(Playersfp, 0L, 0);
802 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
803 if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED)
804 /* found a member of the council */
808 mvaddstr(8, 30, "Council of the Wise:");
812 /* This assumes a finite (<=5) number of C.O.W.: */
813 sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login);
814 mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf);
817 /* search for the two highest players */
818 nxtname[0] = hiname[0] = '\0';
822 fseek(Playersfp, 0L, 0);
823 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
824 if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED)
825 /* highest found so far */
828 hiexp = Other.p_experience;
830 hilvl = Other.p_level;
831 strcpy(nxtname, hiname);
832 strcpy(hiname, Other.p_name);
834 else if (Other.p_experience > nxtexp
835 && Other.p_specialtype <= SC_KING
836 && Other.p_status != S_NOTUSED)
837 /* next highest found so far */
839 nxtexp = Other.p_experience;
840 nxtlvl = Other.p_level;
841 strcpy(nxtname, Other.p_name);
844 mvaddstr(15, 28, "Highest characters are:");
845 sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f",
846 hiname, hilvl, nxtname, nxtlvl);
847 mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf);
849 /* print last to die */
850 if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL
851 && fgets(Databuf, SZ_DATABUF, fp) != NULL)
853 mvaddstr(19, 25, "The last character to die was:");
854 mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf);
861 /************************************************************************
863 / FUNCTION NAME: recallplayer()
865 / FUNCTION: find a character on file
867 / AUTHOR: E. A. Estes, 12/4/85
873 / MODULES CALLED: writerecord(), truncstring(), more(), death(), wmove(),
874 / wclear(), strcmp(), printw(), cleanup(), waddstr(), findname(), mvprintw(),
875 / getanswer(), getstring()
877 / GLOBAL INPUTS: Player, *stdscr, Databuf[]
879 / GLOBAL OUTPUTS: Echo, Player
882 / Search for a character of a certain name, and check password.
884 *************************************************************************/
889 long loc = 0L; /* location in player file */
890 int loop; /* loop counter */
894 mvprintw(10, 0, "What was your character's name ? ");
895 getstring(Databuf, SZ_NAME);
896 truncstring(Databuf);
898 if ((loc = findname(Databuf, &Player)) >= 0L)
899 /* found character */
903 for (loop = 0; loop < 2; ++loop)
905 /* prompt for password */
906 mvaddstr(11, 0, "Password ? ");
907 getstring(Databuf, SZ_PASSWORD);
908 if (strcmp(Databuf, Player.p_password) == 0)
913 if (Player.p_status != S_OFF)
914 /* player did not exit normally last time */
917 addstr("Your character did not exit normally last time.\n");
918 addstr("If you think you have good cause to have your character saved,\n");
919 printw("you may quit and mail your reason to 'root'.\n");
920 addstr("Otherwise, continuing spells certain death.\n");
921 addstr("Do you want to quit ? ");
922 ch = getanswer("YN", FALSE);
925 Player.p_status = S_HUNGUP;
926 writerecord(&Player, loc);
936 mvaddstr(12, 0, "No good.\n");
942 mvaddstr(11, 0, "Not found.\n");
948 /************************************************************************
950 / FUNCTION NAME: neatstuff()
952 / FUNCTION: do random stuff
954 / AUTHOR: E. A. Estes, 3/3/86
960 / MODULES CALLED: collecttaxes(), floor(), wmove(), drandom(), infloat(),
961 / waddstr(), mvprintw(), getanswer()
963 / GLOBAL INPUTS: Player, *stdscr, *Statptr
965 / GLOBAL OUTPUTS: Player
968 / Handle gurus, medics, etc.
970 *************************************************************************/
974 double temp; /* for temporary calculations */
977 switch ((int) ROLL(0.0, 100.0))
981 if (Player.p_poison > 0.0)
983 mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? ");
984 temp = floor(infloat());
985 if (temp < 0.0 || temp > Player.p_gold)
986 /* negative gold, or more than available */
988 mvaddstr(6, 0, "He was not amused, and made you worse.\n");
989 Player.p_poison += 1.0;
991 else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1))
992 /* medic wants 1/2 of available gold */
993 mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
996 mvaddstr(5, 0, "He accepted.");
997 Player.p_poison = MAX(0.0, Player.p_poison - 1.0);
998 Player.p_gold -= temp;
1004 mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
1005 Player.p_experience += 4000.0;
1006 Player.p_sin += 0.5;
1010 temp = ROLL(10.0, 75.0);
1011 mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp);
1012 ch = getanswer("NY", FALSE);
1015 collecttaxes(temp, 0.0);
1019 if (Player.p_sin > 1.0)
1021 mvaddstr(4, 0, "You've found a Holy Orb!\n");
1022 Player.p_sin -= 0.25;
1027 if (Player.p_poison < 1.0)
1029 mvaddstr(4, 0, "You've been hit with a plague!\n");
1030 Player.p_poison += 1.0;
1035 mvaddstr(4, 0, "You've found some holy water.\n");
1036 ++Player.p_holywater;
1040 mvaddstr(4, 0, "You've met a Guru. . .");
1041 if (drandom() * Player.p_sin > 1.0)
1042 addstr("You disgusted him with your sins!\n");
1043 else if (Player.p_poison > 0.0)
1045 addstr("He looked kindly upon you, and cured you.\n");
1046 Player.p_poison = 0.0;
1050 addstr("He rewarded you for your virtue.\n");
1051 Player.p_mana += 50.0;
1052 Player.p_shield += 2.0;
1057 mvaddstr(4, 0, "You've found an amulet.\n");
1062 if (Player.p_blindness)
1064 mvaddstr(4, 0, "You've regained your sight!\n");
1065 Player.p_blindness = FALSE;
1069 default: /* deal with poison */
1070 if (Player.p_poison > 0.0)
1072 temp = Player.p_poison * Statptr->c_weakness
1073 * Player.p_maxenergy / 600.0;
1074 if (Player.p_energy > Player.p_maxenergy / 10.0
1075 && temp + 5.0 < Player.p_energy)
1076 Player.p_energy -= temp;
1082 /************************************************************************
1084 / FUNCTION NAME: genchar()
1086 / FUNCTION: generate a random character
1088 / AUTHOR: E. A. Estes, 12/4/85
1091 / int type - ASCII value of character type to generate
1093 / RETURN VALUE: none
1095 / MODULES CALLED: floor(), drandom()
1097 / GLOBAL INPUTS: Wizard, Player, Stattable[]
1099 / GLOBAL OUTPUTS: Player
1102 / Use the lookup table for rolling stats.
1104 *************************************************************************/
1109 int subscript; /* used for subscripting into Stattable */
1110 struct charstats *statptr;/* for pointing into Stattable */
1112 subscript = type - '1';
1114 if (subscript < C_MAGIC || subscript > C_EXPER)
1115 if (subscript != C_SUPER || !Wizard)
1116 /* fighter is default */
1117 subscript = C_FIGHTER;
1119 statptr = &Stattable[subscript];
1121 Player.p_quickness =
1122 ROLL(statptr->c_quickness.base, statptr->c_quickness.interval);
1124 ROLL(statptr->c_strength.base, statptr->c_strength.interval);
1126 ROLL(statptr->c_mana.base, statptr->c_mana.interval);
1127 Player.p_maxenergy =
1129 ROLL(statptr->c_energy.base, statptr->c_energy.interval);
1131 ROLL(statptr->c_brains.base, statptr->c_brains.interval);
1133 ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval);
1135 Player.p_type = subscript;
1137 if (Player.p_type == C_HALFLING)
1138 /* give halfling some experience */
1139 Player.p_experience = ROLL(600.0, 200.0);
1142 /************************************************************************
1144 / FUNCTION NAME: playinit()
1146 / FUNCTION: initialize for playing game
1148 / AUTHOR: E. A. Estes, 12/4/85
1152 / RETURN VALUE: none
1154 / MODULES CALLED: signal(), wclear(), noecho(), crmode(), initscr(),
1157 / GLOBAL INPUTS: *stdscr, ill_sig()
1159 / GLOBAL OUTPUTS: Windows
1162 / Catch a bunch of signals, and turn on curses stuff.
1164 *************************************************************************/
1168 /* catch/ingnore signals */
1178 sigset(SIGHUP, ill_sig);
1179 sigset(SIGTRAP, ill_sig);
1180 sigset(SIGIOT, ill_sig);
1181 sigset(SIGEMT, ill_sig);
1182 sigset(SIGFPE, ill_sig);
1183 sigset(SIGBUS, ill_sig);
1184 sigset(SIGSEGV, ill_sig);
1185 sigset(SIGSYS, ill_sig);
1186 sigset(SIGPIPE, ill_sig);
1189 signal(SIGQUIT, ill_sig);
1190 signal(SIGALRM, SIG_IGN);
1191 signal(SIGTERM, SIG_IGN);
1192 signal(SIGTSTP, SIG_IGN);
1193 signal(SIGTTIN, SIG_IGN);
1194 signal(SIGTTOU, SIG_IGN);
1195 signal(SIGINT, ill_sig);
1196 signal(SIGHUP, SIG_DFL);
1197 signal(SIGTRAP, ill_sig);
1198 signal(SIGIOT, ill_sig);
1199 signal(SIGEMT, ill_sig);
1200 signal(SIGFPE, ill_sig);
1201 signal(SIGBUS, ill_sig);
1202 signal(SIGSEGV, ill_sig);
1203 signal(SIGSYS, ill_sig);
1204 signal(SIGPIPE, ill_sig);
1207 signal(SIGINT, SIG_IGN);
1208 signal(SIGQUIT, SIG_IGN);
1209 signal(SIGTERM, SIG_IGN);
1210 signal(SIGALRM, SIG_IGN);
1211 signal(SIGHUP, ill_sig);
1212 signal(SIGTRAP, ill_sig);
1213 signal(SIGIOT, ill_sig);
1214 signal(SIGEMT, ill_sig);
1215 signal(SIGFPE, ill_sig);
1216 signal(SIGBUS, ill_sig);
1217 signal(SIGSEGV, ill_sig);
1218 signal(SIGSYS, ill_sig);
1219 signal(SIGPIPE, ill_sig);
1222 signal(SIGINT, SIG_IGN);
1223 signal(SIGQUIT, SIG_IGN);
1224 signal(SIGTERM, SIG_IGN);
1225 signal(SIGALRM, SIG_IGN);
1226 signal(SIGHUP, ill_sig);
1227 signal(SIGTRAP, ill_sig);
1228 signal(SIGIOT, ill_sig);
1229 signal(SIGEMT, ill_sig);
1230 signal(SIGFPE, ill_sig);
1231 signal(SIGBUS, ill_sig);
1232 signal(SIGSEGV, ill_sig);
1233 signal(SIGSYS, ill_sig);
1234 signal(SIGPIPE, ill_sig);
1237 initscr(); /* turn on curses */
1238 noecho(); /* do not echo input */
1239 crmode(); /* do not process erase, kill */
1242 Windows = TRUE; /* mark the state */
1246 /************************************************************************
1248 / FUNCTION NAME: cleanup()
1250 / FUNCTION: close some files, and maybe exit
1252 / AUTHOR: E. A. Estes, 12/4/85
1255 / bool doexit - exit flag
1257 / RETURN VALUE: none
1259 / MODULES CALLED: exit(), wmove(), fclose(), endwin(), nocrmode(), wrefresh()
1261 / GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
1262 / *Messagefp, *Playersfp
1264 / GLOBAL OUTPUTS: none
1267 / Close all open files. If we are "in curses" terminate curses.
1268 / If 'doexit' is set, exit, otherwise return.
1270 *************************************************************************/
1296 fclose(Energyvoidfp);
1297 Energyvoidfp = NULL;