]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/radmap.c
Fix trailing whitespace
[empserver] / src / lib / subs / radmap.c
index 9a1cbbb675211f66c403f4f0cc5a9a3976ddd819..5461e582af91c3265fa6262819afc76fe86f74dc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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
  *  ---
  *
  *  radmap.c: Do a radar map given an x,y location, effic, and other
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1989
  */
 
 #include <config.h>
 
+#include <stdlib.h>
+#include "file.h"
+#include "map.h"
 #include "misc.h"
-#include "player.h"
-#include "xy.h"
 #include "nat.h"
-#include "sect.h"
-#include "ship.h"
-#include "plane.h"
-#include "file.h"
 #include "nsc.h"
-#include "prototypes.h"
 #include "optlist.h"
+#include "plane.h"
+#include "player.h"
+#include "prototypes.h"
+#include "sect.h"
+#include "ship.h"
+#include "xy.h"
 
 static void radmap2(int, int, int, int, int, double, int);
 
@@ -70,14 +72,14 @@ radmapupd(int own, int cx, int cy, int eff, int range, double seesub)
  * want to do this in other places too where it doesn't matter. */
 static char **rad;
 static char *radbuf;
-static s_char **vis;
-static s_char *visbuf;
+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)
 {
-    int rng;
+    int visib, rng;
     struct sctstr sect;
     struct shpstr ship;
     struct plnstr plane;
@@ -89,18 +91,18 @@ radmap2(int owner,
     int changed = 0;
 
     if (!radbuf)
-       radbuf = malloc(WORLD_Y * (WORLD_X + 1));
+       radbuf = malloc(WORLD_Y * MAPWIDTH(1));
     if (!visbuf)
-       visbuf = malloc(WORLD_Y * (WORLD_X + 1));
+       visbuf = malloc(WORLD_Y * MAPWIDTH(1));
     if (!rad) {
-       rad = malloc(WORLD_Y * sizeof(s_char *));
+       rad = malloc(WORLD_Y * sizeof(char *));
        if (rad && radbuf) {
            for (x = 0; x < WORLD_Y; x++)
                rad[x] = &radbuf[(WORLD_X + 1) * x];
        }
     }
     if (!vis) {
-       vis = malloc(WORLD_Y * sizeof(s_char *));
+       vis = malloc(WORLD_Y * sizeof(signed char *));
        if (vis && visbuf) {
            for (x = 0; x < WORLD_Y; x++)
                vis[x] = &visbuf[(WORLD_X + 1) * x];
@@ -143,7 +145,7 @@ radmap2(int owner,
        x = deltx(&ns.range, (int)plane.pln_x);
        y = delty(&ns.range, (int)plane.pln_y);
 
-       if ((plane.pln_flags & PLN_LAUNCHED) && plane.pln_own != owner) {
+       if (pln_is_in_orbit(&plane) && plane.pln_own != owner) {
            vis[y][x] = 100;
            rad[y][x] = '$';
        }
@@ -156,56 +158,53 @@ radmap2(int owner,
        x = deltx(&ns.range, (int)ship.shp_x);
        y = delty(&ns.range, (int)ship.shp_y);
 
-       rng = (int)(range * ship.shp_visib / 20.0);
+       visib = shp_visib(&ship);
+       rng = (int)(range * visib / 20.0);
        if (ni.curdist > rng)
            continue;
        if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
            ni.curdist > rng * seesub)
            continue;
-       if (ship.shp_visib > vis[y][x]) {
-           vis[y][x] = ship.shp_visib;
+       if (visib > vis[y][x]) {
+           vis[y][x] = visib;
            /* &~0x20 makes it a cap letter */
            rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
        }
     }
-    /* 
+    /*
      * make the center of the display 0
      * so ve et al can find it.
      */
-    rad[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx)] = '0';
-    /* won't work for radar maps > WORLD_Y/2 */
-#ifdef HAY
-    /* This is not correct for small, hitech worlds. */
-    n = deltay(ns.range.hy, ns.range.ly);
-#else
-    /* This is already available, so why not use it. */
+    rad[delty(&ns.range, cy)][deltx(&ns.range, cx)] = '0';
+
     n = ns.range.height;
-#endif
     for (row = 0; row < n; row++)
        pr("%s\n", rad[row]);
     pr("\n");
 }
 
+/*
+ * Return distance from left edge of R to X.
+ * Value is between 0 (inclusive) and WORLD_X (exclusive).
+ * X must be normalized.
+ */
 int
 deltx(struct range *r, coord x)
 {
-    if (r->lx < r->hx)
-       return x - r->lx;
-
     if (x >= r->lx)
        return x - r->lx;
-
     return x + WORLD_X - r->lx;
 }
 
+/*
+ * Return distance from top edge of R to Y.
+ * Value is between 0 (inclusive) and WORLD_Y (exclusive).
+ * Y must be normalized.
+ */
 int
 delty(struct range *r, coord y)
 {
-    if (r->ly < r->hy)
-       return y - r->ly;
-
     if (y >= r->ly)
        return y - r->ly;
-
     return y + WORLD_Y - r->ly;
 }