]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - phantasia/main.c
Sort options. End sentence with a dot.
[bsdgames-darwin.git] / phantasia / main.c
index 3698b412903086532f8e084a8bf7a935421233d6..996622eded279c0b1c046b1d739e961274d6ee96 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.4 1997/10/13 02:18:27 lukem Exp $   */
+/*     $NetBSD: main.c,v 1.17 2008/08/08 16:10:47 drochner Exp $       */
 
 /*
  * Phantasia 3.3.2 -- Interterminal fantasy game
@@ -27,6 +27,7 @@
  * AT&T is in no way connected with this game.
  */
 
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
 
  */
 
 #include "include.h"
+#undef bool
+#include <curses.h>
 
-int    main __P((int, char **));
+int    main(int, char **);
 
 int
 main(argc, argv)
@@ -218,7 +221,7 @@ main(argc, argv)
                checkbattle();  /* check for player to player battle */
                neatstuff();    /* gurus, medics, etc. */
 
-               if (Player.p_status == S_CLOAKED)
+               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;
@@ -228,6 +231,7 @@ main(argc, argv)
                                Player.p_status = S_PLAYING;
                                Changed = TRUE;
                        }
+               }
 
                if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED)
                        /* change status back to S_PLAYING */
@@ -268,6 +272,8 @@ main(argc, argv)
 void
 initialstate()
 {
+       struct stat sb;
+
        Beyond = FALSE;
        Marsh = FALSE;
        Throne = FALSE;
@@ -286,6 +292,8 @@ initialstate()
        if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
                error(_PATH_PEOPLE);
        /* NOTREACHED */
+       if (fileno(Playersfp) < 3)
+               exit(1);
 
        if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL)
                error(_PATH_MONST);
@@ -297,6 +305,16 @@ initialstate()
 
        if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL)
                error(_PATH_VOID);
+       if (fstat(fileno(Energyvoidfp), &sb) == -1)
+               error("stat");
+       if (sb.st_size == 0) {
+               /* initialize grail to new location */
+               Enrgyvoid.ev_active = TRUE;
+               Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
+               Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
+               writevoid(&Enrgyvoid, 0L);
+       }
+
        /* NOTREACHED */
 
        srandom((unsigned) time(NULL)); /* prime random numbers */
@@ -382,7 +400,7 @@ rollnewplayer()
        do {
                mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? ");
                getstring(Player.p_password, SZ_PASSWORD);
-               mvaddstr(21, 0, "One more time to verify ? ");
+               mvaddstr(21, 0, "Enter again to verify: ");
                getstring(Databuf, SZ_PASSWORD);
        }
        while (strcmp(Player.p_password, Databuf) != 0);
@@ -625,7 +643,7 @@ titlelist()
                fclose(fp);
        }
        /* search for king */
-       fseek(Playersfp, 0L, 0);
+       fseek(Playersfp, 0L, SEEK_SET);
        while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
                if (Other.p_specialtype == SC_KING &&
                    Other.p_status != S_NOTUSED)
@@ -641,7 +659,7 @@ titlelist()
                mvaddstr(4, 24, "There is no ruler at this time.");
 
        /* search for valar */
-       fseek(Playersfp, 0L, 0);
+       fseek(Playersfp, 0L, SEEK_SET);
        while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
                if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
                        /* found the valar */
@@ -651,7 +669,7 @@ titlelist()
                        break;
                }
        /* search for council of the wise */
-       fseek(Playersfp, 0L, 0);
+       fseek(Playersfp, 0L, SEEK_SET);
        Lines = 10;
        while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
                if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED)
@@ -670,7 +688,7 @@ titlelist()
        hiexp = 0.0;
        nxtlvl = hilvl = 0;
 
-       fseek(Playersfp, 0L, 0);
+       fseek(Playersfp, 0L, SEEK_SET);
        while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
                if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED)
                        /* highest found so far */
@@ -701,8 +719,9 @@ titlelist()
            && fgets(Databuf, SZ_DATABUF, fp) != NULL) {
                mvaddstr(19, 25, "The last character to die was:");
                mvaddstr(20, 40 - strlen(Databuf) / 2, Databuf);
-               fclose(fp);
        }
+       if (fp)
+               fclose(fp);
        refresh();
 }
 
@@ -872,7 +891,7 @@ genchar(type)
        int     type;
 {
        int     subscript;      /* used for subscripting into Stattable */
-       struct charstats *statptr;      /* for pointing into Stattable */
+       const struct charstats *statptr; /* for pointing into Stattable */
 
        subscript = type - '1';
 
@@ -976,9 +995,12 @@ playinit()
        signal(SIGPIPE, ill_sig);
 #endif
 
-       initscr();              /* turn on curses */
+       if (!initscr()) {       /* turn on curses */
+               fprintf(stderr, "couldn't initialize screen\n");
+               exit (0);
+       }
        noecho();               /* do not echo input */
-       crmode();               /* do not process erase, kill */
+       cbreak();               /* do not process erase, kill */
        clear();
        refresh();
        Windows = TRUE;         /* mark the state */
@@ -991,13 +1013,17 @@ cleanup(doexit)
        if (Windows) {
                move(LINES - 2, 0);
                refresh();
-               nocrmode();
+               nocbreak();
                endwin();
        }
-       fclose(Playersfp);
-       fclose(Monstfp);
-       fclose(Messagefp);
-       fclose(Energyvoidfp);
+       if (Playersfp)
+               fclose(Playersfp);
+       if (Monstfp)
+               fclose(Monstfp);
+       if (Messagefp)
+               fclose(Messagefp);
+       if (Energyvoidfp)
+               fclose(Energyvoidfp);
 
        if (doexit)
                exit(0);