]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - trek/help.c
Get all the games compiling for iOS
[bsdgames-darwin.git] / trek / help.c
index 0f9f6fccc2dbe868a2e8443fe7e11ed604986c41..16b4716aab8ed0900e21aad9d69fbb06fbeae2b1 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: help.c,v 1.13 2009/08/12 08:54:54 dholland Exp $       */
+
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 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
-/*static char sccsid[] = "from: @(#)help.c     5.4 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: help.c,v 1.2 1993/08/01 18:50:32 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)help.c     8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: help.c,v 1.13 2009/08/12 08:54:54 dholland Exp $");
+#endif
 #endif /* not lint */
 
-# include      "trek.h"
+#include <stdio.h>
+#include <math.h>
+#include <unistd.h>
+#include <limits.h>
+#include "trek.h"
 
 /*
 **  call starbase for help
@@ -58,36 +64,43 @@ static char rcsid[] = "$Id: help.c,v 1.2 1993/08/01 18:50:32 mycroft Exp $";
 **     to drop you.  After that, it's your problem.
 */
 
-char   *Cntvect[3] =
-{"first", "second", "third"};
+static const char *const Cntvect[3] = {
+       "first", "second", "third"
+};
 
-help()
+/*ARGSUSED*/
+void
+help(int v __unused)
 {
-       register int            i;
-       double                  dist, x;
-       register int            dx, dy;
-       int                     j, l;
+       int             i;
+       double          dist, x;
+       int             dx = 0, dy = 0;
+       int             j, l = 0;
 
        /* check to see if calling for help is reasonable ... */
-       if (Ship.cond == DOCKED)
-               return (printf("Uhura: But Captain, we're already docked\n"));
+       if (Ship.cond == DOCKED) {
+               printf("Uhura: But Captain, we're already docked\n");
+               return;
+       }
 
        /* or possible */
-       if (damaged(SSRADIO))
-               return (out(SSRADIO));
-       if (Now.bases <= 0)
-               return (printf("Uhura: I'm not getting any response from starbase\n"));
+       if (damaged(SSRADIO)) {
+               out(SSRADIO);
+               return;
+       }
+       if (Now.bases <= 0) {
+               printf("Uhura: I'm not getting any response from starbase\n");
+               return;
+       }
 
        /* tut tut, there goes the score */
        Game.helps += 1;
 
        /* find the closest base */
-       dist = 1e50;
-       if (Quad[Ship.quadx][Ship.quady].bases <= 0)
-       {
+       dist = TOOLARGE;
+       if (Quad[Ship.quadx][Ship.quady].bases <= 0) {
                /* there isn't one in this quadrant */
-               for (i = 0; i < Now.bases; i++)
-               {
+               for (i = 0; i < Now.bases; i++) {
                        /* compute distance */
                        dx = Now.base[i].x - Ship.quadx;
                        dy = Now.base[i].y - Ship.quady;
@@ -95,8 +108,7 @@ help()
                        x = sqrt(x);
 
                        /* see if better than what we already have */
-                       if (x < dist)
-                       {
+                       if (x < dist) {
                                dist = x;
                                l = i;
                        }
@@ -106,9 +118,7 @@ help()
                Ship.quadx = Now.base[l].x;
                Ship.quady = Now.base[l].y;
                initquad(1);
-       }
-       else
-       {
+       } else {
                dist = 0.0;
        }
 
@@ -120,31 +130,28 @@ help()
        x = pow(1.0 - pow(0.94, dist), 0.3333333);
 
        /* attempt to rematerialize */
-       for (i = 0; i < 3; i++)
-       {
+       for (i = 0; i < 3; i++) {
                sleep(2);
                printf("%s attempt to rematerialize ", Cntvect[i]);
-               if (franf() > x)
-               {
+               if (franf() > x) {
                        /* ok, that's good.  let's see if we can set her down */
-                       for (j = 0; j < 5; j++)
-                       {
+                       for (j = 0; j < 5; j++) {
                                dx = Etc.starbase.x + ranf(3) - 1;
                                if (dx < 0 || dx >= NSECTS)
                                        continue;
                                dy = Etc.starbase.y + ranf(3) - 1;
-                               if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY)
+                               if (dy < 0 || dy >= NSECTS ||
+                                   Sect[dx][dy] != EMPTY)
                                        continue;
                                break;
                        }
-                       if (j < 5)
-                       {
+                       if (j < 5) {
                                /* found an empty spot */
                                printf("succeeds\n");
                                Ship.sectx = dx;
                                Ship.secty = dy;
                                Sect[dx][dy] = Ship.ship;
-                               dock();
+                               dock(0);
                                compkldist(0);
                                return;
                        }