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); }
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 klmove(int fl) { int n; struct kling *k; double dx, dy; int nextx, nexty; int lookx, looky; int motion; int fudgex, fudgey; int qx, qy; double bigger; int i; # ifdef xTRACE if (Trace) printf("klmove: fl = %d, Etc.nkling = %d\n", fl, Etc.nkling); # endif for (n = 0; n < Etc.nkling; n++) { k = &Etc.klingon[n]; i = 100; if (fl) i = 100.0 * k->power / Param.klingpwr; if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl]) continue; /* compute distance to move */ motion = ranf(75) - 25; motion *= k->avgdist * Param.movefac[2 * Move.newquad + fl]; /* compute direction */ dx = Ship.sectx - k->x + ranf(3) - 1; dy = Ship.secty - k->y + ranf(3) - 1; bigger = dx; if (dy > bigger) bigger = dy; if (bigger == 0.0) bigger = 1.0; dx = dx / bigger + 0.5; dy = dy / bigger + 0.5; if (motion < 0) { motion = -motion; dx = -dx; dy = -dy; } fudgex = fudgey = 1; /* try to move the klingon */ nextx = k->x; nexty = k->y; for (; motion > 0; motion--) { lookx = nextx + dx; looky = nexty + dy; if (lookx < 0 || lookx >= NSECTS || looky < 0 || looky >= NSECTS) { /* new quadrant */ qx = Ship.quadx; qy = Ship.quady; if (lookx < 0) qx -= 1; else if (lookx >= NSECTS) qx += 1; if (looky < 0) qy -= 1; else if (looky >= NSECTS) qy += 1; if (qx < 0 || qx >= NQUADS || qy < 0 || qy >= NQUADS || Quad[qx][qy].stars < 0 || Quad[qx][qy].klings > MAXKLQUAD - 1) break; if (!damaged(SRSCAN)) { printf("Klingon at %d,%d escapes to quadrant %d,%d\n", k->x, k->y, qx, qy); motion = Quad[qx][qy].scanned; if (motion >= 0 && motion < 1000) Quad[qx][qy].scanned += 100; motion = Quad[Ship.quadx][Ship.quady].scanned; if (motion >= 0 && motion < 1000) Quad[Ship.quadx][Ship.quady].scanned -= 100; } Sect[k->x][k->y] = EMPTY; Quad[qx][qy].klings += 1; Etc.nkling -= 1; *k = Etc.klingon[Etc.nkling]; Quad[Ship.quadx][Ship.quady].klings -= 1; k = 0; break; } if (Sect[lookx][looky] != EMPTY) { lookx = nextx + fudgex; if (lookx < 0 || lookx >= NSECTS) lookx = nextx + dx; if (Sect[lookx][looky] != EMPTY) { fudgex = -fudgex; looky = nexty + fudgey; if (looky < 0 || looky >= NSECTS || Sect[lookx][looky] != EMPTY) { fudgey = -fudgey; break; } } } nextx = lookx; nexty = looky; } if (k && (k->x != nextx || k->y != nexty)) { if (!damaged(SRSCAN)) printf("Klingon at %d,%d moves to %d,%d\n", k->x, k->y, nextx, nexty); Sect[k->x][k->y] = EMPTY; Sect[k->x = nextx][k->y = nexty] = KLINGON; } } compkldist(0); }