/* ** REST FOR REPAIRS ** ** You sit around and wait for repairs to happen. Actually, you ** sit around and wait for anything to happen. I do want to point ** out however, that Klingons are not as patient as you are, and ** they tend to attack you while you are resting. ** ** You can never rest through a long range tractor beam. ** ** In events() you will be given an opportunity to cancel the ** rest period if anything momentous happens. */ void rest() { double t; register int percent; /* get the time to rest */ t = getfltpar("How long"); if (t <= 0.0) return; percent = 100 * t / Now.time + 0.5; if (percent >= 70) { printf("Spock: That would take %d%% of our remaining time.\n", percent); if (!getynpar("Are you really certain that is wise")) return; } Move.time = t; /* boundary condition is the LRTB */ t = Now.eventptr[E_LRTB]->date - Now.date; if (Ship.cond != DOCKED && Move.time > t) Move.time = t + 0.0001; Move.free = 0; Move.resting = 1; }
int main(int argc, char **argv) { int ac; char **av; /* Revoke setgid privileges */ setgid(getgid()); av = argv; ac = argc; av++; srandom((unsigned)time(NULL)); /* srandomdev() */ while (ac > 1 && av[0][0] == '-') { switch (av[0][1]) { #ifdef xTRACE case 't': /* trace */ if (getuid() != Mother) goto badflag; Trace++; break; #endif default: badflag: printf("Invalid option: %s\n", av[0]); } ac--; av++; } if (ac > 1) syserr("arg count"); printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n"); if (setjmp(env)) { if ( !getynpar("Another game") ) exit(0); } do { setup(); play(); } while (getynpar("Another game")); fflush(stdout); return (0); }
impulse() { int course; register int power; double dist, time; register int percent; extern double move(); if (Ship.cond == DOCKED) return (printf("Scotty: Sorry captain, but we are still docked.\n")); if (damaged(IMPULSE)) return (out(IMPULSE)); if (getcodi(&course, &dist)) return; power = 20 + 100 * dist; percent = 100 * power / Ship.energy + 0.5; if (percent >= 85) { printf("Scotty: That would consume %d%% of our remaining energy.\n", percent); if (!getynpar("Are you sure that is wise")) return; printf("Aye aye, sir\n"); } time = dist / 0.095; percent = 100 * time / Now.time + 0.5; if (percent >= 85) { printf("Spock: That would take %d%% of our remaining time.\n", percent); if (!getynpar("Are you sure that is wise")) return; printf("(He's finally gone mad)\n"); } Move.time = move(0, course, time, 0.095); Ship.energy -= 20 + 100 * Move.time * 0.095; }
/*ARGSUSED*/ void torped(int v __unused) { int ix, iy; double x, y, dx, dy; double angle; int course, course2; int k; double bigger; double sectsize; int burst; int n; if (Ship.cloaked) { printf("Federation regulations do not permit attack while " "cloaked.\n"); return; } if (check_out(TORPED)) return; if (Ship.torped <= 0) { printf("All photon torpedos expended\n"); return; } /* get the course */ course = getintpar("Torpedo course"); if (course < 0 || course > 360) return; burst = -1; /* need at least three torpedoes for a burst */ if (Ship.torped < 3) { printf("No-burst mode selected\n"); burst = 0; } else { /* see if the user wants one */ if (!testnl()) { k = ungetc(getchar(), stdin); if (k >= '0' && k <= '9') burst = 1; } } if (burst < 0) { burst = getynpar("Do you want a burst"); } if (burst) { burst = getintpar("burst angle"); if (burst <= 0) return; if (burst > 15) { printf("Maximum burst angle is 15 degrees\n"); return; } } sectsize = NSECTS; n = -1; if (burst) { n = 1; course -= burst; } for (; n && n <= 3; n++) { /* select a nice random course */ course2 = course + randcourse(n); /* convert to radians */ angle = course2 * 0.0174532925; dx = -cos(angle); dy = sin(angle); bigger = fabs(dx); x = fabs(dy); if (x > bigger) bigger = x; dx /= bigger; dy /= bigger; x = Ship.sectx + 0.5; y = Ship.secty + 0.5; if (Ship.cond != DOCKED) Ship.torped -= 1; printf("Torpedo track"); if (n > 0) printf(", torpedo number %d", n); printf(":\n%6.1f\t%4.1f\n", x, y); while (1) { ix = x += dx; iy = y += dy; if (x < 0.0 || x >= sectsize || y < 0.0 || y >= sectsize) { printf("Torpedo missed\n"); break; } printf("%6.1f\t%4.1f\n", x, y); switch (Sect[ix][iy]) { case EMPTY: continue; case HOLE: printf("Torpedo disappears into a black " "hole\n"); break; case KLINGON: for (k = 0; k < Etc.nkling; k++) { if (Etc.klingon[k].x != ix || Etc.klingon[k].y != iy) continue; Etc.klingon[k].power -= 500 + ranf(501); if (Etc.klingon[k].power > 0) { printf("*** Hit on Klingon at " "%d,%d: extensive " "damages\n", ix, iy); break; } killk(ix, iy); break; } break; case STAR: nova(ix, iy); break; case INHABIT: kills(ix, iy, -1); break; case BASE: killb(Ship.quadx, Ship.quady); Game.killb += 1; break; default: printf("Unknown object %c at %d,%d destroyed\n", Sect[ix][iy], ix, iy); Sect[ix][iy] = EMPTY; break; } break; } if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0) break; course += burst; } Move.free = 0; }
void warp(int fl, int c, double d) { int course; double power; double dist; double p_time; double speed; double frac; int percent; int i; char *s; if (Ship.cond == DOCKED) { printf("%s is docked\n", Ship.shipname); return; } if (damaged(WARP)) { out(WARP); return; } course = c; dist = d; /* check to see that we are not using an absurd amount of power */ power = (dist + 0.05) * Ship.warp3; percent = 100 * power / Ship.energy + 0.5; if (percent >= 85) { printf("Scotty: That would consume %d%% of our remaining energy.\n", percent); if (!getynpar("Are you sure that is wise")) return; } /* compute the speed we will move at, and the time it will take */ speed = Ship.warp2 / Param.warptime; p_time = dist / speed; /* check to see that that value is not ridiculous */ percent = 100 * p_time / Now.time + 0.5; if (percent >= 85) { printf("Spock: That would take %d%% of our remaining time.\n", percent); if (!getynpar("Are you sure that is wise")) return; } /* compute how far we will go if we get damages */ if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0)) { frac = franf(); dist *= frac; p_time *= frac; damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20); } /* do the move */ Move.time = move(fl, course, p_time, speed); /* see how far we actually went, and decrement energy appropriately */ dist = Move.time * speed; Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1); /* test for bizarre events */ if (Ship.warp <= 9.0) return; printf("\n\n ___ Speed exceeding warp nine ___\n\n"); sleep(2); printf("Ship's safety systems malfunction\n"); sleep(2); printf("Crew experiencing extreme sensory distortion\n"); sleep(4); if (ranf(100) >= 100 * dist) { printf("Equilibrium restored -- all systems normal\n"); return; } /* select a bizzare thing to happen to us */ percent = ranf(100); if (percent < 70) { /* time warp */ if (percent < 35 || !Game.snap) { /* positive time warp */ p_time = (Ship.warp - 8.0) * dist * (franf() + 1.0); Now.date += p_time; printf("Positive time portal entered -- it is now Stardate %.2f\n", Now.date); for (i = 0; i < MAXEVENTS; i++) { percent = Event[i].evcode; if (percent == E_FIXDV || percent == E_LRTB) Event[i].date += p_time; } return; } /* s/he got lucky: a negative time portal */ p_time = Now.date; s = Etc.snapshot; bmove(s, Quad, sizeof Quad); bmove(s += sizeof Quad, Event, sizeof Event); bmove(s += sizeof Event, &Now, sizeof Now); printf("Negative time portal entered -- it is now Stardate %.2f\n", Now.date); for (i = 0; i < MAXEVENTS; i++) if (Event[i].evcode == E_FIXDV) reschedule(&Event[i], Event[i].date - p_time); return; } /* test for just a lot of damage */ if (percent < 80) lose(L_TOOFAST); printf("Equilibrium restored -- extreme damage occurred to ship systems\n"); for (i = 0; i < NDEV; i++) damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]); Ship.shldup = 0; }