printfs have been banished. All outputnow goes through prout/proutn/prouts.
[super-star-trek.git] / setup.c
diff --git a/setup.c b/setup.c
index 9b5ac4241b9abda67b875a4ef39c89fb6af1446c..747618c4bde4f7fae9a656798c1b9e28e3901837 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -36,6 +36,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
@@ -69,6 +70,11 @@ void thaw(void) {
                return;\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
+               return;\r
+       }\r
 \r
        fclose(fp);\r
 \r
@@ -161,7 +167,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
@@ -195,7 +201,7 @@ 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
@@ -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
@@ -334,24 +340,26 @@ void setup(void) {
        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
@@ -593,9 +601,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