X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fsetup.c;h=efd70473264e899205ab14fbcdb4de3cb2b6984c;hp=06ff22ac3f8e7271cc1263e8c5ca3d1bb5734c1f;hb=05845f1a048926f08b0df44ed8c729a8797a2d85;hpb=4bc011b7554580ae94eefab1067cefd30b20be48 diff --git a/src/setup.c b/src/setup.c index 06ff22a..efd7047 100644 --- a/src/setup.c +++ b/src/setup.c @@ -104,7 +104,6 @@ bool thaw(void) * Some planets marked Class G and P here will be displayed as class M \ * because of the way planets are generated. This is a known bug. \ */ \ - "ERROR", \ /* Federation Worlds */ \ _("Andoria (Fesoan)"), /* several episodes */ \ _("Tellar Prime (Miracht)"), /* TOS: "Journey to Babel" */ \ @@ -175,8 +174,8 @@ static void setup_names(void) /* Sets up some arrays with localized names. * Must be done after iostart() for localization to work. */ { - char *tmp1[] = SYSTEM_NAMES; - char *tmp2[] = DEVICE_NAMES; + char *tmp1[ARRAY_SIZE(systnames)] = SYSTEM_NAMES; + char *tmp2[ARRAY_SIZE(device)] = DEVICE_NAMES; memcpy(systnames, tmp1, sizeof(systnames)); memcpy(device, tmp2, sizeof(device)); @@ -192,7 +191,8 @@ void setup(bool needprompt) setup_names(); // Decide how many of everything - if (choose(needprompt)) return; // frozen game + if (choose(needprompt)) + return; // frozen game // Prepare the Enterprise game.alldone = game.gamewon = false; game.ship = IHE; @@ -212,7 +212,7 @@ void setup(bool needprompt) for (i=0; i < NDEVICES; i++) game.damage[i] = 0.0; // Set up assorted game parameters - game.battle.x = game.battle.y = 0; + invalidate(game.battle); game.state.date = game.indate = 100.0*(int)(31.0*Rand()+20.0); game.nkinks = game.nhelp = game.casual = game.abandoned = 0; game.iscate = game.resting = game.imine = game.icrystl = game.icraft = false; @@ -222,9 +222,9 @@ void setup(bool needprompt) game.landed = false; game.alive = true; game.docfac = 0.25; - for_quadrants(i) - for_quadrants(j) { - struct quadrant *quad = &game.state.galaxy[i][j]; + for (i = 1; i <= GALSIZE; i++) + for (j = 1; j <= GALSIZE; j++) { + struct quadrant *quad = &game.state.galaxy[i][j]; quad->charted = 0; quad->planet = NOPLANET; quad->romulans = 0; @@ -255,8 +255,8 @@ void setup(bool needprompt) game.lastchart = FOREVER; // Put stars in the galaxy game.instar = 0; - for_quadrants(i) - for_quadrants(j) { + for (i = 1; i <= GALSIZE; i++) + for (j = 1; j <= GALSIZE; j++) { int k = Rand()*9.0 + 1.0; game.instar += k; game.state.galaxy[i][j].stars = k; @@ -296,7 +296,8 @@ void setup(bool needprompt) do { double r = Rand(); int klump = (1.0 - r*r)*klumper; - if (klump > krem) klump = krem; + if (klump > krem) + klump = krem; krem -= klump; do w = randplace(GALSIZE); while (game.state.galaxy[w.x][w.y].supernova || @@ -324,7 +325,8 @@ void setup(bool needprompt) game.state.galaxy[w.x][w.y].klingons > 8); // check for duplicate for (j = 1; j < i; j++) - if (game.state.kcmdr[j].x==w.x && game.state.kcmdr[j].y==w.y) break; + if (same(game.state.kcmdr[j], w)) + break; } while (j < i); game.state.galaxy[w.x][w.y].klingons++; game.state.kcmdr[i] = w; @@ -333,20 +335,19 @@ void setup(bool needprompt) for (i = 0; i < game.inplan; i++) { do w = randplace(GALSIZE); while (game.state.galaxy[w.x][w.y].planet != NOPLANET); - game.state.plnets[i].w = w; - if (i < NINHAB) { - game.state.plnets[i].pclass = M; // All inhabited planets are class M - game.state.plnets[i].crystals = 0; - game.state.plnets[i].known = known; - game.state.plnets[i].inhabited = i; + game.state.planets[i].w = w; + if ((game.options & OPTION_WORLDS) && i < NINHAB) { + game.state.planets[i].pclass = M; // All inhabited planets are class M + game.state.planets[i].crystals = absent; + game.state.planets[i].known = known; + game.state.planets[i].inhabited = i; } else { - 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 = unknown; - game.state.plnets[i].inhabited = UNINHABITED; + game.state.planets[i].pclass = Rand()*3.0; // Planet class M N or O + game.state.planets[i].crystals = Rand()*1.5; // 1 in 3 chance of crystals + game.state.planets[i].known = unknown; + game.state.planets[i].inhabited = UNINHABITED; } - if ((game.options & OPTION_WORLDS) || i >= NINHAB) - game.state.galaxy[w.x][w.y].planet = i; + game.state.galaxy[w.x][w.y].planet = i; } // Locate Romulans for (i = 1; i <= game.state.nromrem; i++) { @@ -365,7 +366,7 @@ void setup(bool needprompt) thing = randplace(GALSIZE); } else - thing.x = thing.y = 0; + invalidate(thing); skip(2); game.state.snap = false; @@ -376,19 +377,20 @@ void setup(bool needprompt) 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."), - INKLINGTOT); + (game.inkling + game.incom + game.inscom)); prout(_("You have an initial allotment of %d stardates to complete"), (int)game.intime); prout(_("your mission. As you proceed you may be given more time.")); - prout(""); + skip(1); prout(_("You will have %d supporting starbases."), game.inbase); proutn(_("Starbase locations- ")); } else { prout(_("Stardate %d."), (int)game.state.date); - prout(""); - prout(_("%d Klingons."), INKLINGTOT); + skip(1); + prout(_("%d Klingons."), game.inkling + game.incom + game.inscom); prout(_("An unknown number of Romulans.")); - if (game.state.nscrem) prout(_("And one (GULP) Super-Commander.")); + if (game.state.nscrem) + prout(_("And one (GULP) Super-Commander.")); prout(_("%d stardates."),(int)game.intime); proutn(_("%d starbases in "), game.inbase); } @@ -403,11 +405,14 @@ void setup(bool needprompt) proutn(cramlc(sector, game.sector)); skip(2); prout(_("Good Luck!")); - if (game.state.nscrem) prout(_(" YOU'LL NEED IT.")); + if (game.state.nscrem) + prout(_(" YOU'LL NEED IT.")); waitfor(); newqad(false); - if (game.nenhere-iqhere-game.ithere) game.shldup = true; - if (game.neutz) attack(0); // bad luck to start in a Romulan Neutral Zone + if (game.nenhere-iqhere-game.ithere) + game.shldup = true; + if (game.neutz) // bad luck to start in a Romulan Neutral Zone + attack(false); } bool choose(bool needprompt) @@ -421,7 +426,8 @@ bool choose(bool needprompt) if (needprompt) /* Can start with command line options */ proutn(_("Would you like a regular, tournament, or saved game? ")); scan(); - if (strlen(citem)==0) continue; // Try again + if (strlen(citem)==0) // Try again + continue; if (isit("tournament")) { while (scan() == IHEOL) { proutn(_("Type in tournament number-")); @@ -436,15 +442,19 @@ bool choose(bool needprompt) break; } if (isit("saved") || isit("frozen")) { - if (thaw()) continue; + if (thaw()) + continue; chew(); - if (*game.passwd==0) continue; - if (!game.alldone) game.thawed = 1; // No plaque if not finished + if (*game.passwd==0) + continue; + if (!game.alldone) + game.thawed = true; // No plaque if not finished report(); waitfor(); return true; } - if (isit("regular")) break; + if (isit("regular")) + break; proutn(_("What is \"")); proutn(citem); prout("\"?"); @@ -452,14 +462,22 @@ bool choose(bool needprompt) } while (game.length==0 || game.skill==SKILL_NONE) { if (scan() == IHALPHA) { - if (isit("short")) game.length = 1; - else if (isit("medium")) game.length = 2; - else if (isit("long")) game.length = 4; - else if (isit("novice")) game.skill = SKILL_NOVICE; - else if (isit("fair")) game.skill = SKILL_FAIR; - else if (isit("good")) game.skill = SKILL_GOOD; - else if (isit("expert")) game.skill = SKILL_EXPERT; - else if (isit("emeritus")) game.skill = SKILL_EMERITUS; + if (isit("short")) + game.length = 1; + else if (isit("medium")) + game.length = 2; + else if (isit("long")) + game.length = 4; + else if (isit("novice")) + game.skill = SKILL_NOVICE; + else if (isit("fair")) + game.skill = SKILL_FAIR; + else if (isit("good")) + game.skill = SKILL_GOOD; + else if (isit("expert")) + game.skill = SKILL_EXPERT; + else if (isit("emeritus")) + game.skill = SKILL_EMERITUS; else { proutn(_("What is \"")); proutn(citem); @@ -468,8 +486,10 @@ bool choose(bool needprompt) } else { chew(); - if (game.length==0) proutn(_("Would you like a Short, Medium, or Long game? ")); - else if (game.skill == SKILL_NONE) proutn(_("Are you a Novice, Fair, Good, Expert, or Emeritus player? ")); + if (game.length==0) + proutn(_("Would you like a Short, Medium, or Long game? ")); + else if (game.skill == SKILL_NONE) + proutn(_("Are you a Novice, Fair, Good, Expert, or Emeritus player? ")); } } // Choose game options -- added by ESR for SST2K @@ -505,8 +525,11 @@ bool choose(bool needprompt) game.damfac = 0.5 * game.skill; game.state.rembase = 2.0 + Rand()*(BASEMAX-2.0); game.inbase = game.state.rembase; + game.inplan = 0; if (game.options & OPTION_PLANETS) - game.inplan = NINHAB + (MAXUNINHAB/2) + (MAXUNINHAB/2+1)*Rand(); + game.inplan += (MAXUNINHAB/2) + (MAXUNINHAB/2+1)*Rand(); + if (game.options & OPTION_WORLDS) + game.inplan += NINHAB; game.state.nromrem = game.inrom = (2.0+Rand())*game.skill; game.state.nscrem = game.inscom = (game.skill > SKILL_FAIR ? 1 : 0); game.state.remtime = 7.0 * game.length; @@ -537,10 +560,12 @@ void newcnd(void) /* update our alert status */ { game.condition = green; - if (game.energy < 1000.0) game.condition = yellow; + if (game.energy < 1000.0) + game.condition = yellow; if (game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons || game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans) game.condition = red; - if (!game.alive) game.condition=dead; + if (!game.alive) + game.condition=dead; } coord newkling(int i) @@ -560,12 +585,11 @@ void newqad(bool shutup) coord w; struct quadrant *q; - game.iattak = 1; game.justin = true; - game.base.x = game.base.y = 0; + invalidate(game.base); game.klhere = 0; game.comhere = false; - game.plnet.x = game.plnet.y = 0; + invalidate(game.plnet); game.ishere = false; game.irhere = 0; game.iplnet = 0; @@ -584,8 +608,8 @@ void newqad(bool shutup) game.ientesc = true; } // Clear quadrant - for_sectors(i) - for_sectors(j) + for (i = 1; i <= QUADSIZE; i++) + for (j = 1; j <= QUADSIZE; j++) game.quad[i][j] = IHDOT; q = &game.state.galaxy[game.quadrant.x][game.quadrant.y]; // cope with supernova @@ -604,7 +628,7 @@ void newqad(bool shutup) for (i = 1; i <= game.klhere; i++) w = newkling(i); // If we need a commander, promote a Klingon - for_commanders(i) + for (i = 1; i <= game.state.remcom; i++) if (same(game.state.kcmdr[i], game.quadrant)) break; @@ -636,7 +660,7 @@ void newqad(bool shutup) // If quadrant needs a planet, put it in if (q->planet != NOPLANET) { game.iplnet = q->planet; - if (game.state.plnets[q->planet].inhabited == UNINHABITED) + if (game.state.planets[q->planet].inhabited == UNINHABITED) game.plnet = dropin(IHP); else game.plnet = dropin(IHW); @@ -648,7 +672,7 @@ void newqad(bool shutup) dropin(IHSTAR); // Check for RNZ - if (game.irhere > 0 && game.klhere == 0 && (q->planet == NOPLANET || game.state.plnets[q->planet].inhabited == UNINHABITED)) { + if (game.irhere > 0 && game.klhere == 0) { game.neutz = true; if (!damaged(DRADIO)) { skip(1); @@ -697,14 +721,18 @@ void newqad(bool shutup) distance(game.sector, game.tholian); game.kpower[game.nenhere] = Rand()*400.0 +100.0 +25.0*game.skill; /* Reserve unocupied corners */ - if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X'; - if (game.quad[1][QUADSIZE]==IHDOT) game.quad[1][QUADSIZE] = 'X'; - if (game.quad[QUADSIZE][1]==IHDOT) game.quad[QUADSIZE][1] = 'X'; - if (game.quad[QUADSIZE][QUADSIZE]==IHDOT) game.quad[QUADSIZE][QUADSIZE] = 'X'; + if (game.quad[1][1]==IHDOT) + game.quad[1][1] = 'X'; + if (game.quad[1][QUADSIZE]==IHDOT) + game.quad[1][QUADSIZE] = 'X'; + if (game.quad[QUADSIZE][1]==IHDOT) + game.quad[QUADSIZE][1] = 'X'; + if (game.quad[QUADSIZE][QUADSIZE]==IHDOT) + game.quad[QUADSIZE][QUADSIZE] = 'X'; } } - sortkl(); + sortklings(); // Put in a few black holes for (i = 1; i <= 3; i++) @@ -713,14 +741,18 @@ void newqad(bool shutup) // Take out X's in corners if Tholian present if (game.ithere) { - if (game.quad[1][1]=='X') game.quad[1][1] = IHDOT; - if (game.quad[1][QUADSIZE]=='X') game.quad[1][QUADSIZE] = IHDOT; - if (game.quad[QUADSIZE][1]=='X') game.quad[QUADSIZE][1] = IHDOT; - if (game.quad[QUADSIZE][QUADSIZE]=='X') game.quad[QUADSIZE][QUADSIZE] = IHDOT; + if (game.quad[1][1]=='X') + game.quad[1][1] = IHDOT; + if (game.quad[1][QUADSIZE]=='X') + game.quad[1][QUADSIZE] = IHDOT; + if (game.quad[QUADSIZE][1]=='X') + game.quad[QUADSIZE][1] = IHDOT; + if (game.quad[QUADSIZE][QUADSIZE]=='X') + game.quad[QUADSIZE][QUADSIZE] = IHDOT; } } -void sortkl(void) +void sortklings(void) /* sort Klingons by distance from us */ { double t; @@ -729,7 +761,8 @@ void sortkl(void) // The author liked bubble sort. So we will use it. :-( - if (game.nenhere-iqhere-game.ithere < 2) return; + if (game.nenhere-iqhere-game.ithere < 2) + return; do { sw = false; @@ -758,17 +791,19 @@ void sortkl(void) void setpassword(void) /* set the self-destruct password */ { - if (!(game.options & OPTION_CURSES)) { + if (game.options & OPTION_PLAIN) { while (TRUE) { + chew(); + proutn(_("Please type in a secret password- ")); scan(); strcpy(game.passwd, citem); - chew(); - if (*game.passwd != 0) break; - proutn(_("Please type in a secret password-")); + if (*game.passwd != 0) + break; } } else { int i; - for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25)); + for(i=0;i<3;i++) + game.passwd[i]=(char)(97+(int)(Rand()*25)); game.passwd[3]=0; } }