X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=setup.c;h=8bd5bd190b28143df437eb70ded1a2c29580aa75;hp=9b5ac4241b9abda67b875a4ef39c89fb6af1446c;hb=aac11e9fd173e65886e2ee33c556e84bb2859f77;hpb=48763357ef69f0b711fc332b13e2170ab914d881 diff --git a/setup.c b/setup.c index 9b5ac42..8bd5bd1 100644 --- a/setup.c +++ b/setup.c @@ -10,7 +10,6 @@ void prelim(void) { } void freeze(int boss) { - char *x, *y; FILE *fp; int key; if (boss) { @@ -36,6 +35,7 @@ void freeze(int boss) { skip(1); return; } + strcpy(game.magic, SSTMAGIC); fwrite(&game, sizeof(game), 1, fp); fclose(fp); @@ -44,10 +44,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 +55,7 @@ void thaw(void) { } if (key != IHALPHA) { huh(); - return; + return 1; } chew(); if (strchr(citem, '.') == NULL) { @@ -66,13 +65,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) { @@ -161,7 +166,7 @@ void abandn(void) { iscraft=0; /* Gallileo disappears */ /* Resupply ship */ condit=IHDOCKED; - for (l = 1; l <= ndevice; l++) game.damage[l] = 0.0; + for (l = 1; l <= NDEVICES; l++) game.damage[l] = 0.0; game.damage[DSHUTTL] = -1; energy = inenrg = 3000.0; shield = inshld = 1250.0; @@ -173,16 +178,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; @@ -195,12 +200,13 @@ void setup(void) { nprobes = (int)(3.0*Rand() + 2.0); /* Give them 2-4 of these wonders */ warpfac = 5.0; wfacsq = warpfac * warpfac; - for (i=0; i <= ndevice; i++) game.damage[i] = 0.0; + for (i=0; i <= NDEVICES; i++) game.damage[i] = 0.0; // Set up assorted game parameters batx = baty = 0; 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 +245,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 } @@ -298,15 +304,15 @@ void setup(void) { game.state.cy[i] = iy; } // Locate planets in galaxy - for (i = 1; i <= inplan; i++) { + for (i = 0; i < inplan; i++) { do iran8(&ix, &iy); while (game.state.newstuf[ix][iy] > 0); game.state.newstuf[ix][iy] = 1; game.state.plnets[i].x = ix; game.state.plnets[i].y = iy; - game.state.plnets[i].pclass = Rand()*3.0 + 1.0; // Planet class M N or O + game.state.plnets[i].pclass = Rand()*3.0; // Planet class M N or O game.state.plnets[i].crystals = 1.5*Rand(); // 1 in 3 chance of crystals - game.state.plnets[i].known = 0; + game.state.plnets[i].known = unknown; } // Locate Romulans for (i = 1; i <= game.state.nromrem; i++) { @@ -322,7 +328,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 +336,60 @@ 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."); 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")) { @@ -506,6 +515,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 +538,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 +562,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; } } @@ -593,9 +583,9 @@ void newqad(int shutup) { if (nplan) { // If quadrant needs a planet, put it in - for (i=1; i <= inplan; i++) + for (i=0; i < inplan; i++) if (game.state.plnets[i].x == quadx && game.state.plnets[i].y == quady) break; - if (i <= inplan) { + if (i < inplan) { iplnet = i; dropin(IHP, &plnetx, &plnety); } @@ -606,7 +596,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 +612,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 +628,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 +675,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;