X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=setup.c;h=932faa8a037c3fef105260ff2a4b033a726f73f3;hp=24c5f6f6d25e58a82da1c78e1650ed046cd1f875;hb=32451d917434ca14d53a068f2ac57b504c794d07;hpb=77e371705e1e059173ec9c88f63be7a460e44e50 diff --git a/setup.c b/setup.c index 24c5f6f..932faa8 100644 --- a/setup.c +++ b/setup.c @@ -1,16 +1,31 @@ #include +#ifdef SERGEEV +#include +#include +#endif /* SERGEEV */ #include "sst.h" +#ifdef SERGEEV +#ifdef __linux__ +static long filelength(int fd) { +struct stat buf; + fstat(fd, &buf); + return buf.st_size; +} +#endif +#endif /* SERGEEV */ + void prelim(void) { skip(2); prout("-SUPER- STAR TREK"); skip(1); +#ifndef SERGEEV prout("Latest update-21 Sept 78"); skip(1); +#endif /* SERGEEV */ } void freeze(int boss) { - char *x, *y; FILE *fp; int key; if (boss) { @@ -36,6 +51,7 @@ void freeze(int boss) { skip(1); return; } + strcpy(game.magic, SSTMAGIC); fwrite(&game, sizeof(game), 1, fp); fclose(fp); @@ -44,10 +60,9 @@ void freeze(int boss) { } -void thaw(void) { - char *x, *y; +int thaw(void) { FILE *fp; - int key; + int key; game.passwd[0] = '\0'; if ((key = scan()) == IHEOL) { @@ -56,7 +71,7 @@ void thaw(void) { } if (key != IHALPHA) { huh(); - return; + return 1; } chew(); if (strchr(citem, '.') == NULL) { @@ -66,13 +81,19 @@ void thaw(void) { proutn("Can't find game file "); proutn(citem); skip(1); - return; + return 1; } fread(&game, sizeof(game), 1, fp); + if (strcmp(game.magic, SSTMAGIC)) { + prout("Game file format is bad, should begin with " SSTMAGIC); + skip(1); + fclose(fp); + return 1; + } fclose(fp); - /* I hope that's enough! */ + return 0; } void abandn(void) { @@ -173,16 +194,16 @@ void abandn(void) { return; } -void setup(void) { +void setup(int needprompt) { int i,j, krem, klumper; int ix, iy; - alldone = gamewon = 0; #ifdef DEBUG idebug = 0; #endif // Decide how many of everything - if (choose()) return; // frozen game + if (choose(needprompt)) return; // frozen game // Prepare the Enterprise + alldone = gamewon = 0; ship = IHE; energy = inenrg = 5000.0; shield = inshld = 2500.0; @@ -201,6 +222,7 @@ void setup(void) { game.state.date = indate = 100.0*(int)(31.0*Rand()+20.0); game.state.killk = game.state.killc = nkinks = nhelp = resting = casual = game.state.nromkl = 0; isatb = iscate = imine = icrystl = icraft = game.state.nsckill = game.state.nplankl = 0; + game.state.starkl = game.state.basekl = 0; iscraft = 1; landed = -1; alive = 1; @@ -239,13 +261,13 @@ void setup(void) { if (distq < 6.0*(6-inbase) && Rand() < 0.75) { contflag = TRUE; #ifdef DEBUG - printf("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy); + proutn("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy); #endif break; } #ifdef DEBUG else if (distq < 6.0 * (6-inbase)) { - printf("DEBUG: saving base #%d, close to #%d\n", i, j); + proutn("DEBUG: saving base #%d, close to #%d\n", i, j); } #endif } @@ -322,7 +344,7 @@ void setup(void) { game.state.galaxy[ix][iy] += 100; } // Place thing (in tournament game, thingx == -1, don't want one!) - if (Rand() < 0.1 && thingx != -1) { + if (thingx != -1) { iran8(&thingx, &thingy); } else { @@ -330,57 +352,63 @@ void setup(void) { } // idate = date; - skip(3); + skip(2); game.state.snap = 0; if (skill == 1) { - printf("It is stardate %d. The Federation is being attacked by\n", + prout("It is stardate %d. The Federation is being attacked by", (int)game.state.date); - printf("a deadly Klingon invasion force. As captain of the United\n" - "Starship U.S.S. Enterprise, it is your mission to seek out\n" - "and destroy this invasion force of %d battle cruisers.\n", + prout("a deadly Klingon invasion force. As captain of the United"); + prout("Starship U.S.S. Enterprise, it is your mission to seek out"); + prout("and destroy this invasion force of %d battle cruisers.", inkling); - printf("You have an initial allotment of %d stardates to complete\n" - "your mission. As you proceed you may be given more time.\n\n" - "You will have %d supporting starbases.\n" - "Starbase locations- ", - (int)intime, inbase); + prout("You have an initial allotment of %d stardates to complete", (int)intime); + prout("your mission. As you proceed you may be given more time."); + prout(""); + prout("You will have %d supporting starbases.", inbase); + proutn("Starbase locations- "); } else { - printf("Stardate %d.\n\n" - "%d Klingons.\nAn unknown number of Romulans\n", - (int)game.state.date, inkling); - if (game.state.nscrem) printf("and one (GULP) Super-Commander.\n"); - printf("%d stardates\n%d starbases in ",(int)intime, inbase); + prout("Stardate %d.", (int)game.state.date); + prout(""); + prout("%d Klingons.", inkling); + prout("An unknown number of Romulans."); + if (game.state.nscrem) prout("and one (GULP) Super-Commander."); + prout("%d stardates.",(int)intime); + proutn("%d starbases in ", inbase); } for (i = 1; i <= inbase; i++) { - cramlc(0, game.state.baseqx[i], game.state.baseqy[i]); - if (i < inbase) proutn(" "); + proutn(cramlc(0, game.state.baseqx[i], game.state.baseqy[i])); + proutn(" "); } skip(2); - proutn("The Enterprise is currently in"); - cramlc(1, quadx, quady); + proutn("The Enterprise is currently in "); + proutn(cramlc(quadrant, quadx, quady)); proutn(" "); - cramlc(2, sectx, secty); + proutn(cramlc(sector, sectx, secty)); skip(2); prout("Good Luck!"); - if (game.state.nscrem) proutn(" YOU'LL NEED IT."); - skip(1); + if (game.state.nscrem) prout(" YOU'LL NEED IT."); +#ifdef SERGEEV + getche(); +#endif /* SERGEEV */ newqad(0); - if (nenhere) shldup=1.0; + if (nenhere-iqhere-ithere) shldup=1.0; if (neutz) attack(0); // bad luck to start in a Romulan Neutral Zone } -int choose(void) { +void randomize(void) { + srand((int)time(NULL)); +} + +int choose(int needprompt) { tourn = 0; thawed = 0; skill = 0; length = 0; while (TRUE) { - if (fromcommandline) /* Can start with command line options */ - fromcommandline = 0; - else - proutn("Would you like a regular, tournament, or frozen game?"); + if (needprompt) /* Can start with command line options */ + proutn("Would you like a regular, tournament, or frozen game?"); scan(); if (strlen(citem)==0) continue; // Try again if (isit("tournament")) { @@ -436,9 +464,10 @@ int choose(void) { else { chew(); if (length==0) proutn("Would you like a Short, Medium, or Long game? "); - else if (skill == 0) proutn("Are you a Novice, Fair, Good, Expert, or Emeritus player?"); + else if (skill == 0) proutn("Are you a Novice, Fair, Good, Expert, or Emeritus player? "); } } +#ifndef SERGEEV while (TRUE) { scan(); strcpy(game.passwd, citem); @@ -446,6 +475,10 @@ int choose(void) { if (*game.passwd != 0) break; proutn("Please type in a secret password-"); } +#else + for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25)); + game.passwd[3]=0; +#endif /* SERGEEV */ #ifdef DEBUG if (strcmp(game.passwd, "debug")==0) idebug = 1; #endif @@ -483,6 +516,7 @@ void newcnd(void) { if (energy < 1000.0) condit = IHYELLOW; if (game.state.galaxy[quadx][quady] > 99 || game.state.newstuf[quadx][quady] > 9) condit = IHRED; + if (!alive) condit=IHDEAD; } @@ -506,6 +540,8 @@ void newqad(int shutup) { landed = -1; ientesc = 0; ithere = 0; + iqhere=0; + iqengry=0; iseenit = 0; if (iscate) { // Attempt to escape Super-commander, so tbeam back! @@ -527,27 +563,6 @@ void newqad(int shutup) { // Position Starship game.quad[sectx][secty] = ship; - // Decide if quadrant needs a Tholian - if ((skill < 3 && Rand() <= 0.02) || /* Lighten up if skill is low */ - (skill == 3 && Rand() <= 0.05) || - (skill > 3 && Rand() <= 0.08) -#ifdef DEBUG - || strcmp(game.passwd, "tholianx")==0 -#endif - ) { - do { - ithx = Rand() > 0.5 ? 10 : 1; - ithy = Rand() > 0.5 ? 10 : 1; - } while (game.quad[ithx][ithy] != IHDOT); - game.quad[ithx][ithy] = IHT; - ithere = 1; - /* Reserve unocupied corners */ - if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X'; - if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X'; - if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X'; - if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X'; - } - if (quadnum >= 100) { // Position ordinary Klingons quadnum -= 100*klhere; @@ -572,7 +587,7 @@ void newqad(int shutup) { if (quadx == game.state.isx && quady == game.state.isy) { game.quad[game.kx[1]][game.ky[1]] = IHS; game.kpower[1] = 1175.0 + 400.0*Rand() + 125.0*skill; - iscate = 1; + iscate = game.state.remkl>1; ishere = 1; } } @@ -606,7 +621,7 @@ void newqad(int shutup) { for (i = 1; i <= quadnum; i++) dropin(IHSTAR, &ix, &iy); // Check for RNZ - if (irhere > 0 && klhere == 0 && basex == 0) { + if (irhere > 0 && klhere == 0) { neutz = 1; if (game.damage[DRADIO] <= 0.0) { skip(1); @@ -622,7 +637,14 @@ void newqad(int shutup) { // Put in THING if needed if (thingx == quadx && thingy == quady) { dropin(IHQUEST, &ix, &iy); - thingx = thingy = 0; // Transient + iran8(&thingx, &thingy); + nenhere++; + iqhere=1; + game.kx[nenhere] = ix; + game.ky[nenhere] = iy; + game.kdist[nenhere] = game.kavgd[nenhere] = + sqrt(square(sectx-ix) + square(secty-iy)); + game.kpower[nenhere] = Rand()*6000.0 +500.0 +250.0*skill; if (game.damage[DSRSENS] == 0.0) { skip(1); prout("MR. SPOCK- \"Captain, this is most unusual."); @@ -631,6 +653,34 @@ void newqad(int shutup) { } } + // Decide if quadrant needs a Tholian + if ((skill < 3 && Rand() <= 0.02) || /* Lighten up if skill is low */ + (skill == 3 && Rand() <= 0.05) || + (skill > 3 && Rand() <= 0.08) +#ifdef DEBUG + || strcmp(passwd, "tholianx")==0 +#endif + ) { + do { + ithx = Rand() > 0.5 ? 10 : 1; + ithy = Rand() > 0.5 ? 10 : 1; + } while (game.quad[ithx][ithy] != IHDOT); + game.quad[ithx][ithy] = IHT; + ithere = 1; + nenhere++; + game.kx[nenhere] = ithx; + game.ky[nenhere] = ithy; + game.kdist[nenhere] = game.kavgd[nenhere] = + sqrt(square(sectx-ithx) + square(secty-ithy)); + game.kpower[nenhere] = Rand()*400.0 +100.0 +25.0*skill; + /* Reserve unocupied corners */ + if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X'; + if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X'; + if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X'; + if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X'; + } + sortkl(); + // Put in a few black holes for (i = 1; i <= 3; i++) if (Rand() > 0.5) dropin(IHBLANK, &ix, &iy); @@ -650,7 +700,7 @@ void sortkl(void) { // The author liked bubble sort. So we will use it. :-( - if (nenhere < 2) return; + if (nenhere-iqhere-ithere < 2) return; do { sw = FALSE;