void abandon(int v __unused) { struct quad *q; int i; int j; struct event *e; if (Ship.ship == QUEENE) { printf("You may not abandon ye Faire Queene\n"); return; } if (Ship.cond != DOCKED) { if (damaged(SHUTTLE)) { out(SHUTTLE); return; } printf("Officers escape in shuttlecraft\n"); /* decide on fate of crew */ q = &Quad[Ship.quadx][Ship.quady]; if (q->qsystemname == 0 || damaged(XPORTER)) { printf("Entire crew of %d left to die in outer space\n", Ship.crew); Game.deaths += Ship.crew; } else { printf("Crew beams down to planet %s\n", systemname(q)); } } /* see if you can be exchanged */ if (Now.bases == 0 || Game.captives < 20 * Game.skill) lose(L_CAPTURED); /* re-outfit new ship */ printf("You are hereby put in charge of an antiquated but still\n"); printf(" functional ship, the Fairie Queene.\n"); Ship.ship = QUEENE; Ship.shipname = "Fairie Queene"; Param.energy = Ship.energy = 3000; Param.torped = Ship.torped = 6; Param.shield = Ship.shield = 1250; Ship.shldup = 0; Ship.cloaked = 0; Ship.warp = 5.0; Ship.warp2 = 25.0; Ship.warp3 = 125.0; Ship.cond = GREEN; /* clear out damages on old ship */ for (i = 0; i < MAXEVENTS; i++) { e = &Event[i]; if (e->evcode != E_FIXDV) continue; unschedule(e); } /* get rid of some devices and redistribute probabilities */ i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK]; Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0; while (i > 0) for (j = 0; j < NDEV; j++) { if (Param.damprob[j] != 0) { Param.damprob[j] += 1; i--; if (i <= 0) break; } } /* pick a starbase to restart at */ i = ranf(Now.bases); Ship.quadx = Now.base[i].x; Ship.quady = Now.base[i].y; /* setup that quadrant */ while (1) { initquad(1); Sect[Ship.sectx][Ship.secty] = EMPTY; for (i = 0; i < 5; i++) { Ship.sectx = Etc.starbase.x + ranf(3) - 1; if (Ship.sectx < 0 || Ship.sectx >= NSECTS) continue; Ship.secty = Etc.starbase.y + ranf(3) - 1; if (Ship.secty < 0 || Ship.secty >= NSECTS) continue; if (Sect[Ship.sectx][Ship.secty] == EMPTY) { Sect[Ship.sectx][Ship.secty] = QUEENE; dock(0); compkldist(0); return; } } } }
void setup() { const struct cvntab *r; int i, j; double f; int d; int klump; int ix, iy; struct quad *q; struct event *e; while (1) { r = getcodpar("What length game", Lentab); Game.length = (long) r->value; if (Game.length == 0) { if (restartgame()) continue; return; } break; } r = getcodpar("What skill game", Skitab); Game.skill = (long) r->value; Game.tourn = 0; getstrpar("Enter a password", Game.passwd, 14, 0); if (strcmp(Game.passwd, "tournament") == 0) { getstrpar("Enter tournament code", Game.passwd, 14, 0); Game.tourn = 1; d = 0; for (i = 0; Game.passwd[i]; i++) d += Game.passwd[i] << i; srand(d); } Param.bases = Now.bases = ranf(6 - Game.skill) + 2; if (Game.skill == 6) Param.bases = Now.bases = 1; Param.time = Now.time = 6.0 * Game.length + 2.0; i = Game.skill; j = Game.length; Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75); if (Param.klings < i * j * 5) Param.klings = Now.klings = i * j * 5; if (Param.klings <= i) /* numerical overflow problems */ Param.klings = Now.klings = 127; Param.energy = Ship.energy = 5000; Param.torped = Ship.torped = 10; Ship.ship = ENTERPRISE; Ship.shipname = "Enterprise"; Param.shield = Ship.shield = 1500; Param.resource = Now.resource = Param.klings * Param.time; Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0; Param.crew = Ship.crew = 387; Param.brigfree = Ship.brigfree = 400; Ship.shldup = 1; Ship.cond = GREEN; Ship.warp = 5.0; Ship.warp2 = 25.0; Ship.warp3 = 125.0; Ship.sinsbad = 0; Ship.cloaked = 0; Param.date = Now.date = (ranf(20) + 20) * 100; f = Game.skill; f = log(f + 0.5); for (i = 0; i < NDEV; i++) if (Device[i].name[0] == '*') Param.damfac[i] = 0; else Param.damfac[i] = f; /* these probabilities must sum to 1000 */ Param.damprob[WARP] = 70; /* warp drive 7.0% */ Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */ Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */ Param.damprob[PHASER] = 125; /* phasers 12.5% */ Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */ Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */ Param.damprob[SHIELD] = 150; /* shield control 15.0% */ Param.damprob[COMPUTER] = 20; /* computer 2.0% */ Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */ Param.damprob[LIFESUP] = 30; /* life support 3.0% */ Param.damprob[SINS] = 20; /* navigation system 2.0% */ Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */ Param.damprob[XPORTER] = 80; /* transporter 8.0% */ /* check to see that I didn't blow it */ for (i = j = 0; i < NDEV; i++) j += Param.damprob[i]; if (j != 1000) errx(1, "Device probabilities sum to %d", j); Param.dockfac = 0.5; Param.regenfac = (5 - Game.skill) * 0.05; if (Param.regenfac < 0.0) Param.regenfac = 0.0; Param.warptime = 10; Param.stopengy = 50; Param.shupengy = 40; i = Game.skill; Param.klingpwr = 100 + 150 * i; if (i >= 6) Param.klingpwr += 150; Param.phasfac = 0.8; Param.hitfac = 0.5; Param.klingcrew = 200; Param.srndrprob = 0.0035; Param.moveprob[KM_OB] = 45; Param.movefac[KM_OB] = .09; Param.moveprob[KM_OA] = 40; Param.movefac[KM_OA] = -0.05; Param.moveprob[KM_EB] = 40; Param.movefac[KM_EB] = 0.075; Param.moveprob[KM_EA] = 25 + 5 * Game.skill; Param.movefac[KM_EA] = -0.06 * Game.skill; Param.moveprob[KM_LB] = 0; Param.movefac[KM_LB] = 0.0; Param.moveprob[KM_LA] = 10 + 10 * Game.skill; Param.movefac[KM_LA] = 0.25; Param.eventdly[E_SNOVA] = 0.5; Param.eventdly[E_LRTB] = 25.0; Param.eventdly[E_KATSB] = 1.0; Param.eventdly[E_KDESB] = 3.0; Param.eventdly[E_ISSUE] = 1.0; Param.eventdly[E_SNAP] = 0.5; Param.eventdly[E_ENSLV] = 0.5; Param.eventdly[E_REPRO] = 2.0; Param.navigcrud[0] = 1.50; Param.navigcrud[1] = 0.75; Param.cloakenergy = 1000; Param.energylow = 1000; for (i = 0; i < MAXEVENTS; i++) { e = &Event[i]; e->date = 1e50; e->evcode = 0; } xsched(E_SNOVA, 1, 0, 0, 0); xsched(E_LRTB, Param.klings, 0, 0, 0); xsched(E_KATSB, 1, 0, 0, 0); xsched(E_ISSUE, 1, 0, 0, 0); xsched(E_SNAP, 1, 0, 0, 0); Ship.sectx = ranf(NSECTS); Ship.secty = ranf(NSECTS); Game.killk = Game.kills = Game.killb = 0; Game.deaths = Game.negenbar = 0; Game.captives = 0; Game.killinhab = 0; Game.helps = 0; Game.killed = 0; Game.snap = 0; Move.endgame = 0; /* setup stars */ for (i = 0; i < NQUADS; i++) for (j = 0; j < NQUADS; j++) { q = &Quad[i][j]; q->klings = q->bases = 0; q->scanned = -1; q->stars = ranf(9) + 1; q->holes = ranf(3) - q->stars / 5; if (q->holes < 0) q->holes = 0; q->qsystemname = 0; } /* select inhabited starsystems */ for (d = 1; d < NINHAB; d++) { do { i = ranf(NQUADS); j = ranf(NQUADS); q = &Quad[i][j]; } while (q->qsystemname); q->qsystemname = d; } /* position starbases */ for (i = 0; i < Param.bases; i++) { while (1) { ix = ranf(NQUADS); iy = ranf(NQUADS); q = &Quad[ix][iy]; if (q->bases > 0) continue; break; } q->bases = 1; Now.base[i].x = ix; Now.base[i].y = iy; q->scanned = 1001; /* start the Enterprise near starbase */ if (i == 0) { Ship.quadx = ix; Ship.quady = iy; } } /* position klingons */ for (i = Param.klings; i > 0; ) { klump = ranf(4) + 1; if (klump > i) klump = i; while (1) { ix = ranf(NQUADS); iy = ranf(NQUADS); q = &Quad[ix][iy]; if (q->klings + klump > MAXKLQUAD) continue; q->klings += klump; i -= klump; break; } } /* initialize this quadrant */ printf("%d Klingons\n%d starbase", Param.klings, Param.bases); if (Param.bases > 1) printf("s"); printf(" at %d,%d", Now.base[0].x, Now.base[0].y); for (i = 1; i < Param.bases; i++) printf(", %d,%d", Now.base[i].x, Now.base[i].y); printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr); Move.free = 0; initquad(0); srscan(1); attack(0); }
double move(int ramflag, int course, double p_time, double speed) { double angle; double x, y, dx, dy; int ix, iy; double bigger; int n; int i; double dist; double sectsize; double xn; double evtime; ix = iy = 0; #ifdef xTRACE if (Trace) printf("move: ramflag %d course %d time %.2f speed %.2f\n", ramflag, course, p_time, speed); #endif sectsize = NSECTS; /* initialize delta factors for move */ angle = course * 0.0174532925; if (damaged(SINS)) angle += Param.navigcrud[1] * (franf() - 0.5); else if (Ship.sinsbad) angle += Param.navigcrud[0] * (franf() - 0.5); dx = -cos(angle); dy = sin(angle); bigger = fabs(dx); dist = fabs(dy); if (dist > bigger) bigger = dist; dx /= bigger; dy /= bigger; /* check for long range tractor beams */ /**** TEMPORARY CODE == DEBUGGING ****/ evtime = Now.eventptr[E_LRTB]->date - Now.date; #ifdef xTRACE if (Trace) printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n", (void *)Now.eventptr[E_LRTB], Now.eventptr[E_LRTB]->evcode, Now.eventptr[E_LRTB]->date, evtime); #endif if (p_time > evtime && Etc.nkling < 3) { /* then we got a LRTB */ evtime += 0.005; p_time = evtime; } else evtime = -1.0e50; dist = p_time * speed; /* move within quadrant */ Sect[Ship.sectx][Ship.secty] = EMPTY; x = Ship.sectx + 0.5; y = Ship.secty + 0.5; xn = NSECTS * dist * bigger; n = xn + 0.5; #ifdef xTRACE if (Trace) printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n); #endif Move.free = 0; for (i = 0; i < n; i++) { ix = (x += dx); iy = (y += dy); #ifdef xTRACE if (Trace) printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y); #endif if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) { /* enter new quadrant */ dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn; dy = Ship.quady * NSECTS + Ship.secty + dy * xn; if (dx < 0.0) ix = -1; else ix = dx + 0.5; if (dy < 0.0) iy = -1; else iy = dy + 0.5; #ifdef xTRACE if (Trace) printf("New quad: ix = %d, iy = %d\n", ix, iy); #endif Ship.sectx = x; Ship.secty = y; compkldist(0); Move.newquad = 2; attack(0); checkcond(); Ship.quadx = ix / NSECTS; Ship.quady = iy / NSECTS; Ship.sectx = ix % NSECTS; Ship.secty = iy % NSECTS; if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 || Ship.quady >= NQUADS) { if (!damaged(COMPUTER)) { dumpme(0); } else lose(L_NEGENB); } initquad(0); n = 0; break; } if (Sect[ix][iy] != EMPTY) { /* we just hit something */ if (!damaged(COMPUTER) && ramflag <= 0) { ix = x - dx; iy = y - dy; printf("Computer reports navigation error; %s stopped at %d,%d\n", Ship.shipname, ix, iy); Ship.energy -= Param.stopengy * speed; break; } /* test for a black hole */ if (Sect[ix][iy] == HOLE) { /* get dumped elsewhere in the galaxy */ dumpme(1); initquad(0); n = 0; break; } ram(ix, iy); break; } } if (n > 0) { dx = Ship.sectx - ix; dy = Ship.secty - iy; dist = sqrt(dx * dx + dy * dy) / NSECTS; p_time = dist / speed; if (evtime > p_time) p_time = evtime; /* spring the LRTB trap */ Ship.sectx = ix; Ship.secty = iy; } Sect[Ship.sectx][Ship.secty] = Ship.ship; compkldist(0); return (p_time); }