]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/radmap.c
Update copyright notice
[empserver] / src / lib / subs / radmap.c
index 5461e582af91c3265fa6262819afc76fe86f74dc..026233c71bc820be1d9fbc0f9691826e124d0dc4 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -29,6 +28,7 @@
  *
  *  Known contributors to this file:
  *     Dave Pare, 1989
+ *     Markus Armbruster, 2004-2010
  */
 
 #include <config.h>
 #include "ship.h"
 #include "xy.h"
 
-static void radmap2(int, int, int, int, int, double, int);
-
-void
-radmap(int cx, int cy, int eff, int range, double seesub)
-{
-    radmap2(player->cnum, cx, cy, eff, range, seesub, 1);
-}
-
-void
-radmapnopr(int cx, int cy, int eff, int range, double seesub)
-{
-    radmap2(player->cnum, cx, cy, eff, range, seesub, 0);
-}
-
-void
-radmapupd(int own, int cx, int cy, int eff, int range, double seesub)
-{
-    radmap2(own, cx, cy, eff, range, seesub, 0);
-}
+static int rad_range(int, double, int);
+static char rad_char(struct sctstr *, int, int, natid);
 
 /* More dynamic world sized buffers.  We create 'em once, and then
  * never again.  No need to keep creating/tearing apart.  We may
@@ -75,9 +58,13 @@ static char *radbuf;
 static signed char **vis;
 static signed char *visbuf;
 
-static void
-radmap2(int owner,
-       int cx, int cy, int eff, int range, double seesub, int pr_flag)
+/*
+ * Draw a radar map for radar at CX,CY.
+ * EFF is the radar's efficiency, TLEV its tech level, SPY its power.
+ * Submarines are detected at fraction SEESUB of the range.
+ */
+void
+radmap(int cx, int cy, int eff, double tlev, int spy, double seesub)
 {
     int visib, rng;
     struct sctstr sect;
@@ -88,6 +75,7 @@ radmap2(int owner,
     int x, y;
     int row;
     int n;
+    int range = rad_range(eff, tlev, spy);
     int changed = 0;
 
     if (!radbuf)
@@ -114,29 +102,17 @@ radmap2(int owner,
     }
 
     memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1)));
-    range = (int)(range * (eff / 100.0));
-    if (range < 1)
-       range = 1;
-    if (pr_flag)
-       pr("%s efficiency %d%%, max range %d\n",
-          xyas(cx, cy, owner), eff, range);
+    pr("%s efficiency %d%%, max range %d\n",
+       xyas(cx, cy, player->cnum), eff, range);
     snxtsct_dist(&ns, cx, cy, range);
     blankfill(radbuf, &ns.range, 1);
     while (nxtsct(&ns, &sect)) {
-       if (sect.sct_own == owner
-           || sect.sct_type == SCT_WATER
-           || sect.sct_type == SCT_MOUNT
-           || sect.sct_type == SCT_WASTE
-           || ns.curdist <= range / 3)
-           rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
-       else
-           rad[ns.dy][ns.dx] = '?';
-       changed += map_set(owner, ns.x, ns.y, rad[ns.dy][ns.dx], 0);
+       rad[ns.dy][ns.dx] = rad_char(&sect, ns.curdist, range,
+                                    player->cnum);
+       changed += map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx], 0);
     }
     if (changed)
-       writemap(owner);
-    if (!pr_flag)
-       return;
+       writemap(player->cnum);
     snxtitem_dist(&ni, EF_PLANE, cx, cy, range);
     while (nxtitem(&ni, &plane)) {
        if (plane.pln_own == 0)
@@ -145,7 +121,7 @@ radmap2(int owner,
        x = deltx(&ns.range, (int)plane.pln_x);
        y = delty(&ns.range, (int)plane.pln_y);
 
-       if (pln_is_in_orbit(&plane) && plane.pln_own != owner) {
+       if (pln_is_in_orbit(&plane) && plane.pln_own != player->cnum) {
            vis[y][x] = 100;
            rad[y][x] = '$';
        }
@@ -208,3 +184,57 @@ delty(struct range *r, coord y)
        return y - r->ly;
     return y + WORLD_Y - r->ly;
 }
+
+/*
+ * Update OWNER's bmap for radar at CX,CY.
+ * EFF is the radar's efficiency, TLEV its tech level, SPY its power.
+ */
+void
+rad_map_set(natid owner, int cx, int cy, int eff, double tlev, int spy)
+{
+    struct nstr_sect ns;
+    struct sctstr sect;
+    int range = rad_range(eff, tlev, spy);
+    int changed = 0;
+    char ch;
+
+    snxtsct_dist(&ns, cx, cy, range);
+    while (nxtsct(&ns, &sect)) {
+       ch = rad_char(&sect, ns.curdist, range, owner);
+       changed += map_set(owner, ns.x, ns.y, ch, 0);
+    }
+    if (changed)
+       writemap(owner);
+}
+
+/*
+ * Range of a radar with EFF efficiency, TLEV tech, and SPY power.
+ */
+static int
+rad_range(int eff, double tlev, int spy)
+{
+    int range;
+
+    range = (int)techfact(tlev, spy);
+    range = (int)(range * (eff / 100.0));
+    if (range < 1)
+       range = 1;
+    return range;
+}
+
+/*
+ * Return character to use in radar maps for sector SP.
+ * DIST is the distance from the radar, RANGE its range.
+ * Country CN is using the radar.
+ */
+static char
+rad_char(struct sctstr *sp, int dist, int range, natid cn)
+{
+    if (sp->sct_own == cn
+       || sp->sct_type == SCT_WATER
+       || sp->sct_type == SCT_MOUNT
+       || sp->sct_type == SCT_WASTE
+       || dist <= range / 3)
+       return dchr[sp->sct_type].d_mnem;
+    return '?';
+}