1 /* $NetBSD: main.c,v 1.23 2009/08/31 08:27:16 dholland Exp $ */
4 * Phantasia 3.3.2 -- Interterminal fantasy game
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 * The scoreboard file is updated when someone dies, and keeps track
45 * of the highest character to date for that login.
46 * Being purged from the character file does not cause the scoreboard
53 static void genchar(int);
54 static void initialstate(void);
55 static void neatstuff(void);
56 static void playinit(void);
57 static void procmain(void);
58 static long recallplayer(void);
59 static long rollnewplayer(void);
60 static void titlelist(void);
70 * FUNCTION: initialize state, and call main process
72 * GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
73 * Fileloc, Stattable[]
75 * GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
78 * Process arguments, initialize program, and loop forever processing
83 main(int argc
, char **argv
)
85 bool noheader
= FALSE
; /* set if don't want header */
86 bool headeronly
= FALSE
; /* set if only want header */
87 bool examine
= FALSE
; /* set if examine a character */
88 time_t seconds
; /* for time of day */
89 double dtemp
; /* for temporary calculations */
91 initialstate(); /* init globals */
93 /* process arguments */
94 while (--argc
&& (*++argv
)[0] == '-')
100 case 'H': /* Header */
104 case 'a': /* all users */
109 case 'p': /* purge old players */
114 case 'S': /* set 'Wizard' */
118 case 'x': /* examine */
122 case 'm': /* monsters */
127 case 'b': /* scoreboard */
133 if (!isatty(0)) /* don't let non-tty's play */
137 playinit(); /* set up to catch signals, init curses */
147 purgeoldplayers(); /* clean up old characters */
155 /* get the player structure filled */
158 mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
160 switch (getanswer("NYQ", FALSE
)) {
162 Fileloc
= recallplayer();
170 Fileloc
= rollnewplayer();
174 } while (Fileloc
< 0L);
176 if (Player
.p_level
> 5.0)
177 /* low level players have long timeout */
180 /* update some important player statistics */
181 strcpy(Player
.p_login
, Login
);
183 Player
.p_lastused
= localtime(&seconds
)->tm_yday
;
184 Player
.p_status
= S_PLAYING
;
185 writerecord(&Player
, Fileloc
);
187 Statptr
= &Stattable
[Player
.p_type
]; /* initialize pointer */
189 /* catch interrupts */
191 sigset(SIGINT
, interrupt
);
194 signal(SIGINT
, interrupt
);
197 signal(SIGINT
, interrupt
);
200 signal(SIGINT
, interrupt
);
203 altercoordinates(Player
.p_x
, Player
.p_y
, A_FORCED
); /* set some flags */
208 /* loop forever, processing input */
210 adjuststats(); /* cleanup stats */
212 if (Throne
&& Player
.p_crowns
== 0 && Player
.p_specialtype
!= SC_KING
) {
213 /* not allowed on throne -- move */
214 mvaddstr(5, 0, "You're not allowed in the Lord's Chamber without a crown.\n");
215 altercoordinates(0.0, 0.0, A_NEAR
);
218 checktampered(); /* check for energy voids, etc. */
220 if (Player
.p_status
!= S_CLOAKED
222 && (dtemp
= fabs(Player
.p_x
)) == fabs(Player
.p_y
)
226 dtemp
= sqrt(dtemp
/ 100.0);
227 if (floor(dtemp
) == dtemp
) {
228 /* |x| / 100 == n*n; at a trading post */
234 checkbattle(); /* check for player to player battle */
235 neatstuff(); /* gurus, medics, etc. */
237 if (Player
.p_status
== S_CLOAKED
) {
238 /* costs 3 mana per turn to be cloaked */
239 if (Player
.p_mana
> 3.0)
240 Player
.p_mana
-= 3.0;
242 /* ran out of mana, uncloak */
243 Player
.p_status
= S_PLAYING
;
248 if (Player
.p_status
!= S_PLAYING
&& Player
.p_status
!= S_CLOAKED
) {
249 /* change status back to S_PLAYING */
250 Player
.p_status
= S_PLAYING
;
255 /* update file only if important stuff has changed */
256 writerecord(&Player
, Fileloc
);
261 readmessage(); /* read message, if any */
263 displaystats(); /* print statistics */
268 /* maybe make king, print prompt, etc. */
271 /* print status line */
272 addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit ");
273 if (Player
.p_level
>= MEL_CLOAK
&& Player
.p_magiclvl
>= ML_CLOAK
)
275 if (Player
.p_level
>= MEL_TELEPORT
&& Player
.p_magiclvl
>= ML_TELEPORT
)
276 addstr("7:Teleport ");
277 if (Player
.p_specialtype
>= SC_COUNCIL
|| Wizard
)
278 addstr("8:Intervene ");
280 procmain(); /* process input */
285 * FUNCTION: initialize some important global variable
287 * GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
288 * Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
292 * Set global flags, and open files which remain open.
308 /* setup login name */
309 if ((Login
= getlogin()) == NULL
)
310 Login
= getpwuid(getuid())->pw_name
;
312 /* open some files */
313 if ((Playersfp
= fopen(_PATH_PEOPLE
, "r+")) == NULL
)
317 if ((Monstfp
= fopen(_PATH_MONST
, "r+")) == NULL
)
321 if ((Messagefp
= fopen(_PATH_MESS
, "r")) == NULL
)
325 if ((Energyvoidfp
= fopen(_PATH_VOID
, "r+")) == NULL
)
333 * FUNCTION: roll up a new character
335 * GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
337 * GLOBAL OUTPUTS: Echo
340 * Prompt player, and roll up new character.
346 int chartype
; /* character type */
349 initplayer(&Player
); /* initialize player structure */
352 mvaddstr(4, 21, "Which type of character do you want:");
353 mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento ");
355 addstr("7:Super ? ");
356 chartype
= getanswer("1234567", FALSE
);
359 chartype
= getanswer("123456", FALSE
);
363 genchar(chartype
); /* roll up a character */
365 /* print out results */
367 "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n",
368 Player
.p_strength
, Player
.p_quickness
, Player
.p_mana
);
370 "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n",
371 Player
.p_energy
, Player
.p_brains
, Player
.p_magiclvl
);
373 if (Player
.p_type
== C_EXPER
|| Player
.p_type
== C_SUPER
)
376 mvaddstr(14, 14, "Type '1' to keep >");
377 ch
= getanswer(" ", TRUE
);
380 if (Player
.p_type
== C_EXPER
|| Player
.p_type
== C_SUPER
)
381 /* get coordinates for experimento */
383 mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
384 getstring(Databuf
, SZ_DATABUF
);
385 sscanf(Databuf
, "%lf %lf", &Player
.p_x
, &Player
.p_y
);
387 if (fabs(Player
.p_x
) > D_EXPER
|| fabs(Player
.p_y
) > D_EXPER
)
388 mvaddstr(17, 0, "Invalid coordinates. Try again.\n");
394 /* name the new character */
396 "Give your character a name [up to %d characters] ? ", SZ_NAME
- 1);
397 getstring(Player
.p_name
, SZ_NAME
);
398 truncstring(Player
.p_name
); /* remove trailing blanks */
400 if (Player
.p_name
[0] == '\0')
402 mvaddstr(19, 0, "Invalid name.");
403 else if (findname(Player
.p_name
, &Other
) >= 0L)
404 /* cannot have duplicate names */
405 mvaddstr(19, 0, "Name already in use.");
407 /* name is acceptable */
410 addstr(" Pick another.\n");
413 /* get a password for character */
417 mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
418 getstring(Player
.p_password
, SZ_PASSWORD
);
419 mvaddstr(21, 0, "One more time to verify ? ");
420 getstring(Databuf
, SZ_PASSWORD
);
421 } while (strcmp(Player
.p_password
, Databuf
) != 0);
425 return (allocrecord());
429 * FUNCTION: process input from player
431 * GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
432 * Databuf[], Illmove[]
434 * GLOBAL OUTPUTS: Player, Changed
437 * Process main menu options.
444 double x
; /* desired new x coordinate */
445 double y
; /* desired new y coordinate */
446 double temp
; /* for temporary calculations */
447 FILE *fp
; /* for opening files */
448 int loop
; /* a loop counter */
449 bool hasmoved
= FALSE
; /* set if player has moved */
452 mvaddstr(4, 0, "\n\n"); /* clear status area */
455 clrtobot(); /* clear data on bottom area of screen */
457 if (Player
.p_specialtype
== SC_VALAR
&& (ch
== '1' || ch
== '7'))
458 /* valar cannot move */
462 case 'K': /* move up/north */
465 y
= Player
.p_y
+ MAXMOVE();
469 case 'J': /* move down/south */
472 y
= Player
.p_y
- MAXMOVE();
476 case 'L': /* move right/east */
478 x
= Player
.p_x
+ MAXMOVE();
483 case 'H': /* move left/west */
485 x
= Player
.p_x
- MAXMOVE();
491 Player
.p_energy
+= (Player
.p_maxenergy
+ Player
.p_shield
) / 15.0 +
492 Player
.p_level
/ 3.0 + 2.0;
494 MIN(Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
);
496 if (Player
.p_status
!= S_CLOAKED
) {
497 /* cannot find mana if cloaked */
498 Player
.p_mana
+= (Circle
+ Player
.p_level
) / 4.0;
500 if (drandom() < 0.2 && Player
.p_status
== S_PLAYING
&& !Throne
)
501 /* wandering monster */
506 case 'X': /* change/examine a character */
511 for (loop
= 3; loop
; --loop
) {
512 mvaddstr(4, 0, "X Y Coordinates ? ");
513 getstring(Databuf
, SZ_DATABUF
);
515 if (sscanf(Databuf
, "%lf %lf", &x
, &y
) != 2)
516 mvaddstr(5, 0, "Try again\n");
517 else if (distance(Player
.p_x
, x
, Player
.p_y
, y
) > MAXMOVE())
526 case '2': /* players */
530 case '3': /* message */
531 mvaddstr(4, 0, "Message ? ");
532 getstring(Databuf
, SZ_DATABUF
);
533 /* we open the file for writing to erase any data which is already there */
534 fp
= fopen(_PATH_MESS
, "w");
535 if (Databuf
[0] != '\0')
536 fprintf(fp
, "%s: %s", Player
.p_name
, Databuf
);
540 case '4': /* stats */
544 case '5': /* good-bye */
548 case '6': /* cloak */
549 if (Player
.p_level
< MEL_CLOAK
|| Player
.p_magiclvl
< ML_CLOAK
)
551 else if (Player
.p_status
== S_CLOAKED
)
552 Player
.p_status
= S_PLAYING
;
553 else if (Player
.p_mana
< MM_CLOAK
)
554 mvaddstr(5, 0, "No mana left.\n");
557 Player
.p_mana
-= MM_CLOAK
;
558 Player
.p_status
= S_CLOAKED
;
562 case '7': /* teleport */
565 * conditions for teleport
566 * - 20 per (level plus magic level)
567 * - OR council of the wise or valar or ex-valar
568 * - OR transport from throne
569 * transports from throne cost no mana
571 if (Player
.p_level
< MEL_TELEPORT
|| Player
.p_magiclvl
< ML_TELEPORT
)
574 for (loop
= 3; loop
; --loop
) {
575 mvaddstr(4, 0, "X Y Coordinates ? ");
576 getstring(Databuf
, SZ_DATABUF
);
578 if (sscanf(Databuf
, "%lf %lf", &x
, &y
) == 2) {
579 temp
= distance(Player
.p_x
, x
, Player
.p_y
, y
);
581 /* can transport anywhere from throne */
582 && Player
.p_specialtype
<= SC_COUNCIL
583 /* council, valar can transport anywhere */
584 && temp
> (Player
.p_level
+ Player
.p_magiclvl
) * 20.0)
585 /* can only move 20 per exp. level + mag. level */
588 temp
= (temp
/ 75.0 + 1.0) * 20.0; /* mana used */
590 if (!Throne
&& temp
> Player
.p_mana
)
591 mvaddstr(5, 0, "Not enough power for that distance.\n");
594 Player
.p_mana
-= temp
;
604 case '9': /* monster */
606 /* no monsters while on throne */
607 mvaddstr(5, 0, "No monsters in the chamber!\n");
608 else if (Player
.p_specialtype
!= SC_VALAR
) {
609 /* the valar cannot call monsters */
610 Player
.p_sin
+= 1e-6;
615 case '0': /* decree */
616 if (Wizard
|| (Player
.p_specialtype
== SC_KING
&& Throne
))
617 /* kings must be on throne to decree */
623 case '8': /* intervention */
624 if (Wizard
|| Player
.p_specialtype
>= SC_COUNCIL
)
632 /* player has moved -- alter coordinates, and do random monster */
633 altercoordinates(x
, y
, A_SPECIFIC
);
635 if (drandom() < 0.2 && Player
.p_status
== S_PLAYING
&& !Throne
)
641 * FUNCTION: print title page
643 * GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
645 * GLOBAL OUTPUTS: Lines
648 * Print important information about game, players, etc.
654 FILE *fp
; /* used for opening various files */
655 bool councilfound
= FALSE
; /* set if we find a member of the council */
656 bool kingfound
= FALSE
; /* set if we find a king */
657 double hiexp
, nxtexp
; /* used for finding the two highest players */
658 double hilvl
, nxtlvl
; /* used for finding the two highest players */
659 char hiname
[21], nxtname
[21]; /* used for finding the two highest players */
662 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)!");
664 /* print message of the day */
665 if ((fp
= fopen(_PATH_MOTD
, "r")) != NULL
666 && fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
) {
667 mvaddstr(2, 40 - strlen(Databuf
) / 2, Databuf
);
671 /* search for king */
672 fseek(Playersfp
, 0L, SEEK_SET
);
673 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
674 if (Other
.p_specialtype
== SC_KING
&&
675 Other
.p_status
!= S_NOTUSED
) {
677 sprintf(Databuf
, "The present ruler is %s Level:%.0f",
678 Other
.p_name
, Other
.p_level
);
679 mvaddstr(4, 40 - strlen(Databuf
) / 2, Databuf
);
685 mvaddstr(4, 24, "There is no ruler at this time.");
687 /* search for valar */
688 fseek(Playersfp
, 0L, SEEK_SET
);
689 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
690 if (Other
.p_specialtype
== SC_VALAR
&& Other
.p_status
!= S_NOTUSED
) {
691 /* found the valar */
692 sprintf(Databuf
, "The Valar is %s Login: %s",
693 Other
.p_name
, Other
.p_login
);
694 mvaddstr(6, 40 - strlen(Databuf
) / 2, Databuf
);
698 /* search for council of the wise */
699 fseek(Playersfp
, 0L, SEEK_SET
);
701 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
702 if (Other
.p_specialtype
== SC_COUNCIL
&& Other
.p_status
!= S_NOTUSED
) {
703 /* found a member of the council */
705 mvaddstr(8, 30, "Council of the Wise:");
709 /* This assumes a finite (<=5) number of C.O.W.: */
710 sprintf(Databuf
, "%s Login: %s", Other
.p_name
, Other
.p_login
);
711 mvaddstr(Lines
++, 40 - strlen(Databuf
) / 2, Databuf
);
714 /* search for the two highest players */
715 nxtname
[0] = hiname
[0] = '\0';
719 fseek(Playersfp
, 0L, SEEK_SET
);
720 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
721 if (Other
.p_experience
> hiexp
&& Other
.p_specialtype
<= SC_KING
&& Other
.p_status
!= S_NOTUSED
) {
722 /* highest found so far */
724 hiexp
= Other
.p_experience
;
726 hilvl
= Other
.p_level
;
727 strcpy(nxtname
, hiname
);
728 strcpy(hiname
, Other
.p_name
);
729 } else if (Other
.p_experience
> nxtexp
&&
730 Other
.p_specialtype
<= SC_KING
&&
731 Other
.p_status
!= S_NOTUSED
) {
732 /* next highest found so far */
733 nxtexp
= Other
.p_experience
;
734 nxtlvl
= Other
.p_level
;
735 strcpy(nxtname
, Other
.p_name
);
738 mvaddstr(15, 28, "Highest characters are:");
739 sprintf(Databuf
, "%s Level:%.0f and %s Level:%.0f",
740 hiname
, hilvl
, nxtname
, nxtlvl
);
741 mvaddstr(17, 40 - strlen(Databuf
) / 2, Databuf
);
743 /* print last to die */
744 if ((fp
= fopen(_PATH_LASTDEAD
, "r")) != NULL
745 && fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
) {
746 mvaddstr(19, 25, "The last character to die was:");
747 mvaddstr(20, 40 - strlen(Databuf
) / 2, Databuf
);
755 * FUNCTION: find a character on file
757 * GLOBAL INPUTS: Player, *stdscr, Databuf[]
759 * GLOBAL OUTPUTS: Echo, Player
762 * Search for a character of a certain name, and check password.
768 long loc
= 0L; /* location in player file */
769 int loop
; /* loop counter */
773 mvprintw(10, 0, "What was your character's name ? ");
774 getstring(Databuf
, SZ_NAME
);
775 truncstring(Databuf
);
777 if ((loc
= findname(Databuf
, &Player
)) >= 0L) {
778 /* found character */
781 for (loop
= 0; loop
< 2; ++loop
) {
782 /* prompt for password */
783 mvaddstr(11, 0, "Password ? ");
784 getstring(Databuf
, SZ_PASSWORD
);
785 if (strcmp(Databuf
, Player
.p_password
) == 0) {
789 if (Player
.p_status
!= S_OFF
) {
790 /* player did not exit normally last time */
792 addstr("Your character did not exit normally last time.\n");
793 addstr("If you think you have good cause to have your character saved,\n");
794 printw("you may quit and mail your reason to 'root'.\n");
795 addstr("Otherwise, continuing spells certain death.\n");
796 addstr("Do you want to quit ? ");
797 ch
= getanswer("YN", FALSE
);
799 Player
.p_status
= S_HUNGUP
;
800 writerecord(&Player
, loc
);
809 mvaddstr(12, 0, "No good.\n");
814 mvaddstr(11, 0, "Not found.\n");
821 * FUNCTION: do random stuff
823 * GLOBAL INPUTS: Player, *stdscr, *Statptr
825 * GLOBAL OUTPUTS: Player
828 * Handle gurus, medics, etc.
834 double temp
; /* for temporary calculations */
837 switch ((int)ROLL(0.0, 100.0)) {
840 if (Player
.p_poison
> 0.0) {
841 mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? ");
842 temp
= floor(infloat());
843 if (temp
< 0.0 || temp
> Player
.p_gold
) {
844 /* negative gold, or more than available */
845 mvaddstr(6, 0, "He was not amused, and made you worse.\n");
846 Player
.p_poison
+= 1.0;
847 } else if (drandom() / 2.0 > (temp
+ 1.0) / MAX(Player
.p_gold
, 1))
848 /* medic wants 1/2 of available gold */
849 mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
851 mvaddstr(5, 0, "He accepted.");
852 Player
.p_poison
= MAX(0.0, Player
.p_poison
- 1.0);
853 Player
.p_gold
-= temp
;
859 mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
860 Player
.p_experience
+= 4000.0;
865 temp
= ROLL(10.0, 75.0);
866 mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp
);
867 ch
= getanswer("NY", FALSE
);
870 collecttaxes(temp
, 0.0);
874 if (Player
.p_sin
> 1.0) {
875 mvaddstr(4, 0, "You've found a Holy Orb!\n");
876 Player
.p_sin
-= 0.25;
881 if (Player
.p_poison
< 1.0) {
882 mvaddstr(4, 0, "You've been hit with a plague!\n");
883 Player
.p_poison
+= 1.0;
888 mvaddstr(4, 0, "You've found some holy water.\n");
889 ++Player
.p_holywater
;
893 mvaddstr(4, 0, "You've met a Guru. . .");
894 if (drandom() * Player
.p_sin
> 1.0)
895 addstr("You disgusted him with your sins!\n");
896 else if (Player
.p_poison
> 0.0) {
897 addstr("He looked kindly upon you, and cured you.\n");
898 Player
.p_poison
= 0.0;
900 addstr("He rewarded you for your virtue.\n");
901 Player
.p_mana
+= 50.0;
902 Player
.p_shield
+= 2.0;
907 mvaddstr(4, 0, "You've found an amulet.\n");
912 if (Player
.p_blindness
) {
913 mvaddstr(4, 0, "You've regained your sight!\n");
914 Player
.p_blindness
= FALSE
;
918 default: /* deal with poison */
919 if (Player
.p_poison
> 0.0) {
920 temp
= Player
.p_poison
* Statptr
->c_weakness
921 * Player
.p_maxenergy
/ 600.0;
922 if (Player
.p_energy
> Player
.p_maxenergy
/ 10.0
923 && temp
+ 5.0 < Player
.p_energy
)
924 Player
.p_energy
-= temp
;
931 * FUNCTION: generate a random character
934 * int type - ASCII value of character type to generate
936 * GLOBAL INPUTS: Wizard, Player, Stattable[]
938 * GLOBAL OUTPUTS: Player
941 * Use the lookup table for rolling stats.
947 int subscript
; /* used for subscripting into Stattable */
948 const struct charstats
*statptr
; /* for pointing into Stattable */
950 subscript
= type
- '1';
952 if (subscript
< C_MAGIC
|| subscript
> C_EXPER
)
953 if (subscript
!= C_SUPER
|| !Wizard
)
954 /* fighter is default */
955 subscript
= C_FIGHTER
;
957 statptr
= &Stattable
[subscript
];
960 ROLL(statptr
->c_quickness
.base
, statptr
->c_quickness
.interval
);
962 ROLL(statptr
->c_strength
.base
, statptr
->c_strength
.interval
);
964 ROLL(statptr
->c_mana
.base
, statptr
->c_mana
.interval
);
967 ROLL(statptr
->c_energy
.base
, statptr
->c_energy
.interval
);
969 ROLL(statptr
->c_brains
.base
, statptr
->c_brains
.interval
);
971 ROLL(statptr
->c_magiclvl
.base
, statptr
->c_magiclvl
.interval
);
973 Player
.p_type
= subscript
;
975 if (Player
.p_type
== C_HALFLING
)
976 /* give halfling some experience */
977 Player
.p_experience
= ROLL(600.0, 200.0);
981 * FUNCTION: initialize for playing game
983 * GLOBAL INPUTS: *stdscr, ill_sig()
985 * GLOBAL OUTPUTS: Windows
988 * Catch a bunch of signals, and turn on curses stuff.
994 /* catch/ingnore signals */
1004 sigset(SIGHUP
, ill_sig
);
1005 sigset(SIGTRAP
, ill_sig
);
1006 sigset(SIGIOT
, ill_sig
);
1007 sigset(SIGEMT
, ill_sig
);
1008 sigset(SIGFPE
, ill_sig
);
1009 sigset(SIGBUS
, ill_sig
);
1010 sigset(SIGSEGV
, ill_sig
);
1011 sigset(SIGSYS
, ill_sig
);
1012 sigset(SIGPIPE
, ill_sig
);
1015 signal(SIGQUIT
, ill_sig
);
1016 signal(SIGALRM
, SIG_IGN
);
1017 signal(SIGTERM
, SIG_IGN
);
1018 signal(SIGTSTP
, SIG_IGN
);
1019 signal(SIGTTIN
, SIG_IGN
);
1020 signal(SIGTTOU
, SIG_IGN
);
1021 signal(SIGINT
, ill_sig
);
1022 signal(SIGHUP
, SIG_DFL
);
1023 signal(SIGTRAP
, ill_sig
);
1024 signal(SIGIOT
, ill_sig
);
1025 signal(SIGEMT
, ill_sig
);
1026 signal(SIGFPE
, ill_sig
);
1027 signal(SIGBUS
, ill_sig
);
1028 signal(SIGSEGV
, ill_sig
);
1029 signal(SIGSYS
, ill_sig
);
1030 signal(SIGPIPE
, ill_sig
);
1033 signal(SIGINT
, SIG_IGN
);
1034 signal(SIGQUIT
, SIG_IGN
);
1035 signal(SIGTERM
, SIG_IGN
);
1036 signal(SIGALRM
, SIG_IGN
);
1037 signal(SIGHUP
, ill_sig
);
1038 signal(SIGTRAP
, ill_sig
);
1039 signal(SIGIOT
, ill_sig
);
1040 signal(SIGEMT
, ill_sig
);
1041 signal(SIGFPE
, ill_sig
);
1042 signal(SIGBUS
, ill_sig
);
1043 signal(SIGSEGV
, ill_sig
);
1044 signal(SIGSYS
, ill_sig
);
1045 signal(SIGPIPE
, ill_sig
);
1048 signal(SIGINT
, SIG_IGN
);
1049 signal(SIGQUIT
, SIG_IGN
);
1050 signal(SIGTERM
, SIG_IGN
);
1051 signal(SIGALRM
, SIG_IGN
);
1052 signal(SIGHUP
, ill_sig
);
1053 signal(SIGTRAP
, ill_sig
);
1054 signal(SIGIOT
, ill_sig
);
1055 signal(SIGEMT
, ill_sig
);
1056 signal(SIGFPE
, ill_sig
);
1057 signal(SIGBUS
, ill_sig
);
1058 signal(SIGSEGV
, ill_sig
);
1059 signal(SIGSYS
, ill_sig
);
1060 signal(SIGPIPE
, ill_sig
);
1063 initscr(); /* turn on curses */
1064 noecho(); /* do not echo input */
1065 cbreak(); /* do not process erase, kill */
1068 Windows
= TRUE
; /* mark the state */
1073 * FUNCTION: close some files, and maybe exit
1076 * bool doexit - exit flag
1078 * GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
1079 * *Messagefp, *Playersfp
1082 * Close all open files. If we are "in curses" terminate curses.
1083 * If 'doexit' is set, exit, otherwise return.
1087 cleanup(bool doexit
)
1108 fclose(Energyvoidfp
);
1109 Energyvoidfp
= NULL
;