These are unused.
[super-star-trek.git] / setup.c
diff --git a/setup.c b/setup.c
index 9b5ac4241b9abda67b875a4ef39c89fb6af1446c..8bd5bd190b28143df437eb70ded1a2c29580aa75 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -10,7 +10,6 @@ void prelim(void) {
 }\r
 \r
 void freeze(int boss) {\r
-       char *x, *y;\r
        FILE *fp;\r
        int key;\r
        if (boss) {\r
@@ -36,6 +35,7 @@ void freeze(int boss) {
                skip(1);\r
                return;\r
        }\r
+       strcpy(game.magic, SSTMAGIC);\r
        fwrite(&game, sizeof(game), 1, fp);\r
 \r
        fclose(fp);\r
@@ -44,10 +44,9 @@ void freeze(int boss) {
 }\r
 \r
 \r
-void thaw(void) {\r
-       char *x, *y;\r
+int thaw(void) {\r
        FILE *fp;\r
-       int key;\r
+        int key;\r
 \r
        game.passwd[0] = '\0';\r
        if ((key = scan()) == IHEOL) {\r
@@ -56,7 +55,7 @@ void thaw(void) {
        }\r
        if (key != IHALPHA) {\r
                huh();\r
-               return;\r
+               return 1;\r
        }\r
        chew();\r
        if (strchr(citem, '.') == NULL) {\r
@@ -66,13 +65,19 @@ void thaw(void) {
                proutn("Can't find game file ");\r
                proutn(citem);\r
                skip(1);\r
-               return;\r
+               return 1;\r
        }\r
        fread(&game, sizeof(game), 1, fp);\r
+       if (strcmp(game.magic, SSTMAGIC)) {\r
+               prout("Game file format is bad, should begin with " SSTMAGIC);\r
+               skip(1);\r
+               fclose(fp);\r
+               return 1;\r
+       }\r
 \r
        fclose(fp);\r
 \r
-       /* I hope that's enough! */\r
+        return 0;\r
 }\r
 \r
 void abandn(void) {\r
@@ -161,7 +166,7 @@ void abandn(void) {
        iscraft=0; /* Gallileo disappears */\r
        /* Resupply ship */\r
        condit=IHDOCKED;\r
-       for (l = 1; l <= ndevice; l++) game.damage[l] = 0.0;\r
+       for (l = 1; l <= NDEVICES; l++) game.damage[l] = 0.0;\r
        game.damage[DSHUTTL] = -1;\r
        energy = inenrg = 3000.0;\r
        shield = inshld = 1250.0;\r
@@ -173,16 +178,16 @@ void abandn(void) {
        return;\r
 }\r
        \r
-void setup(void) {\r
+void setup(int needprompt) {\r
        int i,j, krem, klumper;\r
        int ix, iy;\r
-       alldone = gamewon = 0;\r
 #ifdef DEBUG\r
        idebug = 0;\r
 #endif\r
        //  Decide how many of everything\r
-       if (choose()) return; // frozen game\r
+       if (choose(needprompt)) return; // frozen game\r
        // Prepare the Enterprise\r
+        alldone = gamewon = 0;\r
        ship = IHE;\r
        energy = inenrg = 5000.0;\r
        shield = inshld = 2500.0;\r
@@ -195,12 +200,13 @@ void setup(void) {
        nprobes = (int)(3.0*Rand() + 2.0);      /* Give them 2-4 of these wonders */\r
        warpfac = 5.0;\r
        wfacsq = warpfac * warpfac;\r
-       for (i=0; i <= ndevice; i++) game.damage[i] = 0.0;\r
+       for (i=0; i <= NDEVICES; i++) game.damage[i] = 0.0;\r
        // Set up assorted game parameters\r
        batx = baty = 0;\r
        game.state.date = indate = 100.0*(int)(31.0*Rand()+20.0);\r
        game.state.killk = game.state.killc = nkinks = nhelp = resting = casual = game.state.nromkl = 0;\r
        isatb = iscate = imine = icrystl = icraft = game.state.nsckill = game.state.nplankl = 0;\r
+        game.state.starkl = game.state.basekl = 0;\r
        iscraft = 1;\r
        landed = -1;\r
        alive = 1;\r
@@ -239,13 +245,13 @@ void setup(void) {
                                if (distq < 6.0*(6-inbase) && Rand() < 0.75) {\r
                                        contflag = TRUE;\r
 #ifdef DEBUG\r
-                                       printf("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);\r
+                                       proutn("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);\r
 #endif\r
                                        break;\r
                                }\r
 #ifdef DEBUG\r
                                else if (distq < 6.0 * (6-inbase)) {\r
-                                       printf("DEBUG: saving base #%d, close to #%d\n", i, j);\r
+                                       proutn("DEBUG: saving base #%d, close to #%d\n", i, j);\r
                                }\r
 #endif\r
                        }\r
@@ -298,15 +304,15 @@ void setup(void) {
                game.state.cy[i] = iy;\r
        }\r
        // Locate planets in galaxy\r
-       for (i = 1; i <= inplan; i++) {\r
+       for (i = 0; i < inplan; i++) {\r
                do iran8(&ix, &iy);\r
                while (game.state.newstuf[ix][iy] > 0);\r
                game.state.newstuf[ix][iy] = 1;\r
                game.state.plnets[i].x = ix;\r
                game.state.plnets[i].y = iy;\r
-               game.state.plnets[i].pclass = Rand()*3.0 + 1.0; // Planet class M N or O\r
+               game.state.plnets[i].pclass = Rand()*3.0; // Planet class M N or O\r
                game.state.plnets[i].crystals = 1.5*Rand();             // 1 in 3 chance of crystals\r
-               game.state.plnets[i].known = 0;\r
+               game.state.plnets[i].known = unknown;\r
        }\r
        // Locate Romulans\r
        for (i = 1; i <= game.state.nromrem; i++) {\r
@@ -322,7 +328,7 @@ void setup(void) {
                game.state.galaxy[ix][iy] += 100;\r
        }\r
        // Place thing (in tournament game, thingx == -1, don't want one!)\r
-       if (Rand() < 0.1 && thingx != -1) {\r
+       if (thingx != -1) {\r
                iran8(&thingx, &thingy);\r
        }\r
        else {\r
@@ -330,57 +336,60 @@ void setup(void) {
        }\r
 \r
 //     idate = date;\r
-       skip(3);\r
+       skip(2);\r
        game.state.snap = 0;\r
                \r
        if (skill == 1) {\r
-               printf("It is stardate %d. The Federation is being attacked by\n",\r
+               prout("It is stardate %d. The Federation is being attacked by",\r
                           (int)game.state.date);\r
-               printf("a deadly Klingon invasion force. As captain of the United\n"\r
-                          "Starship U.S.S. Enterprise, it is your mission to seek out\n"\r
-                          "and destroy this invasion force of %d battle cruisers.\n",\r
+               prout("a deadly Klingon invasion force. As captain of the United");\r
+               prout("Starship U.S.S. Enterprise, it is your mission to seek out");\r
+               prout("and destroy this invasion force of %d battle cruisers.",\r
                           inkling);\r
-               printf("You have an initial allotment of %d stardates to complete\n"\r
-                          "your mission.  As you proceed you may be given more time.\n\n"\r
-                          "You will have %d supporting starbases.\n"\r
-                          "Starbase locations-  ",\r
-                          (int)intime, inbase);\r
+               prout("You have an initial allotment of %d stardates to complete", (int)intime);\r
+               prout("your mission.  As you proceed you may be given more time.");\r
+               prout("");\r
+               prout("You will have %d supporting starbases.", inbase);\r
+               proutn("Starbase locations-  ");\r
        }\r
        else {\r
-               printf("Stardate %d.\n\n"\r
-                          "%d Klingons.\nAn unknown number of Romulans\n",\r
-                          (int)game.state.date, inkling);\r
-               if (game.state.nscrem) printf("and one (GULP) Super-Commander.\n");\r
-               printf("%d stardates\n%d starbases in  ",(int)intime, inbase);\r
+               prout("Stardate %d.", (int)game.state.date);\r
+               prout("");\r
+               prout("%d Klingons.", inkling);\r
+               prout("An unknown number of Romulans.");\r
+               if (game.state.nscrem) prout("and one (GULP) Super-Commander.");\r
+                       prout("%d stardates.",(int)intime);\r
+                       proutn("%d starbases in ", inbase);\r
        }\r
        for (i = 1; i <= inbase; i++) {\r
-               cramlc(0, game.state.baseqx[i], game.state.baseqy[i]);\r
-               if (i < inbase) proutn("  ");\r
+               proutn(cramlc(0, game.state.baseqx[i], game.state.baseqy[i]));\r
+               proutn("  ");\r
        }\r
        skip(2);\r
-       proutn("The Enterprise is currently in");\r
-       cramlc(1, quadx, quady);\r
+       proutn("The Enterprise is currently in ");\r
+       proutn(cramlc(quadrant, quadx, quady));\r
        proutn(" ");\r
-       cramlc(2, sectx, secty);\r
+        proutn(cramlc(sector, sectx, secty));\r
        skip(2);\r
        prout("Good Luck!");\r
-       if (game.state.nscrem) proutn("  YOU'LL NEED IT.");\r
-       skip(1);\r
+       if (game.state.nscrem) prout("  YOU'LL NEED IT.");\r
        newqad(0);\r
-       if (nenhere) shldup=1.0;\r
+        if (nenhere-iqhere-ithere) shldup=1.0;\r
        if (neutz) attack(0);   // bad luck to start in a Romulan Neutral Zone\r
 }\r
 \r
-int choose(void) {\r
+void randomize(void) {\r
+       srand((int)time(NULL));\r
+}\r
+\r
+int choose(int needprompt) {\r
        tourn = 0;\r
        thawed = 0;\r
        skill = 0;\r
        length = 0;\r
        while (TRUE) {\r
-               if (fromcommandline) /* Can start with command line options */\r
-                       fromcommandline = 0;\r
-               else\r
-                       proutn("Would you like a regular, tournament, or frozen game?");\r
+               if (needprompt) /* Can start with command line options */\r
+                   proutn("Would you like a regular, tournament, or frozen game?");\r
                scan();\r
                if (strlen(citem)==0) continue; // Try again\r
                if (isit("tournament")) {\r
@@ -506,6 +515,8 @@ void newqad(int shutup) {
        landed = -1;\r
        ientesc = 0;\r
        ithere = 0;\r
+        iqhere=0;\r
+        iqengry=0;\r
        iseenit = 0;\r
        if (iscate) {\r
                // Attempt to escape Super-commander, so tbeam back!\r
@@ -527,27 +538,6 @@ void newqad(int shutup) {
        // Position Starship\r
        game.quad[sectx][secty] = ship;\r
 \r
-       // Decide if quadrant needs a Tholian\r
-       if ((skill < 3 && Rand() <= 0.02) ||   /* Lighten up if skill is low */\r
-               (skill == 3 && Rand() <= 0.05) ||\r
-               (skill > 3 && Rand() <= 0.08)\r
-#ifdef DEBUG\r
-               || strcmp(game.passwd, "tholianx")==0\r
-#endif\r
-               ) {\r
-               do {\r
-                       ithx = Rand() > 0.5 ? 10 : 1;\r
-                       ithy = Rand() > 0.5 ? 10 : 1;\r
-               } while (game.quad[ithx][ithy] != IHDOT);\r
-               game.quad[ithx][ithy] = IHT;\r
-               ithere = 1;\r
-               /* Reserve unocupied corners */\r
-               if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X';\r
-               if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X';\r
-               if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X';\r
-               if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X';\r
-       }\r
-\r
        if (quadnum >= 100) {\r
                // Position ordinary Klingons\r
                quadnum -= 100*klhere;\r
@@ -572,7 +562,7 @@ void newqad(int shutup) {
                if (quadx == game.state.isx && quady == game.state.isy) {\r
                        game.quad[game.kx[1]][game.ky[1]] = IHS;\r
                        game.kpower[1] = 1175.0 + 400.0*Rand() + 125.0*skill;\r
-                       iscate = 1;\r
+                        iscate = game.state.remkl>1;\r
                        ishere = 1;\r
                }\r
        }\r
@@ -593,9 +583,9 @@ void newqad(int shutup) {
        \r
        if (nplan) {\r
                // If quadrant needs a planet, put it in\r
-               for (i=1; i <= inplan; i++)\r
+               for (i=0; i < inplan; i++)\r
                        if (game.state.plnets[i].x == quadx && game.state.plnets[i].y == quady) break;\r
-               if (i <= inplan) {\r
+               if (i < inplan) {\r
                        iplnet = i;\r
                        dropin(IHP, &plnetx, &plnety);\r
                }\r
@@ -606,7 +596,7 @@ void newqad(int shutup) {
        for (i = 1; i <= quadnum; i++) dropin(IHSTAR, &ix, &iy);\r
 \r
        // Check for RNZ\r
-       if (irhere > 0 && klhere == 0 && basex == 0) {\r
+       if (irhere > 0 && klhere == 0) {\r
                neutz = 1;\r
                if (game.damage[DRADIO] <= 0.0) {\r
                        skip(1);\r
@@ -622,7 +612,14 @@ void newqad(int shutup) {
                // Put in THING if needed\r
                if (thingx == quadx && thingy == quady) {\r
                        dropin(IHQUEST, &ix, &iy);\r
-                       thingx = thingy = 0; // Transient\r
+                        iran8(&thingx, &thingy);\r
+                        nenhere++;\r
+                        iqhere=1;\r
+                        game.kx[nenhere] = ix;\r
+                        game.ky[nenhere] = iy;\r
+                        game.kdist[nenhere] = game.kavgd[nenhere] =\r
+                           sqrt(square(sectx-ix) + square(secty-iy));\r
+                        game.kpower[nenhere] = Rand()*6000.0 +500.0 +250.0*skill;\r
                        if (game.damage[DSRSENS] == 0.0) {\r
                                skip(1);\r
                                prout("MR. SPOCK- \"Captain, this is most unusual.");\r
@@ -631,6 +628,34 @@ void newqad(int shutup) {
                }\r
        }\r
 \r
+        // Decide if quadrant needs a Tholian\r
+        if ((skill < 3 && Rand() <= 0.02) ||   /* Lighten up if skill is low */\r
+                (skill == 3 && Rand() <= 0.05) ||\r
+                (skill > 3 && Rand() <= 0.08)\r
+#ifdef DEBUG\r
+                || strcmp(passwd, "tholianx")==0\r
+#endif\r
+                ) {\r
+                do {\r
+                        ithx = Rand() > 0.5 ? 10 : 1;\r
+                        ithy = Rand() > 0.5 ? 10 : 1;\r
+                } while (game.quad[ithx][ithy] != IHDOT);\r
+                game.quad[ithx][ithy] = IHT;\r
+                ithere = 1;\r
+                nenhere++;\r
+                game.kx[nenhere] = ithx;\r
+                game.ky[nenhere] = ithy;\r
+                game.kdist[nenhere] = game.kavgd[nenhere] =\r
+                   sqrt(square(sectx-ithx) + square(secty-ithy));\r
+                game.kpower[nenhere] = Rand()*400.0 +100.0 +25.0*skill;\r
+                /* Reserve unocupied corners */\r
+                if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X';\r
+                if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X';\r
+                if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X';\r
+                if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X';\r
+        }\r
+        sortkl();\r
+\r
        // Put in a few black holes\r
        for (i = 1; i <= 3; i++)\r
                if (Rand() > 0.5) dropin(IHBLANK, &ix, &iy);\r
@@ -650,7 +675,7 @@ void sortkl(void) {
 \r
        // The author liked bubble sort. So we will use it. :-(\r
 \r
-       if (nenhere < 2) return;\r
+        if (nenhere-iqhere-ithere < 2) return;\r
 \r
        do {\r
                sw = FALSE;\r