]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/satmap.c
Move declarations for chance.c to new chance.h
[empserver] / src / lib / subs / satmap.c
index b1167692085bdf6cb7b45de99331c4a057bca32f..e016e54d3fa6531bc940c5d0548a4a16be26a6fc 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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/>.
  *
  *  ---
  *
  *  ---
  *
  *  satmap.c: Do a satellite map given an x,y location, effic and other
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
+ *     Markus Armbruster, 2004-2011
  */
 
 #include <config.h>
 
+#include <stdlib.h>
+#include "chance.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;
 
-void
+int
 satmap(int x, int y, int eff, int range, int flags, int type)
 {
-    int acc;
     struct sctstr sect;
     struct shpstr ship;
     struct lndstr land;
@@ -65,13 +67,12 @@ satmap(int x, int y, int eff, int range, int flags, int type)
     int changed = 0;
     long crackle;
     signed char noise[100];
-    char selection[1024];
 
     if (!eff)
-       return;
+       return RET_OK;
 
     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) {
@@ -82,7 +83,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
 
     if (!radbuf || !rad) {
        pr("Memory error in satmap, tell the deity.\n");
-       return;
+       return RET_FAIL;
     }
 
     range = range * (eff / 100.0);
@@ -95,22 +96,17 @@ satmap(int x, int y, int eff, int range, int flags, int type)
            noise[100 * n / (100 - eff)] = 1;
     }
 
-    /* Have to convert to player coords, since it gets converted
-       back from there */
-    sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range);
-
     if (type == EF_BAD || type == EF_SECTOR) {
-       if (type == EF_SECTOR)  /* Use ?conditionals */
-           snxtsct(&ns, selection);
-       else
-           snxtsct_dist(&ns, x, y, range);
+       snxtsct_dist(&ns, x, y, range);
+       if (type == EF_SECTOR && !snxtsct_use_condarg(&ns))
+           return RET_SYN;
+           
 
        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,7 +116,9 @@ 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(&sect, acc);
+                   satdisp_sect(&sect, (flags & P_I) ? 5 : 50);
+                   changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
+                                      dchr[sect.sct_type].d_mnem, 0);
                    ++count;
                    if (opt_HIDDEN)
                        setcont(player->cnum, sect.sct_own, FOUND_FLY);
@@ -142,10 +140,9 @@ 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);
-       else
-           snxtitem_dist(&ni, EF_SHIP, x, y, range);
+       snxtitem_dist(&ni, EF_SHIP, x, y, range);
+       if (type == EF_SHIP && !snxtitem_use_condarg(&ni))
+           return RET_SYN;
 
        crackle = count = 0;
        if (flags & P_S) {
@@ -167,7 +164,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
                pr("%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);
+               prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);
                pr("%3d%%\n", ship.shp_effic);
                ++count;
                if (opt_HIDDEN)
@@ -175,15 +172,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;
            }
@@ -194,10 +184,9 @@ 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);
-       else
-           snxtitem_dist(&ni, EF_LAND, x, y, range);
+       snxtitem_dist(&ni, EF_LAND, x, y, range);
+       if (type == EF_LAND && !snxtitem_use_condarg(&ni))
+           return RET_SYN;
 
        crackle = count = 0;
        if (flags & P_S) {
@@ -220,7 +209,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
                pr("%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);
+               prxy("%4d,%-4d", land.lnd_x, land.lnd_y);
                pr("%3d%%\n", land.lnd_effic);
                ++count;
                if (opt_HIDDEN)
@@ -228,15 +217,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;
            }
@@ -252,20 +234,15 @@ 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");
     }
+    return RET_OK;
 }
 
 void
@@ -278,12 +255,12 @@ sathead(void)
 void
 satdisp_sect(struct sctstr *sp, int acc)
 {
-    prxy("%4d,%-4d   ", sp->sct_x, sp->sct_y, player->cnum);
+    prxy("%4d,%-4d   ", sp->sct_x, sp->sct_y);
     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),
@@ -292,8 +269,6 @@ satdisp_sect(struct sctstr *sp, int acc)
        roundintby(sp->sct_item[I_IRON], acc),
        roundintby(sp->sct_item[I_PETROL], acc),
        roundintby(sp->sct_item[I_FOOD], acc));
-    map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem,
-           0);
 }
 
 void
@@ -318,7 +293,7 @@ satdisp_units(coord x, coord y)
        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);
+       prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);
        pr("%3d%%\n", ship.shp_effic);
     }
 
@@ -345,7 +320,7 @@ satdisp_units(coord x, coord y)
 
        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);
+       prxy("%4d,%-4d ", land.lnd_x, land.lnd_y);
        pr("%3d%%\n", land.lnd_effic);
     }