📄 main.c
字号:
/* * Phantasia 3.3.2 -- Interterminal fantasy game * * Edward A. Estes * AT&T, March 12, 1986 *//* DISCLAIMER: * * This game is distributed for free as is. It is not guaranteed to work * in every conceivable environment. It is not even guaranteed to work * in ANY environment. * * This game is distributed without notice of copyright, therefore it * may be used in any manner the recipient sees fit. However, the * author assumes no responsibility for maintaining or revising this * game, in its original form, or any derivitives thereof. * * The author shall not be responsible for any loss, cost, or damage, * including consequential damage, caused by reliance on this material. * * The author makes no warranties, express or implied, including warranties * of merchantability or fitness for a particular purpose or use. * * AT&T is in no way connected with this game. */#include <sys/types.h>#include <pwd.h>/* * The program allocates as much file space as it needs to store characters, * so the possibility exists for the character file to grow without bound. * The file is purged upon normal entry to try to avoid that problem. * A similar problem exists for energy voids. To alleviate the problem here, * the void file is cleared with every new king, and a limit is placed * on the size of the energy void file. *//* * Put one line of text into the file 'motd' for announcements, etc. *//* * The scoreboard file is updated when someone dies, and keeps track * of the highest character to date for that login. * Being purged from the character file does not cause the scoreboard * to be updated. *//* * All source files are set up for 'vi' with shiftwidth=4, tabstop=8. *//**//* * main.c Main routines for Phantasia */#include "include.h"/***************************************************************************/ FUNCTION NAME: main()// FUNCTION: initialize state, and call main process// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS:/ int argc - argument count/ char **argv - argument vector// RETURN VALUE: none// MODULES CALLED: monstlist(), checkenemy(), activelist(), / throneroom(), checkbattle(), readmessage(), changestats(), writerecord(), / tradingpost(), adjuststats(), recallplayer(), displaystats(), checktampered(), / fabs(), rollnewplayer(), time(), exit(), sqrt(), floor(), wmove(), / signal(), strcat(), purgeoldplayers(), getuid(), isatty(), wclear(), / strcpy(), system(), altercoordinates(), cleanup(), waddstr(), procmain(), / playinit(), leavegame(), localtime(), getanswer(), neatstuff(), initialstate(), / scorelist(), titlelist()// GLOBAL INPUTS: *Login, Throne, Wizard, Player, *stdscr, Changed, Databuf[], / Fileloc, Stattable[]// GLOBAL OUTPUTS: Wizard, Player, Changed, Fileloc, Timeout, *Statptr// DESCRIPTION:/ Process arguments, initialize program, and loop forever processing/ player input.//***************************************************************************/main(argc, argv)int argc;char **argv;{bool noheader = FALSE; /* set if don't want header */bool headeronly = FALSE; /* set if only want header */bool examine = FALSE; /* set if examine a character */long seconds; /* for time of day */double dtemp; /* for temporary calculations */ initialstate(); /* init globals */ /* process arguments */ while (--argc && (*++argv)[0] == '-') switch ((*argv)[1]) { case 's': /* short */ noheader = TRUE; break; case 'H': /* Header */ headeronly = TRUE; break; case 'a': /* all users */ activelist(); cleanup(TRUE); /*NOTREACHED*/ case 'p': /* purge old players */ purgeoldplayers(); cleanup(TRUE); /*NOTREACHED*/ case 'S': /* set 'Wizard' */ Wizard = !getuid(); break; case 'x': /* examine */ examine = TRUE; break; case 'm': /* monsters */ monstlist(); cleanup(TRUE); /*NOTREACHED*/ case 'b': /* scoreboard */ scorelist(); cleanup(TRUE); /*NOTREACHED*/ } if (!isatty(0)) /* don't let non-tty's play */ cleanup(TRUE); /*NOTREACHED*/ playinit(); /* set up to catch signals, init curses */ if (examine) { changestats(FALSE); cleanup(TRUE); /*NOTREACHED*/ } if (!noheader) { titlelist(); purgeoldplayers(); /* clean up old characters */ } if (headeronly) cleanup(TRUE); /*NOTREACHED*/ do /* get the player structure filled */ { Fileloc = -1L; mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? "); switch (getanswer("NYQ", FALSE)) { case 'Y': Fileloc = recallplayer(); break; case 'Q': cleanup(TRUE); /*NOTREACHED*/ default: Fileloc = rollnewplayer(); break; } clear(); } while (Fileloc < 0L); if (Player.p_level > 5.0) /* low level players have long timeout */ Timeout = TRUE; /* update some important player statistics */ strcpy(Player.p_login, Login); time(&seconds); Player.p_lastused = localtime(&seconds)->tm_yday; Player.p_status = S_PLAYING; writerecord(&Player, Fileloc); Statptr = &Stattable[Player.p_type]; /* initialize pointer */ /* catch interrupts */#ifdef BSD41 sigset(SIGINT, interrupt);#endif#ifdef BSD42 signal(SIGINT, interrupt);#endif#ifdef SYS3 signal(SIGINT, interrupt);#endif#ifdef SYS5 signal(SIGINT, interrupt);#endif altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */ clear(); for (;;) /* loop forever, processing input */ { adjuststats(); /* cleanup stats */ if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING) /* not allowed on throne -- move */ { mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n"); altercoordinates(0.0, 0.0, A_NEAR); } checktampered(); /* check for energy voids, etc. */ if (Player.p_status != S_CLOAKED /* not cloaked */ && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y) /* |x| = |y| */ && !Throne) /* not on throne */ { dtemp = sqrt(dtemp / 100.0); if (floor(dtemp) == dtemp) /* |x| / 100 == n*n; at a trading post */ { tradingpost(); clear(); } } checkbattle(); /* check for player to player battle */ neatstuff(); /* gurus, medics, etc. */ if (Player.p_status == S_CLOAKED) /* costs 3 mana per turn to be cloaked */ if (Player.p_mana > 3.0) Player.p_mana -= 3.0; else /* ran out of mana, uncloak */ { Player.p_status = S_PLAYING; Changed = TRUE; } if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) /* change status back to S_PLAYING */ { Player.p_status = S_PLAYING; Changed = TRUE; } if (Changed) /* update file only if important stuff has changed */ { writerecord(&Player, Fileloc); Changed = FALSE; continue; } readmessage(); /* read message, if any */ displaystats(); /* print statistics */ move(6, 0); if (Throne) /* maybe make king, print prompt, etc. */ throneroom(); /* print status line */ addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit "); if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK) addstr("6:Cloak "); if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT) addstr("7:Teleport "); if (Player.p_specialtype >= SC_COUNCIL || Wizard) addstr("8:Intervene "); procmain(); /* process input */ }}/**//************************************************************************// FUNCTION NAME: initialstate()// FUNCTION: initialize some important global variable// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(), / getpwuid()// GLOBAL INPUTS: // GLOBAL OUTPUTS: *Energyvoidfp, Echo, Marsh, *Login, Users, Beyond, / Throne, Wizard, Changed, Okcount, Timeout, Windows, *Monstfp, *Messagefp, / *Playersfp// DESCRIPTION:/ Set global flags, and open files which remain open.//************************************************************************/initialstate(){ Beyond = FALSE; Marsh = FALSE; Throne = FALSE; Changed = FALSE; Wizard = FALSE; Timeout = FALSE; Users = 0; Windows = FALSE; Echo = TRUE; /* setup login name */ if ((Login = getlogin()) == NULL) Login = getpwuid(getuid())->pw_name; /* open some files */ if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL) error(_PATH_PEOPLE); /*NOTREACHED*/ if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL) error(_PATH_MONST); /*NOTREACHED*/ if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL) error(_PATH_MESS); /*NOTREACHED*/ if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL) error(_PATH_VOID); /*NOTREACHED*/ srandom((unsigned) time((long *) NULL)); /* prime random numbers */}/**//************************************************************************// FUNCTION NAME: rollnewplayer()// FUNCTION: roll up a new character// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: initplayer(), allocrecord(), truncstring(), fabs(), wmove(), / wclear(), sscanf(), strcmp(), genchar(), waddstr(), findname(), mvprintw(), / getanswer(), getstring()// GLOBAL INPUTS: Other, Wizard, Player, *stdscr, Databuf[]// GLOBAL OUTPUTS: Echo// DESCRIPTION:/ Prompt player, and roll up new character.//************************************************************************/longrollnewplayer(){int chartype; /* character type */int ch; /* input */ initplayer(&Player); /* initialize player structure */ clear(); mvaddstr(4, 21, "Which type of character do you want:"); mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento "); if (Wizard) { addstr("7:Super ? "); chartype = getanswer("1234567", FALSE); } else { addstr("? "); chartype = getanswer("123456", FALSE); } do { genchar(chartype); /* roll up a character */ /* print out results */ mvprintw(12, 14, "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n", Player.p_strength, Player.p_quickness, Player.p_mana); mvprintw(13, 14, "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n", Player.p_energy, Player.p_brains, Player.p_magiclvl); if (Player.p_type == C_EXPER || Player.p_type == C_SUPER)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -