First round of changes from Stas Sergeev.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 19 Jan 2005 03:45:27 +0000 (03:45 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 19 Jan 2005 03:45:27 +0000 (03:45 +0000)
1. The Space Thingy can now be shoved.

2. Black holes are not instant  death any more, one has a chance of
   getting timewarped.

Various small code cleanups are included.

15 files changed:
ai.c
battle.c
conio.c [new file with mode: 0644]
conio.h [new file with mode: 0644]
events.c
finish.c
io.c
moving.c
planets.c
reports.c
setup.c
sst.c
sst.h
sstlinux.c [new file with mode: 0644]
sstlinux.h [new file with mode: 0644]

diff --git a/ai.c b/ai.c
index 3deab689799c2bc2a91c56db62eea833a24c5358..ba970a36ee9f18dcdbf2f43aa1fcf564e19788cc 100644 (file)
--- a/ai.c
+++ b/ai.c
@@ -24,12 +24,12 @@ static int tryexit(int lookx, int looky, int ienm, int loccom, int irun) {
           We know this if either short or long range sensors are working */\r
        if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 ||\r
                condit == IHDOCKED) {\r
-               proutn("***");\r
-               cramen(ienm);\r
+               crmena(1, ienm, 2, game.kx[loccom], game.ky[loccom]);\r
                proutn(" escapes to %s (and regains strength).",\r
                       cramlc(quadrant, iqx, iqy));\r
        }\r
        /* handle local matters related to escape */\r
+       game.quad[game.kx[loccom]][game.ky[loccom]] = IHDOT;\r
        game.kx[loccom] = game.kx[nenhere];\r
        game.ky[loccom] = game.ky[nenhere];\r
        game.kavgd[loccom] = game.kavgd[nenhere];\r
@@ -181,7 +181,6 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
        if (my != 0) my = my*motion < 0 ? -1 : 1;\r
        nextx = comx;\r
        nexty = comy;\r
-       game.quad[comx][comy] = IHDOT;\r
        /* main move loop */\r
        for (ll = 1; ll <= nsteps; ll++) {\r
 #ifdef DEBUG\r
@@ -242,6 +241,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
                else break; /* done early */\r
        }\r
        /* Put commander in place within same quadrant */\r
+       game.quad[comx][comy] = IHDOT;\r
        game.quad[nextx][nexty] = ienm;\r
        if (nextx != comx || nexty != comy) {\r
                /* it moved */\r
@@ -252,6 +252,8 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
                if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) {\r
                        proutn("***");\r
                        cramen(ienm);\r
+                       proutn(" from");\r
+                       cramlc(2, comx, comy);\r
                        if (game.kdist[loccom] < dist1) proutn(" advances to");\r
                        else proutn(" retreats to ");\r
                        prout(cramlc(sector, nextx, nexty));\r
@@ -297,8 +299,8 @@ void movcom(void) {
        sortkl();\r
 }\r
 \r
-static int checkdest(int iqx, int iqy, int flag, int *ipage) {\r
-       int i, j;\r
+static int movescom(int iqx, int iqy, int flag, int *ipage) {\r
+       int i;\r
 \r
        if ((iqx==quadx && iqy==quady) ||\r
                iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 ||\r
@@ -308,13 +310,13 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) {
                for (i = 1; i <= game.state.rembase; i++)\r
                        if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;\r
        }\r
-\r
+       if (justin && !iscate) return 1;\r
        /* do the move */\r
        game.state.galaxy[game.state.isx][game.state.isy] -= 100;\r
        game.state.isx = iqx;\r
        game.state.isy = iqy;\r
        game.state.galaxy[game.state.isx][game.state.isy] += 100;\r
-       if (iscate) {\r
+       if (ishere) {\r
                /* SC has scooted, Remove him from current quadrant */\r
                iscate=0;\r
                isatb=0;\r
@@ -342,7 +344,7 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) {
                        DESTROY(&game.state.plnets[i]);\r
                        game.state.newstuf[game.state.isx][game.state.isy] -= 1;\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
                                prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");\r
                                proutn("   a planet in ");\r
@@ -458,32 +460,32 @@ void scom(int *ipage) {
        /* try moving in both x and y directions */\r
        iqx = game.state.isx + ideltax;\r
        iqy = game.state.isy + ideltax;\r
-       if (checkdest(iqx, iqy, flag, ipage)) {\r
+       if (movescom(iqx, iqy, flag, ipage)) {\r
                /* failed -- try some other maneuvers */\r
                if (ideltax==0 || ideltay==0) {\r
                        /* attempt angle move */\r
                        if (ideltax != 0) {\r
                                iqy = game.state.isy + 1;\r
-                               if (checkdest(iqx, iqy, flag, ipage)) {\r
+                               if (movescom(iqx, iqy, flag, ipage)) {\r
                                        iqy = game.state.isy - 1;\r
-                                       checkdest(iqx, iqy, flag, ipage);\r
+                                       movescom(iqx, iqy, flag, ipage);\r
                                }\r
                        }\r
                        else {\r
                                iqx = game.state.isx + 1;\r
-                               if (checkdest(iqx, iqy, flag, ipage)) {\r
+                               if (movescom(iqx, iqy, flag, ipage)) {\r
                                        iqx = game.state.isx - 1;\r
-                                       checkdest(iqx, iqy, flag, ipage);\r
+                                       movescom(iqx, iqy, flag, ipage);\r
                                }\r
                        }\r
                }\r
                else {\r
                        /* try moving just in x or y */\r
                        iqy = game.state.isy;\r
-                       if (checkdest(iqx, iqy, flag, ipage)) {\r
+                       if (movescom(iqx, iqy, flag, ipage)) {\r
                                iqy = game.state.isy + ideltay;\r
                                iqx = game.state.isx;\r
-                               checkdest(iqx, iqy, flag, ipage);\r
+                               movescom(iqx, iqy, flag, ipage);\r
                        }\r
                }\r
        }\r
@@ -500,11 +502,12 @@ void scom(int *ipage) {
                        iseenit = 0;\r
                        isatb=1;\r
                        game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();\r
-                       if (batx != 0) game.future[FSCDBAS] += game.future[FCDBAS]-game.state.date;\r
+                       if (game.future[FCDBAS] < 1e30) game.future[FSCDBAS] +=\r
+                               game.future[FCDBAS]-game.state.date;\r
                        if (game.damage[DRADIO] > 0 && condit != IHDOCKED)\r
                                return; /* no warning */\r
                        iseenit = 1;\r
-                       if (*ipage == 0)  pause(1);\r
+                       if (*ipage == 0)  pause_game(1);\r
                        *ipage=1;\r
                        proutn("Lt. Uhura-  \"Captain, the starbase in ");\r
                        proutn(cramlc(quadrant, game.state.isx, game.state.isy));\r
@@ -529,7 +532,7 @@ void scom(int *ipage) {
                 (game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||\r
                 game.starch[game.state.isx][game.state.isy] > 0))\r
                return;\r
-       if (*ipage==0) pause(1);\r
+       if (*ipage==0) pause_game(1);\r
        *ipage = 1;\r
        prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");\r
        proutn("   the Super-commander is in ");\r
@@ -582,6 +585,8 @@ void movetho(void) {
                }\r
        }\r
        game.quad[ithx][ithy] = IHT;\r
+        game.kx[nenhere]=ithx;\r
+        game.ky[nenhere]=ithy;\r
 \r
        /* check to see if all holes plugged */\r
        for (i = 1; i < 11; i++) {\r
@@ -596,5 +601,6 @@ void movetho(void) {
        crmena(1,IHT, 2, ithx, ithy);\r
        prout(" completes web.");\r
        ithere = ithx = ithy = 0;\r
+       nenhere--;\r
        return;\r
 }\r
index 5a29bb8ea4f16545d75cb3c54a331f68eee4ba13..dd102aa8e250464188ddcaf3ad3ae46eb3e642c7 100644 (file)
--- a/battle.c
+++ b/battle.c
@@ -124,6 +124,7 @@ void doshield(int i) {
                        shield += aaitem;\r
                        energy -= aaitem;\r
                        return;\r
+               case NONE:;     /* avoid gcc warning */\r
        }\r
 }\r
 \r
@@ -142,6 +143,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) {
                case IHC: type = 2.0; break;\r
                case IHS: type = 2.5; break;\r
                case IHT: type = 0.5; break;\r
+                case IHQUEST: type = 4.0; break;\r
        }\r
        proutn(ibumpd ? " rammed by " : " rams ");\r
        crmena(0, ienm, 2, ix, iy);\r
@@ -162,7 +164,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) {
        }\r
        shldup = 0;\r
        if (game.state.remkl) {\r
-               pause(2);\r
+               pause_game(2);\r
                dreprt();\r
        }\r
        else finish(FWON);\r
@@ -209,7 +211,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                *hit = fabs(*hit);\r
                                newcnd(); /* undock */\r
                                /* We may be displaced. */\r
-                               if (landed==1) return; /* Cheat if on a planet */\r
+                               if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */\r
                                ang = angle + 2.5*(Rand()-0.5);\r
                                temp = fabs(sin(ang));\r
                                if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));\r
@@ -279,12 +281,13 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                        prout(" damaged but not destroyed.");\r
                                        return;\r
                                }\r
-                               prout(" damaged--");\r
+                               proutn(" damaged--");\r
                                game.kx[ll] = jx;\r
                                game.ky[ll] = jy;\r
                                shoved = 1;\r
                                break;\r
                        case IHB: /* Hit a base */\r
+                               skip(1);\r
                                prout("***STARBASE DESTROYED..");\r
                                if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;\r
                                for (ll=1; ll<=game.state.rembase; ll++) {\r
@@ -324,16 +327,25 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                prout(" unaffected by photon blast.");\r
                                return;\r
                        case IHQUEST: /* Hit a thingy */\r
+                            if (Rand()>0.7) {  // Used to be certain death \r
                                skip(1);\r
                                prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");\r
                                skip(1);\r
                                prouts("    HACK!     HACK!    HACK!        *CHOKE!*  ");\r
                                skip(1);\r
                                proutn("Mr. Spock-");\r
-                               prouts("  \"Facinating!\"");\r
+                               prouts("  \"Fascinating!\"");\r
                                skip(1);\r
-                               game.quad[ix][iy] = IHDOT;\r
-                               return;\r
+                                deadkl(ix, iy, iquad, ix, iy);\r
+                            } else {\r
+                               /*\r
+                                * Stas Sergeev added the possibility that\r
+                                * you can shove the Thingy.\r
+                                */\r
+                                iqengry=1;\r
+                                shoved=1;\r
+                            }\r
+                           return;\r
                        case IHBLANK: /* Black hole */\r
                                skip(1);\r
                                crmena(1, IHBLANK, 2, ix, iy);\r
@@ -344,8 +356,6 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                prout("***Torpedo absorbed by Tholian web.");\r
                                return;\r
                        case IHT:  /* Hit a Tholian */\r
-                               skip(1);\r
-                               crmena(1, IHT, 2, ix, iy);\r
                                h1 = 700.0 + 100.0*Rand() -\r
                                         1000.0*sqrt(square(ix-inx)+square(iy-iny))*\r
                                         fabs(sin(bullseye-angle));\r
@@ -357,6 +367,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                        ithx = ithy = 0;\r
                                        return;\r
                                }\r
+                               skip(1);\r
+                               crmena(1, IHT, 2, ix, iy);\r
                                if (Rand() > 0.05) {\r
                                        prout(" survives photon blast.");\r
                                        return;\r
@@ -364,6 +376,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                prout(" disappears.");\r
                                game.quad[ix][iy] = IHWEB;\r
                                ithere = ithx = ithy = 0;\r
+                               nenhere--;\r
                                {\r
                                        int dum, my;\r
                                        dropin(IHBLANK, &dum, &my);\r
@@ -395,7 +408,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
 \r
 static void fry(double hit) {\r
        double ncrit, extradm;\r
-       int ktr=1, l, ll, j, cdam[6], crptr;\r
+       int ktr=1, l, ll, j, cdam[NDEVICES+1], crptr;\r
 \r
        /* a critical hit occured */\r
        if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;\r
@@ -403,7 +416,7 @@ static void fry(double hit) {
        ncrit = 1.0 + hit/(500.0+100.0*Rand());\r
        proutn("***CRITICAL HIT--");\r
        /* Select devices and cause damage */\r
-       for (l = 1; l <= ncrit; l++) {\r
+       for (l = 1; l <= ncrit && l <= NDEVICES; l++) {\r
                do {\r
                        j = NDEVICES*Rand()+1.0;\r
                        /* Cheat to prevent shuttle damage unless on ship */\r
@@ -447,8 +460,8 @@ void attack(int k) {
                neutz = 0;\r
                return;\r
        }\r
-       if (((comhere || ishere) && (justin == 0)) || skill == 5) movcom();\r
-       if (nenhere==0) return;\r
+       if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();\r
+       if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;\r
        pfac = 1.0/inshld;\r
        if (shldchg == 1) chgfac = 0.25+0.5*Rand();\r
        skip(1);\r
@@ -463,10 +476,12 @@ void attack(int k) {
                jx = game.kx[l];\r
                jy = game.ky[l];\r
                iquad = game.quad[jx][jy];\r
+                if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;\r
                itflag = (iquad == IHK && r > 0.0005) || k == 0 ||\r
                        (iquad==IHC && r > 0.015) ||\r
                        (iquad==IHR && r > 0.3) ||\r
-                       (iquad==IHS && r > 0.07);\r
+                        (iquad==IHS && r > 0.07) ||\r
+                        (iquad==IHQUEST && r > 0.05);\r
                if (itflag) {\r
                        /* Enemy uses phasers */\r
                        if (condit == IHDOCKED) continue; /* Don't waste the effort! */\r
@@ -484,7 +499,7 @@ void attack(int k) {
                                crmena(0, iquad, i, jx, jy);\r
                        }\r
                        attempt = 1;\r
-                       prout("--");\r
+                       prout("  ");\r
                        r = (Rand()+Rand())*0.5 -0.5;\r
                        r += 0.002*game.kpower[l]*r;\r
                        torpedo(course, r, jx, jy, &hit);\r
@@ -493,9 +508,9 @@ void attack(int k) {
                                alldone) return; /* Supernova or finished */\r
                        if (hit == 0) continue;\r
                }\r
-               if (shldup != 0 || shldchg != 0) {\r
+                if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {\r
                        /* shields will take hits */\r
-                       double absorb, hitsh, propor = pfac*shield;\r
+                        double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);\r
                        if(propor < 0.1) propor = 0.1;\r
                        hitsh = propor*chgfac*hit+1.0;\r
                        atackd=1;\r
@@ -584,6 +599,10 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) {
                /* Killed a Tholian */\r
                ithere = 0;\r
        }\r
+        else if (type == IHQUEST) {\r
+               /* Killed a Thingy */\r
+             iqhere=iqengry=thingx=thingy=0;\r
+        }\r
        else {\r
                /* Some type of a Klingon */\r
                game.state.galaxy[quadx][quady] -= 100;\r
@@ -622,10 +641,9 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) {
 \r
        game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);\r
 \r
-       if (type == IHT) return;\r
-\r
        /* Remove enemy ship from arrays describing local conditions */\r
-\r
+        if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)\r
+           game.future[FCDBAS] = 1e30;\r
        for (i=1; i<=nenhere; i++)\r
                if (game.kx[i]==ix && game.ky[i]==iy) break;\r
        nenhere--;\r
@@ -658,7 +676,7 @@ static int targetcheck(double x, double y, double *course) {
                skip(1);\r
                prout("Spock-  \"Bridge to sickbay.  Dr. McCoy,");\r
                prout("  I recommend an immediate review of");\r
-               prout("  the Captain's psychological profile.");\r
+               prout("  the Captain's psychological profile.\"");\r
                chew();\r
                return 1;\r
        }\r
@@ -704,6 +722,7 @@ void photon(void) {
                                chew();\r
                                prout("Maximum of 3 torpedoes per burst.");\r
                                key = IHEOL;\r
+                                return;\r
                        }\r
                        if (n <= torps) break;\r
                        chew();\r
@@ -856,7 +875,7 @@ void phasers(void) {
        int kz = 0, k=1, i; /* Cheating inhibitor */\r
        int ifast=0, no=0, ipoop=1, msgflag = 1;\r
        enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;\r
-       int key;\r
+       int key=0;\r
 \r
        skip(1);\r
        /* SR sensors and Computer */\r
@@ -953,7 +972,7 @@ void phasers(void) {
                                key = scan();\r
                        }\r
                        if (key != IHREAL && nenhere != 0) {\r
-                               prout("Phasers locked on target. Energy available = %.2f", ifast?energy-200.0:energy);\r
+                               prout("Phasers locked on target. Energy available: %.2f", ifast?energy-200.0:energy);\r
                        }\r
                        do {\r
                                while (key != IHREAL) {\r
@@ -1081,7 +1100,6 @@ void phasers(void) {
                                }\r
                                if (aaitem < 0) {\r
                                        /* abort out */\r
-                                       ididit = 0;\r
                                        chew();\r
                                        return;\r
                                }\r
@@ -1106,7 +1124,7 @@ void phasers(void) {
                                chew();\r
                                return;\r
                        }\r
-                       if (key == IHALPHA & isit("no")) {\r
+                       if (key == IHALPHA && isit("no")) {\r
                                no = 1;\r
                        }\r
                        energy -= rpow;\r
@@ -1161,6 +1179,7 @@ void hittem(double *hits) {
                else\r
                        proutn("Very small hit on ");\r
                ienm = game.quad[ii][jj];\r
+                if (ienm==IHQUEST) iqengry=1;\r
                crmena(0,ienm,2,ii,jj);\r
                skip(1);\r
                if (kpow == 0) {\r
diff --git a/conio.c b/conio.c
new file mode 100644 (file)
index 0000000..adf42e5
--- /dev/null
+++ b/conio.c
@@ -0,0 +1,326 @@
+/****************************************************************************
+ * This is the implementation file for conio.h - a conio.h for Linux.       *
+ * It uses ncurses and some internal functions of Linux to simulate the     *
+ * I/O-functions.                                                           *
+ * This is copyright (c) 1996,97 by Fractor / Mental eXPlosion (MXP)        *
+ * Use and distribution is only allowed if you follow the terms of the      *
+ * GNU Library Public License Version 2.                                    *
+ * Since this work is based on ncurses please read its copyright notices as *
+ * well !                                                                   *
+ * Look into the readme to this file for further information.               *
+ * Thanx to SubZero / MXP for his little tutorial on the curses library !   *
+ * Many thanks to Mark Hahn and Rich Cochran for solving the inpw and inpd  *
+ * mega-bug !!!                                                             *
+ * Watch out for other MXP releases, too !                                  *
+ * Send bugreports to: fractor@germanymail.com                              *
+ ****************************************************************************/
+
+#define _ISOC99_SOURCE
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/io.h>
+#include <ncurses.h>
+#include "conio.h" 
+
+static attr_t txtattr,oldattr;
+static int fgc,bgc;
+char color_warning=1;
+int directvideo;
+WINDOW *conio_scr;
+
+/* Some internals... */
+static int colortab(int a) /* convert LINUX Color code to DOS-standard */
+{
+   switch(a) {
+      case 0 : return COLOR_BLACK;
+      case 1 : return COLOR_BLUE;
+      case 2 : return COLOR_GREEN;
+      case 3 : return COLOR_CYAN;
+      case 4 : return COLOR_RED;
+      case 5 : return COLOR_MAGENTA;
+      case 6 : return COLOR_YELLOW;
+      case 7 : return COLOR_WHITE;
+   }
+   return COLOR_BLACK;
+} 
+
+static void docolor (int color) /* Set DOS-like text mode colors */
+{
+   wattrset(conio_scr,0); /* My curses-version needs this ... */
+   if ((color&128)==128) txtattr=A_BLINK; else txtattr=A_NORMAL;
+   if ((color&15)>7) txtattr|=A_STANDOUT; else txtattr|=A_NORMAL;
+   txtattr|=COLOR_PAIR((1+(color&7)+(color&112)) >> 1);
+   if (((color&127)==15) | ((color&127)==7)) txtattr=COLOR_PAIR(0);
+   if (((color&127)==127) | ((color&127)==119)) txtattr=COLOR_PAIR(8);
+   wattron(conio_scr,txtattr);
+   wattron(conio_scr,COLOR_PAIR(1+(color&7)+((color&112)>>1))); 
+}
+
+/* Call this before any call to linux conio - except the port functions ! */
+void __attribute__((constructor)) initconio (void) /* This is needed, because ncurses needs to be initialized */
+{
+   int x,y;
+   short pair;
+   if (atexit(doneconio)){
+      fprintf(stderr,"Unable to register doneconio(), exiting...\n");
+      exit(1);
+   }
+   initscr();
+   start_color();
+//   attr_get(&oldattr,&pair,NULL);
+   nonl();
+   raw();
+   if (!has_colors() & (color_warning>-1))
+      fprintf(stderr,"Attention: A color terminal may be required to run this application !\n");   
+   noecho();
+   conio_scr=newwin(0,0,0,0);
+   keypad(conio_scr,TRUE);
+   meta(conio_scr,TRUE);
+   idlok(conio_scr,TRUE);
+   scrollok(conio_scr,TRUE);
+   /* Color initialization */
+   for (y=0;y<=7;y++)
+      for (x=0;x<=7;x++)
+         init_pair((8*y)+x+1, colortab(x), colortab(y));              
+   wattr_get(conio_scr,&txtattr,&pair,NULL);
+   bgc=0;
+   textcolor(7);
+   textbackground(0);
+}
+
+/* Call this on exiting your program */
+void doneconio (void)
+{
+   endwin();
+}
+
+/* Here it starts... */
+void _setcursortype (int cur_t)
+{
+   curs_set(cur_t);
+   wrefresh(conio_scr);
+}
+
+char *cgets (char *str) /* ugly function :-( */
+{
+   char strng[257];
+   unsigned char i=2;
+   echo();
+   strncpy(strng,str,1);
+   wgetnstr(conio_scr,&strng[2],(int) strng[0]);
+   while (strng[i]!=0) i++;
+   i=i-2;
+   strng[1]=i;
+   memcpy(str,strng,i+3);
+   noecho();
+   return(&str[2]);
+}
+
+void clreol (void)
+{
+   wclrtoeol(conio_scr);
+   wrefresh(conio_scr);
+}
+
+void clrscr (void)
+{
+   wclear(conio_scr);
+   wmove(conio_scr,0,0);
+   wrefresh(conio_scr);
+}
+
+int cprintf (char *format, ... )
+{
+   int i;
+   char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses...  */
+   va_list argp;
+   va_start(argp,format);
+   vsprintf(buffer,format,argp);
+   va_end(argp);
+   i=waddstr(conio_scr,buffer);
+   wrefresh(conio_scr);
+   return(i);
+}
+
+void cputs (char *str)
+{
+   waddstr(conio_scr,str);
+   wrefresh(conio_scr);
+}
+
+int cscanf (const char *format, ...)
+{
+   int i;
+   char buffer[BUFSIZ]; /* See cprintf */
+   va_list argp;
+   echo();
+   if (wgetstr(conio_scr,buffer)==ERR) return(-1);                    
+   va_start(argp,format);
+   i=vsscanf(buffer,format,argp);                         
+   va_end(argp);
+   noecho();
+   return(i);
+}
+
+void delline (void)
+{
+   wdeleteln(conio_scr);
+   wrefresh(conio_scr);
+}
+
+int getche (void)
+{
+   int i;
+   echo();
+   i=wgetch(conio_scr);
+   if (i==-1) i=0;
+   noecho();
+   return(i);
+}
+
+void gettextinfo(struct text_info *inforec)
+{
+   short pair;
+   unsigned char xp,yp;
+   unsigned char x1,x2,y1,y2;
+   attr_t dattr,dnattr,a; /* The "d" stands for DOS */
+   getyx(conio_scr,yp,xp);
+   getbegyx(conio_scr,y1,x1);
+   getmaxyx(conio_scr,y2,x2);
+   dattr=(bgc*16)+fgc;
+   wattr_get(conio_scr,&a,&pair,NULL);
+   if (a==(a & A_BLINK)) dattr=dattr+128;
+   dnattr=oldattr;  /* Well, this cannot be right, 
+                       because we don't know the COLORPAIR values from before initconio() !*/
+   inforec->winleft=x1+1;
+   inforec->wintop=y1+1;
+   if (x1==0) x2--;
+   if (y1==0) y2--;
+   inforec->winright=x1+x2+1;
+   inforec->winbottom=y1+y2+1;
+   inforec->curx=xp+1;
+   inforec->cury=yp+1;
+   inforec->screenheight=y2+1;
+   inforec->screenwidth=x2+1;
+   inforec->currmode=3; /* This is C80 */
+   inforec->normattr=dnattr; /* Don't use this ! */
+   inforec->attribute=dattr;
+} 
+
+void gotoxy (int x, int y)
+{
+   y--;
+   x--;
+   wmove(conio_scr,y,x);
+   wrefresh(conio_scr);
+}
+
+void highvideo (void)
+{
+   textcolor(15); /* White */
+   textbackground(0); /* Black */
+}
+
+void insline (void)
+{ 
+   winsertln(conio_scr);
+   wrefresh(conio_scr);
+}
+
+int kbhit (void)
+{
+   int i;
+   nodelay(conio_scr,TRUE);
+   i=wgetch(conio_scr);
+   nodelay(conio_scr,FALSE);
+   if (i==-1) i=0;
+   return(i);
+}
+
+void lowvideo (void)
+{
+   textbackground(0); /* Black */
+   textcolor(8); /* Should be darkgray */
+}
+
+void normvideo (void)
+{
+   wattrset(conio_scr,oldattr);
+}
+
+int putch (int c)
+{
+   if (waddch(conio_scr,c)!=ERR) {
+      wrefresh(conio_scr); 
+      return(c);
+   }
+   return(0);
+}
+                                     
+void textattr (int attr)
+{
+   docolor(attr);
+}
+
+void textbackground (int color)
+{
+   bgc=color;
+   color=(bgc*16)+fgc;
+   docolor(color);
+}
+
+void textcolor (int color)
+{
+   fgc=color;
+   color=(bgc*16)+fgc;
+   docolor(color);
+}
+void textmode (int mode)
+{
+   /* Ignored */
+}
+
+int wherex (void)
+{
+   int y;
+   int x;
+   getyx(conio_scr,y,x);
+   x++;
+   return(x);
+}
+
+int wherey (void)
+{
+   int y;
+   int x;
+   getyx(conio_scr,y,x);
+   y++;
+   return(y);
+}
+
+void window (int left,int top,int right,int bottom)
+{
+   int nlines,ncols;
+   delwin(conio_scr);
+   top--;
+   left--;
+   right--;
+   bottom--;
+   nlines=bottom-top;
+   ncols=right-left;
+   if (top==0) nlines++;
+   if (left==0) ncols++;
+   if ((nlines<1) | (ncols<1)) return;
+   conio_scr=newwin(nlines,ncols,top,left);   
+   keypad(conio_scr,TRUE);
+   meta(conio_scr,TRUE);
+   idlok(conio_scr,TRUE);
+   scrollok(conio_scr,TRUE);
+   wrefresh(conio_scr);
+}
+
+/* Linux is cool */
diff --git a/conio.h b/conio.h
new file mode 100644 (file)
index 0000000..1b28c2e
--- /dev/null
+++ b/conio.h
@@ -0,0 +1,103 @@
+/***************************************************************************/
+/** File: conio.h     Date: 03/09/1997       Version: 1.02                **/
+/** --------------------------------------------------------------------- **/
+/** CONIO.H an implementation of the conio.h for Linux based on ncurses.  **/
+/** This is copyright (c) 1996,97 by Fractor / Mental EXPlosion.          **/
+/** If you want to copy it you must do this following the terms of the    **/
+/** GNU Library Public License                                            **/
+/** Please read the file "README" before using this library.              **/
+/** --------------------------------------------------------------------- **/
+/** To use this thing you must have got the curses library.               **/
+/** This thing was tested on Linux Kernel 2.0.29, GCC 2.7.2 and           **/
+/** ncurses 1.9.9e which is (c) 1992-1995 by Zeyd M. Ben-Halim and Eric S.**/
+/** Raymond.                                                              **/
+/** Please also read the copyright notices for ncurses before using this !**/
+/***************************************************************************/             
+
+#ifndef __linux__
+#error This conio.h was only tested to work under LINUX !
+#endif
+
+#ifndef __LINUXCONIO_H
+#define __LINUXCONIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ncurses.h>
+
+#define linux_conio_version 1.04
+
+extern int directvideo; /* ignored by linux conio.h */
+extern char color_warning; /* Tell the users when terminal can't display colors ? */
+extern WINDOW *conio_scr;
+#define _NOCURSOR      0
+#define _NORMALCURSOR  1
+
+struct text_info {
+    unsigned char winleft;
+    unsigned char wintop;
+    unsigned char winright;
+    unsigned char winbottom;
+    unsigned char attribute;
+    unsigned char normattr;
+    unsigned char currmode;
+    unsigned char screenheight;
+    unsigned char screenwidth;
+    unsigned char curx;
+    unsigned char cury;
+};
+
+enum text_modes { LASTMODE=-1, BW40=0, C40, BW80, C80, MONO=7, C4350=64 };
+
+enum COLORS {
+   BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
+   DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE
+};
+
+#define BLINK 128    
+
+extern void initconio(void); /* Please run this function before any other */ 
+extern void doneconio(void); /* Please run this function before exiting your program */
+
+extern int wherex(void);
+extern int wherey(void);
+extern int putch(int c);
+extern int getche(void); 
+extern int kbhit(void);
+extern void _setcursortype(int);
+extern int cprintf(char *format, ...);
+extern int cscanf(const char *format, ...); 
+
+extern unsigned inp(unsigned port);
+extern unsigned inpw(unsigned port);
+extern unsigned outp(unsigned port, unsigned value);
+extern unsigned outpw(unsigned port,unsigned value);
+extern unsigned inpd(unsigned port);
+extern unsigned outpd(unsigned port, unsigned value);
+
+extern void clreol(void);
+extern void clrscr(void);
+extern void gotoxy(int x, int y);
+extern void delline(void);
+extern void gettextinfo(struct text_info *r);
+extern void highvideo(void);
+extern void insline(void);
+extern void lowvideo(void);
+extern void normvideo(void);
+extern void textattr(int attribute);
+extern void textbackground(int color);
+extern void textcolor(int color);
+extern void textmode(int unused_mode);
+extern void window(int left, int top, int right, int bottom);
+extern void cputs(char *str);
+
+extern char *cgets(char *str); 
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
index 940ad7b54e126d03834a0b118ca1d02f52c52b4c..194901df53c3f9d2e69e1b0d9edca42ab070d6ed 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
@@ -170,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
@@ -212,12 +211,12 @@ 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
                                prout(cramlc(quadrant, batx, baty));\r
-                               prout("   reports that it is under atttack and that it can");\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
@@ -267,7 +266,7 @@ 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
@@ -314,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
@@ -328,7 +327,7 @@ 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
@@ -373,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
@@ -394,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
@@ -412,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
index 7144086973e2c8cca21efc56ed33578dcfa7c15e..8a8427a79c3c5b01ad68b9e3195d7327e993dcb6 100644 (file)
--- a/finish.c
+++ b/finish.c
@@ -307,7 +307,7 @@ void score(void) {
        double timused = game.state.date - indate;\r
        int ithperd, iwon, klship;\r
 \r
-       pause(0);\r
+       pause_game(0);\r
 \r
        iskill = skill;\r
        if ((timused == 0 || game.state.remkl != 0) && timused < 5.0) timused = 5.0;\r
diff --git a/io.c b/io.c
index a5ac6d9e30411105399ca04869758b15ffcee87a..81f1c8a18b70fdb3953cb5d7530f43de77d1b1f6 100644 (file)
--- a/io.c
+++ b/io.c
@@ -82,7 +82,7 @@ void clearscreen(void) {
 #endif
 }
 
-void pause(int i) {
+void pause_game(int i) {
     char buf[BUFSIZ], *prompt;
        if (i==1) {
                if (skill > 2)
@@ -121,13 +121,13 @@ void skip(int i) {
            int y, x;
            getyx(stdscr, y, x);
            if (y == screenheight-1)
-               pause(0);
+               pause_game(0);
            else
                waddch(stdscr, '\n');
        } else {
            linecount++;
            if (linecount >= screenheight)
-               pause(0);
+               pause_game(0);
            else
                putchar('\n');
        }
index 07eb148b3eecdbc0eb4c9af5925aac61ff736c82..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 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 imove(void) {
                                quady = (iy+9)/10;\r
                                sectx = ix - 10*(quadx-1);\r
                                secty = iy - 10*(quady-1);\r
-                               prout("");\r
-                               prout("Entering %s.",\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 imove(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
@@ -131,7 +133,23 @@ void imove(void) {
                                                crmshp();\r
                                                proutn(" pulled into black hole at ");\r
                                                prout(cramlc(sector, ix, iy));\r
-                                               finish(FHOLE);\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
@@ -186,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
@@ -211,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
@@ -226,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
@@ -443,7 +461,7 @@ 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
@@ -519,8 +537,8 @@ void warp(int i) {
                        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
@@ -600,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
@@ -628,7 +646,7 @@ void setwrp(void) {
        warpfac = aaitem;\r
        wfacsq=warpfac*warpfac;\r
        if (warpfac <= oldfac || warpfac <= 6.0) {\r
-               proutn("Helmsman Sulu- \"Warp factor %do, Captain.\"", \r
+               proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"", \r
                        (int)warpfac);\r
                return;\r
        }\r
@@ -840,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
@@ -945,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
index a45879f05c8adf225ea236fec6150810117b8eb2..ecc3d600299f4c266f85fceef332764d49766f24 100644 (file)
--- a/planets.c
+++ b/planets.c
@@ -412,7 +412,7 @@ void deathray(void) {
        }\r
        prout("Spock-  \"Captain, the 'Experimental Death Ray'");\r
        prout("  is highly unpredictible.  Considering the alternatives,");\r
-       prout("  are you sure this is wise?\" ");\r
+       proutn("  are you sure this is wise?\" ");\r
        if (ja()==0) return;\r
        prout("Spock-  \"Acknowledged.\"");\r
        skip(1);\r
index e398e776d5c8530b91e00999830ffc5274d390fd..794b18117afe27d06951e3f3899aac37cd0fb2f7 100644 (file)
--- a/reports.c
+++ b/reports.c
@@ -3,9 +3,10 @@
 #include <stdlib.h>\r
 #include <string.h>\r
 \r
-void attakreport(void) {\r
+void attakreport(int l) {\r
+    if (!l) {\r
        if (game.future[FCDBAS] < 1e30) {\r
-               prout("Starbase in %s is currently under attack.",\r
+               prout("Starbase in %s is currently under Commander attack.",\r
                      cramlc(quadrant, batx, baty));\r
                prout("It can hold out until Stardate %d.", \r
                      (int)game.future[FCDBAS]);\r
@@ -16,6 +17,12 @@ void attakreport(void) {
                prout("It can hold out until Stardate %d.", \r
                      (int)game.future[FSCDBAS]);\r
        }\r
+     } else {\r
+        if (game.future[FCDBAS] < 1e30)\r
+           proutn("Base in %i - %i attacked by C. Alive until %.1f", batx, baty, game.future[FCDBAS]);\r
+        if (isatb == 1)\r
+           proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.isx, game.state.isy, game.future[FSCDBAS]);\r
+     }\r
 }\r
        \r
 \r
@@ -63,7 +70,7 @@ void report(int f) {
        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
+               attakreport(0);\r
                iseenit = 1;\r
        }\r
        if (casual) prout("%d casualt%s suffered so far.",\r
@@ -89,7 +96,7 @@ void report(int f) {
        }\r
        if (icrystl) {\r
                if (cryprob <= .05)\r
-                       prout("Dilithium crystals aboard ship...not yet used.");\r
+                       prout("Dilithium crystals aboard ship... not yet used.");\r
                else {\r
                        int i=0;\r
                        double ai = 0.05;\r
@@ -319,7 +326,7 @@ void srscan(int l) {
                                        proutn(" Klingons Left %d", game.state.remkl);\r
                                        break;\r
                                case 10:\r
-                                       proutn(" Time Left     %.2f", game.state.remtime);\r
+                                       attakreport(1);\r
                                        break;\r
                        }\r
                                        \r
@@ -363,11 +370,11 @@ void eta(void) {
                }\r
                ix2 = aaitem + 0.5;\r
        }\r
-       else {  // same quadrant\r
-               ix2 = ix1;\r
-               iy2 = iy1;\r
-               ix1 = quady;    // ya got me why x and y are reversed!\r
-               iy1 = quadx;\r
+        else {\r
+                if (quady>ix1) ix2 = 1;\r
+                else ix2=10;\r
+                if (quadx>iy1) iy2 = 1;\r
+                else iy2=10;\r
        }\r
 \r
        if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 ||\r
diff --git a/setup.c b/setup.c
index 649774487639b56d45ab29ebd98570cf51b849f8..1d7dd0153679b77abc4e5d21520c216fb44bb48e 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -45,10 +45,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
@@ -57,7 +56,7 @@ void thaw(void) {
        }\r
        if (key != IHALPHA) {\r
                huh();\r
-               return;\r
+               return 1;\r
        }\r
        chew();\r
        if (strchr(citem, '.') == NULL) {\r
@@ -67,18 +66,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
-               return;\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
@@ -182,13 +182,13 @@ void abandn(void) {
 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(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
@@ -207,6 +207,7 @@ void setup(int needprompt) {
        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
@@ -328,7 +329,7 @@ void setup(int needprompt) {
                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
@@ -336,7 +337,7 @@ void setup(int needprompt) {
        }\r
 \r
 //     idate = date;\r
-       skip(3);\r
+       skip(2);\r
        game.state.snap = 0;\r
                \r
        if (skill == 1) {\r
@@ -374,7 +375,7 @@ void setup(int needprompt) {
        prout("Good Luck!");\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
@@ -515,6 +516,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
@@ -536,27 +539,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
@@ -581,7 +563,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
@@ -615,7 +597,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
@@ -631,7 +613,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
@@ -640,6 +629,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
@@ -659,7 +676,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
diff --git a/sst.c b/sst.c
index ee80b3fc878ba45048deeea559f9aae42f81b366..888b7ec4780b01333e7a04905a7dbef65e07d6c5 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -217,7 +217,8 @@ static void makemoves(void) {
                                }\r
                                break;\r
                        case 6:                 // dock\r
-                               dock();\r
+                               dock(1);\r
+                                if (ididit) attack(0);\r
                                break;\r
                        case 7:                 // damages\r
                                dreprt();\r
@@ -411,6 +412,7 @@ void cramen(int i) {
                case IHBLANK: s = "Black hole"; break;\r
                case IHT: s = "Tholian"; break;\r
                case IHWEB: s = "Tholian web"; break;\r
+                case IHQUEST: s = "Stranger"; break;\r
                default: s = "Unknown??"; break;\r
        }\r
        proutn(s);\r
@@ -502,6 +504,7 @@ int scan(void) {
        }\r
        if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') {\r
                // treat as a number\r
+           i = 0;\r
            if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {\r
                linep = line; // Invalid numbers are ignored\r
                *linep = 0;\r
@@ -534,8 +537,6 @@ int ja(void) {
        }\r
 }\r
 \r
-double square(double i) { return i*i; }\r
-                                                                       \r
 void huh(void) {\r
        chew();\r
        skip(1);\r
diff --git a/sst.h b/sst.h
index 375e7aaddcfc0d07407d91d80e5486f9bce18397..63ea4cfa1ef9e957e87d66b440fb24c00093b589 100644 (file)
--- a/sst.h
+++ b/sst.h
@@ -131,6 +131,8 @@ EXTERN struct {
        batx,\r
        baty,\r
        ithere,\r
+        iqhere,\r
+        iqengry,\r
        ithx,\r
        ithy,\r
        iseenit,\r
@@ -205,6 +207,8 @@ EXTERN struct {
 #define ishere game.ishere                     // Super-commander in quandrant\r
 #define neutz game.neutz                       // Romulan Neutral Zone\r
 #define irhere game.irhere                     // Romulans in quadrant\r
+#define iqhere game.iqhere                     // Thing in quadrant\r
+#define iqengry game.iqengry                   // Thing attacking\r
 #define icraft game.icraft                     // Kirk in Galileo\r
 #define ientesc game.ientesc           // Attempted escape from supercommander\r
 #define iscraft game.iscraft           // =1 if craft on ship, -1 if removed from game\r
@@ -339,6 +343,10 @@ char *device[NDEVICES+1] = {
 #define IHYELLOW 'Y'\r
 #define IHRED 'R'\r
 #define IHDOCKED 'D'\r
+#define IHDEAD 'Z'\r
+#define IHMATER0 '-'\r
+#define IHMATER1 'o'\r
+#define IHMATER2 '0'\r
 \r
 \r
 /* Function prototypes */\r
@@ -354,7 +362,7 @@ void phasers(void);
 void photon(void);\r
 void warp(int);\r
 void doshield(int);\r
-void dock(void);\r
+void dock(int);\r
 void dreprt(void);\r
 void chart(int);\r
 void impuls(void);\r
@@ -369,7 +377,7 @@ void finish(FINTYPE);
 void dstrct(void);\r
 void kaboom(void);\r
 void freeze(int);\r
-void thaw(void);\r
+int thaw(void);\r
 void plaque(void);\r
 int scan(void);\r
 #define IHEOL (0)\r
@@ -390,7 +398,7 @@ double expran(double);
 double Rand(void);\r
 void iran8(int *, int *);\r
 void iran10(int *, int *);\r
-double square(double);\r
+#define square(i) ((i)*(i))\r
 void dropin(int, int*, int*);\r
 void newcnd(void);\r
 void sortkl(void);\r
@@ -402,7 +410,7 @@ void timwrp(void);
 void movcom(void);\r
 void torpedo(double, double, int, int, double *);\r
 void huh(void);\r
-void pause(int);\r
+void pause_game(int);\r
 void nova(int, int);\r
 void snova(int, int);\r
 void scom(int *);\r
@@ -419,7 +427,7 @@ void usecrystals(void);
 void shuttle(void);\r
 void deathray(void);\r
 void debugme(void);\r
-void attakreport(void);\r
+void attakreport(int);\r
 void movetho(void);\r
 void probe(void);\r
 void clearscreen(void);\r
diff --git a/sstlinux.c b/sstlinux.c
new file mode 100644 (file)
index 0000000..b376b39
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdarg.h>
+#include <ncurses/ncurses.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/kd.h>
+
+#include "sstlinux.h"
+
+static int fd = 0;
+
+int c_printf (char *format, ... )
+{
+    char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses...  */
+    va_list argp;
+    va_start(argp,format);
+    vsprintf(buffer,format,argp);
+    va_end(argp);
+    return waddstr(conio_scr,buffer);
+}
+
+void sound(unsigned int freq)
+{
+    if(fd==0) fd=open("/dev/console", O_RDONLY);
+    if(fd>0) ioctl(fd, KDMKTONE, 1193180/freq + (0xFFFF<<16));
+}
+
+void nosound(void)
+{
+    if(fd>0) ioctl(fd, KDMKTONE, 0);
+}
diff --git a/sstlinux.h b/sstlinux.h
new file mode 100644 (file)
index 0000000..779f8eb
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __SSTLINUX_H
+#define __SSTLINUX_H
+
+int c_printf (char *format, ... );
+void sound(unsigned int);
+void nosound(void);
+
+extern WINDOW *conio_scr;
+
+#define delay(x) usleep(x*1000)
+#define randomize() srand((unsigned)time(NULL))
+
+#endif