Better project documentation.
[super-star-trek.git] / reports.c
index afed60a5aaaea88811f3dfbd2c5477a88dff3bf1..858c70cb479f66689b0b5b3ff3a3fda391658fa2 100644 (file)
--- a/reports.c
+++ b/reports.c
@@ -4,21 +4,17 @@
 #include <string.h>\r
 \r
 void attakreport(void) {\r
-       if (future[FCDBAS] < 1e30) {\r
-               proutn("Starbase in ");\r
-               cramlc(1, batx, baty);\r
-               prout(" is currently under attack.");\r
-               proutn("It can hold out until Stardate ");\r
-               cramf(future[FCDBAS], 0,1);\r
-               prout(".");\r
+       if (game.future[FCDBAS] < 1e30) {\r
+               prout("Starbase in %s is currently under attack.",\r
+                     cramlc(quadrant, batx, baty));\r
+               prout("It can hold out until Stardate %d.", \r
+                     (int)game.future[FCDBAS]);\r
        }\r
        if (isatb == 1) {\r
-               proutn("Starbase in ");\r
-               cramlc(1, state.isx, state.isy);\r
-               prout(" is under Super-commander attack.");\r
-               proutn("It can hold out until Stardate ");\r
-               cramf(future[FSCDBAS], 0, 1);\r
-               prout(".");\r
+               prout("Starbase in %s is under Super-commander attack.",\r
+                     cramlc(quadrant, game.state.isx, game.state.isy));\r
+               prout("It can hold out until Stardate %d.", \r
+                     (int)game.future[FSCDBAS]);\r
        }\r
 }\r
        \r
@@ -42,56 +38,53 @@ void report(int f) {
                case 5: s3="emeritus"; break;\r
                default: s3="skilled"; break;\r
        }\r
-       printf("\nYou %s playing a %s%s %s frozen.\n",\r
+       prout("");\r
+       prout("You %s playing a %s%s %s game.",\r
                   alldone? "were": "are now", s1, s2, s3);\r
        if (skill>3 && thawed && !alldone) prout("No plaque is allowed.");\r
-       if (tourn) printf("This is tournament game %d.\n", tourn);\r
-       if (f) printf("Your secret password is \"%s\"\n",passwd);\r
-       printf("%d of %d Klingons have been killed",\r
-                  state.killk+state.killc+state.nsckill, inkling);\r
-       if (state.killc) printf(", including %d Commander%s.\n", state.killc, state.killc==1?"":"s");\r
-       else if (state.killk+state.nsckill > 0) prout(", but no Commanders.");\r
+       if (tourn) prout("This is tournament game %d.", tourn);\r
+       if (f) prout("Your secret password is \"%s\"",game.passwd);\r
+       proutn("%d of %d Klingons have been killed",\r
+                  game.state.killk+game.state.killc+game.state.nsckill, inkling);\r
+       if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s");\r
+       else if (game.state.killk+game.state.nsckill > 0) prout(", but no Commanders.");\r
        else prout(".");\r
-       if (skill > 2) printf("The Super Commander has %sbeen destroyed.\n",\r
-                                                 state.nscrem?"not ":"");\r
-       if (state.rembase != inbase) {\r
+       if (skill > 2) prout("The Super Commander has %sbeen destroyed.",\r
+                                                 game.state.nscrem?"not ":"");\r
+       if (game.state.rembase != inbase) {\r
                proutn("There ");\r
-               if (inbase-state.rembase==1) proutn("has been 1 base");\r
+               if (inbase-game.state.rembase==1) proutn("has been 1 base");\r
                else {\r
-                       proutn("have been ");\r
-                       crami(inbase-state.rembase, 1);\r
-                       proutn(" bases");\r
+                   proutn("have been %d bases", inbase-game.state.rembase);\r
                }\r
-               proutn(" destroyed, ");\r
-               crami(state.rembase, 1);\r
-               prout(" remaining.");\r
+               prout(" destroyed, %d remaining.", game.state.rembase);\r
        }\r
-       else printf("There are %d bases.\n", inbase);\r
-       if (damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) {\r
+       else prout("There are %d bases.", inbase);\r
+       if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) {\r
                /* Don't report this if not seen and\r
                        either the radio is dead or not at base! */\r
                attakreport();\r
                iseenit = 1;\r
        }\r
-       if (casual) printf("%d casualt%s suffered so far.\n",\r
+       if (casual) prout("%d casualt%s suffered so far.",\r
                                           casual, casual==1? "y" : "ies");\r
-       if (nhelp) printf("There were %d call%s for help.\n",\r
+       if (nhelp) prout("There were %d call%s for help.",\r
                                          nhelp, nhelp==1 ? "" : "s");\r
        if (ship == IHE) {\r
                proutn("You have ");\r
-               if (nprobes) crami(nprobes,1);\r
+               if (nprobes) proutn("%d", nprobes);\r
                else proutn("no");\r
                proutn(" deep space probe");\r
                if (nprobes!=1) proutn("s");\r
                prout(".");\r
        }\r
-       if ((damage[DRADIO] == 0.0 || condit == IHDOCKED)&&\r
-               future[FDSPROB] != 1e30) {\r
+       if ((game.damage[DRADIO] == 0.0 || condit == IHDOCKED)&&\r
+               game.future[FDSPROB] != 1e30) {\r
                if (isarmed) \r
                        proutn("An armed deep space probe is in");\r
                else\r
                        proutn("A deep space probe is in");\r
-               cramlc(1, probecx, probecy);\r
+               proutn(cramlc(quadrant, probecx, probecy));\r
                prout(".");\r
        }\r
        if (icrystl) {\r
@@ -104,7 +97,7 @@ void report(int f) {
                                ai *= 2.0;\r
                                i++;\r
                        }\r
-                       printf("Dilithium crystals have been used %d time%s.\n",\r
+                       prout("Dilithium crystals have been used %d time%s.",\r
                                   i, i==1? "" : "s");\r
                }\r
        }\r
@@ -114,7 +107,7 @@ void report(int f) {
 void lrscan(void) {\r
        int x, y;\r
        chew();\r
-       if (damage[DLRSENS] != 0.0) {\r
+       if (game.damage[DLRSENS] != 0.0) {\r
                /* Now allow base's sensors if docked */\r
                if (condit != IHDOCKED) {\r
                        prout("LONG-RANGE SENSORS DAMAGED.");\r
@@ -127,15 +120,14 @@ void lrscan(void) {
                skip(1);\r
                proutn("Long-range scan for");\r
        }\r
-       cramlc(1, quadx, quady);\r
-       skip(1);\r
+       prout(cramlc(quadrant, quadx, quady));\r
        for (x = quadx-1; x <= quadx+1; x++) {\r
                for (y = quady-1; y <= quady+1; y++) {\r
                        if (x == 0 || x > 8 || y == 0 || y > 8)\r
-                               printf("   -1");\r
+                               proutn("   -1");\r
                        else {\r
-                               printf("%5d", state.galaxy[x][y]);\r
-                               starch[x][y] = damage[DRADIO] > 0 ? state.galaxy[x][y]+1000 :1;\r
+                               proutn("%5d", game.state.galaxy[x][y]);\r
+                               game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+1000 :1;\r
                        }\r
                }\r
                putchar('\n');\r
@@ -147,19 +139,18 @@ void dreprt(void) {
        int jdam = FALSE, i;\r
        chew();\r
 \r
-       for (i = 1; i <= ndevice; i++) {\r
-               if (damage[i] > 0.0) {\r
+       for (i = 1; i <= NDEVICES; i++) {\r
+               if (game.damage[i] > 0.0) {\r
                        if (!jdam) {\r
                                skip(1);\r
                                prout("DEVICE            -REPAIR TIMES-");\r
                                prout("                IN FLIGHT   DOCKED");\r
                                jdam = TRUE;\r
                        }\r
-                       printf("  %16s ", device[i]);\r
-                       cramf(damage[i]+0.05, 8, 2);\r
-                       proutn("  ");\r
-                       cramf(docfac*damage[i]+0.005, 8, 2);\r
-                       skip(1);\r
+                       prout("  %16s %8.2f  %8.2f", \r
+                               device[i],\r
+                               game.damage[i]+0.05,\r
+                               docfac*game.damage[i]+0.005);\r
                }\r
        }\r
        if (!jdam) prout("All devices functional.");\r
@@ -170,7 +161,7 @@ void chart(int nn) {
 \r
        chew();\r
        skip(1);\r
-       if (stdamtim != 1e30 && stdamtim != state.date && condit == IHDOCKED) {\r
+       if (stdamtim != 1e30 && stdamtim != game.state.date && condit == IHDOCKED) {\r
                prout("Spock-  \"I revised the Star Chart from the");\r
                prout("  starbase's records.\"");\r
                skip(1);\r
@@ -179,43 +170,40 @@ void chart(int nn) {
        if (stdamtim != 1e30) {\r
                if (condit == IHDOCKED) {\r
                        /* We are docked, so restore chart from base information */\r
-                       stdamtim = state.date;\r
+                       stdamtim = game.state.date;\r
                        for (i=1; i <= 8 ; i++)\r
                                for (j=1; j <= 8; j++)\r
-                                       if (starch[i][j] == 1) starch[i][j] = state.galaxy[i][j]+1000;\r
+                                       if (game.starch[i][j] == 1) game.starch[i][j] = game.state.galaxy[i][j]+1000;\r
                }\r
                else {\r
-                       proutn("(Last surveillance update ");\r
-                       cramf(state.date-stdamtim, 0, 1);\r
-                       prout(" stardates ago.)");\r
+                   proutn("(Last surveillance update %d stardates ago.",\r
+                          (int)(game.state.date-stdamtim));\r
                }\r
        }\r
        if (nn ==0) skip(1);\r
 \r
        prout("      1    2    3    4    5    6    7    8");\r
        prout("    ----------------------------------------");\r
-       if (nn==0) prout("  -");\r
+       /* if (nn==0) prout("  -"); */\r
        for (i = 1; i <= 8; i++) {\r
-               printf("%d -", i);\r
+               proutn("%d -", i);\r
                for (j = 1; j <= 8; j++) {\r
-                       if (starch[i][j] < 0)\r
-                               printf("  .1.");\r
-                       else if (starch[i][j] == 0)\r
-                               printf("  ...");\r
-                       else if (starch[i][j] > 999)\r
-                               printf("%5d", starch[i][j]-1000);\r
+                       if (game.starch[i][j] < 0)\r
+                               proutn("  .1.");\r
+                       else if (game.starch[i][j] == 0)\r
+                               proutn("  ...");\r
+                       else if (game.starch[i][j] > 999)\r
+                               proutn("%5d", game.starch[i][j]-1000);\r
                        else\r
-                               printf("%5d", state.galaxy[i][j]);\r
+                               proutn("%5d", game.state.galaxy[i][j]);\r
                }\r
                prout("  -");\r
        }\r
        if (nn == 0) {\r
                skip(1);\r
                crmshp();\r
-               proutn(" is currently in");\r
-               cramlc(1, quadx, quady);\r
-               skip(1);\r
-       }\r
+               prout(" is currently in %s", cramlc(quadrant, quadx, quady));\r
+}\r
 }\r
                \r
                \r
@@ -227,7 +215,7 @@ void srscan(int l) {
        int goodScan=TRUE;\r
        switch (l) {\r
                case 1: // SRSCAN\r
-                       if (damage[DSRSENS] != 0) {\r
+                       if (game.damage[DSRSENS] != 0) {\r
                                /* Allow base's sensors if docked */\r
                                if (condit != IHDOCKED) {\r
                                        prout("SHORT-RANGE SENSORS DAMAGED");\r
@@ -237,8 +225,8 @@ void srscan(int l) {
                                        prout("[Using starbase's sensors]");\r
                        }\r
                        if (goodScan)\r
-                               starch[quadx][quady] = damage[DRADIO]>0.0 ?\r
-                                                                          state.galaxy[quadx][quady]+1000:1;\r
+                           game.starch[quadx][quady] = game.damage[DRADIO]>0.0 ?\r
+                                                                          game.state.galaxy[quadx][quady]+1000:1;\r
                        scan();\r
                        if (isit("chart")) nn = TRUE;\r
                        if (isit("no")) rightside = FALSE;\r
@@ -247,7 +235,7 @@ void srscan(int l) {
                        break;\r
                case 2: // REQUEST\r
                        while (scan() == IHEOL)\r
-                               printf("Information desired? ");\r
+                               proutn("Information desired? ");\r
                        chew();\r
                        for (k = 1; k <= 10; k++)\r
                                if (strncmp(citem,requests[k],min(2,strlen(citem)))==0)\r
@@ -267,18 +255,18 @@ void srscan(int l) {
        for (i = 1; i <= 10; i++) {\r
                int jj = (k!=0 ? k : i);\r
                if (leftside) {\r
-                       printf("%2d  ", i);\r
+                       proutn("%2d  ", i);\r
                        for (j = 1; j <= 10; j++) {\r
                                if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1))\r
-                                       printf("%c ",quad[i][j]);\r
+                                       proutn("%c ",game.quad[i][j]);\r
                                else\r
-                                       printf("- ");\r
+                                       proutn("- ");\r
                        }\r
                }\r
                if (rightside) {\r
                        switch (jj) {\r
                                case 1:\r
-                                       printf(" Stardate      %.1f", state.date);\r
+                                       proutn(" Stardate      %.1f", game.state.date);\r
                                        break;\r
                                case 2:\r
                                        if (condit != IHDOCKED) newcnd();\r
@@ -288,50 +276,50 @@ void srscan(int l) {
                                                case IHYELLOW: cp = "YELLOW"; break;\r
                                                case IHDOCKED: cp = "DOCKED"; break;\r
                                        }\r
-                                       printf(" Condition     %s", cp);\r
+                                       proutn(" Condition     %s", cp);\r
                                        break;\r
                                case 3:\r
-                                       printf(" Position     ");\r
-                                       cramlc(0, quadx, quady);\r
-                                       putchar(',');\r
-                                       cramlc(0, sectx, secty);\r
+                                       proutn(" Position      ");\r
+                                       proutn(cramlc(neither, quadx, quady));\r
+                                       proutn(" , ");\r
+                                       proutn(cramlc(neither, sectx, secty));\r
                                        break;\r
                                case 4:\r
-                                       printf(" Life Support  ");\r
-                                       if (damage[DLIFSUP] != 0.0) {\r
+                                       proutn(" Life Support  ");\r
+                                       if (game.damage[DLIFSUP] != 0.0) {\r
                                                if (condit == IHDOCKED)\r
-                                                       printf("DAMAGED, supported by starbase");\r
+                                                       proutn("DAMAGED, supported by starbase");\r
                                                else\r
-                                                       printf("DAMAGED, reserves=%4.2f", lsupres);\r
+                                                       proutn("DAMAGED, reserves=%.2f", lsupres);\r
                                        }\r
                                        else\r
-                                               printf("ACTIVE");\r
+                                               proutn("ACTIVE");\r
                                        break;\r
                                case 5:\r
-                                       printf(" Warp Factor   %.1f", warpfac);\r
+                                       proutn(" Warp Factor   %.1f", warpfac);\r
                                        break;\r
                                case 6:\r
-                                       printf(" Energy        %.2f", energy);\r
+                                       proutn(" Energy        %.2f", energy);\r
                                        break;\r
                                case 7:\r
-                                       printf(" Torpedoes     %d", torps);\r
+                                       proutn(" Torpedoes     %d", torps);\r
                                        break;\r
                                case 8:\r
-                                       printf(" Shields       ");\r
-                                       if (damage[DSHIELD] != 0)\r
-                                               printf("DAMAGED,");\r
+                                       proutn(" Shields       ");\r
+                                       if (game.damage[DSHIELD] != 0)\r
+                                               proutn("DAMAGED,");\r
                                        else if (shldup)\r
-                                               printf("UP,");\r
+                                               proutn("UP,");\r
                                        else\r
-                                               printf("DOWN,");\r
-                                       printf(" %d%% %.1f units",\r
+                                               proutn("DOWN,");\r
+                                       proutn(" %d%% %.1f units",\r
                                                   (int)((100.0*shield)/inshld + 0.5), shield);\r
                                        break;\r
                                case 9:\r
-                                       printf(" Klingons Left %d", state.remkl);\r
+                                       proutn(" Klingons Left %d", game.state.remkl);\r
                                        break;\r
                                case 10:\r
-                                       printf(" Time Left     %.2f", state.remtime);\r
+                                       proutn(" Time Left     %.2f", game.state.remtime);\r
                                        break;\r
                        }\r
                                        \r
@@ -347,7 +335,7 @@ void eta(void) {
        int key, ix1, ix2, iy1, iy2, prompt=FALSE;\r
        int wfl;\r
        double ttime, twarp, tpower;\r
-       if (damage[DCOMPTR] != 0.0) {\r
+       if (game.damage[DCOMPTR] != 0.0) {\r
                prout("COMPUTER DAMAGED, USE A POCKET CALCULATOR.");\r
                skip(1);\r
                return;\r
@@ -397,7 +385,7 @@ void eta(void) {
                proutn("Time or arrival date? ");\r
                if (scan()==IHREAL) {\r
                        ttime = aaitem;\r
-                       if (ttime > state.date) ttime -= state.date; // Actually a star date\r
+                       if (ttime > game.state.date) ttime -= game.state.date; // Actually a star date\r
                        if (ttime <= 1e-10 ||\r
                                (twarp=(floor(sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0) > 10) {\r
                                prout("We'll never make it, sir.");\r
@@ -450,31 +438,25 @@ void eta(void) {
                }\r
                else\r
                        proutn("Remaining");\r
-               proutn(" energy will be ");\r
-               cramf(energy-tpower, 1, 1);\r
-               prout(".");\r
+               prout(" energy will be %.2f.", energy-tpower);\r
                if (wfl) {\r
-                       proutn("And we will arrive at stardate ");\r
-                       cramf(state.date+ttime, 1, 1);\r
-                       prout(".");\r
+                       prout("And we will arrive at stardate %.2f.",\r
+                               game.state.date+ttime);\r
                }\r
                else if (twarp==1.0)\r
                        prout("Any warp speed is adequate.");\r
                else {\r
-                       proutn("Minimum warp needed is ");\r
-                       cramf(twarp, 1, 2);\r
-                       skip(1);\r
-                       proutn("and we will arrive at stardate ");\r
-                       cramf(state.date+ttime, 1, 2);\r
-                       prout(".");\r
+                       prout("Minimum warp needed is %.2f,", twarp);\r
+                       prout("and we will arrive at stardate %.2f.",\r
+                               game.state.date+ttime);\r
                }\r
-               if (state.remtime < ttime)\r
+               if (game.state.remtime < ttime)\r
                        prout("Unfortunately, the Federation will be destroyed by then.");\r
                if (twarp > 6.0)\r
                        prout("You'll be taking risks at that speed, Captain");\r
-               if ((isatb==1 && state.isy == ix1 && state.isx == iy1 &&\r
-                        future[FSCDBAS]< ttime+state.date)||\r
-                       (future[FCDBAS]<ttime+state.date && baty==ix1 && batx == iy1))\r
+               if ((isatb==1 && game.state.isy == ix1 && game.state.isx == iy1 &&\r
+                        game.future[FSCDBAS]< ttime+game.state.date)||\r
+                       (game.future[FCDBAS]<ttime+game.state.date && baty==ix1 && batx == iy1))\r
                        prout("The starbase there will be destroyed by then.");\r
                proutn("New warp factor to try? ");\r
                if (scan() == IHREAL) {\r