More merging of SERGEEV changes.
[super-star-trek.git] / events.c
index 0cbc88071c8060f71d49a272290b4855d76d2c0e..641b77ad65f325944a9842f0ca345f7a8b052cb9 100644 (file)
--- a/events.c
+++ b/events.c
@@ -2,10 +2,8 @@
 #include <math.h>\r
 \r
 void events(void) {\r
-\r
-       int ictbeam=0, ipage=0, istract=0, line, i, j, k, l, ixhold, iyhold;\r
-       double fintim = game.state.date + Time, datemin, xtime, repair, yank;\r
-       \r
+        int ictbeam=0, ipage=0, istract=0, line, i=0, j, k, l, ixhold=0, iyhold=0;\r
+        double fintim = game.state.date + Time, datemin, xtime, repair, yank=0;\r
 \r
 #ifdef DEBUG\r
        if (idebug) prout("EVENTS");\r
@@ -25,7 +23,7 @@ void events(void) {
                if (alldone) return;\r
                datemin = fintim;\r
                for (l=1; l<=NEVENTS; l++)\r
-                       if (game.future[l] <= datemin) {\r
+                       if (game.future[l] < datemin) {\r
                                line = l;\r
                                datemin = game.future[l];\r
                        }\r
@@ -64,7 +62,7 @@ void events(void) {
                                for (j=1; j <= 8; j++)\r
                                        if (game.starch[i][j] > 999) game.starch[i][j] = 1;\r
                        if (iseenit==0) {\r
-                               attakreport();\r
+                               attakreport(0);\r
                                iseenit = 1;\r
                        }\r
                        skip(1);\r
@@ -75,7 +73,7 @@ void events(void) {
                Time -= xtime;\r
                switch (line) {\r
                        case FSNOVA: /* Supernova */\r
-                               if (ipage==0) pause(1);\r
+                               if (ipage==0) pause_game(1);\r
                                ipage=1;\r
                                snova(0,0);\r
                                game.future[FSNOVA] = game.state.date + expran(0.5*intime);\r
@@ -114,7 +112,7 @@ void events(void) {
                                }\r
                                /* tractor beaming cases merge here */\r
                                yank = sqrt(yank);\r
-                               if (ipage==0) pause(1);\r
+                               if (ipage==0) pause_game(1);\r
                                ipage=1;\r
                                Time = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */\r
                                ictbeam = 1;\r
@@ -152,11 +150,10 @@ void events(void) {
                                }\r
                                iran10(&sectx, &secty);\r
                                crmshp();\r
-                               proutn(" is pulled to");\r
-                               cramlc(1, quadx, quady);\r
+                               proutn(" is pulled to ");\r
+                               proutn(cramlc(quadrant, quadx, quady));\r
                                proutn(", ");\r
-                               cramlc(2, sectx, secty);\r
-                               skip(1);\r
+                               prout(cramlc(sector, sectx, secty));\r
                                if (resting) {\r
                                        prout("(Remainder of rest/repair period cancellegame.state.)");\r
                                        resting = 0;\r
@@ -171,6 +168,7 @@ void events(void) {
                                newqad(0);\r
                                /* Adjust finish time to time of tractor beaming */\r
                                fintim = game.state.date+Time;\r
+                                attack(0);\r
                                if (game.state.remcom <= 0) game.future[FTBEAM] = 1e30;\r
                                else game.future[FTBEAM] = game.state.date+Time+expran(1.5*intime/game.state.remcom);\r
                                break;\r
@@ -213,19 +211,18 @@ void events(void) {
                                if (game.damage[DRADIO] != 0.0 &&\r
                                        condit != IHDOCKED) break; /* No warning :-( */\r
                                iseenit = 1;\r
-                               if (ipage==0) pause(1);\r
+                               if (ipage==0) pause_game(1);\r
                                ipage = 1;\r
                                skip(1);\r
-                               proutn("Lt. Uhura-  \"Captain, the starbase in");\r
-                               cramlc(1, batx, baty);\r
-                               skip(1);\r
-                               prout("   reports that it is under atttack and that it can");\r
-                               proutn("   hold out only until stardate ");\r
-                               cramf(game.future[FCDBAS],1,1);\r
+                               proutn("Lt. Uhura-  \"Captain, the starbase in ");\r
+                               prout(cramlc(quadrant, batx, baty));\r
+                               prout("   reports that it is under attack and that it can");\r
+                               proutn("   hold out only until stardate %d",\r
+                                       (int)game.future[FCDBAS]);\r
                                prout(".\"");\r
                                if (resting) {\r
                                        skip(1);\r
-                                       proutn("Mr. Spock-  \"Captain, shall we cancel the rest period?\"");\r
+                                       proutn("Mr. Spock-  \"Captain, shall we cancel the rest period?\" ");\r
                                        if (ja()) {\r
                                                resting = 0;\r
                                                Time = 0.0;\r
@@ -269,12 +266,12 @@ void events(void) {
                                else if (game.state.rembase != 1 &&\r
                                                 (game.damage[DRADIO] <= 0.0 || condit == IHDOCKED)) {\r
                                        /* Get word via subspace radio */\r
-                                       if (ipage==0) pause(1);\r
+                                       if (ipage==0) pause_game(1);\r
                                        ipage = 1;\r
                                        skip(1);\r
                                        prout("Lt. Uhura-  \"Captain, Starfleet Command reports that");\r
-                                       proutn("   the starbase in");\r
-                                       cramlc(1, batx, baty);\r
+                                       proutn("   the starbase in ");\r
+                                       proutn(cramlc(quadrant, batx, baty));\r
                                        prout(" has been destroyed by");\r
                                        if (isatb==2) prout("the Klingon Super-Commander");\r
                                        else prout("a Klingon Commander");\r
@@ -316,7 +313,7 @@ void events(void) {
                                                game.state.galaxy[probecx][probecy] == 1000) {\r
                                                // Left galaxy or ran into supernova\r
                                                if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) {\r
-                                                       if (ipage==0) pause(1);\r
+                                                       if (ipage==0) pause_game(1);\r
                                                        ipage = 1;\r
                                                        skip(1);\r
                                                        proutn("Lt. Uhura-  \"The deep space probe ");\r
@@ -330,11 +327,11 @@ void events(void) {
                                                break;\r
                                        }\r
                                        if (game.damage[DRADIO]==0.0   || condit == IHDOCKED) {\r
-                                               if (ipage==0) pause(1);\r
+                                               if (ipage==0) pause_game(1);\r
                                                ipage = 1;\r
                                                skip(1);\r
                                                proutn("Lt. Uhura-  \"The deep space probe is now in ");\r
-                                               cramlc(1, probecx, probecy);\r
+                                               proutn(cramlc(quadrant, probecx, probecy));\r
                                                prout(".\"");\r
                                        }\r
                                }\r
@@ -375,7 +372,7 @@ void wait(void) {
        origTime = delay = aaitem;\r
        if (delay <= 0.0) return;\r
        if (delay >= game.state.remtime || nenhere != 0) {\r
-               prout("Are you sure? ");\r
+               proutn("Are you sure? ");\r
                if (ja() == 0) return;\r
        }\r
 \r
@@ -385,8 +382,7 @@ void wait(void) {
        do {\r
                if (delay <= 0) resting = 0;\r
                if (resting == 0) {\r
-                       cramf(game.state.remtime, 0, 2);\r
-                       prout(" stardates left.");\r
+                       prout("%d stardates left.", (int)game.state.remtime);\r
                        return;\r
                }\r
                temp = Time = delay;\r
@@ -397,7 +393,6 @@ void wait(void) {
                        Time = temp;\r
                }\r
                if (Time < delay) attack(0);\r
-               if (nenhere==0) movetho();\r
                if (alldone) return;\r
                events();\r
                ididit = 1;\r
@@ -415,7 +410,7 @@ void wait(void) {
 void nova(int ix, int iy) {\r
        static double course[] =\r
                {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5};\r
-       int bot, top, top2, burst, hits[11][3], kount, icx, icy, mm, nn, j;\r
+        int bot, top, top2, hits[11][3], kount, icx, icy, mm, nn, j;\r
        int iquad, iquad1, i, ll, newcx, newcy, ii, jj;\r
        if (Rand() < 0.05) {\r
                /* Wow! We've supernova'ed */\r
@@ -554,8 +549,8 @@ void nova(int ix, int iy) {
                                                        skip(1);\r
                                                        break;\r
                                                }\r
-                                               proutn(", buffeted to");\r
-                                               cramlc(2, newcx, newcy);\r
+                                               proutn(", buffeted to ");\r
+                                               proutn(cramlc(sector, newcx, newcy));\r
                                                game.quad[ii][jj] = IHDOT;\r
                                                game.quad[newcx][newcy] = iquad;\r
                                                game.kx[ll] = newcx;\r
@@ -583,14 +578,14 @@ void nova(int ix, int iy) {
        skip(1);\r
        prout("Force of nova displaces starship.");\r
        iattak=2;       /* Eliminates recursion problem */\r
-       move();\r
+       imove();\r
        Time = 10.0*dist/16.0;\r
        return;\r
 }\r
        \r
        \r
 void snova(int insx, int insy) {\r
-       int comdead, nqx, nqy, nsx, nsy, num, kldead, iscdead;\r
+        int comdead, nqx=0, nqy=0, nsx, nsy, num, kldead, iscdead;\r
        int nrmdead, npdead;\r
        int insipient=0;\r
 \r
@@ -637,12 +632,9 @@ void snova(int insx, int insy) {
                        /* it isn't here, or we just entered (treat as inroute) */\r
                        if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {\r
                                skip(1);\r
-                               proutn("Message from Starfleet Command       Stardate ");\r
-                               cramf(game.state.date, 0, 1);\r
-                               skip(1);\r
-                               proutn("     Supernova in");\r
-                               cramlc(1, nqx, nqy);\r
-                               prout("; caution advised.");\r
+                               prout("Message from Starfleet Command       Stardate %.2f", game.state.date);\r
+                               prout("     Supernova in %s; caution advised.",\r
+                                      cramlc(quadrant, nqx, nqy));\r
                        }\r
                }\r
                else {\r
@@ -668,9 +660,7 @@ void snova(int insx, int insy) {
                skip(1);\r
                prouts("***RED ALERT!  RED ALERT!");\r
                skip(1);\r
-               proutn("***Incipient supernova detected at");\r
-               cramlc(2, nsx, nsy);\r
-               skip(1);\r
+               prout("***Incipient supernova detected at ", cramlc(sector, nsx, nsy));\r
                nqx = quadx;\r
                nqy = quady;\r
                if (square(nsx-sectx) + square(nsy-secty) <= 2.1) {\r
@@ -753,9 +743,8 @@ void snova(int insx, int insy) {
        if (game.state.remkl==0 && (nqx != quadx || nqy != quady)) {\r
                skip(2);\r
                if (insx == 0) prout("Lucky you!");\r
-               proutn("A supernova in");\r
-               cramlc(1, nqx, nqy);\r
-               prout(" has just destroyed the last Klingons.");\r
+               proutn("A supernova in %s has just destroyed the last Klingons.",\r
+                      cramlc(quadrant, nqx, nqy));\r
                finish(FWON);\r
                return;\r
        }\r