]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/satmap.c
Update copyright notice
[empserver] / src / lib / subs / satmap.c
index b24f9e382196f52bef7a9c31d0fb84568cd60f51..a14810fcb8201b531841de1c39bdb808349329fe 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  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 s_char **rad;
-static s_char *radbuf;
+static char **rad;
+static char *radbuf;
 
 void
 satmap(int x, int y, int eff, int range, int flags, int type)
 {
-    int acc;
     struct sctstr sect;
     struct shpstr ship;
     struct lndstr land;
@@ -63,17 +65,16 @@ satmap(int x, int y, int eff, int range, int flags, int type)
     int n;
     int changed = 0;
     long crackle;
-    s_char noise[100];
-    s_char selection[1024];
+    signed char noise[100];
+    char selection[1024];
 
     if (!eff)
        return;
 
     if (!radbuf)
-       radbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) *
-                                 sizeof(s_char));
+       radbuf = malloc(WORLD_Y * MAPWIDTH(1));
     if (!rad) {
-       rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
+       rad = malloc(WORLD_Y * sizeof(char *));
        if (rad && radbuf) {
            for (rx = 0; rx < WORLD_Y; rx++)
                rad[rx] = &radbuf[(WORLD_X + 1) * rx];
@@ -86,8 +87,8 @@ satmap(int x, int y, int eff, int range, int flags, int type)
     }
 
     range = range * (eff / 100.0);
-    pr("%s efficiency %d%%, max range %d\n", xyas(x, y, player->cnum),
-       eff, range);
+    pr("%s efficiency %d%%, max range %d\n",
+       xyas(x, y, player->cnum), eff, range);
     memset(noise, 0, sizeof(noise));
     if (eff < 100) {
        pr("Some noise on the transmission...\n");
@@ -105,12 +106,11 @@ satmap(int x, int y, int eff, int range, int flags, int type)
        else
            snxtsct_dist(&ns, x, y, range);
 
-       blankfill((s_char *)radbuf, &ns.range, 1);
+       blankfill(radbuf, &ns.range, 1);
        if (flags & P_S) {
            pr("Satellite sector report\n");
            prdate();
            sathead();
-           acc = (flags & P_I) ? 5 : 50;
        }
        crackle = count = 0;
        while (nxtsct(&ns, &sect)) {
@@ -120,11 +120,10 @@ satmap(int x, int y, int eff, int range, int flags, int type)
                continue;
            if (flags & P_S) {
                if (sect.sct_own && sect.sct_own != player->cnum) {
-                   satdisp(&sect, acc, 0);
+                   satdisp_sect(&sect, (flags & P_I) ? 5 : 50);
                    ++count;
-               }
-               if (opt_HIDDEN) {
-                   setcont(player->cnum, sect.sct_own, FOUND_FLY);
+                   if (opt_HIDDEN)
+                       setcont(player->cnum, sect.sct_own, FOUND_FLY);
                }
            }
            if ((flags & P_I) ||
@@ -144,7 +143,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);
 
@@ -152,11 +151,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
        if (flags & P_S) {
            pr("Satellite ship report\n");
            prdate();
-           if (opt_SHIPNAMES) {
-               pr(" own  shp# ship type                                  sector   eff\n");
-           } else {
-               pr(" own  shp# ship type         sector   eff\n");
-           }
+           pr(" own  shp# ship type                                  sector   eff\n");
        }
        while (nxtitem(&ni, &ship)) {
            if (ship.shp_own == 0)
@@ -169,29 +164,19 @@ satmap(int x, int y, int eff, int range, int flags, int type)
            if (noise[crackle])
                continue;
            if (flags & P_S) {
-               pr("%4d %4d %-16.16s ",
+               pr("%4d %4d %-16.16s %-25.25s ",
                   ship.shp_own, ship.shp_uid,
-                  mchr[(int)ship.shp_type].m_name);
-               if (opt_SHIPNAMES)
-                   pr("%-25.25s ", ship.shp_name);
+                  mchr[(int)ship.shp_type].m_name, ship.shp_name);
                prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
                pr("%3d%%\n", ship.shp_effic);
                ++count;
-               if (opt_HIDDEN) {
+               if (opt_HIDDEN)
                    setcont(player->cnum, ship.shp_own, FOUND_FLY);
-               }
            }
            /* 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;
            }
@@ -203,7 +188,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);
 
@@ -216,7 +201,9 @@ satmap(int x, int y, int eff, int range, int flags, int type)
        while (nxtitem(&ni, &land)) {
            if (land.lnd_own == 0)
                continue;
-           if (!chance((double)land.lnd_effic / 20.0))
+           if (lchr[(int)land.lnd_type].l_flags & L_SPY)
+               continue;
+           if (!chance(land.lnd_effic / 20.0))
                continue;
            if (++crackle == 100)
                crackle = 0;
@@ -229,18 +216,13 @@ satmap(int x, int y, int eff, int range, int flags, int type)
                prxy("%4d,%-4d", land.lnd_x, land.lnd_y, player->cnum);
                pr("%3d%%\n", land.lnd_effic);
                ++count;
+               if (opt_HIDDEN)
+                   setcont(player->cnum, land.lnd_own, FOUND_FLY);
            }
            /* 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;
            }
@@ -256,16 +238,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");
@@ -280,19 +256,14 @@ sathead(void)
 }
 
 void
-satdisp(struct sctstr *sp, int acc, int showstuff)
+satdisp_sect(struct sctstr *sp, int acc)
 {
-    int first;
-    struct nstr_item ni;
-    struct shpstr ship;
-    struct lndstr land;
-
     prxy("%4d,%-4d   ", sp->sct_x, sp->sct_y, player->cnum);
     pr("%c  %3d  %3d %3d %3d %3d %4d %4d %4d %4d %4d %4d %5d\n",
        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),
@@ -303,9 +274,17 @@ satdisp(struct sctstr *sp, int acc, int showstuff)
        roundintby(sp->sct_item[I_FOOD], acc));
     map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem,
            0);
-    if (!showstuff)
-       return;
-    snxtitem_xy(&ni, EF_SHIP, sp->sct_x, sp->sct_y);
+}
+
+void
+satdisp_units(coord x, coord y)
+{
+    int first;
+    struct nstr_item ni;
+    struct shpstr ship;
+    struct lndstr land;
+
+    snxtitem_xy(&ni, EF_SHIP, x, y);
     first = 1;
     while (nxtitem(&ni, &ship)) {
        if (ship.shp_own == 0)
@@ -313,17 +292,12 @@ satdisp(struct sctstr *sp, int acc, int showstuff)
        if (mchr[(int)ship.shp_type].m_flags & M_SUB)
            continue;
        if (first) {
-           if (opt_SHIPNAMES) {
-               pr("\t own  shp# ship type                                  sector   eff\n");
-           } else {
-               pr("\t own  shp# ship type         sector   eff\n");
-           }
+           pr("\t own  shp# ship type                                  sector   eff\n");
            first = 0;
        }
-       pr("\t%4d %4d %-16.16s ", ship.shp_own, ship.shp_uid,
-          mchr[(int)ship.shp_type].m_name);
-       if (opt_SHIPNAMES)
-           pr("%-25.25s ", ship.shp_name);
+       pr("\t%4d %4d %-16.16s %-25.25s ",
+          ship.shp_own, ship.shp_uid,
+          mchr[(int)ship.shp_type].m_name, ship.shp_name);
        prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
        pr("%3d%%\n", ship.shp_effic);
     }
@@ -331,22 +305,26 @@ satdisp(struct sctstr *sp, int acc, int showstuff)
     if (!first)
        pr("\n");
 
-    snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
+    snxtitem_xy(&ni, EF_LAND, x, y);
     first = 1;
 
     while (nxtitem(&ni, &land)) {
        if (land.lnd_own == 0)
            continue;
-       if (!chance((double)land.lnd_effic / 20.0))
+       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;
        }
 
-       pr("\t%4d %4d %-16.16s ", land.lnd_own, land.lnd_uid,
-          lchr[(int)land.lnd_type].l_name);
+       pr("\t%4d %4d %-16.16s ",
+          land.lnd_own, land.lnd_uid, lchr[(int)land.lnd_type].l_name);
        prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum);
        pr("%3d%%\n", land.lnd_effic);
     }