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 $
8 * $DragonFly: src/games/phantasia/main.c,v 1.2 2003/06/17 04:25:24 dillon Exp $
13 * This game is distributed for free as is. It is not guaranteed to work
14 * in every conceivable environment. It is not even guaranteed to work
17 * This game is distributed without notice of copyright, therefore it
18 * may be used in any manner the recipient sees fit. However, the
19 * author assumes no responsibility for maintaining or revising this
20 * game, in its original form, or any derivitives thereof.
22 * The author shall not be responsible for any loss, cost, or damage,
23 * including consequential damage, caused by reliance on this material.
25 * The author makes no warranties, express or implied, including warranties
26 * of merchantability or fitness for a particular purpose or use.
28 * AT&T is in no way connected with this game.
31 #include <sys/types.h>
36 * The program allocates as much file space as it needs to store characters,
37 * so the possibility exists for the character file to grow without bound.
38 * The file is purged upon normal entry to try to avoid that problem.
39 * A similar problem exists for energy voids. To alleviate the problem here,
40 * the void file is cleared with every new king, and a limit is placed
41 * on the size of the energy void file.
45 * Put one line of text into the file 'motd' for announcements, etc.
49 * The scoreboard file is updated when someone dies, and keeps track
50 * of the highest character to date for that login.
51 * Being purged from the character file does not cause the scoreboard
56 * All source files are set up for 'vi' with shiftwidth=4, tabstop=8.
62 * main.c Main routines for Phantasia
67 /***************************************************************************
68 / FUNCTION NAME: main()
70 / FUNCTION: initialize state, and call main process
72 / AUTHOR: E. A. Estes, 12/4/85
75 / int argc - argument count
76 / char **argv - argument vector
80 / MODULES CALLED: monstlist(), checkenemy(), activelist(),
81 / throneroom(), checkbattle(), readmessage(), changestats(), writerecord(),
82 / tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(),
83 / fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(),
84 / signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(),
85 / strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(),
86 / playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(),
87 / scorelist(), titlelist()
89 / GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
90 / Fileloc, Stattable[]
92 / GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
95 / Process arguments, initialize program, and loop forever processing
98 ****************************************************************************/
104 bool noheader = FALSE; /* set if don't want header */
105 bool headeronly = FALSE; /* set if only want header */
106 bool examine = FALSE; /* set if examine a character */
107 time_t seconds; /* for time of day */
108 double dtemp; /* for temporary calculations */
110 initialstate(); /* init globals */
112 /* process arguments */
113 while (--argc && (*++argv)[0] == '-')
116 case 's': /* short */
120 case 'H': /* Header */
124 case 'a': /* all users */
129 case 'p': /* purge old players */
134 case 'S': /* set 'Wizard' */
138 case 'x': /* examine */
142 case 'm': /* monsters */
147 case 'b': /* scoreboard */
153 if (!isatty(0)) /* don't let non-tty's play */
157 playinit(); /* set up to catch signals, init curses */
169 purgeoldplayers(); /* clean up old characters */
177 /* get the player structure filled */
181 mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
183 switch (getanswer("NYQ", FALSE))
186 Fileloc = recallplayer();
194 Fileloc = rollnewplayer();
199 while (Fileloc < 0L);
201 if (Player.p_level > 5.0)
202 /* low level players have long timeout */
205 /* update some important player statistics */
206 strcpy(Player.p_login, Login);
208 Player.p_lastused = localtime(&seconds)->tm_yday;
209 Player.p_status = S_PLAYING;
210 writerecord(&Player, Fileloc);
212 Statptr = &Stattable[Player.p_type]; /* initialize pointer */
214 /* catch interrupts */
216 sigset(SIGINT, interrupt);
219 signal(SIGINT, interrupt);
222 signal(SIGINT, interrupt);
225 signal(SIGINT, interrupt);
228 altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */
233 /* loop forever, processing input */
236 adjuststats(); /* cleanup stats */
238 if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING)
239 /* not allowed on throne -- move */
241 mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n");
242 altercoordinates(0.0, 0.0, A_NEAR);
245 checktampered(); /* check for energy voids, etc. */
247 if (Player.p_status != S_CLOAKED
249 && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y)
254 dtemp = sqrt(dtemp / 100.0);
255 if (floor(dtemp) == dtemp)
256 /* |x| / 100 == n*n; at a trading post */
263 checkbattle(); /* check for player to player battle */
264 neatstuff(); /* gurus, medics, etc. */
266 if (Player.p_status == S_CLOAKED)
267 /* costs 3 mana per turn to be cloaked */
268 if (Player.p_mana > 3.0)
269 Player.p_mana -= 3.0;
271 /* ran out of mana, uncloak */
273 Player.p_status = S_PLAYING;
277 if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED)
278 /* change status back to S_PLAYING */
280 Player.p_status = S_PLAYING;
285 /* update file only if important stuff has changed */
287 writerecord(&Player, Fileloc);
292 readmessage(); /* read message, if any */
294 displaystats(); /* print statistics */
299 /* maybe make king, print prompt, etc. */
302 /* print status line */
303 addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit ");
304 if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK)
306 if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT)
307 addstr("7:Teleport ");
308 if (Player.p_specialtype >= SC_COUNCIL || Wizard)
309 addstr("8:Intervene ");
311 procmain(); /* process input */
315 /************************************************************************
317 / FUNCTION NAME: initialstate()
319 / FUNCTION: initialize some important global variable
321 / AUTHOR: E. A. Estes, 12/4/85
327 / MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(),
332 / GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
333 / Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
337 / Set global flags, and open files which remain open.
339 *************************************************************************/
353 /* setup login name */
354 if ((Login = getlogin()) == NULL)
355 Login = getpwuid(getuid())->pw_name;
357 /* open some files */
358 if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
362 if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL)
366 if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL)
370 if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL)
377 /************************************************************************
379 / FUNCTION NAME: rollnewplayer()
381 / FUNCTION: roll up a new character
383 / AUTHOR: E. A. Estes, 12/4/85
389 / MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(),
390 / wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(),
391 / getanswer(), getstring()
393 / GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
395 / GLOBAL OUTPUTS: Echo
398 / Prompt player, and roll up new character.
400 *************************************************************************/
405 int chartype; /* character type */
408 initplayer(&Player); /* initialize player structure */
411 mvaddstr(4, 21, "Which type of character do you want:");
412 mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento ");
414 addstr("7:Super ? ");
415 chartype = getanswer("1234567", FALSE);
419 chartype = getanswer("123456", FALSE);
424 genchar(chartype); /* roll up a character */
426 /* print out results */
428 "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n",
429 Player.p_strength, Player.p_quickness, Player.p_mana);
431 "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n",
432 Player.p_energy, Player.p_brains, Player.p_magiclvl);
434 if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
437 mvaddstr(14, 14, "Type '1' to keep >");
438 ch = getanswer(" ", TRUE);
442 if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
443 /* get coordinates for experimento */
446 mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
447 getstring(Databuf, SZ_DATABUF);
448 sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y);
450 if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER)
451 mvaddstr(17, 0, "Invalid coordinates. Try again.\n");
457 /* name the new character */
460 "Give your character a name [up to %d characters] ? ", SZ_NAME - 1);
461 getstring(Player.p_name, SZ_NAME);
462 truncstring(Player.p_name); /* remove trailing blanks */
464 if (Player.p_name[0] == '\0')
466 mvaddstr(19, 0, "Invalid name.");
467 else if (findname(Player.p_name, &Other) >= 0L)
468 /* cannot have duplicate names */
469 mvaddstr(19, 0, "Name already in use.");
471 /* name is acceptable */
474 addstr(" Pick another.\n");
477 /* get a password for character */
482 mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
483 getstring(Player.p_password, SZ_PASSWORD);
484 mvaddstr(21, 0, "One more time to verify ? ");
485 getstring(Databuf, SZ_PASSWORD);
487 while (strcmp(Player.p_password, Databuf) != 0);
491 return(allocrecord());
494 /************************************************************************
496 / FUNCTION NAME: procmain()
498 / FUNCTION: process input from player
500 / AUTHOR: E. A. Estes, 12/4/85
506 / MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(),
507 / fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(),
508 / waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(),
509 / getstring(), wclrtobot()
511 / GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
512 / Databuf[], Illmove[]
514 / GLOBAL OUTPUTS: Player, Changed
517 / Process main menu options.
519 *************************************************************************/
524 double x; /* desired new x coordinate */
525 double y; /* desired new y coordinate */
526 double temp; /* for temporary calculations */
527 FILE *fp; /* for opening files */
528 int loop; /* a loop counter */
529 bool hasmoved = FALSE; /* set if player has moved */
532 mvaddstr(4, 0, "\n\n"); /* clear status area */
535 clrtobot(); /* clear data on bottom area of screen */
537 if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7'))
538 /* valar cannot move */
543 case 'K': /* move up/north */
546 y = Player.p_y + MAXMOVE();
550 case 'J': /* move down/south */
553 y = Player.p_y - MAXMOVE();
557 case 'L': /* move right/east */
559 x = Player.p_x + MAXMOVE();
564 case 'H': /* move left/west */
566 x = Player.p_x - MAXMOVE();
572 Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0
573 + Player.p_level / 3.0 + 2.0;
575 MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield);
577 if (Player.p_status != S_CLOAKED)
578 /* cannot find mana if cloaked */
580 Player.p_mana += (Circle + Player.p_level) / 4.0;
582 if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
583 /* wandering monster */
588 case 'X': /* change/examine a character */
593 for (loop = 3; loop; --loop)
595 mvaddstr(4, 0, "X Y Coordinates ? ");
596 getstring(Databuf, SZ_DATABUF);
598 if (sscanf(Databuf, "%lf %lf", &x, &y) != 2)
599 mvaddstr(5, 0, "Try again\n");
600 else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE())
610 case '2': /* players */
614 case '3': /* message */
615 mvaddstr(4, 0, "Message ? ");
616 getstring(Databuf, SZ_DATABUF);
617 /* we open the file for writing to erase any data which is already there */
618 fp = fopen(_PATH_MESS, "w");
619 if (Databuf[0] != '\0')
620 fprintf(fp, "%s: %s", Player.p_name, Databuf);
624 case '4': /* stats */
628 case '5': /* good-bye */
632 case '6': /* cloak */
633 if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK)
635 else if (Player.p_status == S_CLOAKED)
636 Player.p_status = S_PLAYING;
637 else if (Player.p_mana < MM_CLOAK)
638 mvaddstr(5, 0, "No mana left.\n");
642 Player.p_mana -= MM_CLOAK;
643 Player.p_status = S_CLOAKED;
647 case '7': /* teleport */
649 * conditions for teleport
650 * - 20 per (level plus magic level)
651 * - OR council of the wise or valar or ex-valar
652 * - OR transport from throne
653 * transports from throne cost no mana
655 if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT)
658 for (loop = 3; loop; --loop)
660 mvaddstr(4, 0, "X Y Coordinates ? ");
661 getstring(Databuf, SZ_DATABUF);
663 if (sscanf(Databuf, "%lf %lf", &x, &y) == 2)
665 temp = distance(Player.p_x, x, Player.p_y, y);
667 /* can transport anywhere from throne */
668 && Player.p_specialtype <= SC_COUNCIL
669 /* council, valar can transport anywhere */
670 && temp > (Player.p_level + Player.p_magiclvl) * 20.0)
671 /* can only move 20 per exp. level + mag. level */
675 temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */
677 if (!Throne && temp > Player.p_mana)
678 mvaddstr(5, 0, "Not enough power for that distance.\n");
682 Player.p_mana -= temp;
692 case '9': /* monster */
694 /* no monsters while on throne */
695 mvaddstr(5, 0, "No monsters in the chamber!\n");
696 else if (Player.p_specialtype != SC_VALAR)
697 /* the valar cannot call monsters */
699 Player.p_sin += 1e-6;
704 case '0': /* decree */
705 if (Wizard || Player.p_specialtype == SC_KING && Throne)
706 /* kings must be on throne to decree */
712 case '8': /* intervention */
713 if (Wizard || Player.p_specialtype >= SC_COUNCIL)
721 /* player has moved -- alter coordinates, and do random monster */
723 altercoordinates(x, y, A_SPECIFIC);
725 if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne)
730 /************************************************************************
732 / FUNCTION NAME: titlelist()
734 / FUNCTION: print title page
736 / AUTHOR: E. A. Estes, 12/4/85
742 / MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(),
743 / fclose(), strlen(), waddstr(), sprintf(), wrefresh()
745 / GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
747 / GLOBAL OUTPUTS: Lines
750 / Print important information about game, players, etc.
752 *************************************************************************/
756 FILE *fp; /* used for opening various files */
757 bool councilfound = FALSE; /* set if we find a member of the council */
758 bool kingfound = FALSE; /* set if we find a king */
759 double hiexp, nxtexp; /* used for finding the two highest players */
760 double hilvl, nxtlvl; /* used for finding the two highest players */
761 char hiname[21], nxtname[21];/* used for finding the two highest players */
763 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 /* print message of the day */
766 if ((fp = fopen(_PATH_MOTD, "r")) != NULL
767 && fgets(Databuf, SZ_DATABUF, fp) != NULL)
769 mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf);
773 /* search for king */
774 fseek(Playersfp, 0L, 0);
775 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
776 if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
779 sprintf(Databuf, "The present ruler is %s Level:%.0f",
780 Other.p_name, Other.p_level);
781 mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf);
787 mvaddstr(4, 24, "There is no ruler at this time.");
789 /* search for valar */
790 fseek(Playersfp, 0L, 0);
791 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
792 if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
793 /* found the valar */
795 sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login);
796 mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf);
800 /* search for council of the wise */
801 fseek(Playersfp, 0L, 0);
803 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
804 if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED)
805 /* found a member of the council */
809 mvaddstr(8, 30, "Council of the Wise:");
813 /* This assumes a finite (<=5) number of C.O.W.: */
814 sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login);
815 mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf);
818 /* search for the two highest players */
819 nxtname[0] = hiname[0] = '\0';
823 fseek(Playersfp, 0L, 0);
824 while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
825 if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED)
826 /* highest found so far */
829 hiexp = Other.p_experience;
831 hilvl = Other.p_level;
832 strcpy(nxtname, hiname);
833 strcpy(hiname, Other.p_name);
835 else if (Other.p_experience > nxtexp
836 && Other.p_specialtype <= SC_KING
837 && Other.p_status != S_NOTUSED)
838 /* next highest found so far */
840 nxtexp = Other.p_experience;
841 nxtlvl = Other.p_level;
842 strcpy(nxtname, Other.p_name);
845 mvaddstr(15, 28, "Highest characters are:");
846 sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f",
847 hiname, hilvl, nxtname, nxtlvl);
848 mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf);
850 /* print last to die */
851 if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL
852 && fgets(Databuf, SZ_DATABUF, fp) != NULL)
854 mvaddstr(19, 25, "The last character to die was:");
855 mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf);
862 /************************************************************************
864 / FUNCTION NAME: recallplayer()
866 / FUNCTION: find a character on file
868 / AUTHOR: E. A. Estes, 12/4/85
874 / MODULES CALLED: writerecord(), truncstring(), more(), death(), wmove(),
875 / wclear(), strcmp(), printw(), cleanup(), waddstr(), findname(), mvprintw(),
876 / getanswer(), getstring()
878 / GLOBAL INPUTS: Player, *stdscr, Databuf[]
880 / GLOBAL OUTPUTS: Echo, Player
883 / Search for a character of a certain name, and check password.
885 *************************************************************************/
890 long loc = 0L; /* location in player file */
891 int loop; /* loop counter */
895 mvprintw(10, 0, "What was your character's name ? ");
896 getstring(Databuf, SZ_NAME);
897 truncstring(Databuf);
899 if ((loc = findname(Databuf, &Player)) >= 0L)
900 /* found character */
904 for (loop = 0; loop < 2; ++loop)
906 /* prompt for password */
907 mvaddstr(11, 0, "Password ? ");
908 getstring(Databuf, SZ_PASSWORD);
909 if (strcmp(Databuf, Player.p_password) == 0)
914 if (Player.p_status != S_OFF)
915 /* player did not exit normally last time */
918 addstr("Your character did not exit normally last time.\n");
919 addstr("If you think you have good cause to have your character saved,\n");
920 printw("you may quit and mail your reason to 'root'.\n");
921 addstr("Otherwise, continuing spells certain death.\n");
922 addstr("Do you want to quit ? ");
923 ch = getanswer("YN", FALSE);
926 Player.p_status = S_HUNGUP;
927 writerecord(&Player, loc);
937 mvaddstr(12, 0, "No good.\n");
943 mvaddstr(11, 0, "Not found.\n");
949 /************************************************************************
951 / FUNCTION NAME: neatstuff()
953 / FUNCTION: do random stuff
955 / AUTHOR: E. A. Estes, 3/3/86
961 / MODULES CALLED: collecttaxes(), floor(), wmove(), drandom(), infloat(),
962 / waddstr(), mvprintw(), getanswer()
964 / GLOBAL INPUTS: Player, *stdscr, *Statptr
966 / GLOBAL OUTPUTS: Player
969 / Handle gurus, medics, etc.
971 *************************************************************************/
975 double temp; /* for temporary calculations */
978 switch ((int) ROLL(0.0, 100.0))
982 if (Player.p_poison > 0.0)
984 mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? ");
985 temp = floor(infloat());
986 if (temp < 0.0 || temp > Player.p_gold)
987 /* negative gold, or more than available */
989 mvaddstr(6, 0, "He was not amused, and made you worse.\n");
990 Player.p_poison += 1.0;
992 else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1))
993 /* medic wants 1/2 of available gold */
994 mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
997 mvaddstr(5, 0, "He accepted.");
998 Player.p_poison = MAX(0.0, Player.p_poison - 1.0);
999 Player.p_gold -= temp;
1005 mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
1006 Player.p_experience += 4000.0;
1007 Player.p_sin += 0.5;
1011 temp = ROLL(10.0, 75.0);
1012 mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp);
1013 ch = getanswer("NY", FALSE);
1016 collecttaxes(temp, 0.0);
1020 if (Player.p_sin > 1.0)
1022 mvaddstr(4, 0, "You've found a Holy Orb!\n");
1023 Player.p_sin -= 0.25;
1028 if (Player.p_poison < 1.0)
1030 mvaddstr(4, 0, "You've been hit with a plague!\n");
1031 Player.p_poison += 1.0;
1036 mvaddstr(4, 0, "You've found some holy water.\n");
1037 ++Player.p_holywater;
1041 mvaddstr(4, 0, "You've met a Guru. . .");
1042 if (drandom() * Player.p_sin > 1.0)
1043 addstr("You disgusted him with your sins!\n");
1044 else if (Player.p_poison > 0.0)
1046 addstr("He looked kindly upon you, and cured you.\n");
1047 Player.p_poison = 0.0;
1051 addstr("He rewarded you for your virtue.\n");
1052 Player.p_mana += 50.0;
1053 Player.p_shield += 2.0;
1058 mvaddstr(4, 0, "You've found an amulet.\n");
1063 if (Player.p_blindness)
1065 mvaddstr(4, 0, "You've regained your sight!\n");
1066 Player.p_blindness = FALSE;
1070 default: /* deal with poison */
1071 if (Player.p_poison > 0.0)
1073 temp = Player.p_poison * Statptr->c_weakness
1074 * Player.p_maxenergy / 600.0;
1075 if (Player.p_energy > Player.p_maxenergy / 10.0
1076 && temp + 5.0 < Player.p_energy)
1077 Player.p_energy -= temp;
1083 /************************************************************************
1085 / FUNCTION NAME: genchar()
1087 / FUNCTION: generate a random character
1089 / AUTHOR: E. A. Estes, 12/4/85
1092 / int type - ASCII value of character type to generate
1094 / RETURN VALUE: none
1096 / MODULES CALLED: floor(), drandom()
1098 / GLOBAL INPUTS: Wizard, Player, Stattable[]
1100 / GLOBAL OUTPUTS: Player
1103 / Use the lookup table for rolling stats.
1105 *************************************************************************/
1110 int subscript; /* used for subscripting into Stattable */
1111 struct charstats *statptr;/* for pointing into Stattable */
1113 subscript = type - '1';
1115 if (subscript < C_MAGIC || subscript > C_EXPER)
1116 if (subscript != C_SUPER || !Wizard)
1117 /* fighter is default */
1118 subscript = C_FIGHTER;
1120 statptr = &Stattable[subscript];
1122 Player.p_quickness =
1123 ROLL(statptr->c_quickness.base, statptr->c_quickness.interval);
1125 ROLL(statptr->c_strength.base, statptr->c_strength.interval);
1127 ROLL(statptr->c_mana.base, statptr->c_mana.interval);
1128 Player.p_maxenergy =
1130 ROLL(statptr->c_energy.base, statptr->c_energy.interval);
1132 ROLL(statptr->c_brains.base, statptr->c_brains.interval);
1134 ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval);
1136 Player.p_type = subscript;
1138 if (Player.p_type == C_HALFLING)
1139 /* give halfling some experience */
1140 Player.p_experience = ROLL(600.0, 200.0);
1143 /************************************************************************
1145 / FUNCTION NAME: playinit()
1147 / FUNCTION: initialize for playing game
1149 / AUTHOR: E. A. Estes, 12/4/85
1153 / RETURN VALUE: none
1155 / MODULES CALLED: signal(), wclear(), noecho(), crmode(), initscr(),
1158 / GLOBAL INPUTS: *stdscr, ill_sig()
1160 / GLOBAL OUTPUTS: Windows
1163 / Catch a bunch of signals, and turn on curses stuff.
1165 *************************************************************************/
1169 /* catch/ingnore signals */
1179 sigset(SIGHUP, ill_sig);
1180 sigset(SIGTRAP, ill_sig);
1181 sigset(SIGIOT, ill_sig);
1182 sigset(SIGEMT, ill_sig);
1183 sigset(SIGFPE, ill_sig);
1184 sigset(SIGBUS, ill_sig);
1185 sigset(SIGSEGV, ill_sig);
1186 sigset(SIGSYS, ill_sig);
1187 sigset(SIGPIPE, ill_sig);
1190 signal(SIGQUIT, ill_sig);
1191 signal(SIGALRM, SIG_IGN);
1192 signal(SIGTERM, SIG_IGN);
1193 signal(SIGTSTP, SIG_IGN);
1194 signal(SIGTTIN, SIG_IGN);
1195 signal(SIGTTOU, SIG_IGN);
1196 signal(SIGINT, ill_sig);
1197 signal(SIGHUP, SIG_DFL);
1198 signal(SIGTRAP, ill_sig);
1199 signal(SIGIOT, ill_sig);
1200 signal(SIGEMT, ill_sig);
1201 signal(SIGFPE, ill_sig);
1202 signal(SIGBUS, ill_sig);
1203 signal(SIGSEGV, ill_sig);
1204 signal(SIGSYS, ill_sig);
1205 signal(SIGPIPE, ill_sig);
1208 signal(SIGINT, SIG_IGN);
1209 signal(SIGQUIT, SIG_IGN);
1210 signal(SIGTERM, SIG_IGN);
1211 signal(SIGALRM, SIG_IGN);
1212 signal(SIGHUP, ill_sig);
1213 signal(SIGTRAP, ill_sig);
1214 signal(SIGIOT, ill_sig);
1215 signal(SIGEMT, ill_sig);
1216 signal(SIGFPE, ill_sig);
1217 signal(SIGBUS, ill_sig);
1218 signal(SIGSEGV, ill_sig);
1219 signal(SIGSYS, ill_sig);
1220 signal(SIGPIPE, ill_sig);
1223 signal(SIGINT, SIG_IGN);
1224 signal(SIGQUIT, SIG_IGN);
1225 signal(SIGTERM, SIG_IGN);
1226 signal(SIGALRM, SIG_IGN);
1227 signal(SIGHUP, ill_sig);
1228 signal(SIGTRAP, ill_sig);
1229 signal(SIGIOT, ill_sig);
1230 signal(SIGEMT, ill_sig);
1231 signal(SIGFPE, ill_sig);
1232 signal(SIGBUS, ill_sig);
1233 signal(SIGSEGV, ill_sig);
1234 signal(SIGSYS, ill_sig);
1235 signal(SIGPIPE, ill_sig);
1238 initscr(); /* turn on curses */
1239 noecho(); /* do not echo input */
1240 crmode(); /* do not process erase, kill */
1243 Windows = TRUE; /* mark the state */
1247 /************************************************************************
1249 / FUNCTION NAME: cleanup()
1251 / FUNCTION: close some files, and maybe exit
1253 / AUTHOR: E. A. Estes, 12/4/85
1256 / bool doexit - exit flag
1258 / RETURN VALUE: none
1260 / MODULES CALLED: exit(), wmove(), fclose(), endwin(), nocrmode(), wrefresh()
1262 / GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
1263 / *Messagefp, *Playersfp
1265 / GLOBAL OUTPUTS: none
1268 / Close all open files. If we are "in curses" terminate curses.
1269 / If 'doexit' is set, exit, otherwise return.
1271 *************************************************************************/
1297 fclose(Energyvoidfp);
1298 Energyvoidfp = NULL;