# 2.11BSD#431 - /usr/src/games/trek/move.c

##### Functions

    move              X

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

#### Defined functions

move defined in line 48; used 4 times

- in /usr/src/games/trek/impulse.c line 23, 51
- in /usr/src/games/trek/warp.c line 41, 93

#### Defined variables

sccsid defined in line 8; never used

Last modified: 1985-05-30 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 634 |