]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - trek/shield.c
robots: Use arc4random_uniform for better uniform distribution
[bsdgames-darwin.git] / trek / shield.c
index ed78e2d0ce56948cccd52bf7af429bc7e91a785f..a14c22a7c56d40dfeb8561def97b7b0d2fb945cc 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: shield.c,v 1.5 1997/10/12 21:25:17 christos Exp $      */
+/*     $NetBSD: shield.c,v 1.13 2009/08/12 08:54:54 dholland 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.
  *
@@ -38,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)shield.c   8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: shield.c,v 1.5 1997/10/12 21:25:17 christos Exp $");
+__RCSID("$NetBSD: shield.c,v 1.13 2009/08/12 08:54:54 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -63,31 +59,29 @@ __RCSID("$NetBSD: shield.c,v 1.5 1997/10/12 21:25:17 christos Exp $");
 **     so you get partial hits.
 */
 
-struct cvntab Udtab[] =
-{
+static const struct cvntab Udtab[] = {
        { "u",          "p",            (cmdfun)1,      0 },
        { "d",          "own",          (cmdfun)0,      0 },
        { NULL,         NULL,           NULL,           0 }
 };
 
 void
-shield(f)
-int    f;
+shield(int f)
 {
        int             i;
-       struct cvntab   *r;
+       const struct cvntab     *r;
        char            s[100];
-       char            *device, *dev2, *dev3;
+       const char      *device, *dev2, *dev3;
        int             ind;
        char            *stat;
 
        if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
                return;
-       if (f < 0)
-       {
+       if (f < 0) {
                /* cloaking device */
                if (Ship.ship == QUEENE) {
-                       printf("Ye Faire Queene does not have the cloaking device.\n");
+                       printf("Ye Faire Queene does not have the "
+                              "cloaking device.\n");
                        return;
                }
                device = "Cloaking device";
@@ -95,9 +89,7 @@ int   f;
                ind = CLOAK;
                dev3 = "it";
                stat = &Ship.cloaked;
-       }
-       else
-       {
+       } else {
                /* shields */
                device = "Shields";
                dev2 = "are";
@@ -105,34 +97,32 @@ int        f;
                ind = SHIELD;
                stat = &Ship.shldup;
        }
-       if (damaged(ind))
-       {
+       if (damaged(ind)) {
                if (f <= 0)
                        out(ind);
                return;
        }
-       if (Ship.cond == DOCKED)
-       {
+       if (Ship.cond == DOCKED) {
                printf("%s %s down while docked\n", device, dev2);
                return;
        }
-       if (f <= 0 && !testnl())
-       {
+       if (f <= 0 && !testnl()) {
                r = getcodpar("Up or down", Udtab);
                i = (long) r->value;
-       }
-       else
-       {
+       } else {
                if (*stat)
-                       (void)sprintf(s, "%s %s up.  Do you want %s down", device, dev2, dev3);
+                       (void)snprintf(s, sizeof(s),
+                               "%s %s up.  Do you want %s down",
+                               device, dev2, dev3);
                else
-                       (void)sprintf(s, "%s %s down.  Do you want %s up", device, dev2, dev3);
+                       (void)snprintf(s, sizeof(s),
+                               "%s %s down.  Do you want %s up",
+                               device, dev2, dev3);
                if (!getynpar(s))
                        return;
                i = !*stat;
        }
-       if (*stat == i)
-       {
+       if (*stat == i) {
                printf("%s already ", device);
                if (i)
                        printf("up\n");
@@ -140,11 +130,12 @@ int       f;
                        printf("down\n");
                return;
        }
-       if (i)
+       if (i) {
                if (f >= 0)
                        Ship.energy -= Param.shupengy;
                else
                        Ship.cloakgood = 0;
+       }
        Move.free = 0;
        if (f >= 0)
                Move.shldchg = 1;