]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - trek/move.c
speed limit 80
[bsdgames-darwin.git] / trek / move.c
index b20faf218b84f07cf0ecc5ca72353c9d3623b6ac..cec5dfcafa584a47a4b9c9e5211b91e39a06ed0d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: move.c,v 1.3 1995/04/22 10:59:12 cgd Exp $     */
+/*     $NetBSD: move.c,v 1.11 2011/07/03 06:44:01 mrg Exp $    */
 
 /*
  * Copyright (c) 1980, 1993
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)move.c     8.1 (Berkeley) 5/31/93";
 #else
-static char rcsid[] = "$NetBSD: move.c,v 1.3 1995/04/22 10:59:12 cgd Exp $";
+__RCSID("$NetBSD: move.c,v 1.11 2011/07/03 06:44:01 mrg Exp $");
 #endif
 #endif /* not lint */
 
-# include      "trek.h"
+#include <stdio.h>
+#include <math.h>
+#include <float.h>
+#include "trek.h"
 
 /*
 **  Move Under Warp or Impulse Power
@@ -78,28 +78,25 @@ static char rcsid[] = "$NetBSD: move.c,v 1.3 1995/04/22 10:59:12 cgd Exp $";
 **     Uses trace flag 4.
 */
 
-double move(ramflag, course, time, speed)
-int    ramflag;
-int    course;
-double time;
-double speed;
+double
+move(int ramflag, int course, double time, double speed)
 {
        double                  angle;
        double                  x, y, dx, dy;
-       register int            ix, iy;
+       int             ix = 0, iy = 0;
        double                  bigger;
        int                     n;
-       register int            i;
+       int             i;
        double                  dist;
        double                  sectsize;
        double                  xn;
        double                  evtime;
 
-#      ifdef xTRACE
+#ifdef xTRACE
        if (Trace)
                printf("move: ramflag %d course %d time %.2f speed %.2f\n",
                        ramflag, course, time, speed);
-#      endif
+#endif
        sectsize = NSECTS;
        /* initialize delta factors for move */
        angle = course * 0.0174532925;
@@ -120,20 +117,19 @@ double    speed;
        /* check for long range tractor beams */
        /****  TEMPORARY CODE == DEBUGGING  ****/
        evtime = Now.eventptr[E_LRTB]->date - Now.date;
-#      ifdef xTRACE
+#ifdef xTRACE
        if (Trace)
-               printf("E.ep = %u, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
+               printf("E.ep = %p, ->evcode = %d, ->date = %.2f, "
+                      "evtime = %.2f\n",
                        Now.eventptr[E_LRTB], Now.eventptr[E_LRTB]->evcode,
                        Now.eventptr[E_LRTB]->date, evtime);
-#      endif
-       if (time > evtime && Etc.nkling < 3)
-       {
+#endif
+       if (time > evtime && Etc.nkling < 3) {
                /* then we got a LRTB */
                evtime += 0.005;
                time = evtime;
-       }
-       else
-               evtime = -1.0e50;
+       } else
+               evtime = DBL_MIN;
        dist = time * speed;
 
        /* move within quadrant */
@@ -142,22 +138,22 @@ double    speed;
        y = Ship.secty + 0.5;
        xn = NSECTS * dist * bigger;
        n = xn + 0.5;
-#      ifdef xTRACE
+#ifdef xTRACE
        if (Trace)
-               printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
-#      endif
+               printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n",
+                       dx, dy, xn, n);
+#endif
        Move.free = 0;
 
-       for (i = 0; i < n; i++)
-       {
+       for (i = 0; i < n; i++) {
                ix = (x += dx);
                iy = (y += dy);
-#              ifdef xTRACE
+#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)
-               {
+                       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;
@@ -169,10 +165,10 @@ double    speed;
                                iy = -1;
                        else
                                iy = dy + 0.5;
-#                      ifdef xTRACE
+#ifdef xTRACE
                        if (Trace)
                                printf("New quad: ix = %d, iy = %d\n", ix, iy);
-#                      endif
+#endif
                        Ship.sectx = x;
                        Ship.secty = y;
                        compkldist(0);
@@ -183,32 +179,30 @@ double    speed;
                        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))
-                               {
+                       if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 ||
+                           Ship.quady >= NQUADS) {
+                               if (!damaged(COMPUTER)) {
                                        dumpme(0);
-                               }
-                               else
+                               } else
                                        lose(L_NEGENB);
+                       }
                        initquad(0);
                        n = 0;
                        break;
                }
-               if (Sect[ix][iy] != EMPTY)
-               {
+               if (Sect[ix][iy] != EMPTY) {
                        /* we just hit something */
-                       if (!damaged(COMPUTER) && ramflag <= 0)
-                       {
+                       if (!damaged(COMPUTER) && ramflag <= 0) {
                                ix = x - dx;
                                iy = y - dy;
-                               printf("Computer reports navigation error; %s stopped at %d,%d\n",
+                               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)
-                       {
+                       if (Sect[ix][iy] == HOLE) {
                                /* get dumped elsewhere in the galaxy */
                                dumpme(1);
                                initquad(0);
@@ -219,14 +213,15 @@ double    speed;
                        break;
                }
        }
-       if (n > 0)
-       {
+       if (n > 0) {
                dx = Ship.sectx - ix;
                dy = Ship.secty - iy;
                dist = sqrt(dx * dx + dy * dy) / NSECTS;
                time = dist / speed;
-               if (evtime > time)
-                       time = evtime;          /* spring the LRTB trap */
+               if (evtime > time) {
+                       /* spring the LRTB trap */
+                       time = evtime;
+               }
                Ship.sectx = ix;
                Ship.secty = iy;
        }