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