]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/sona.c
Update copyright notice
[empserver] / src / lib / commands / sona.c
index 11d09b73a97ca3ff2ef8433a4dbed92517978cff..50b21cba6b8f731a2f21a294f842641fdd6a51f4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     Ken Stevens, 1995
  */
 
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "sect.h"
-#include "nsc.h"
-#include "retreat.h"
-#include "ship.h"
-#include "nat.h"
-#include "path.h"
-#include "file.h"
-#include "queue.h"
-#include "plane.h"
-#include <fcntl.h>
-#include <ctype.h>
+#include <config.h>
+
 #include "commands.h"
+#include "map.h"
 #include "optlist.h"
+#include "path.h"
+#include "plane.h"
+#include "retreat.h"
+#include "ship.h"
 
-static int blankrow(s_char *);
+static int blankrow(char *);
 
 int
 sona(void)
@@ -72,39 +65,31 @@ sona(void)
     int changed = 0;
     int row;
     /* Where these are used are non-re-entrant, so we keep 'em around */
-    static s_char **rad = (s_char **)0;
-    static s_char *radbuf = (s_char *)0;
-    static s_char **vis = (s_char **)0;
-    static s_char *visbuf = (s_char *)0;
+    static char **rad = NULL;
+    static char *radbuf = NULL;
+    static signed char **vis = NULL;
+    static signed char *visbuf = NULL;
 
     if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
        return RET_SYN;
     if (!radbuf)
-       radbuf =
-           (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * sizeof(s_char));
+       radbuf = malloc((WORLD_Y * (WORLD_X + 1)));
     if (!visbuf)
-       visbuf =
-           (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * sizeof(s_char));
-    if (!rad) {
-       rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
-       if (rad && radbuf) {
+       visbuf = malloc((WORLD_Y * (WORLD_X + 1)));
+    if (!rad && radbuf) {
+       rad = malloc(WORLD_Y * sizeof(char *));
+       if (rad) {
            for (x = 0; x < WORLD_Y; x++) {
                rad[x] = &radbuf[(WORLD_X + 1) * x];
            }
-       } else if (rad) {
-           free((s_char *)rad);
-           rad = (s_char **)0;
        }
     }
-    if (!vis) {
-       vis = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
-       if (vis && visbuf) {
+    if (!vis && visbuf) {
+       vis = malloc(WORLD_Y * sizeof(signed char *));
+       if (vis) {
            for (x = 0; x < WORLD_Y; x++) {
                vis[x] = &visbuf[(WORLD_X + 1) * x];
            }
-       } else if (vis) {
-           free((s_char *)vis);
-           vis = (s_char **)0;
        }
     }
     if (!radbuf || !visbuf || !rad || !vis) {
@@ -112,7 +97,7 @@ sona(void)
        logerror("malloc failed in sona\n");
        return RET_FAIL;
     }
-    while (nxtitem(&ni, (s_char *)&ship)) {
+    while (nxtitem(&ni, &ship)) {
        if (!player->owner)
            continue;
        mcp = &mchr[(int)ship.shp_type];
@@ -121,14 +106,14 @@ sona(void)
        getsect(ship.shp_x, ship.shp_y, &sect);
        if (sect.sct_type != SCT_WATER)
            continue;
-       range = (int)techfact(ship.shp_tech, (double)mcp->m_vrnge);
-       srange = min(7, 7 * range * ship.shp_effic / 200);
+       range = (int)techfact(ship.shp_tech, mcp->m_vrnge);
+       srange = MIN(7, 7 * range * ship.shp_effic / 200);
        pr("%s at %s efficiency %d%%, max range %d\n",
           prship(&ship),
           xyas(ship.shp_x, ship.shp_y, player->cnum),
           ship.shp_effic, srange);
        snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange);
-       blankfill((s_char *)radbuf, &ns.range, 1);
+       blankfill(radbuf, &ns.range, 1);
        while (nxtsct(&ns, &sect)) {
            if (player->owner || sect.sct_type == SCT_WATER)
                rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
@@ -162,10 +147,10 @@ sona(void)
            if (targ.shp_own == player->cnum || targ.shp_own == 0)
                continue;
            tmcp = &mchr[(int)targ.shp_type];
-           pingrange = min(7, max(targ.shp_visib, 10) * range / 10);
+           pingrange = MIN(7, MAX(targ.shp_visib, 10) * range / 10);
            vrange = pingrange * ship.shp_effic / 200;
            dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y);
-           pingrange = (max(pingrange, 2) * targ.shp_effic) / 100;
+           pingrange = (MAX(pingrange, 2) * targ.shp_effic) / 100;
            if (dist > pingrange)
                continue;
            if (tmcp->m_flags & M_SONAR && targ.shp_own) {
@@ -197,12 +182,12 @@ sona(void)
                       prship(&targ),
                       xyas(targ.shp_x, targ.shp_y, player->cnum));
                else
-                   pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own),
-                      prship(&targ),
+                   pr("Sonar detects %s %s @ %s\n",
+                      cname(targ.shp_own), prship(&targ),
                       xyas(targ.shp_x, targ.shp_y, player->cnum));
            } else
-               pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own),
-                  prship(&targ),
+               pr("Sonar detects %s %s @ %s\n",
+                  cname(targ.shp_own), prship(&targ),
                   xyas(targ.shp_x, targ.shp_y, player->cnum));
 
            if (targ.shp_visib > vis[y][x]) {
@@ -254,12 +239,7 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
        pcp = ip->pcp;
        if (!(pcp->pl_flags & P_A))     /* if it isn't an ASW plane */
            continue;
-       range =
-           (int)techfact(pp->pln_tech,
-                         (double)((100 - pp->pln_acc) / 10));
-/*
-               for (i=0; targ = getshipp(i); i++) {
-*/
+       range = (int)techfact(pp->pln_tech, (100.0 - pp->pln_acc) / 10.0);
        for (i = 0; getship(i, &s); i++) {
            targ = &s;
            if (targ->shp_own == pp->pln_own || targ->shp_own == 0)
@@ -269,13 +249,13 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
            tmcp = &mchr[(int)targ->shp_type];
            if (!(tmcp->m_flags & M_SUB))
                continue;
-           if (roll(100) >
-               pln_identchance(pp, shp_hardtarget(targ), EF_SHIP))
+           if (roll(100) > pln_identchance(pp, shp_hardtarget(targ),
+                                           EF_SHIP))
                continue;
-           pingrange = max(targ->shp_visib, 10) * range / 10;
-           vrange = ((float)pingrange) * ((float)pp->pln_effic / 200.0);
+           pingrange = MAX(targ->shp_visib, 10) * range / 10;
+           vrange = pingrange * (pp->pln_effic / 200.0);
            dist = mapdist(targ->shp_x, targ->shp_y, x, y);
-           pingrange = (max(pingrange, 2) * targ->shp_effic);
+           pingrange = (MAX(pingrange, 2) * targ->shp_effic);
            pingrange = roundavg(pingrange / 100.0);
            if (dist > pingrange)
                continue;
@@ -297,19 +277,17 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
            if (getrel(getnatp(targ->shp_own), pp->pln_own) < FRIENDLY &&
                roll(100) > pln_identchance(pp, shp_hardtarget(targ),
                                            EF_SHIP))
-               if (roll(100) >
-                   pln_identchance(pp, shp_hardtarget(targ), EF_SHIP))
+               if (roll(100) > pln_identchance(pp, shp_hardtarget(targ),
+                                               EF_SHIP))
                    mpr(pp->pln_own, "sub #%d %s\n", targ->shp_uid,
                        xyas(targ->shp_x, targ->shp_y, pp->pln_own));
                else
-                   mpr(pp->pln_own,
-                       "%s %s\n",
+                   mpr(pp->pln_own, "%s %s\n",
                        prship(targ),
                        xyas(targ->shp_x, targ->shp_y, pp->pln_own));
            else
-               mpr(pp->pln_own,
-                   "%s %s @ %s\n", cname(targ->shp_own),
-                   prship(targ),
+               mpr(pp->pln_own, "%s %s @ %s\n",
+                   cname(targ->shp_own), prship(targ),
                    xyas(targ->shp_x, targ->shp_y, pp->pln_own));
        }
     }
@@ -385,7 +363,7 @@ line_of_sight(char **rad, int ax, int ay, int bx, int by)
 }
 
 static int
-blankrow(s_char *s)
+blankrow(char *s)
 {
     while (*s) {
        if (*s != ' ')