First round of changes from Stas Sergeev.
[super-star-trek.git] / moving.c
index d1f5bafaea108c1396b6d5fd2ae2b539ab3f34f2..ec7bc91b4ca0676f45d481991a654879b84679cd 100644 (file)
--- a/moving.c
+++ b/moving.c
@@ -1,11 +1,12 @@
+#include <unistd.h>\r
 #include "sst.h"\r
 \r
 static void getcd(int, int);\r
 \r
-void move(void) {\r
+void imove(void) {\r
        double angle, deltax, deltay, bigger, x, y,\r
-       finald, finalx, finaly, stopegy;\r
-       int trbeam = 0, n, l, ix, iy, kink, kinks, iquad;\r
+        finald, finalx, finaly, stopegy, probf;\r
+        int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad;\r
 \r
        if (inorbit) {\r
                prout("Helmsman Sulu- \"Leaving standard orbit.\"");\r
@@ -98,11 +99,11 @@ void move(void) {
                                quady = (iy+9)/10;\r
                                sectx = ix - 10*(quadx-1);\r
                                secty = iy - 10*(quady-1);\r
-                               proutn("\nEntering");\r
-                               cramlc(1, quadx, quady);\r
-                               skip(1);\r
+                               proutn("\n\rEntering %s.",\r
+                                     cramlc(quadrant, quadx, quady));\r
                                game.quad[sectx][secty] = ship;\r
                                newqad(0);\r
+                                if (skill>1) attack(0);\r
                                return;\r
                        }\r
                        iquad = game.quad[ix][iy];\r
@@ -117,6 +118,7 @@ void move(void) {
                                        case IHC:\r
                                        case IHS:\r
                                        case IHR:\r
+                                        case IHQUEST:\r
                                                sectx = ix;\r
                                                secty = iy;\r
                                                ram(0, iquad, sectx, secty);\r
@@ -129,24 +131,38 @@ void move(void) {
                                                skip(1);\r
                                                proutn("***");\r
                                                crmshp();\r
-                                               proutn(" pulled into black hole at");\r
-                                               cramlc(2, ix, iy);\r
-                                               skip(1);\r
-                                               finish(FHOLE);\r
+                                               proutn(" pulled into black hole at ");\r
+                                               prout(cramlc(sector, ix, iy));\r
+                                               /*\r
+                                                * Getting pulled into a black \r
+                                                * hole was certain death in\r
+                                                * Almy's original.  Stas \r
+                                                * Sergeev added a possibility\r
+                                                * that you'll get timewarped\r
+                                                * instead.\r
+                                                */\r
+                                                n=0;\r
+                                                for (l=1;l<=NDEVICES+1;l++)\r
+                                                    if (game.damage[l]>0) n++;\r
+                                                probf=pow(1.4,(energy+shield)/5000.0-1.0)*\r
+                                                       pow(1.3,1.0/(n+1)-1.0);\r
+                                                if (Rand()>probf) \r
+                                                   timwrp();\r
+                                                else \r
+                                                   finish(FHOLE);\r
                                                return;\r
                                        default:\r
                                                /* something else */\r
                                                skip(1);\r
                                                crmshp();\r
                                                if (iquad == IHWEB)\r
-                                                       proutn(" encounters Tholian web at");\r
+                                                       proutn(" encounters Tholian web at ");\r
                                                else\r
-                                                       proutn(" blocked by object at");\r
-                                               cramlc(2, ix,iy);\r
+                                                       proutn(" blocked by object at ");\r
+                                               proutn(cramlc(sector, ix,iy));\r
                                                prout(";");\r
                                                proutn("Emergency stop required ");\r
-                                               cramf(stopegy, 0, 2);\r
-                                               prout(" units of energy.");\r
+                                               prout("%2d units of energy.", (int)stopegy);\r
                                                energy -= stopegy;\r
                                                finalx = x-deltax+0.5;\r
                                                sectx = finalx;\r
@@ -188,9 +204,9 @@ label100:
        return;\r
 }\r
 \r
-void dock(void) {\r
+void dock(int l) {\r
        chew();\r
-       if (condit == IHDOCKED) {\r
+        if (condit == IHDOCKED && l) {\r
                prout("Already docked.");\r
                return;\r
        }\r
@@ -213,7 +229,7 @@ void dock(void) {
                (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) {\r
                /* get attack report from base */\r
                prout("Lt. Uhura- \"Captain, an important message from the starbase:\"");\r
-               attakreport();\r
+               attakreport(0);\r
                iseenit = 1;\r
        }\r
 }\r
@@ -228,7 +244,7 @@ static void getcd(int isprobe, int akey) {
           are always displayed y - x, where +y is downward! */\r
 \r
        \r
-       int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key;\r
+        int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key=0;\r
        double xi, xj, xk, xl;\r
        double deltax, deltay;\r
        int automatic = -1;\r
@@ -357,9 +373,8 @@ static void getcd(int isprobe, int akey) {
                if (!isprobe) {\r
                        if (itemp) {\r
                                if (iprompt) {\r
-                                       proutn("Helmsman Sulu- \"Course locked in for");\r
-                                       cramlc(2, irows, icols);\r
-                                       prout(".\"");\r
+                                       proutn("Helmsman Sulu- \"Course locked in for %s.\"",\r
+                                               cramlc(sector, irows, icols));\r
                                }\r
                        }\r
                        else prout("Ensign Chekov- \"Course laid in, Captain.\"");\r
@@ -431,8 +446,8 @@ void impuls(void) {
                prout("First Officer Spock- \"Captain, the impulse engines");\r
                prout("require 20.0 units to engage, plus 100.0 units per");\r
                if (energy > 30) {\r
-                       proutn("quadrant.  We can go, therefore, a maximum of ");\r
-                       cramf(0.01 * (energy-20.0)-0.05, 0, 1);\r
+                       proutn("quadrant.  We can go, therefore, a maximum of %d", \r
+                              (int)(0.01 * (energy-20.0)-0.05));\r
                        prout(" quadrants.\"");\r
                }\r
                else {\r
@@ -446,11 +461,11 @@ void impuls(void) {
        if (Time >= game.state.remtime) {\r
                prout("First Officer Spock- \"Captain, our speed under impulse");\r
                prout("power is only 0.95 sectors per stardate. Are you sure");\r
-               prout("we dare spend the time?\"");\r
+               proutn("we dare spend the time?\" ");\r
                if (ja() == 0) return;\r
        }\r
        /* Activate impulse engines and pay the cost */\r
-       move();\r
+       imove();\r
        ididit = 1;\r
        if (alldone) return;\r
        power = 20.0 + 100.0*dist;\r
@@ -519,11 +534,11 @@ void warp(int i) {
                if (Time >= 0.8*game.state.remtime) {\r
                        skip(1);\r
                        prout("First Officer Spock- \"Captain, I compute that such");\r
-                       proutn("  a trip would require approximately ");\r
-                       cramf(100.0*Time/game.state.remtime, 0, 2);\r
+                       proutn("  a trip would require approximately %2.0f",\r
+                               100.0*Time/game.state.remtime);\r
                        prout(" percent of our");\r
-                       prout(" remaining time.  Are you sure this is wise?\"");\r
-                       if (ja() == 0) { ididit = 0; return;}\r
+                        proutn("  remaining time.  Are you sure this is wise?\" ");\r
+                        if (ja() == 0) { ididit = 0; Time=0; return;}\r
                }\r
        }\r
        /* Entry WARPX */\r
@@ -578,7 +593,7 @@ void warp(int i) {
                                \r
 \r
        /* Activate Warp Engines and pay the cost */\r
-       move();\r
+       imove();\r
        if (alldone) return;\r
        energy -= dist*warpfac*warpfac*warpfac*(shldup+1);\r
        if (energy <= 0) finish(FNRG);\r
@@ -603,7 +618,7 @@ void setwrp(void) {
        \r
        while ((key=scan()) == IHEOL) {\r
                chew();\r
-               proutn("Warp factor-");\r
+               proutn("Warp factor- ");\r
        }\r
        chew();\r
        if (key != IHREAL) {\r
@@ -631,9 +646,8 @@ void setwrp(void) {
        warpfac = aaitem;\r
        wfacsq=warpfac*warpfac;\r
        if (warpfac <= oldfac || warpfac <= 6.0) {\r
-               proutn("Helmsman Sulu- \"Warp factor ");\r
-               cramf(warpfac, 0, 1);\r
-               prout(", Captain.\"");\r
+               proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"", \r
+                       (int)warpfac);\r
                return;\r
        }\r
        if (warpfac < 8.00) {\r
@@ -715,9 +729,7 @@ void atover(int igrab) {
                }\r
                warpfac = 6.0+2.0*Rand();\r
                wfacsq = warpfac * warpfac;\r
-               proutn("Warp factor set to ");\r
-               cramf(warpfac, 1, 1);\r
-               skip(1);\r
+               prout("Warp factor set to %d", (int)warpfac);\r
                power = 0.75*energy;\r
                dist = power/(warpfac*warpfac*warpfac*(shldup+1));\r
                distreq = 1.4142+Rand();\r
@@ -745,9 +757,8 @@ void timwrp() {
        prout("***TIME WARP ENTERED.");\r
        if (game.state.snap && Rand() < 0.5) {\r
                /* Go back in time */\r
-               proutn("You are traveling backwards in time ");\r
-               cramf(game.state.date-game.snapsht.date, 0, 2);\r
-               prout(" stardates.");\r
+               prout("You are traveling backwards in time %d stardates.",\r
+                     (int)(game.state.date-game.snapsht.date));\r
                game.state = game.snapsht;\r
                game.state.snap = 0;\r
                if (game.state.remcom) {\r
@@ -794,9 +805,7 @@ void timwrp() {
        else {\r
                /* Go forward in time */\r
                Time = -0.5*intime*log(Rand());\r
-               proutn("You are traveling forward in time ");\r
-               cramf(Time, 1, 2);\r
-               prout(" stardates.");\r
+               prout("You are traveling forward in time %d stardates.", (int)Time);\r
                /* cheat to make sure no tractor beams occur during time warp */\r
                game.future[FTBEAM] += Time;\r
                game.damage[DRADIO] += Time;\r
@@ -849,7 +858,7 @@ void probe(void) {
                key = scan();\r
        }\r
        else if (key == IHEOL) {\r
-               proutn("Arm NOVAMAX warhead?");\r
+               proutn("Arm NOVAMAX warhead? ");\r
                isarmed = ja();\r
        }\r
        getcd(TRUE, key);\r
@@ -922,9 +931,8 @@ void help(void) {
        }\r
        /* dematerialize starship */\r
        game.quad[sectx][secty]=IHDOT;\r
-       proutn("Starbase in");\r
-       cramlc(1, quadx, quady);\r
-       proutn(" responds--");\r
+       proutn("Starbase in %s responds--", cramlc(quadrant, quadx, quady));\r
+       proutn("");\r
        crmshp();\r
        prout(" dematerializes.");\r
        /* Give starbase three chances to rematerialize starship */\r
@@ -955,7 +963,7 @@ void help(void) {
                        sectx=ix;\r
                        secty=iy;\r
                        game.quad[ix][iy]=ship;\r
-                       dock();\r
+                       dock(0);\r
                        skip(1);\r
                        prout("Lt. Uhura-  \"Captain, we made it!\"");\r
                        return;\r