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 02: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 * 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 /* functions which we need to know about */
69 extern void encounter(int);
71 extern void activelist(void);
72 extern void changestats(bool);
73 extern void monstlist(void);
74 extern void purgeoldplayers(void);
75 extern void scorelist(void);
77 extern void checkbattle(void);
78 extern void checktampered(void);
79 extern void dotampered(void);
80 extern void throneroom(void);
81 extern void userlist(bool);
83 extern int getanswer(const char *, bool);
84 extern void getstring(char *, int);
85 extern double infloat(void);
86 extern int inputoption(void);
87 extern void more(int);
89 extern void adjuststats(void);
90 extern long allocrecord(void);
91 extern void allstatslist(void);
92 extern void altercoordinates(double, double, int);
93 extern void collecttaxes(double, double);
94 extern void death(const char *);
95 extern void displaystats(void);
96 extern double distance(double, double, double, double);
97 extern void error(const char *);
98 extern long findname(char *, struct player
*);
99 extern void initplayer(struct player
*);
100 extern void leavegame(void);
101 extern void readmessage(void);
102 extern void tradingpost(void);
103 extern void truncstring(char *);
104 extern void writerecord(struct player
*, long);
106 extern double drandom(void);
108 void initialstate(void);
109 long rollnewplayer(void);
111 void titlelist(void);
112 long recallplayer(void);
113 void neatstuff(void);
118 /***************************************************************************
119 / FUNCTION NAME: main()
121 / FUNCTION: initialize state, and call main process
123 / AUTHOR: E. A. Estes, 12/4/85
126 / int argc - argument count
127 / char **argv - argument vector
131 / MODULES CALLED: monstlist(), checkenemy(), activelist(),
132 / throneroom(), checkbattle(), readmessage(), changestats(), writerecord(),
133 / tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(),
134 / fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(),
135 / signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(),
136 / strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(),
137 / playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(),
138 / scorelist(), titlelist()
140 / GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[],
141 / Fileloc, Stattable[]
143 / GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr
146 / Process arguments, initialize program, and loop forever processing
149 ****************************************************************************/
152 main(int argc
, char **argv
)
154 bool noheader
= FALSE
; /* set if don't want header */
155 bool headeronly
= FALSE
; /* set if only want header */
156 bool examine
= FALSE
; /* set if examine a character */
157 time_t seconds
; /* for time of day */
158 double dtemp
; /* for temporary calculations */
160 initialstate(); /* init globals */
162 /* process arguments */
163 while (--argc
&& (*++argv
)[0] == '-')
166 case 's': /* short */
170 case 'H': /* Header */
174 case 'a': /* all users */
179 case 'p': /* purge old players */
184 case 'S': /* set 'Wizard' */
188 case 'x': /* examine */
192 case 'm': /* monsters */
197 case 'b': /* scoreboard */
203 if (!isatty(0)) /* don't let non-tty's play */
207 playinit(); /* set up to catch signals, init curses */
219 purgeoldplayers(); /* clean up old characters */
227 /* get the player structure filled */
231 mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");
233 switch (getanswer("NYQ", FALSE
))
236 Fileloc
= recallplayer();
244 Fileloc
= rollnewplayer();
249 while (Fileloc
< 0L);
251 if (Player
.p_level
> 5.0)
252 /* low level players have long timeout */
255 /* update some important player statistics */
256 strcpy(Player
.p_login
, Login
);
258 Player
.p_lastused
= localtime(&seconds
)->tm_yday
;
259 Player
.p_status
= S_PLAYING
;
260 writerecord(&Player
, Fileloc
);
262 Statptr
= &Stattable
[Player
.p_type
]; /* initialize pointer */
264 /* catch interrupts */
266 sigset(SIGINT
, interrupt
);
269 signal(SIGINT
, interrupt
);
272 signal(SIGINT
, interrupt
);
275 signal(SIGINT
, interrupt
);
278 altercoordinates(Player
.p_x
, Player
.p_y
, A_FORCED
); /* set some flags */
283 /* loop forever, processing input */
286 adjuststats(); /* cleanup stats */
288 if (Throne
&& Player
.p_crowns
== 0 && Player
.p_specialtype
!= SC_KING
)
289 /* not allowed on throne -- move */
291 mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n");
292 altercoordinates(0.0, 0.0, A_NEAR
);
295 checktampered(); /* check for energy voids, etc. */
297 if (Player
.p_status
!= S_CLOAKED
299 && (dtemp
= fabs(Player
.p_x
)) == fabs(Player
.p_y
)
304 dtemp
= sqrt(dtemp
/ 100.0);
305 if (floor(dtemp
) == dtemp
)
306 /* |x| / 100 == n*n; at a trading post */
313 checkbattle(); /* check for player to player battle */
314 neatstuff(); /* gurus, medics, etc. */
316 if (Player
.p_status
== S_CLOAKED
)
317 /* costs 3 mana per turn to be cloaked */
319 if (Player
.p_mana
> 3.0)
320 Player
.p_mana
-= 3.0;
322 /* ran out of mana, uncloak */
324 Player
.p_status
= S_PLAYING
;
329 if (Player
.p_status
!= S_PLAYING
&& Player
.p_status
!= S_CLOAKED
)
330 /* change status back to S_PLAYING */
332 Player
.p_status
= S_PLAYING
;
337 /* update file only if important stuff has changed */
339 writerecord(&Player
, Fileloc
);
344 readmessage(); /* read message, if any */
346 displaystats(); /* print statistics */
351 /* maybe make king, print prompt, etc. */
354 /* print status line */
355 addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit ");
356 if (Player
.p_level
>= MEL_CLOAK
&& Player
.p_magiclvl
>= ML_CLOAK
)
358 if (Player
.p_level
>= MEL_TELEPORT
&& Player
.p_magiclvl
>= ML_TELEPORT
)
359 addstr("7:Teleport ");
360 if (Player
.p_specialtype
>= SC_COUNCIL
|| Wizard
)
361 addstr("8:Intervene ");
363 procmain(); /* process input */
367 /************************************************************************
369 / FUNCTION NAME: initialstate()
371 / FUNCTION: initialize some important global variable
373 / AUTHOR: E. A. Estes, 12/4/85
379 / MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(),
384 / GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond,
385 / Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp,
389 / Set global flags, and open files which remain open.
391 *************************************************************************/
406 /* setup login name */
407 if ((Login
= getlogin()) == NULL
)
408 Login
= getpwuid(getuid())->pw_name
;
410 /* open some files */
411 if ((Playersfp
= fopen(_PATH_PEOPLE
, "r+")) == NULL
)
415 if ((Monstfp
= fopen(_PATH_MONST
, "r+")) == NULL
)
419 if ((Messagefp
= fopen(_PATH_MESS
, "r")) == NULL
)
423 if ((Energyvoidfp
= fopen(_PATH_VOID
, "r+")) == NULL
)
430 /************************************************************************
432 / FUNCTION NAME: rollnewplayer()
434 / FUNCTION: roll up a new character
436 / AUTHOR: E. A. Estes, 12/4/85
442 / MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(),
443 / wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(),
444 / getanswer(), getstring()
446 / GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]
448 / GLOBAL OUTPUTS: Echo
451 / Prompt player, and roll up new character.
453 *************************************************************************/
458 int chartype
; /* character type */
461 initplayer(&Player
); /* initialize player structure */
464 mvaddstr(4, 21, "Which type of character do you want:");
465 mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento ");
467 addstr("7:Super ? ");
468 chartype
= getanswer("1234567", FALSE
);
472 chartype
= getanswer("123456", FALSE
);
477 genchar(chartype
); /* roll up a character */
479 /* print out results */
481 "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n",
482 Player
.p_strength
, Player
.p_quickness
, Player
.p_mana
);
484 "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n",
485 Player
.p_energy
, Player
.p_brains
, Player
.p_magiclvl
);
487 if (Player
.p_type
== C_EXPER
|| Player
.p_type
== C_SUPER
)
490 mvaddstr(14, 14, "Type '1' to keep >");
491 ch
= getanswer(" ", TRUE
);
495 if (Player
.p_type
== C_EXPER
|| Player
.p_type
== C_SUPER
)
496 /* get coordinates for experimento */
499 mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? ");
500 getstring(Databuf
, SZ_DATABUF
);
501 sscanf(Databuf
, "%lf %lf", &Player
.p_x
, &Player
.p_y
);
503 if (fabs(Player
.p_x
) > D_EXPER
|| fabs(Player
.p_y
) > D_EXPER
)
504 mvaddstr(17, 0, "Invalid coordinates. Try again.\n");
510 /* name the new character */
513 "Give your character a name [up to %d characters] ? ", SZ_NAME
- 1);
514 getstring(Player
.p_name
, SZ_NAME
);
515 truncstring(Player
.p_name
); /* remove trailing blanks */
517 if (Player
.p_name
[0] == '\0')
519 mvaddstr(19, 0, "Invalid name.");
520 else if (findname(Player
.p_name
, &Other
) >= 0L)
521 /* cannot have duplicate names */
522 mvaddstr(19, 0, "Name already in use.");
524 /* name is acceptable */
527 addstr(" Pick another.\n");
530 /* get a password for character */
535 mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
536 getstring(Player
.p_password
, SZ_PASSWORD
);
537 mvaddstr(21, 0, "One more time to verify ? ");
538 getstring(Databuf
, SZ_PASSWORD
);
540 while (strcmp(Player
.p_password
, Databuf
) != 0);
544 return(allocrecord());
547 /************************************************************************
549 / FUNCTION NAME: procmain()
551 / FUNCTION: process input from player
553 / AUTHOR: E. A. Estes, 12/4/85
559 / MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(),
560 / fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(),
561 / waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(),
562 / getstring(), wclrtobot()
564 / GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr,
565 / Databuf[], Illmove[]
567 / GLOBAL OUTPUTS: Player, Changed
570 / Process main menu options.
572 *************************************************************************/
578 double x
; /* desired new x coordinate */
579 double y
; /* desired new y coordinate */
580 double temp
; /* for temporary calculations */
581 FILE *fp
; /* for opening files */
582 int loop
; /* a loop counter */
583 bool hasmoved
= FALSE
; /* set if player has moved */
586 mvaddstr(4, 0, "\n\n"); /* clear status area */
589 clrtobot(); /* clear data on bottom area of screen */
591 if (Player
.p_specialtype
== SC_VALAR
&& (ch
== '1' || ch
== '7'))
592 /* valar cannot move */
597 case 'K': /* move up/north */
600 y
= Player
.p_y
+ MAXMOVE();
604 case 'J': /* move down/south */
607 y
= Player
.p_y
- MAXMOVE();
611 case 'L': /* move right/east */
613 x
= Player
.p_x
+ MAXMOVE();
618 case 'H': /* move left/west */
620 x
= Player
.p_x
- MAXMOVE();
626 Player
.p_energy
+= (Player
.p_maxenergy
+ Player
.p_shield
) / 15.0
627 + Player
.p_level
/ 3.0 + 2.0;
629 MIN(Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
);
631 if (Player
.p_status
!= S_CLOAKED
)
632 /* cannot find mana if cloaked */
634 Player
.p_mana
+= (Circle
+ Player
.p_level
) / 4.0;
636 if (drandom() < 0.2 && Player
.p_status
== S_PLAYING
&& !Throne
)
637 /* wandering monster */
642 case 'X': /* change/examine a character */
647 for (loop
= 3; loop
; --loop
)
649 mvaddstr(4, 0, "X Y Coordinates ? ");
650 getstring(Databuf
, SZ_DATABUF
);
652 if (sscanf(Databuf
, "%lf %lf", &x
, &y
) != 2)
653 mvaddstr(5, 0, "Try again\n");
654 else if (distance(Player
.p_x
, x
, Player
.p_y
, y
) > MAXMOVE())
664 case '2': /* players */
668 case '3': /* message */
669 mvaddstr(4, 0, "Message ? ");
670 getstring(Databuf
, SZ_DATABUF
);
671 /* we open the file for writing to erase any data which is already there */
672 fp
= fopen(_PATH_MESS
, "w");
673 if (Databuf
[0] != '\0')
674 fprintf(fp
, "%s: %s", Player
.p_name
, Databuf
);
678 case '4': /* stats */
682 case '5': /* good-bye */
686 case '6': /* cloak */
687 if (Player
.p_level
< MEL_CLOAK
|| Player
.p_magiclvl
< ML_CLOAK
)
689 else if (Player
.p_status
== S_CLOAKED
)
690 Player
.p_status
= S_PLAYING
;
691 else if (Player
.p_mana
< MM_CLOAK
)
692 mvaddstr(5, 0, "No mana left.\n");
696 Player
.p_mana
-= MM_CLOAK
;
697 Player
.p_status
= S_CLOAKED
;
701 case '7': /* teleport */
703 * conditions for teleport
704 * - 20 per (level plus magic level)
705 * - OR council of the wise or valar or ex-valar
706 * - OR transport from throne
707 * transports from throne cost no mana
709 if (Player
.p_level
< MEL_TELEPORT
|| Player
.p_magiclvl
< ML_TELEPORT
)
712 for (loop
= 3; loop
; --loop
)
714 mvaddstr(4, 0, "X Y Coordinates ? ");
715 getstring(Databuf
, SZ_DATABUF
);
717 if (sscanf(Databuf
, "%lf %lf", &x
, &y
) == 2)
719 temp
= distance(Player
.p_x
, x
, Player
.p_y
, y
);
721 /* can transport anywhere from throne */
722 && Player
.p_specialtype
<= SC_COUNCIL
723 /* council, valar can transport anywhere */
724 && temp
> (Player
.p_level
+ Player
.p_magiclvl
) * 20.0)
725 /* can only move 20 per exp. level + mag. level */
729 temp
= (temp
/ 75.0 + 1.0) * 20.0; /* mana used */
731 if (!Throne
&& temp
> Player
.p_mana
)
732 mvaddstr(5, 0, "Not enough power for that distance.\n");
736 Player
.p_mana
-= temp
;
746 case '9': /* monster */
748 /* no monsters while on throne */
749 mvaddstr(5, 0, "No monsters in the chamber!\n");
750 else if (Player
.p_specialtype
!= SC_VALAR
)
751 /* the valar cannot call monsters */
753 Player
.p_sin
+= 1e-6;
758 case '0': /* decree */
759 if (Wizard
|| (Player
.p_specialtype
== SC_KING
&& Throne
))
760 /* kings must be on throne to decree */
766 case '8': /* intervention */
767 if (Wizard
|| Player
.p_specialtype
>= SC_COUNCIL
)
775 /* player has moved -- alter coordinates, and do random monster */
777 altercoordinates(x
, y
, A_SPECIFIC
);
779 if (drandom() < 0.2 && Player
.p_status
== S_PLAYING
&& !Throne
)
784 /************************************************************************
786 / FUNCTION NAME: titlelist()
788 / FUNCTION: print title page
790 / AUTHOR: E. A. Estes, 12/4/85
796 / MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(),
797 / fclose(), strlen(), waddstr(), sprintf(), wrefresh()
799 / GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp
801 / GLOBAL OUTPUTS: Lines
804 / Print important information about game, players, etc.
806 *************************************************************************/
811 FILE *fp
; /* used for opening various files */
812 bool councilfound
= FALSE
; /* set if we find a member of the council */
813 bool kingfound
= FALSE
; /* set if we find a king */
814 double hiexp
, nxtexp
= 0; /* used for finding the two highest players */
815 double hilvl
, nxtlvl
; /* used for finding the two highest players */
816 char hiname
[21], nxtname
[21];/* used for finding the two highest players */
818 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)!");
820 /* print message of the day */
821 if ((fp
= fopen(_PATH_MOTD
, "r")) != NULL
822 && fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
824 mvaddstr(2, 40 - strlen(Databuf
) / 2, Databuf
);
828 /* search for king */
829 fseek(Playersfp
, 0L, 0);
830 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
831 if (Other
.p_specialtype
== SC_KING
&& Other
.p_status
!= S_NOTUSED
)
834 sprintf(Databuf
, "The present ruler is %s Level:%.0f",
835 Other
.p_name
, Other
.p_level
);
836 mvaddstr(4, 40 - strlen(Databuf
) / 2, Databuf
);
842 mvaddstr(4, 24, "There is no ruler at this time.");
844 /* search for valar */
845 fseek(Playersfp
, 0L, 0);
846 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
847 if (Other
.p_specialtype
== SC_VALAR
&& Other
.p_status
!= S_NOTUSED
)
848 /* found the valar */
850 sprintf(Databuf
, "The Valar is %s Login: %s", Other
.p_name
, Other
.p_login
);
851 mvaddstr(6, 40 - strlen(Databuf
) / 2 , Databuf
);
855 /* search for council of the wise */
856 fseek(Playersfp
, 0L, 0);
858 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
859 if (Other
.p_specialtype
== SC_COUNCIL
&& Other
.p_status
!= S_NOTUSED
)
860 /* found a member of the council */
864 mvaddstr(8, 30, "Council of the Wise:");
868 /* This assumes a finite (<=5) number of C.O.W.: */
869 sprintf(Databuf
, "%s Login: %s", Other
.p_name
, Other
.p_login
);
870 mvaddstr(Lines
++, 40 - strlen(Databuf
) / 2, Databuf
);
873 /* search for the two highest players */
874 nxtname
[0] = hiname
[0] = '\0';
878 fseek(Playersfp
, 0L, 0);
879 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
880 if (Other
.p_experience
> hiexp
&& Other
.p_specialtype
<= SC_KING
&& Other
.p_status
!= S_NOTUSED
)
881 /* highest found so far */
884 hiexp
= Other
.p_experience
;
886 hilvl
= Other
.p_level
;
887 strcpy(nxtname
, hiname
);
888 strcpy(hiname
, Other
.p_name
);
890 else if (Other
.p_experience
> nxtexp
891 && Other
.p_specialtype
<= SC_KING
892 && Other
.p_status
!= S_NOTUSED
)
893 /* next highest found so far */
895 nxtexp
= Other
.p_experience
;
896 nxtlvl
= Other
.p_level
;
897 strcpy(nxtname
, Other
.p_name
);
900 mvaddstr(15, 28, "Highest characters are:");
901 sprintf(Databuf
, "%s Level:%.0f and %s Level:%.0f",
902 hiname
, hilvl
, nxtname
, nxtlvl
);
903 mvaddstr(17, 40 - strlen(Databuf
) / 2, Databuf
);
905 /* print last to die */
906 if ((fp
= fopen(_PATH_LASTDEAD
,"r")) != NULL
907 && fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
909 mvaddstr(19, 25, "The last character to die was:");
910 mvaddstr(20, 40 - strlen(Databuf
) / 2,Databuf
);
917 /************************************************************************
919 / FUNCTION NAME: recallplayer()
921 / FUNCTION: find a character on file
923 / AUTHOR: E. A. Estes, 12/4/85
929 / MODULES CALLED: writerecord(), truncstring(), more(), death(), wmove(),
930 / wclear(), strcmp(), printw(), cleanup(), waddstr(), findname(), mvprintw(),
931 / getanswer(), getstring()
933 / GLOBAL INPUTS: Player, *stdscr, Databuf[]
935 / GLOBAL OUTPUTS: Echo, Player
938 / Search for a character of a certain name, and check password.
940 *************************************************************************/
945 long loc
= 0L; /* location in player file */
946 int loop
; /* loop counter */
950 mvprintw(10, 0, "What was your character's name ? ");
951 getstring(Databuf
, SZ_NAME
);
952 truncstring(Databuf
);
954 if ((loc
= findname(Databuf
, &Player
)) >= 0L)
955 /* found character */
959 for (loop
= 0; loop
< 2; ++loop
)
961 /* prompt for password */
962 mvaddstr(11, 0, "Password ? ");
963 getstring(Databuf
, SZ_PASSWORD
);
964 if (strcmp(Databuf
, Player
.p_password
) == 0)
969 if (Player
.p_status
!= S_OFF
)
970 /* player did not exit normally last time */
973 addstr("Your character did not exit normally last time.\n");
974 addstr("If you think you have good cause to have your character saved,\n");
975 printw("you may quit and mail your reason to 'root'.\n");
976 addstr("Otherwise, continuing spells certain death.\n");
977 addstr("Do you want to quit ? ");
978 ch
= getanswer("YN", FALSE
);
981 Player
.p_status
= S_HUNGUP
;
982 writerecord(&Player
, loc
);
992 mvaddstr(12, 0, "No good.\n");
998 mvaddstr(11, 0, "Not found.\n");
1004 /************************************************************************
1006 / FUNCTION NAME: neatstuff()
1008 / FUNCTION: do random stuff
1010 / AUTHOR: E. A. Estes, 3/3/86
1014 / RETURN VALUE: none
1016 / MODULES CALLED: collecttaxes(), floor(), wmove(), drandom(), infloat(),
1017 / waddstr(), mvprintw(), getanswer()
1019 / GLOBAL INPUTS: Player, *stdscr, *Statptr
1021 / GLOBAL OUTPUTS: Player
1024 / Handle gurus, medics, etc.
1026 *************************************************************************/
1031 double temp
; /* for temporary calculations */
1034 switch ((int) ROLL(0.0, 100.0))
1038 if (Player
.p_poison
> 0.0)
1040 mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? ");
1041 temp
= floor(infloat());
1042 if (temp
< 0.0 || temp
> Player
.p_gold
)
1043 /* negative gold, or more than available */
1045 mvaddstr(6, 0, "He was not amused, and made you worse.\n");
1046 Player
.p_poison
+= 1.0;
1048 else if (drandom() / 2.0 > (temp
+ 1.0) / MAX(Player
.p_gold
, 1))
1049 /* medic wants 1/2 of available gold */
1050 mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
1053 mvaddstr(5, 0, "He accepted.");
1054 Player
.p_poison
= MAX(0.0, Player
.p_poison
- 1.0);
1055 Player
.p_gold
-= temp
;
1061 mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
1062 Player
.p_experience
+= 4000.0;
1063 Player
.p_sin
+= 0.5;
1067 temp
= ROLL(10.0, 75.0);
1068 mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp
);
1069 ch
= getanswer("NY", FALSE
);
1072 collecttaxes(temp
, 0.0);
1076 if (Player
.p_sin
> 1.0)
1078 mvaddstr(4, 0, "You've found a Holy Orb!\n");
1079 Player
.p_sin
-= 0.25;
1084 if (Player
.p_poison
< 1.0)
1086 mvaddstr(4, 0, "You've been hit with a plague!\n");
1087 Player
.p_poison
+= 1.0;
1092 mvaddstr(4, 0, "You've found some holy water.\n");
1093 ++Player
.p_holywater
;
1097 mvaddstr(4, 0, "You've met a Guru. . .");
1098 if (drandom() * Player
.p_sin
> 1.0)
1099 addstr("You disgusted him with your sins!\n");
1100 else if (Player
.p_poison
> 0.0)
1102 addstr("He looked kindly upon you, and cured you.\n");
1103 Player
.p_poison
= 0.0;
1107 addstr("He rewarded you for your virtue.\n");
1108 Player
.p_mana
+= 50.0;
1109 Player
.p_shield
+= 2.0;
1114 mvaddstr(4, 0, "You've found an amulet.\n");
1119 if (Player
.p_blindness
)
1121 mvaddstr(4, 0, "You've regained your sight!\n");
1122 Player
.p_blindness
= FALSE
;
1126 default: /* deal with poison */
1127 if (Player
.p_poison
> 0.0)
1129 temp
= Player
.p_poison
* Statptr
->c_weakness
1130 * Player
.p_maxenergy
/ 600.0;
1131 if (Player
.p_energy
> Player
.p_maxenergy
/ 10.0
1132 && temp
+ 5.0 < Player
.p_energy
)
1133 Player
.p_energy
-= temp
;
1139 /************************************************************************
1141 / FUNCTION NAME: genchar()
1143 / FUNCTION: generate a random character
1145 / AUTHOR: E. A. Estes, 12/4/85
1148 / int type - ASCII value of character type to generate
1150 / RETURN VALUE: none
1152 / MODULES CALLED: floor(), drandom()
1154 / GLOBAL INPUTS: Wizard, Player, Stattable[]
1156 / GLOBAL OUTPUTS: Player
1159 / Use the lookup table for rolling stats.
1161 *************************************************************************/
1166 int subscript
; /* used for subscripting into Stattable */
1167 struct charstats
*statptr
;/* for pointing into Stattable */
1169 subscript
= type
- '1';
1171 if (subscript
< C_MAGIC
|| subscript
> C_EXPER
)
1172 if (subscript
!= C_SUPER
|| !Wizard
)
1173 /* fighter is default */
1174 subscript
= C_FIGHTER
;
1176 statptr
= &Stattable
[subscript
];
1178 Player
.p_quickness
=
1179 ROLL(statptr
->c_quickness
.base
, statptr
->c_quickness
.interval
);
1181 ROLL(statptr
->c_strength
.base
, statptr
->c_strength
.interval
);
1183 ROLL(statptr
->c_mana
.base
, statptr
->c_mana
.interval
);
1184 Player
.p_maxenergy
=
1186 ROLL(statptr
->c_energy
.base
, statptr
->c_energy
.interval
);
1188 ROLL(statptr
->c_brains
.base
, statptr
->c_brains
.interval
);
1190 ROLL(statptr
->c_magiclvl
.base
, statptr
->c_magiclvl
.interval
);
1192 Player
.p_type
= subscript
;
1194 if (Player
.p_type
== C_HALFLING
)
1195 /* give halfling some experience */
1196 Player
.p_experience
= ROLL(600.0, 200.0);
1199 /************************************************************************
1201 / FUNCTION NAME: playinit()
1203 / FUNCTION: initialize for playing game
1205 / AUTHOR: E. A. Estes, 12/4/85
1209 / RETURN VALUE: none
1211 / MODULES CALLED: signal(), wclear(), noecho(), crmode(), initscr(),
1214 / GLOBAL INPUTS: *stdscr, ill_sig()
1216 / GLOBAL OUTPUTS: Windows
1219 / Catch a bunch of signals, and turn on curses stuff.
1221 *************************************************************************/
1226 /* catch/ingnore signals */
1236 sigset(SIGHUP
, ill_sig
);
1237 sigset(SIGTRAP
, ill_sig
);
1238 sigset(SIGIOT
, ill_sig
);
1239 sigset(SIGEMT
, ill_sig
);
1240 sigset(SIGFPE
, ill_sig
);
1241 sigset(SIGBUS
, ill_sig
);
1242 sigset(SIGSEGV
, ill_sig
);
1243 sigset(SIGSYS
, ill_sig
);
1244 sigset(SIGPIPE
, ill_sig
);
1247 signal(SIGQUIT
, ill_sig
);
1248 signal(SIGALRM
, SIG_IGN
);
1249 signal(SIGTERM
, SIG_IGN
);
1250 signal(SIGTSTP
, SIG_IGN
);
1251 signal(SIGTTIN
, SIG_IGN
);
1252 signal(SIGTTOU
, SIG_IGN
);
1253 signal(SIGINT
, ill_sig
);
1254 signal(SIGHUP
, SIG_DFL
);
1255 signal(SIGTRAP
, ill_sig
);
1256 signal(SIGIOT
, ill_sig
);
1257 signal(SIGEMT
, ill_sig
);
1258 signal(SIGFPE
, ill_sig
);
1259 signal(SIGBUS
, ill_sig
);
1260 signal(SIGSEGV
, ill_sig
);
1261 signal(SIGSYS
, ill_sig
);
1262 signal(SIGPIPE
, ill_sig
);
1265 signal(SIGINT
, SIG_IGN
);
1266 signal(SIGQUIT
, SIG_IGN
);
1267 signal(SIGTERM
, SIG_IGN
);
1268 signal(SIGALRM
, SIG_IGN
);
1269 signal(SIGHUP
, ill_sig
);
1270 signal(SIGTRAP
, ill_sig
);
1271 signal(SIGIOT
, ill_sig
);
1272 signal(SIGEMT
, ill_sig
);
1273 signal(SIGFPE
, ill_sig
);
1274 signal(SIGBUS
, ill_sig
);
1275 signal(SIGSEGV
, ill_sig
);
1276 signal(SIGSYS
, ill_sig
);
1277 signal(SIGPIPE
, ill_sig
);
1280 signal(SIGINT
, SIG_IGN
);
1281 signal(SIGQUIT
, SIG_IGN
);
1282 signal(SIGTERM
, SIG_IGN
);
1283 signal(SIGALRM
, SIG_IGN
);
1284 signal(SIGHUP
, ill_sig
);
1285 signal(SIGTRAP
, ill_sig
);
1286 signal(SIGIOT
, ill_sig
);
1287 signal(SIGEMT
, ill_sig
);
1288 signal(SIGFPE
, ill_sig
);
1289 signal(SIGBUS
, ill_sig
);
1290 signal(SIGSEGV
, ill_sig
);
1291 signal(SIGSYS
, ill_sig
);
1292 signal(SIGPIPE
, ill_sig
);
1295 initscr(); /* turn on curses */
1296 noecho(); /* do not echo input */
1297 crmode(); /* do not process erase, kill */
1300 Windows
= TRUE
; /* mark the state */
1304 /************************************************************************
1306 / FUNCTION NAME: cleanup()
1308 / FUNCTION: close some files, and maybe exit
1310 / AUTHOR: E. A. Estes, 12/4/85
1313 / bool doexit - exit flag
1315 / RETURN VALUE: none
1317 / MODULES CALLED: exit(), wmove(), fclose(), endwin(), nocrmode(), wrefresh()
1319 / GLOBAL INPUTS: *Energyvoidfp, LINES, *stdscr, Windows, *Monstfp,
1320 / *Messagefp, *Playersfp
1322 / GLOBAL OUTPUTS: none
1325 / Close all open files. If we are "in curses" terminate curses.
1326 / If 'doexit' is set, exit, otherwise return.
1328 *************************************************************************/
1331 cleanup(bool doexit
)
1354 fclose(Energyvoidfp
);
1355 Energyvoidfp
= NULL
;