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.3 2005/05/31 00:06:26 swildner 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 * The scoreboard file is updated when someone dies, and keeps track
46 * of the highest character to date for that login.
47 * Being purged from the character file does not cause the scoreboard
54 /* functions which we need to know about */
56 extern void encounter(int);
58 extern void activelist(void);
59 extern void changestats(bool);
60 extern void monstlist(void);
61 extern void purgeoldplayers(void);
62 extern void scorelist(void);
64 extern void checkbattle(void);
65 extern void checktampered(void);
66 extern void dotampered(void);
67 extern void throneroom(void);
68 extern void userlist(bool);
70 extern int getanswer(const char *, bool);
71 extern void getstring(char *, int);
72 extern double infloat(void);
73 extern int inputoption(void);
74 extern void more(int);
76 extern void adjuststats(void);
77 extern long allocrecord(void);
78 extern void allstatslist(void);
79 extern void altercoordinates(double, double, int);
80 extern void collecttaxes(double, double);
81 extern void death(const char *);
82 extern void displaystats(void);
83 extern double distance(double, double, double, double);
84 extern void error(const char *);
85 extern long findname(char *, struct player
*);
86 extern void initplayer(struct player
*);
87 extern void leavegame(void);
88 extern void readmessage(void);
89 extern void tradingpost(void);
90 extern void truncstring(char *);
91 extern void writerecord(struct player
*, long);
93 extern double drandom(void);
97 void initialstate(void);
101 long recallplayer(void);
102 long rollnewplayer(void);
103 void titlelist(void);
106 * FUNCTION: initialize state, and call main process
108 * GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
109 * Fileloc, Stattable[]
111 * GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
114 * Process arguments, initialize program, and loop forever processing
119 main(int argc
, char **argv
)
121 bool noheader
= FALSE
; /* set if don't want header */
122 bool headeronly
= FALSE
; /* set if only want header */
123 bool examine
= FALSE
; /* set if examine a character */
124 time_t seconds
; /* for time of day */
125 double dtemp
; /* for temporary calculations */
127 initialstate(); /* init globals */
129 /* process arguments */
130 while (--argc
&& (*++argv
)[0] == '-')
131 switch ((*argv
)[1]) {
132 case 's': /* short */
136 case 'H': /* Header */
140 case 'a': /* all users */
145 case 'p': /* purge old players */
150 case 'S': /* set 'Wizard' */
154 case 'x': /* examine */
158 case 'm': /* monsters */
163 case 'b': /* scoreboard */
169 if (!isatty(0)) /* don't let non-tty's play */
173 playinit(); /* set up to catch signals, init curses */
183 purgeoldplayers(); /* clean up old characters */
191 /* get the player structure filled */
194 mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
196 switch (getanswer("NYQ", FALSE
)) {
198 Fileloc
= recallplayer();
206 Fileloc
= rollnewplayer();
210 } while (Fileloc
< 0L);
212 if (Player
.p_level
> 5.0)
213 /* low level players have long timeout */
216 /* update some important player statistics */
217 strcpy(Player
.p_login
, Login
);
219 Player
.p_lastused
= localtime(&seconds
)->tm_yday
;
220 Player
.p_status
= S_PLAYING
;
221 writerecord(&Player
, Fileloc
);
223 Statptr
= &Stattable
[Player
.p_type
]; /* initialize pointer */
225 /* catch interrupts */
227 sigset(SIGINT
, interrupt
);
230 signal(SIGINT
, interrupt
);
233 signal(SIGINT
, interrupt
);
236 signal(SIGINT
, interrupt
);
239 altercoordinates(Player
.p_x
, Player
.p_y
, A_FORCED
); /* set some flags */
244 /* loop forever, processing input */
246 adjuststats(); /* cleanup stats */
248 if (Throne
&& Player
.p_crowns
== 0 && Player
.p_specialtype
!= SC_KING
) {
249 /* not allowed on throne -- move */
250 mvaddstr(5, 0, "You're not allowed in the Lord's Chamber without a crown.\n");
251 altercoordinates(0.0, 0.0, A_NEAR
);
254 checktampered(); /* check for energy voids, etc. */
256 if (Player
.p_status
!= S_CLOAKED
258 && (dtemp
= fabs(Player
.p_x
)) == fabs(Player
.p_y
)
262 dtemp
= sqrt(dtemp
/ 100.0);
263 if (floor(dtemp
) == dtemp
) {
264 /* |x| / 100 == n*n; at a trading post */
270 checkbattle(); /* check for player to player battle */
271 neatstuff(); /* gurus, medics, etc. */
273 if (Player
.p_status
== S_CLOAKED
) {
274 /* costs 3 mana per turn to be cloaked */
275 if (Player
.p_mana
> 3.0)
276 Player
.p_mana
-= 3.0;
278 /* ran out of mana, uncloak */
279 Player
.p_status
= S_PLAYING
;
284 if (Player
.p_status
!= S_PLAYING
&& Player
.p_status
!= S_CLOAKED
) {
285 /* change status back to S_PLAYING */
286 Player
.p_status
= S_PLAYING
;
291 /* update file only if important stuff has changed */
292 writerecord(&Player
, Fileloc
);
297 readmessage(); /* read message, if any */
299 displaystats(); /* print statistics */
304 /* maybe make king, print prompt, etc. */
307 /* print status line */
308 addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit ");
309 if (Player
.p_level
>= MEL_CLOAK
&& Player
.p_magiclvl
>= ML_CLOAK
)
311 if (Player
.p_level
>= MEL_TELEPORT
&& Player
.p_magiclvl
>= ML_TELEPORT
)
312 addstr("7:Teleport ");
313 if (Player
.p_specialtype
>= SC_COUNCIL
|| Wizard
)
314 addstr("8:Intervene ");
316 procmain(); /* process input */
321 * FUNCTION: initialize some important global variable
323 * GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
324 * Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
328 * Set global flags, and open files which remain open.
344 /* setup login name */
345 if ((Login
= getlogin()) == NULL
)
346 Login
= getpwuid(getuid())->pw_name
;
348 /* open some files */
349 if ((Playersfp
= fopen(_PATH_PEOPLE
, "r+")) == NULL
)
353 if ((Monstfp
= fopen(_PATH_MONST
, "r+")) == NULL
)
357 if ((Messagefp
= fopen(_PATH_MESS
, "r")) == NULL
)
361 if ((Energyvoidfp
= fopen(_PATH_VOID
, "r+")) == NULL
)
369 * FUNCTION: roll up a new character
371 * GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
373 * GLOBAL OUTPUTS: Echo
376 * Prompt player, and roll up new character.
382 int chartype
; /* character type */
385 initplayer(&Player
); /* initialize player structure */
388 mvaddstr(4, 21, "Which type of character do you want:");
389 mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento ");
391 addstr("7:Super ? ");
392 chartype
= getanswer("1234567", FALSE
);
395 chartype
= getanswer("123456", FALSE
);
399 genchar(chartype
); /* roll up a character */
401 /* print out results */
403 "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n",
404 Player
.p_strength
, Player
.p_quickness
, Player
.p_mana
);
406 "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n",
407 Player
.p_energy
, Player
.p_brains
, Player
.p_magiclvl
);
409 if (Player
.p_type
== C_EXPER
|| Player
.p_type
== C_SUPER
)
412 mvaddstr(14, 14, "Type '1' to keep >");
413 ch
= getanswer(" ", TRUE
);
416 if (Player
.p_type
== C_EXPER
|| Player
.p_type
== C_SUPER
)
417 /* get coordinates for experimento */
419 mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
420 getstring(Databuf
, SZ_DATABUF
);
421 sscanf(Databuf
, "%lf %lf", &Player
.p_x
, &Player
.p_y
);
423 if (fabs(Player
.p_x
) > D_EXPER
|| fabs(Player
.p_y
) > D_EXPER
)
424 mvaddstr(17, 0, "Invalid coordinates. Try again.\n");
430 /* name the new character */
432 "Give your character a name [up to %d characters] ? ", SZ_NAME
- 1);
433 getstring(Player
.p_name
, SZ_NAME
);
434 truncstring(Player
.p_name
); /* remove trailing blanks */
436 if (Player
.p_name
[0] == '\0')
438 mvaddstr(19, 0, "Invalid name.");
439 else if (findname(Player
.p_name
, &Other
) >= 0L)
440 /* cannot have duplicate names */
441 mvaddstr(19, 0, "Name already in use.");
443 /* name is acceptable */
446 addstr(" Pick another.\n");
449 /* get a password for character */
453 mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
454 getstring(Player
.p_password
, SZ_PASSWORD
);
455 mvaddstr(21, 0, "One more time to verify ? ");
456 getstring(Databuf
, SZ_PASSWORD
);
457 } while (strcmp(Player
.p_password
, Databuf
) != 0);
461 return (allocrecord());
465 * FUNCTION: process input from player
467 * GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
468 * Databuf[], Illmove[]
470 * GLOBAL OUTPUTS: Player, Changed
473 * Process main menu options.
480 double x
; /* desired new x coordinate */
481 double y
; /* desired new y coordinate */
482 double temp
; /* for temporary calculations */
483 FILE *fp
; /* for opening files */
484 int loop
; /* a loop counter */
485 bool hasmoved
= FALSE
; /* set if player has moved */
488 mvaddstr(4, 0, "\n\n"); /* clear status area */
491 clrtobot(); /* clear data on bottom area of screen */
493 if (Player
.p_specialtype
== SC_VALAR
&& (ch
== '1' || ch
== '7'))
494 /* valar cannot move */
498 case 'K': /* move up/north */
501 y
= Player
.p_y
+ MAXMOVE();
505 case 'J': /* move down/south */
508 y
= Player
.p_y
- MAXMOVE();
512 case 'L': /* move right/east */
514 x
= Player
.p_x
+ MAXMOVE();
519 case 'H': /* move left/west */
521 x
= Player
.p_x
- MAXMOVE();
527 Player
.p_energy
+= (Player
.p_maxenergy
+ Player
.p_shield
) / 15.0 +
528 Player
.p_level
/ 3.0 + 2.0;
530 MIN(Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
);
532 if (Player
.p_status
!= S_CLOAKED
) {
533 /* cannot find mana if cloaked */
534 Player
.p_mana
+= (Circle
+ Player
.p_level
) / 4.0;
536 if (drandom() < 0.2 && Player
.p_status
== S_PLAYING
&& !Throne
)
537 /* wandering monster */
542 case 'X': /* change/examine a character */
547 for (loop
= 3; loop
; --loop
) {
548 mvaddstr(4, 0, "X Y Coordinates ? ");
549 getstring(Databuf
, SZ_DATABUF
);
551 if (sscanf(Databuf
, "%lf %lf", &x
, &y
) != 2)
552 mvaddstr(5, 0, "Try again\n");
553 else if (distance(Player
.p_x
, x
, Player
.p_y
, y
) > MAXMOVE())
562 case '2': /* players */
566 case '3': /* message */
567 mvaddstr(4, 0, "Message ? ");
568 getstring(Databuf
, SZ_DATABUF
);
569 /* we open the file for writing to erase any data which is already there */
570 fp
= fopen(_PATH_MESS
, "w");
571 if (Databuf
[0] != '\0')
572 fprintf(fp
, "%s: %s", Player
.p_name
, Databuf
);
576 case '4': /* stats */
580 case '5': /* good-bye */
584 case '6': /* cloak */
585 if (Player
.p_level
< MEL_CLOAK
|| Player
.p_magiclvl
< ML_CLOAK
)
587 else if (Player
.p_status
== S_CLOAKED
)
588 Player
.p_status
= S_PLAYING
;
589 else if (Player
.p_mana
< MM_CLOAK
)
590 mvaddstr(5, 0, "No mana left.\n");
593 Player
.p_mana
-= MM_CLOAK
;
594 Player
.p_status
= S_CLOAKED
;
598 case '7': /* teleport */
601 * conditions for teleport
602 * - 20 per (level plus magic level)
603 * - OR council of the wise or valar or ex-valar
604 * - OR transport from throne
605 * transports from throne cost no mana
607 if (Player
.p_level
< MEL_TELEPORT
|| Player
.p_magiclvl
< ML_TELEPORT
)
610 for (loop
= 3; loop
; --loop
) {
611 mvaddstr(4, 0, "X Y Coordinates ? ");
612 getstring(Databuf
, SZ_DATABUF
);
614 if (sscanf(Databuf
, "%lf %lf", &x
, &y
) == 2) {
615 temp
= distance(Player
.p_x
, x
, Player
.p_y
, y
);
617 /* can transport anywhere from throne */
618 && Player
.p_specialtype
<= SC_COUNCIL
619 /* council, valar can transport anywhere */
620 && temp
> (Player
.p_level
+ Player
.p_magiclvl
) * 20.0)
621 /* can only move 20 per exp. level + mag. level */
624 temp
= (temp
/ 75.0 + 1.0) * 20.0; /* mana used */
626 if (!Throne
&& temp
> Player
.p_mana
)
627 mvaddstr(5, 0, "Not enough power for that distance.\n");
630 Player
.p_mana
-= temp
;
640 case '9': /* monster */
642 /* no monsters while on throne */
643 mvaddstr(5, 0, "No monsters in the chamber!\n");
644 else if (Player
.p_specialtype
!= SC_VALAR
) {
645 /* the valar cannot call monsters */
646 Player
.p_sin
+= 1e-6;
651 case '0': /* decree */
652 if (Wizard
|| (Player
.p_specialtype
== SC_KING
&& Throne
))
653 /* kings must be on throne to decree */
659 case '8': /* intervention */
660 if (Wizard
|| Player
.p_specialtype
>= SC_COUNCIL
)
668 /* player has moved -- alter coordinates, and do random monster */
669 altercoordinates(x
, y
, A_SPECIFIC
);
671 if (drandom() < 0.2 && Player
.p_status
== S_PLAYING
&& !Throne
)
677 * FUNCTION: print title page
679 * GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
681 * GLOBAL OUTPUTS: Lines
684 * Print important information about game, players, etc.
690 FILE *fp
; /* used for opening various files */
691 bool councilfound
= FALSE
; /* set if we find a member of the council */
692 bool kingfound
= FALSE
; /* set if we find a king */
693 double hiexp
, nxtexp
; /* used for finding the two highest players */
694 double hilvl
, nxtlvl
; /* used for finding the two highest players */
695 char hiname
[21], nxtname
[21]; /* used for finding the two highest players */
698 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)!");
700 /* print message of the day */
701 if ((fp
= fopen(_PATH_MOTD
, "r")) != NULL
702 && fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
) {
703 mvaddstr(2, 40 - strlen(Databuf
) / 2, Databuf
);
707 /* search for king */
708 fseek(Playersfp
, 0L, SEEK_SET
);
709 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
710 if (Other
.p_specialtype
== SC_KING
&&
711 Other
.p_status
!= S_NOTUSED
) {
713 sprintf(Databuf
, "The present ruler is %s Level:%.0f",
714 Other
.p_name
, Other
.p_level
);
715 mvaddstr(4, 40 - strlen(Databuf
) / 2, Databuf
);
721 mvaddstr(4, 24, "There is no ruler at this time.");
723 /* search for valar */
724 fseek(Playersfp
, 0L, SEEK_SET
);
725 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
726 if (Other
.p_specialtype
== SC_VALAR
&& Other
.p_status
!= S_NOTUSED
) {
727 /* found the valar */
728 sprintf(Databuf
, "The Valar is %s Login: %s",
729 Other
.p_name
, Other
.p_login
);
730 mvaddstr(6, 40 - strlen(Databuf
) / 2, Databuf
);
734 /* search for council of the wise */
735 fseek(Playersfp
, 0L, SEEK_SET
);
737 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
738 if (Other
.p_specialtype
== SC_COUNCIL
&& Other
.p_status
!= S_NOTUSED
) {
739 /* found a member of the council */
741 mvaddstr(8, 30, "Council of the Wise:");
745 /* This assumes a finite (<=5) number of C.O.W.: */
746 sprintf(Databuf
, "%s Login: %s", Other
.p_name
, Other
.p_login
);
747 mvaddstr(Lines
++, 40 - strlen(Databuf
) / 2, Databuf
);
750 /* search for the two highest players */
751 nxtname
[0] = hiname
[0] = '\0';
755 fseek(Playersfp
, 0L, SEEK_SET
);
756 while (fread((char *)&Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
757 if (Other
.p_experience
> hiexp
&& Other
.p_specialtype
<= SC_KING
&& Other
.p_status
!= S_NOTUSED
) {
758 /* highest found so far */
760 hiexp
= Other
.p_experience
;
762 hilvl
= Other
.p_level
;
763 strcpy(nxtname
, hiname
);
764 strcpy(hiname
, Other
.p_name
);
765 } else if (Other
.p_experience
> nxtexp
&&
766 Other
.p_specialtype
<= SC_KING
&&
767 Other
.p_status
!= S_NOTUSED
) {
768 /* next highest found so far */
769 nxtexp
= Other
.p_experience
;
770 nxtlvl
= Other
.p_level
;
771 strcpy(nxtname
, Other
.p_name
);
774 mvaddstr(15, 28, "Highest characters are:");
775 sprintf(Databuf
, "%s Level:%.0f and %s Level:%.0f",
776 hiname
, hilvl
, nxtname
, nxtlvl
);
777 mvaddstr(17, 40 - strlen(Databuf
) / 2, Databuf
);
779 /* print last to die */
780 if ((fp
= fopen(_PATH_LASTDEAD
, "r")) != NULL
781 && fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
) {
782 mvaddstr(19, 25, "The last character to die was:");
783 mvaddstr(20, 40 - strlen(Databuf
) / 2, Databuf
);
791 * FUNCTION: find a character on file
793 * GLOBAL INPUTS: Player, *stdscr, Databuf[]
795 * GLOBAL OUTPUTS: Echo, Player
798 * Search for a character of a certain name, and check password.
804 long loc
= 0L; /* location in player file */
805 int loop
; /* loop counter */
809 mvprintw(10, 0, "What was your character's name ? ");
810 getstring(Databuf
, SZ_NAME
);
811 truncstring(Databuf
);
813 if ((loc
= findname(Databuf
, &Player
)) >= 0L) {
814 /* found character */
817 for (loop
= 0; loop
< 2; ++loop
) {
818 /* prompt for password */
819 mvaddstr(11, 0, "Password ? ");
820 getstring(Databuf
, SZ_PASSWORD
);
821 if (strcmp(Databuf
, Player
.p_password
) == 0) {
825 if (Player
.p_status
!= S_OFF
) {
826 /* player did not exit normally last time */
828 addstr("Your character did not exit normally last time.\n");
829 addstr("If you think you have good cause to have your character saved,\n");
830 printw("you may quit and mail your reason to 'root'.\n");
831 addstr("Otherwise, continuing spells certain death.\n");
832 addstr("Do you want to quit ? ");
833 ch
= getanswer("YN", FALSE
);
835 Player
.p_status
= S_HUNGUP
;
836 writerecord(&Player
, loc
);
845 mvaddstr(12, 0, "No good.\n");
850 mvaddstr(11, 0, "Not found.\n");
857 * FUNCTION: do random stuff
859 * GLOBAL INPUTS: Player, *stdscr, *Statptr
861 * GLOBAL OUTPUTS: Player
864 * Handle gurus, medics, etc.
870 double temp
; /* for temporary calculations */
873 switch ((int)ROLL(0.0, 100.0)) {
876 if (Player
.p_poison
> 0.0) {
877 mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? ");
878 temp
= floor(infloat());
879 if (temp
< 0.0 || temp
> Player
.p_gold
) {
880 /* negative gold, or more than available */
881 mvaddstr(6, 0, "He was not amused, and made you worse.\n");
882 Player
.p_poison
+= 1.0;
883 } else if (drandom() / 2.0 > (temp
+ 1.0) / MAX(Player
.p_gold
, 1))
884 /* medic wants 1/2 of available gold */
885 mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
887 mvaddstr(5, 0, "He accepted.");
888 Player
.p_poison
= MAX(0.0, Player
.p_poison
- 1.0);
889 Player
.p_gold
-= temp
;
895 mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
896 Player
.p_experience
+= 4000.0;
901 temp
= ROLL(10.0, 75.0);
902 mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp
);
903 ch
= getanswer("NY", FALSE
);
906 collecttaxes(temp
, 0.0);
910 if (Player
.p_sin
> 1.0) {
911 mvaddstr(4, 0, "You've found a Holy Orb!\n");
912 Player
.p_sin
-= 0.25;
917 if (Player
.p_poison
< 1.0) {
918 mvaddstr(4, 0, "You've been hit with a plague!\n");
919 Player
.p_poison
+= 1.0;
924 mvaddstr(4, 0, "You've found some holy water.\n");
925 ++Player
.p_holywater
;
929 mvaddstr(4, 0, "You've met a Guru. . .");
930 if (drandom() * Player
.p_sin
> 1.0)
931 addstr("You disgusted him with your sins!\n");
932 else if (Player
.p_poison
> 0.0) {
933 addstr("He looked kindly upon you, and cured you.\n");
934 Player
.p_poison
= 0.0;
936 addstr("He rewarded you for your virtue.\n");
937 Player
.p_mana
+= 50.0;
938 Player
.p_shield
+= 2.0;
943 mvaddstr(4, 0, "You've found an amulet.\n");
948 if (Player
.p_blindness
) {
949 mvaddstr(4, 0, "You've regained your sight!\n");
950 Player
.p_blindness
= FALSE
;
954 default: /* deal with poison */
955 if (Player
.p_poison
> 0.0) {
956 temp
= Player
.p_poison
* Statptr
->c_weakness
957 * Player
.p_maxenergy
/ 600.0;
958 if (Player
.p_energy
> Player
.p_maxenergy
/ 10.0
959 && temp
+ 5.0 < Player
.p_energy
)
960 Player
.p_energy
-= temp
;
967 * FUNCTION: generate a random character
970 * int type - ASCII value of character type to generate
972 * GLOBAL INPUTS: Wizard, Player, Stattable[]
974 * GLOBAL OUTPUTS: Player
977 * Use the lookup table for rolling stats.
983 int subscript
; /* used for subscripting into Stattable */
984 struct charstats
*statptr
; /* for pointing into Stattable */
986 subscript
= type
- '1';
988 if (subscript
< C_MAGIC
|| subscript
> C_EXPER
)
989 if (subscript
!= C_SUPER
|| !Wizard
)
990 /* fighter is default */
991 subscript
= C_FIGHTER
;
993 statptr
= &Stattable
[subscript
];
996 ROLL(statptr
->c_quickness
.base
, statptr
->c_quickness
.interval
);
998 ROLL(statptr
->c_strength
.base
, statptr
->c_strength
.interval
);
1000 ROLL(statptr
->c_mana
.base
, statptr
->c_mana
.interval
);
1001 Player
.p_maxenergy
=
1003 ROLL(statptr
->c_energy
.base
, statptr
->c_energy
.interval
);
1005 ROLL(statptr
->c_brains
.base
, statptr
->c_brains
.interval
);
1007 ROLL(statptr
->c_magiclvl
.base
, statptr
->c_magiclvl
.interval
);
1009 Player
.p_type
= subscript
;
1011 if (Player
.p_type
== C_HALFLING
)
1012 /* give halfling some experience */
1013 Player
.p_experience
= ROLL(600.0, 200.0);
1017 * FUNCTION: initialize for playing game
1019 * GLOBAL INPUTS: *stdscr, ill_sig()
1021 * GLOBAL OUTPUTS: Windows
1024 * Catch a bunch of signals, and turn on curses stuff.
1030 /* catch/ingnore signals */
1040 sigset(SIGHUP
, ill_sig
);
1041 sigset(SIGTRAP
, ill_sig
);
1042 sigset(SIGIOT
, ill_sig
);
1043 sigset(SIGEMT
, ill_sig
);
1044 sigset(SIGFPE
, ill_sig
);
1045 sigset(SIGBUS
, ill_sig
);
1046 sigset(SIGSEGV
, ill_sig
);
1047 sigset(SIGSYS
, ill_sig
);
1048 sigset(SIGPIPE
, ill_sig
);
1051 signal(SIGQUIT
, ill_sig
);
1052 signal(SIGALRM
, SIG_IGN
);
1053 signal(SIGTERM
, SIG_IGN
);
1054 signal(SIGTSTP
, SIG_IGN
);
1055 signal(SIGTTIN
, SIG_IGN
);
1056 signal(SIGTTOU
, SIG_IGN
);
1057 signal(SIGINT
, ill_sig
);
1058 signal(SIGHUP
, SIG_DFL
);
1059 signal(SIGTRAP
, ill_sig
);
1060 signal(SIGIOT
, ill_sig
);
1061 signal(SIGEMT
, ill_sig
);
1062 signal(SIGFPE
, ill_sig
);
1063 signal(SIGBUS
, ill_sig
);
1064 signal(SIGSEGV
, ill_sig
);
1065 signal(SIGSYS
, ill_sig
);
1066 signal(SIGPIPE
, ill_sig
);
1069 signal(SIGINT
, SIG_IGN
);
1070 signal(SIGQUIT
, SIG_IGN
);
1071 signal(SIGTERM
, SIG_IGN
);
1072 signal(SIGALRM
, SIG_IGN
);
1073 signal(SIGHUP
, ill_sig
);
1074 signal(SIGTRAP
, ill_sig
);
1075 signal(SIGIOT
, ill_sig
);
1076 signal(SIGEMT
, ill_sig
);
1077 signal(SIGFPE
, ill_sig
);
1078 signal(SIGBUS
, ill_sig
);
1079 signal(SIGSEGV
, ill_sig
);
1080 signal(SIGSYS
, ill_sig
);
1081 signal(SIGPIPE
, ill_sig
);
1084 signal(SIGINT
, SIG_IGN
);
1085 signal(SIGQUIT
, SIG_IGN
);
1086 signal(SIGTERM
, SIG_IGN
);
1087 signal(SIGALRM
, SIG_IGN
);
1088 signal(SIGHUP
, ill_sig
);
1089 signal(SIGTRAP
, ill_sig
);
1090 signal(SIGIOT
, ill_sig
);
1091 signal(SIGEMT
, ill_sig
);
1092 signal(SIGFPE
, ill_sig
);
1093 signal(SIGBUS
, ill_sig
);
1094 signal(SIGSEGV
, ill_sig
);
1095 signal(SIGSYS
, ill_sig
);
1096 signal(SIGPIPE
, ill_sig
);
1099 initscr(); /* turn on curses */
1100 noecho(); /* do not echo input */
1101 cbreak(); /* do not process erase, kill */
1104 Windows
= TRUE
; /* mark the state */
1109 * FUNCTION: close some files, and maybe exit
1112 * bool doexit - exit flag
1114 * GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
1115 * *Messagefp, *Playersfp
1118 * Close all open files. If we are "in curses" terminate curses.
1119 * If 'doexit' is set, exit, otherwise return.
1123 cleanup(bool doexit
)
1144 fclose(Energyvoidfp
);
1145 Energyvoidfp
= NULL
;