]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/satmap.c
Update copyright notice
[empserver] / src / lib / subs / satmap.c
index d11107d698a9f48e1eeb370f33cd5d80dd492797..bac9eecb9dfcfea80d175dcbd2b35eda4fddea81 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-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  satmap.c: Do a satellite map given an x,y location, effic and other
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
  */
 
 #include <config.h>
 
+#include <stdlib.h>
+#include "file.h"
+#include "land.h"
+#include "map.h"
 #include "misc.h"
+#include "nat.h"
+#include "nsc.h"
+#include "optlist.h"
+#include "plane.h"
 #include "player.h"
-#include "xy.h"
+#include "prototypes.h"
 #include "sect.h"
 #include "ship.h"
-#include "land.h"
-#include "plane.h"
-#include "nsc.h"
-#include "nat.h"
-#include "file.h"
-#include "prototypes.h"
-#include "optlist.h"
+#include "xy.h"
 
 static char **rad;
 static char *radbuf;
@@ -71,7 +73,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
        return;
 
     if (!radbuf)
-       radbuf = malloc(WORLD_Y * (WORLD_X + 1));
+       radbuf = malloc(WORLD_Y * MAPWIDTH(1));
     if (!rad) {
        rad = malloc(WORLD_Y * sizeof(char *));
        if (rad && radbuf) {
@@ -143,7 +145,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
     if ((type == EF_BAD || type == EF_SHIP) &&
        (flags & P_S || flags & P_I)) {
        if (type == EF_SHIP)
-           snxtitem(&ni, EF_SHIP, selection);
+           snxtitem(&ni, EF_SHIP, selection, NULL);
        else
            snxtitem_dist(&ni, EF_SHIP, x, y, range);
 
@@ -175,15 +177,8 @@ satmap(int x, int y, int eff, int range, int flags, int type)
            }
            /* If we are imaging *and* drawing the map */
            if ((flags & P_I) && (type == EF_BAD)) {
-               /* Figure out where to put the ship */
-               /* First, figure out the distance from the two */
-               rx = diffx((int)ship.shp_x, x);
-               ry = diffy((int)ship.shp_y, y);
-               /* Next, determine which direction to add it to the center */
-               /* We can only do this if imaging and we have gotten the center
-                  up above by imaging the sectors. */
-               rx = deltax(x, ns.range.lx) + rx;
-               ry = deltay(y, ns.range.ly) + ry;
+               rx = deltx(&ns.range, ship.shp_x);
+               ry = delty(&ns.range, ship.shp_y);
                /* &~0x20 makes it a cap letter */
                rad[ry][rx] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
            }
@@ -195,7 +190,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
     if ((type == EF_BAD || type == EF_LAND) &&
        (flags & P_S || flags & P_I)) {
        if (type == EF_LAND)
-           snxtitem(&ni, EF_LAND, selection);
+           snxtitem(&ni, EF_LAND, selection, NULL);
        else
            snxtitem_dist(&ni, EF_LAND, x, y, range);
 
@@ -208,6 +203,8 @@ satmap(int x, int y, int eff, int range, int flags, int type)
        while (nxtitem(&ni, &land)) {
            if (land.lnd_own == 0)
                continue;
+           if (lchr[(int)land.lnd_type].l_flags & L_SPY)
+               continue;
            if (!chance(land.lnd_effic / 20.0))
                continue;
            if (++crackle == 100)
@@ -226,15 +223,8 @@ satmap(int x, int y, int eff, int range, int flags, int type)
            }
            /* If we are imaging *and* drawing the map */
            if ((flags & P_I) && (type == EF_BAD)) {
-               /* Figure out where to put the unit */
-               /* First, figure out the distance from the two */
-               rx = diffx((int)land.lnd_x, x);
-               ry = diffy((int)land.lnd_y, y);
-               /* Next, determine which direction to add it to the center */
-               /* We can only do this if imaging and we have gotten the center
-                  up above by imaging the sectors. */
-               rx = deltax(x, ns.range.lx) + rx;
-               ry = deltay(y, ns.range.ly) + ry;
+               rx = deltx(&ns.range, land.lnd_x);
+               ry = delty(&ns.range, land.lnd_y);
                /* &~0x20 makes it a cap letter */
                rad[ry][rx] = (*lchr[(int)land.lnd_type].l_name) & ~0x20;
            }
@@ -250,16 +240,10 @@ satmap(int x, int y, int eff, int range, int flags, int type)
         * We have to make the center a '0' for ve
         * ve needs a garbage line to terminate the map
         */
-       rad[deltay(y, ns.range.ly)][deltax(x, ns.range.lx)] = '0';
+       rad[delty(&ns.range, y)][deltx(&ns.range, y)] = '0';
 
        pr("Satellite radar report\n");
-#ifdef HAY
-       /* This is wrong for small, hitech worlds. */
-       n = deltay(ns.range.hy, ns.range.ly);
-#else
-       /* This is already available, so why not use it. */
        n = ns.range.height;
-#endif
        for (row = 0; row < n; row++)
            pr("%s\n", rad[row]);
        pr("\n(c) 1989 Imaginative Images Inc.\n");
@@ -281,7 +265,7 @@ satdisp_sect(struct sctstr *sp, int acc)
        dchr[sp->sct_type].d_mnem,
        sp->sct_own, roundintby((int)sp->sct_effic, acc / 2),
        roundintby((int)sp->sct_road, acc / 2),
-       roundintby((int)sp->sct_rail, acc / 2),
+       opt_RAILWAYS ? !!sct_rail_track(sp) : roundintby(sp->sct_rail, acc / 2),
        roundintby((int)sp->sct_defense, acc / 2),
        roundintby(sp->sct_item[I_CIVIL], acc),
        roundintby(sp->sct_item[I_MILIT], acc),
@@ -329,11 +313,15 @@ satdisp_units(coord x, coord y)
     while (nxtitem(&ni, &land)) {
        if (land.lnd_own == 0)
            continue;
+       if (land.lnd_ship >= 0 || land.lnd_land >= 0)
+           continue;
+       if (lchr[(int)land.lnd_type].l_flags & L_SPY)
+           continue;
        if (!chance(land.lnd_effic / 20.0))
            continue;
 
        if (first) {
-           pr("\t own  lnd# unit type         sector   eff\n");
+           pr("\t own  lnd# unit type       sector   eff\n");
            first = 0;
        }