]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/spy.c
Update copyright notice
[empserver] / src / lib / commands / spy.c
index 54e296880283f8c1820c32f8c1ec1203f6e0a033..291ab46b4ddcab7d8b51392d126dda559f858dab 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, 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
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *     Steve McClure, 1998-2000
  */
 
-#include "misc.h"
-#include "player.h"
-#include "var.h"
-#include "sect.h"
+#include <config.h>
+
+#include "commands.h"
 #include "item.h"
-#include "nat.h"
-#include "xy.h"
-#include "nsc.h"
-#include "nuke.h"
-#include "news.h"
-#include "deity.h"
-#include "path.h"
-#include "file.h"
 #include "land.h"
-#include "commands.h"
+#include "map.h"
+#include "news.h"
 #include "optlist.h"
+#include "path.h"
+#include "plane.h"
 
 /*
  * format:  spy <SECTS>
- *
  */
 
 static int check(coord *table, int *len, coord x, coord y);
@@ -75,8 +68,6 @@ spy(void)
     int i;
     coord *table;              /* sectors already seen */
     int t_len = 0;
-    int vec[I_MAX + 1];
-    int dvec[I_MAX + 1];
     int nrecon;
     int nunits;
     struct nstr_sect nstr;
@@ -104,8 +95,8 @@ spy(void)
      * set up all the goodies we need later
      * 6 = neighbors, 2 = x,y
      */
-    table = (coord *)malloc((nsects + 1) * 6 * 2 * sizeof(coord));
-    bzero((s_char *)table, (nsects + 1) * 6 * 2 * sizeof(coord));
+    table = malloc((nsects + 1) * 6 * 2 * sizeof(coord));
+    memset(table, 0, (nsects + 1) * 6 * 2 * sizeof(coord));
     pr("SPY report\n");
     prdate();
     pr("                 old sct rd  rl  def\n");
@@ -113,16 +104,15 @@ spy(void)
     while (nxtsct(&nstr, &from)) {
        if (!player->owner && !player->god)
            continue;
-       getvec(VT_ITEM, vec, (s_char *)&from, EF_SECTOR);
        nrecon = 0;
        nunits = 0;
        snxtitem_xy(&ni, EF_LAND, from.sct_x, from.sct_y);
-       while (nxtitem(&ni, (s_char *)&land)) {
+       while (nxtitem(&ni, &land)) {
            nunits++;
            if (lchr[(int)land.lnd_type].l_flags & L_RECON)
                nrecon++;
        }
-       if ((military = vec[I_MILIT]) == 0 && (nunits == 0))
+       if ((military = from.sct_item[I_MILIT]) == 0 && (nunits == 0))
            continue;
        x = from.sct_x;
        y = from.sct_y;
@@ -147,16 +137,16 @@ spy(void)
                continue;
            }
            getsect(nx, ny, &dsect);
-           getvec(VT_ITEM, dvec, (s_char *)&dsect, EF_SECTOR);
-           if (player->owner || (dsect.sct_type == SCT_WATER) ||
-               (!dvec[I_MILIT] && !dvec[I_CIVIL] &&
-                (num_units(nx, ny) == 0))) {
+           if (player->owner
+               || (dsect.sct_type == SCT_WATER)
+               || (!dsect.sct_item[I_MILIT] && !dsect.sct_item[I_CIVIL]
+                   && num_units(nx, ny) == 0)) {
                /* mark sector as seen */
                insert(table, &t_len, nx, ny);
                continue;
            }
            /* catch spy N/200 chance, N = # military */
-           caught = chance((double)dvec[I_MILIT] / 200.0);
+           caught = chance(dsect.sct_item[I_MILIT] / 200.0);
            own = dsect.sct_own;
            /* determine spyee relations with spyer */
            relat = getrel(getnatp(own), player->cnum);
@@ -167,8 +157,10 @@ spy(void)
                    wu(0, own, "%s (#%d) spy deported from %s\n",
                       cname(player->cnum), player->cnum,
                       xyas(nx, ny, own));
+               if (opt_HIDDEN)
+                   setcont(own, player->cnum, FOUND_SPY);
            } else if (relat < NEUTRAL && caught) {
-               /* at-war with spy-ee */
+               /* hostile spy-ee */
                pr("BANG!! A spy was shot in %s\n",
                   xyas(nx, ny, player->cnum));
                military--;
@@ -177,17 +169,17 @@ spy(void)
                       cname(player->cnum), player->cnum,
                       xyas(nx, ny, own));
                nreport(player->cnum, N_SPY_SHOT, own, 1);
+               if (opt_HIDDEN)
+                   setcont(own, player->cnum, FOUND_SPY);
            } else {
                insert(table, &t_len, nx, ny);
                spyline(&dsect);
-               changed += map_set(player->cnum, dsect.sct_x,
-                                  dsect.sct_y,
+               changed += map_set(player->cnum, dsect.sct_x, dsect.sct_y,
                                   dchr[dsect.sct_type].d_mnem, 0);
                prunits(dsect.sct_x, dsect.sct_y);
                prplanes(dsect.sct_x, dsect.sct_y);
-               if (opt_HIDDEN) {
+               if (opt_HIDDEN)
                    setcont(player->cnum, own, FOUND_SPY);
-               }
            }
            /*
             * If you have a recon unit, it'll
@@ -196,8 +188,7 @@ spy(void)
            if (nrecon && caught) {
                insert(table, &t_len, nx, ny);
                spyline(&dsect);
-               changed += map_set(player->cnum, dsect.sct_x,
-                                  dsect.sct_y,
+               changed += map_set(player->cnum, dsect.sct_x, dsect.sct_y,
                                   dchr[dsect.sct_type].d_mnem, 0);
                prunits(dsect.sct_x, dsect.sct_y);
                prplanes(dsect.sct_x, dsect.sct_y);
@@ -207,15 +198,14 @@ spy(void)
        if ((savemil != military) && (savemil > 0)) {
            if ((military < 0) || (military > savemil))
                military = 0;
-           vec[I_MILIT] = military;
-           putvec(VT_ITEM, vec, (s_char *)&from, EF_SECTOR);
+           from.sct_item[I_MILIT] = military;
            putsect(&from);
        }
     }
     if (changed)
        writemap(player->cnum);
     player->btused += btucost;
-    free((s_char *)table);
+    free(table);
     return RET_OK;
 }
 
@@ -226,11 +216,25 @@ spy(void)
 static void
 spyline(struct sctstr *sp)
 {
-    int vec[I_MAX + 1];
-
-    getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
     prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
-    pr(" %c%c %3d %3d %3d %3d %3d %3d %4d %4d %4d %3d %4d %4d %4d %3d %3d\n", dchr[sp->sct_type].d_mnem, (sp->sct_newtype == sp->sct_type) ? ' ' : dchr[sp->sct_newtype].d_mnem, sp->sct_own, sp->sct_oldown, roundintby((int)sp->sct_effic, 10), roundintby((int)sp->sct_road, 10), roundintby((int)sp->sct_rail, 10), roundintby((int)sp->sct_defense, 10), roundintby(vec[I_CIVIL], 10), roundintby(vec[I_MILIT], 10), roundintby(vec[I_SHELL], 10), roundintby(vec[I_GUN], 10), roundintby(vec[I_PETROL], 10), roundintby(vec[I_FOOD], 10), roundintby(vec[I_BAR], 10), count_sect_units(sp), count_sect_planes(sp));
+    pr(" %c%c %3d %3d %3d %3d %3d %3d %4d %4d %4d %3d %4d %4d %4d %3d %3d\n",
+       dchr[sp->sct_type].d_mnem,
+       sp->sct_newtype == sp->sct_type ? ' ' : dchr[sp->sct_newtype].d_mnem,
+       sp->sct_own,
+       sp->sct_oldown,
+       roundintby((int)sp->sct_effic, 10),
+       roundintby((int)sp->sct_road, 10),
+       roundintby((int)sp->sct_rail, 10),
+       roundintby((int)sp->sct_defense, 10),
+       roundintby(sp->sct_item[I_CIVIL], 10),
+       roundintby(sp->sct_item[I_MILIT], 10),
+       roundintby(sp->sct_item[I_SHELL], 10),
+       roundintby(sp->sct_item[I_GUN], 10),
+       roundintby(sp->sct_item[I_PETROL], 10),
+       roundintby(sp->sct_item[I_FOOD], 10),
+       roundintby(sp->sct_item[I_BAR], 10),
+       count_sect_units(sp),
+       count_sect_planes(sp));
 }
 
 
@@ -268,7 +272,7 @@ num_units(int x, int y)
     int n = 0;
 
     snxtitem_xy(&ni, EF_LAND, x, y);
-    while (nxtitem(&ni, (s_char *)&land)) {
+    while (nxtitem(&ni, &land)) {
        if ((land.lnd_own == player->cnum) || (land.lnd_own == 0))
            continue;
        if (land.lnd_ship >= 0 || land.lnd_land >= 0)
@@ -284,10 +288,10 @@ prunits(int x, int y)
 {
     struct lndstr land;
     struct nstr_item ni;
-    s_char report[128];
+    char report[128];
 
     snxtitem_xy(&ni, EF_LAND, x, y);
-    while (nxtitem(&ni, (s_char *)&land)) {
+    while (nxtitem(&ni, &land)) {
        if (land.lnd_own == player->cnum || land.lnd_own == 0)
            continue;
        if (land.lnd_ship >= 0 || land.lnd_land >= 0)
@@ -299,16 +303,17 @@ prunits(int x, int y)
        }
        if ((land.lnd_own != player->cnum) && land.lnd_own) {
            int rel;
-           s_char *format;
+           char *relstr;
 
            rel = getrel(getnatp(player->cnum), land.lnd_own);
            if (rel == ALLIED)
-               format = "Allied (%s) unit in %s: ";
+               relstr = "Allied";
            else if (rel == FRIENDLY || rel == NEUTRAL)
-               format = "Neutral (%s) unit in %s: ";
+               relstr = "Neutral";
            else
-               format = "Enemy (%s) unit in %s: ";
-           sprintf(report, format, cname(land.lnd_own),
+               relstr = "Enemy";
+           sprintf(report, "%s (%s) unit in %s: ",
+                   relstr, cname(land.lnd_own),
                    xyas(land.lnd_x, land.lnd_y, player->cnum));
            intelligence_report(player->cnum, &land, 3, report);
        }
@@ -320,10 +325,9 @@ prplanes(int x, int y)
 {
     struct plnstr plane;
     struct nstr_item ni;
-    s_char report[128];
 
     snxtitem_xy(&ni, EF_PLANE, x, y);
-    while (nxtitem(&ni, (s_char *)&plane)) {
+    while (nxtitem(&ni, &plane)) {
        if (plane.pln_own == player->cnum || plane.pln_own == 0)
            continue;
        if (plane.pln_ship >= 0 || plane.pln_land >= 0)
@@ -332,19 +336,19 @@ prplanes(int x, int y)
            continue;
        if ((plane.pln_own != player->cnum) && plane.pln_own) {
            int rel;
-           s_char *format;
+           char *relstr;
 
            rel = getrel(getnatp(player->cnum), plane.pln_own);
            if (rel == ALLIED)
-               format = "Allied (%s) plane in %s: %s\n";
+               relstr = "Allied";
            else if (rel == FRIENDLY || rel == NEUTRAL)
-               format = "Neutral (%s) plane in %s: %s\n";
+               relstr = "Neutral";
            else
-               format = "Enemy (%s) plane in %s: %s\n";
-           sprintf(report, format, cname(plane.pln_own),
-                   xyas(plane.pln_x, plane.pln_y, player->cnum),
-                   prplane(&plane));
-           pr(report);
+               relstr = "Enemy";
+           pr("%s (%s) plane in %s: %s\n",
+              relstr, cname(plane.pln_own),
+              xyas(plane.pln_x, plane.pln_y, player->cnum),
+              prplane(&plane));
        }
     }
 }