|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)move.c 4.3 (Berkeley) 5/27/83"; ! 3: #endif not lint ! 4: ! 5: # include "trek.h" ! 6: ! 7: /* ! 8: ** Move Under Warp or Impulse Power ! 9: ** ! 10: ** `Ramflag' is set if we are to be allowed to ram stars, ! 11: ** Klingons, etc. This is passed from warp(), which gets it from ! 12: ** either play() or ram(). Course is the course (0 -> 360) at ! 13: ** which we want to move. `Speed' is the speed we ! 14: ** want to go, and `time' is the expected time. It ! 15: ** can get cut short if a long range tractor beam is to occur. We ! 16: ** cut short the move so that the user doesn't get docked time and ! 17: ** energy for distance which he didn't travel. ! 18: ** ! 19: ** We check the course through the current quadrant to see that he ! 20: ** doesn't run into anything. After that, though, space sort of ! 21: ** bends around him. Note that this puts us in the awkward posi- ! 22: ** tion of being able to be dropped into a sector which is com- ! 23: ** pletely surrounded by stars. Oh Well. ! 24: ** ! 25: ** If the SINS (Space Inertial Navigation System) is out, we ran- ! 26: ** domize the course accordingly before ever starting to move. ! 27: ** We will still move in a straight line. ! 28: ** ! 29: ** Note that if your computer is out, you ram things anyway. In ! 30: ** other words, if your computer and sins are both out, you're in ! 31: ** potentially very bad shape. ! 32: ** ! 33: ** Klingons get a chance to zap you as you leave the quadrant. ! 34: ** By the way, they also try to follow you (heh heh). ! 35: ** ! 36: ** Return value is the actual amount of time used. ! 37: ** ! 38: ** ! 39: ** Uses trace flag 4. ! 40: */ ! 41: ! 42: double move(ramflag, course, time, speed) ! 43: int ramflag; ! 44: int course; ! 45: double time; ! 46: double speed; ! 47: { ! 48: double angle; ! 49: double x, y, dx, dy; ! 50: register int ix, iy; ! 51: double bigger; ! 52: int n; ! 53: register int i; ! 54: double dist; ! 55: double sectsize; ! 56: double xn; ! 57: double evtime; ! 58: ! 59: # ifdef xTRACE ! 60: if (Trace) ! 61: printf("move: ramflag %d course %d time %.2f speed %.2f\n", ! 62: ramflag, course, time, speed); ! 63: # endif ! 64: sectsize = NSECTS; ! 65: /* initialize delta factors for move */ ! 66: angle = course * 0.0174532925; ! 67: if (damaged(SINS)) ! 68: angle += Param.navigcrud[1] * (franf() - 0.5); ! 69: else ! 70: if (Ship.sinsbad) ! 71: angle += Param.navigcrud[0] * (franf() - 0.5); ! 72: dx = -cos(angle); ! 73: dy = sin(angle); ! 74: bigger = fabs(dx); ! 75: dist = fabs(dy); ! 76: if (dist > bigger) ! 77: bigger = dist; ! 78: dx /= bigger; ! 79: dy /= bigger; ! 80: ! 81: /* check for long range tractor beams */ ! 82: /**** TEMPORARY CODE == DEBUGGING ****/ ! 83: evtime = Now.eventptr[E_LRTB]->date - Now.date; ! 84: # ifdef xTRACE ! 85: if (Trace) ! 86: printf("E.ep = %u, ->evcode = %d, ->date = %.2f, evtime = %.2f\n", ! 87: Now.eventptr[E_LRTB], Now.eventptr[E_LRTB]->evcode, ! 88: Now.eventptr[E_LRTB]->date, evtime); ! 89: # endif ! 90: if (time > evtime && Etc.nkling < 3) ! 91: { ! 92: /* then we got a LRTB */ ! 93: evtime += 0.005; ! 94: time = evtime; ! 95: } ! 96: else ! 97: evtime = -1.0e50; ! 98: dist = time * speed; ! 99: ! 100: /* move within quadrant */ ! 101: Sect[Ship.sectx][Ship.secty] = EMPTY; ! 102: x = Ship.sectx + 0.5; ! 103: y = Ship.secty + 0.5; ! 104: xn = NSECTS * dist * bigger; ! 105: n = xn + 0.5; ! 106: # ifdef xTRACE ! 107: if (Trace) ! 108: printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n); ! 109: # endif ! 110: Move.free = 0; ! 111: ! 112: for (i = 0; i < n; i++) ! 113: { ! 114: ix = (x += dx); ! 115: iy = (y += dy); ! 116: # ifdef xTRACE ! 117: if (Trace) ! 118: printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y); ! 119: # endif ! 120: if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) ! 121: { ! 122: /* enter new quadrant */ ! 123: dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn; ! 124: dy = Ship.quady * NSECTS + Ship.secty + dy * xn; ! 125: if (dx < 0.0) ! 126: ix = -1; ! 127: else ! 128: ix = dx + 0.5; ! 129: if (dy < 0.0) ! 130: iy = -1; ! 131: else ! 132: iy = dy + 0.5; ! 133: # ifdef xTRACE ! 134: if (Trace) ! 135: printf("New quad: ix = %d, iy = %d\n", ix, iy); ! 136: # endif ! 137: Ship.sectx = x; ! 138: Ship.secty = y; ! 139: compkldist(0); ! 140: Move.newquad = 2; ! 141: attack(0); ! 142: checkcond(); ! 143: Ship.quadx = ix / NSECTS; ! 144: Ship.quady = iy / NSECTS; ! 145: Ship.sectx = ix % NSECTS; ! 146: Ship.secty = iy % NSECTS; ! 147: if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 || Ship.quady >= NQUADS) ! 148: if (!damaged(COMPUTER)) ! 149: { ! 150: dumpme(0); ! 151: } ! 152: else ! 153: lose(L_NEGENB); ! 154: initquad(0); ! 155: n = 0; ! 156: break; ! 157: } ! 158: if (Sect[ix][iy] != EMPTY) ! 159: { ! 160: /* we just hit something */ ! 161: if (!damaged(COMPUTER) && ramflag <= 0) ! 162: { ! 163: ix = x - dx; ! 164: iy = y - dy; ! 165: printf("Computer reports navigation error; %s stopped at %d,%d\n", ! 166: Ship.shipname, ix, iy); ! 167: Ship.energy -= Param.stopengy * speed; ! 168: break; ! 169: } ! 170: /* test for a black hole */ ! 171: if (Sect[ix][iy] == HOLE) ! 172: { ! 173: /* get dumped elsewhere in the galaxy */ ! 174: dumpme(1); ! 175: initquad(0); ! 176: n = 0; ! 177: break; ! 178: } ! 179: ram(ix, iy); ! 180: break; ! 181: } ! 182: } ! 183: if (n > 0) ! 184: { ! 185: dx = Ship.sectx - ix; ! 186: dy = Ship.secty - iy; ! 187: dist = sqrt(dx * dx + dy * dy) / NSECTS; ! 188: time = dist / speed; ! 189: if (evtime > time) ! 190: time = evtime; /* spring the LRTB trap */ ! 191: Ship.sectx = ix; ! 192: Ship.secty = iy; ! 193: } ! 194: Sect[Ship.sectx][Ship.secty] = Ship.ship; ! 195: compkldist(0); ! 196: return (time); ! 197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.