From c1bda490aef42a6b3d0e8d97a20fb58236d02ee7 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 3 Feb 2005 18:04:05 +0000 Subject: [PATCH] Merge Stas's patch #3. --- finish.c | 11 +-- moving.c | 56 ++++++++++----- reports.c | 202 +++++++++++++++++++++++++++++++--------------------- setup.c | 33 +++++---- sst-doc.xml | 4 +- sst.c | 23 +++--- sst.h | 6 +- 7 files changed, 200 insertions(+), 135 deletions(-) diff --git a/finish.c b/finish.c index b19ce7f..3369469 100644 --- a/finish.c +++ b/finish.c @@ -403,11 +403,10 @@ void plaque(void) { skip(2); while (fp == NULL) { -#ifdef SERGEEV proutn("File or device name for your plaque: "); +#ifdef SERGEEV getline(winner, sizeof(winner)); #else - proutn("File or device name for your plaque:"); fgets(winner, 128, stdin); winner[strlen(winner)-1] = '\0'; #endif /* SERGEEV */ @@ -419,14 +418,8 @@ void plaque(void) { proutn("Enter name to go on plaque (up to 30 characters): "); getline(winner, sizeof(winner)); - proutn("Enter name to go on plaque (up to 30 characters): "); - getline(winner, sizeof(winner)); - winner[30] = '\0'; -#ifdef SERGEEV + /* The 38 below must be 64 for 132-column paper */ nskip = 38 - strlen(winner)/2; -#else - nskip = 64 - strlen(winner)/2; -#endif /* SERGEEV */ fprintf(fp,"\n\n\n\n"); /* --------DRAW ENTERPRISE PICTURE. */ diff --git a/moving.c b/moving.c index c8947fe..13cd543 100644 --- a/moving.c +++ b/moving.c @@ -386,7 +386,7 @@ static void getcd(int isprobe, int akey) { if (!isprobe) { if (itemp) { if (iprompt) { - proutn("Helmsman Sulu- \"Course locked in for %s.\"", + prout("Helmsman Sulu- \"Course locked in for %s.\"", cramlc(sector, irows, icols)); } } @@ -983,29 +983,47 @@ void help(void) { proutn(" attempt to re-materialize "); crmshp(); prouts(" . . . . . "); +#ifdef SERGEEV + posx=wherex(); + posy=wherey(); + drawmaps(1); + setwnd(4); + gotoxy(posx,posy); + sound(50); + delay(1000); + nosound(); +#endif /* SERGEEV */ if (Rand() > probf) break; +#ifdef SERGEEV + switch (l){ + case 1: game.quad[ix][iy]=IHMATER1; + break; + case 2: game.quad[ix][iy]=IHMATER2; + break; + case 3: game.quad[ix][iy]=IHQUEST; + break; + } + textcolor(RED); +#endif /* SERGEEV */ prout("fails."); +#ifdef SERGEEV + delay(500); + textcolor(LIGHTGRAY); +#endif /* SERGEEV */ } if (l > 3) { finish(FMATERIALIZE); return; } - /* Rematerialization attempt should succeed if can get adj to base */ - for (l = 1; l <= 5; l++) { - ix = basex+3.0*Rand()-1; - iy = basey+3.0*Rand()-1; - if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) { - /* found one -- finish up */ - prout("succeeds."); - sectx=ix; - secty=iy; - game.quad[ix][iy]=ship; - dock(0); - skip(1); - prout("Lt. Uhura- \"Captain, we made it!\""); - return; - } - } - finish(FMATERIALIZE); - return; + game.quad[ix][iy]=ship; +#ifdef SERGEEV + textcolor(WHITE); +#endif /* SERGEEV */ + prout("succeeds."); +#ifdef SERGEEV + textcolor(LIGHTGRAY); +#endif /* SERGEEV */ + dock(0); + skip(1); + prout("Lt. Uhura- \"Captain, we made it!\""); } diff --git a/reports.c b/reports.c index 5c18772..6486d9d 100644 --- a/reports.c +++ b/reports.c @@ -2,9 +2,15 @@ #include #include #include +#ifdef SERGEEV +#include +#include "sstlinux.h" +#else +#define c_printf proutn +#endif /* SERGEEV */ void attakreport(int l) { - if (!l) { + if (!l) { if (game.future[FCDBAS] < 1e30) { prout("Starbase in %s is currently under Commander attack.", cramlc(quadrant, batx, baty)); @@ -23,10 +29,13 @@ void attakreport(int l) { if (isatb == 1) proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.isx, game.state.isy, game.future[FSCDBAS]); } +#ifdef SERGEEV + clreol(); +#endif /* SERGEEV */ } -void report(int f) { +void report(void) { char *s1,*s2,*s3; chew(); @@ -50,7 +59,7 @@ void report(int f) { alldone? "were": "are now", s1, s2, s3); if (skill>3 && thawed && !alldone) prout("No plaque is allowed."); if (tourn) prout("This is tournament game %d.", tourn); - if (f) prout("Your secret password is \"%s\"",game.passwd); + prout("Your secret password is \"%s\"",game.passwd); proutn("%d of %d Klingons have been killed", game.state.killk+game.state.killc+game.state.nsckill, inkling); if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s"); @@ -120,26 +129,24 @@ void lrscan(void) { prout("LONG-RANGE SENSORS DAMAGED."); return; } - skip(1); - proutn("Starbase's long-range scan for"); + proutn("Starbase's long-range scan"); } else { - skip(1); - proutn("Long-range scan for "); + prout("Long-range scan"); } - prout(cramlc(quadrant, quadx, quady)); for (x = quadx-1; x <= quadx+1; x++) { + proutn(" "); for (y = quady-1; y <= quady+1; y++) { if (x == 0 || x > 8 || y == 0 || y > 8) - proutn(" -1"); + proutn(" -1"); else { - proutn("%5d", game.state.galaxy[x][y]); - game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+1000 :1; + if (game.state.galaxy[x][y]<1000) proutn(" %3d", game.state.galaxy[x][y]); + else proutn("***"); + game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+1000 : 1; } } - skip(1); + prout(" "); } - } void dreprt(void) { @@ -149,7 +156,6 @@ void dreprt(void) { for (i = 1; i <= NDEVICES; i++) { if (game.damage[i] > 0.0) { if (!jdam) { - skip(1); prout("DEVICE -REPAIR TIMES-"); prout(" IN FLIGHT DOCKED"); jdam = TRUE; @@ -165,15 +171,12 @@ void dreprt(void) { void chart(int nn) { int i,j; - + char *cp; chew(); - skip(1); if (stdamtim != 1e30 && stdamtim != game.state.date && condit == IHDOCKED) { - prout("Spock- \"I revised the Star Chart from the"); - prout(" starbase's records.\""); - skip(1); + c_printf("Spock- \"I revised the Star Chart from the starbase's records.\"\n\r"); } - if (nn == 0) prout("STAR CHART FOR THE KNOWN GALAXY"); + if (nn == 0) c_printf(" STAR CHART FOR THE KNOWN GALAXY\n\r"); if (stdamtim != 1e30) { if (condit == IHDOCKED) { /* We are docked, so restore chart from base information */ @@ -187,85 +190,116 @@ void chart(int nn) { (int)(game.state.date-stdamtim)); } } - if (nn ==0) skip(1); prout(" 1 2 3 4 5 6 7 8"); - prout(" ----------------------------------------"); - /* if (nn==0) prout(" -"); */ for (i = 1; i <= 8; i++) { - proutn("%d -", i); + c_printf("%d |", i); for (j = 1; j <= 8; j++) { + char buf[4]; + c_printf(" "); if (game.starch[i][j] < 0) - proutn(" .1."); + strcpy(buf, ".1."); else if (game.starch[i][j] == 0) - proutn(" ..."); + strcpy(buf, "..."); else if (game.starch[i][j] > 999) - proutn("%5d", game.starch[i][j]-1000); + if ((i==quadx)&&(j==quady)){ +#ifdef SERGEEV + gotoxy(wherex()-1,wherey()); +#endif /* SERGEEV */ + if (game.starch[i][i]<2000) + sprintf(buf, "%03d", game.starch[i][j]-1000); + else + strcpy(buf, "***"); + } + else + if (game.starch[i][j]<2000) + sprintf(buf, "%03d", game.starch[i][j]-1000); + else + strcpy(buf, "***"); + else if ((i==quadx)&&(j==quady)){ +#ifdef SERGEEV + gotoxy(wherex()-1,wherey()); +#endif /* SERGEEV */ + sprintf(buf, "%03d", game.state.galaxy[i][j]); + } + else if (game.state.galaxy[i][j]>=1000) + strcpy(buf, "***"); else - proutn("%5d", game.state.galaxy[i][j]); + sprintf(buf, "%03d", game.state.galaxy[i][j]); + for (cp = buf; cp < buf + sizeof(buf); cp++) + if (*cp == '0') + *cp = '.'; + c_printf(buf); } - prout(" -"); + c_printf(" |"); + if (i<8) c_printf("\n\r"); } - if (nn == 0) { - skip(1); - crmshp(); - prout(" is currently in %s", cramlc(quadrant, quadx, quady)); -} +#ifdef SERGEEV + proutn(""); /* flush output */ +#else + skip(2); +#endif } -void srscan(int l) { - static char requests[][3] = - {"","da","co","po","ls","wa","en","to","sh","kl","ti"}; - char *cp = NULL; - int leftside=TRUE, rightside=TRUE, i, j, k=0, nn=FALSE; +int srscan(int l) { + char *cp = NULL; + int leftside=TRUE, rightside=TRUE, i, j, jj, k=0, nn=FALSE, t, dam=0; int goodScan=TRUE; switch (l) { case 1: // SRSCAN if (game.damage[DSRSENS] != 0) { /* Allow base's sensors if docked */ if (condit != IHDOCKED) { - prout("SHORT-RANGE SENSORS DAMAGED"); + prout(" S.R. SENSORS DAMAGED!"); goodScan=FALSE; } else - prout("[Using starbase's sensors]"); + prout(" [Using Base's sensors]"); } - if (goodScan) - game.starch[quadx][quady] = game.damage[DRADIO]>0.0 ? - game.state.galaxy[quadx][quady]+1000:1; + else c_printf(" Short-range scan\n\r"); + if (goodScan) game.starch[quadx][quady] = game.damage[DRADIO]>0.0 ? game.state.galaxy[quadx][quady]+1000:1; scan(); if (isit("chart")) nn = TRUE; - if (isit("no")) rightside = FALSE; + rightside = FALSE; chew(); - prout("\n 1 2 3 4 5 6 7 8 9 10"); + c_printf(" 1 2 3 4 5 6 7 8 9 10\n\r"); break; case 2: // REQUEST - while (scan() == IHEOL) - proutn("Information desired? "); - chew(); - for (k = 1; k <= 10; k++) - if (strncmp(citem,requests[k],min(2,strlen(citem)))==0) - break; - if (k > 10) { - prout("UNRECOGNIZED REQUEST. Legal requests are:\n" - " date, condition, position, lsupport, warpfactor,\n" - " energy, torpedoes, shields, klingons, time."); - return; - } - // no "break" + leftside=FALSE; + break; case 3: // STATUS chew(); leftside = FALSE; skip(1); } + if (condit != IHDOCKED) newcnd(); for (i = 1; i <= 10; i++) { - int jj = (k!=0 ? k : i); + jj = (k!=0 ? k : i); if (leftside) { proutn("%2d ", i); for (j = 1; j <= 10; j++) { - if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)) - proutn("%c ",game.quad[i][j]); + if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)){ + if ((game.quad[i][j]==IHMATER0)||(game.quad[i][j]==IHMATER1)||(game.quad[i][j]==IHMATER2)||(game.quad[i][j]==IHE)||(game.quad[i][j]==IHF)){ +#ifdef SERGEEV + switch (condit) { + case IHRED: textcolor(RED); break; + case IHGREEN: textcolor(GREEN); break; + case IHYELLOW: textcolor(YELLOW); break; + case IHDOCKED: textcolor(LIGHTGRAY); break; + case IHDEAD: textcolor(WHITE); + } + if (game.quad[i][j]!=ship) highvideo(); +#endif /* SERGEEV */ + } +#ifdef SERGEEV + if (game.quad[i][j] & 128) highvideo(); +#endif /* SERGEEV */ + c_printf("%c ",game.quad[i][j] & 127); +#ifdef SERGEEV + textcolor(LIGHTGRAY); +#endif /* SERGEEV */ + } else proutn("- "); } @@ -273,7 +307,7 @@ void srscan(int l) { if (rightside) { switch (jj) { case 1: - proutn(" Stardate %.1f", game.state.date); + proutn("Stardate %.1f, Time Left %.2f", game.state.date, game.state.remtime); break; case 2: if (condit != IHDOCKED) newcnd(); @@ -282,37 +316,38 @@ void srscan(int l) { case IHGREEN: cp = "GREEN"; break; case IHYELLOW: cp = "YELLOW"; break; case IHDOCKED: cp = "DOCKED"; break; + case IHDEAD: cp="DEAD"; break; } - proutn(" Condition %s", cp); + for (t=0;t<=NDEVICES;t++) + if (game.damage[t]>0) dam++; + proutn("Condition %s, %i DAMAGES", cp, dam); break; case 3: - proutn(" Position "); - proutn(cramlc(neither, quadx, quady)); - proutn(" , "); - proutn(cramlc(neither, sectx, secty)); + proutn("Position %d - %d , %d - %d", + quadx, quady, sectx, secty); break; case 4: - proutn(" Life Support "); + proutn("Life Support "); if (game.damage[DLIFSUP] != 0.0) { if (condit == IHDOCKED) - proutn("DAMAGED, supported by starbase"); + proutn("DAMAGED, Base provides"); else - proutn("DAMAGED, reserves=%.2f", lsupres); + proutn("DAMAGED, reserves=%4.2f", lsupres); } else proutn("ACTIVE"); break; case 5: - proutn(" Warp Factor %.1f", warpfac); + proutn("Warp Factor %.1f", warpfac); break; case 6: - proutn(" Energy %.2f", energy); + proutn("Energy %.2f", energy); break; case 7: - proutn(" Torpedoes %d", torps); + proutn("Torpedoes %d", torps); break; case 8: - proutn(" Shields "); + proutn("Shields "); if (game.damage[DSHIELD] != 0) proutn("DAMAGED,"); else if (shldup) @@ -323,23 +358,28 @@ void srscan(int l) { (int)((100.0*shield)/inshld + 0.5), shield); break; case 9: - proutn(" Klingons Left %d", game.state.remkl); + proutn("Klingons Left %d", game.state.remkl); break; case 10: - attakreport(1); + attakreport(1); break; } - } - skip(1); - if (k!=0) return; + if (i<10) c_printf("\n\r"); + if (k!=0) return(goodScan); } if (nn) chart(1); +#ifdef SERGEEV + proutn(""); +#else + skip(2); +#endif /* SERGEEV */ + return(goodScan); } void eta(void) { - int ix1, ix2, iy1, iy2, prompt=FALSE; + int ix1, ix2, iy1, iy2, prompt=FALSE; int wfl; double ttime, twarp, tpower; if (game.damage[DCOMPTR] != 0.0) { diff --git a/setup.c b/setup.c index 3a5a794..ca00504 100644 --- a/setup.c +++ b/setup.c @@ -1,11 +1,10 @@ #include -#ifdef SERGEEV #include +#ifdef SERGEEV #include #endif /* SERGEEV */ #include "sst.h" -#ifdef SERGEEV #ifdef __linux__ static long filelength(int fd) { struct stat buf; @@ -13,7 +12,6 @@ struct stat buf; return buf.st_size; } #endif -#endif /* SERGEEV */ void prelim(void) { skip(2); @@ -84,7 +82,7 @@ int thaw(void) { return 1; } fread(&game, sizeof(game), 1, fp); - if (strcmp(game.magic, SSTMAGIC)) { + if (feof(fp) || ftell(fp) != filelength(fileno(fp)) || strcmp(game.magic, SSTMAGIC)) { prout("Game file format is bad, should begin with " SSTMAGIC); skip(1); fclose(fp); @@ -402,13 +400,16 @@ void randomize(void) { } int choose(int needprompt) { +#ifdef SERGEEV + int i; +#endif /* SERGEEV */ + while (TRUE) { tourn = 0; thawed = 0; skill = 0; length = 0; - while (TRUE) { if (needprompt) /* Can start with command line options */ - proutn("Would you like a regular, tournament, or frozen game?"); + proutn("Would you like a regular, tournament, or saved game? "); scan(); if (strlen(citem)==0) continue; // Try again if (isit("tournament")) { @@ -424,22 +425,27 @@ int choose(int needprompt) { srand((unsigned int)(int)aaitem); break; } +#ifdef SERGEEV + if (isit("saved")) { + if (thaw()) continue; +#else if (isit("frozen")) { thaw(); +#endif /* SERGEEV */ chew(); +#ifndef SERGEEV if (*game.passwd==0) continue; randomize(); Rand(); Rand(); Rand(); Rand(); +#endif if (!alldone) thawed = 1; // No plaque if not finished - report(1); + report(); +#ifdef SERGEEV + getche(); +#endif /* SERGEEV */ return TRUE; } - if (isit("regular")) { - skip(2); - randomize(); - Rand(); Rand(); Rand(); Rand(); - break; - } + if (isit("regular")) break; proutn("What is \""); proutn(citem); prout("\"?"); @@ -599,7 +605,6 @@ void newqad(int shutup) { game.kdist[i] = game.kavgd[i] = sqrt(square(sectx-ix) + square(secty-iy)); game.kpower[i] = Rand()*400.0 + 450.0 + 50.0*skill; } - sortkl(); // If quadrant needs a starbase, put it in if (quadnum >= 10) { quadnum -= 10; diff --git a/sst-doc.xml b/sst-doc.xml index 3bf4b00..e810746 100644 --- a/sst-doc.xml +++ b/sst-doc.xml @@ -589,7 +589,7 @@ safely even in the midst of battle. Mnemonic: MOVE Shortest abbreviation: M Full command: MOVE MANUAL <displacement> - MOVE AUTOMATIC <estination*gt; + MOVE AUTOMATIC <destination> This command is the usual way to move from one place to another @@ -635,7 +635,7 @@ scan shown earlier. <para>where <qrow> and <qcol> are the row and column numbers of the destination quadrant, and <srow> and <scol> -are the row and column numbers of thedestination sector in that +are the row and column numbers of the destination sector in that quadrant. This command also moves your ship in a straight line path to the destination. For moving within a quadrant, <qrow> and <qcol> may be omitted. For example, to move to sector 2 - 9 in diff --git a/sst.c b/sst.c index 59b0b32..eb7c8f6 100644 --- a/sst.c +++ b/sst.c @@ -408,7 +408,7 @@ static void makemoves(void) { srscan(2); break; case 21: // Game Report - report(0); + report(); break; case 22: // use COMPUTER! eta(); @@ -417,12 +417,15 @@ static void makemoves(void) { listCommands(TRUE); break; case 24: // Emergency exit - clearscreen(); // Hide screen +#ifdef SERGEEV + clrscr(); // Hide screen +#endif /* SERGEEV */ freeze(TRUE); // forced save exit(1); // And quick exit break; case 25: probe(); // Launch probe + if (ididit) hitme = TRUE; break; case 26: // Abandon Ship abandn(); @@ -432,8 +435,11 @@ static void makemoves(void) { break; case 28: // Save Game freeze(FALSE); +#ifdef SERGEEV + clrscr(); +#endif /* SERGEEV */ if (skill > 3) - prout("WARNING--Frozen games produce no plaques!"); + prout("WARNING--Saved games produce no plaques!"); break; case 29: // Try a desparation measure deathray(); @@ -472,7 +478,6 @@ static void makemoves(void) { atover(0); continue; } - if (nenhere == 0) movetho(); if (hitme && justin==0) { attack(2); if (alldone) break; @@ -490,7 +495,8 @@ static void makemoves(void) { int main(int argc, char **argv) { - int i, option, usecurses = TRUE; + int i, option, usecurses = TRUE; + while ((option = getopt(argc, argv, "t")) != -1) { switch (option) { case 't': @@ -516,14 +522,14 @@ int main(int argc, char **argv) { strcat(line, " "); } while (TRUE) { /* Play a game */ - prelim(); + prelim(); setup(line[0] == '\0'); if (alldone) { score(); alldone = 0; } else makemoves(); - skip(2); + skip(1); stars(); skip(1); @@ -576,7 +582,7 @@ char *cramlc(enum loctype key, int x, int y) { buf[0] = '\0'; if (key == quadrant) strcpy(buf, "Quadrant "); else if (key == sector) strcpy(buf, "Sector "); - sprintf(buf+strlen(buf), "%d-%d", x, y); + sprintf(buf+strlen(buf), "%d - %d", x, y); return buf; } @@ -652,6 +658,7 @@ int scan(void) { clrscr(); setwnd(4); clrscr(); + } #endif /* SERGEEV */ linep = line; } diff --git a/sst.h b/sst.h index db10aab..b82a66b 100644 --- a/sst.h +++ b/sst.h @@ -61,6 +61,8 @@ typedef struct { #define SSTMAGIC "SST2.0\n" +EXTERN short curwnd; + EXTERN struct { char magic[sizeof(SSTMAGIC)]; snapshot state; @@ -356,7 +358,7 @@ int choose(int); void setup(int); void score(void); void atover(int); -void srscan(int); +int srscan(int); void lrscan(void); void phasers(void); void photon(void); @@ -369,7 +371,7 @@ void impuls(void); void wait(void); void setwrp(void); void events(void); -void report(int); +void report(void); void eta(void); void help(void); void abandn(void); -- 2.31.1