]> git.pond.sub.org Git - empserver/commitdiff
Simplify control flow in spy()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 14 Jun 2008 15:51:26 +0000 (17:51 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 14 Jun 2008 15:51:26 +0000 (17:51 +0200)
Rearrange so that we make contact (each way) and print the spy report
in just one place.  No functional change.

src/lib/commands/spy.c

index 4ae5711f86678cfdc4248cd7392f5d4e78613fd2..960f12a22de2895448935dcb6e83ff515a235653 100644 (file)
@@ -57,7 +57,6 @@ static void spyline(struct sctstr *sp);
 int
 spy(void)
 {
-    int caught;
     natid own;
     int relat;
     coord x, y;
@@ -145,56 +144,45 @@ spy(void)
                insert(table, &t_len, nx, ny);
                continue;
            }
-           /* catch spy N/200 chance, N = # military */
-           caught = chance(dsect.sct_item[I_MILIT] / 200.0);
+
            own = dsect.sct_own;
-           /* determine spyee relations with spyer */
            relat = getrel(getnatp(own), player->cnum);
-           if (relat == NEUTRAL && caught) {
-               /* neutral spy-ee */
-               pr("Spy deported from %s\n", xyas(nx, ny, player->cnum));
-               if (own != 0)
-                   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) {
-               /* hostile spy-ee */
-               pr("BANG!! A spy was shot in %s\n",
-                  xyas(nx, ny, player->cnum));
-               military--;
-               if (own != 0)
-                   wu(0, own, "%s (#%d) spy caught in %s\n",
-                      cname(player->cnum), player->cnum,
-                      xyas(nx, ny, own));
-               nreport(player->cnum, N_SPY_SHOT, own, 1);
+           if (relat <= NEUTRAL
+               && chance(dsect.sct_item[I_MILIT] / 200.0)) {
+               /* spy caught */
+               if (relat == NEUTRAL) {
+                   /* deport spy */
+                   pr("Spy deported from %s\n",
+                      xyas(nx, ny, player->cnum));
+                   if (own != 0)
+                       wu(0, own, "%s (#%d) spy deported from %s\n",
+                          cname(player->cnum), player->cnum,
+                          xyas(nx, ny, own));
+               } else {
+                   /* execute spy */
+                   pr("BANG!! A spy was shot in %s\n",
+                      xyas(nx, ny, player->cnum));
+                   military--;
+                   if (own != 0)
+                       wu(0, own, "%s (#%d) spy caught in %s\n",
+                          cname(player->cnum), player->cnum,
+                          xyas(nx, ny, own));
+               }
                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,
-                                  dchr[dsect.sct_type].d_mnem, 0);
-               prunits(dsect.sct_x, dsect.sct_y);
-               prplanes(dsect.sct_x, dsect.sct_y);
-               if (opt_HIDDEN)
-                   setcont(player->cnum, own, FOUND_SPY);
-           }
-           /*
-            * If you have a recon unit, it'll
-            * see the sector anyway...
-            */
-           if (nrecon && caught) {
-               insert(table, &t_len, nx, ny);
-               spyline(&dsect);
-               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)
-                   setcont(player->cnum, own, FOUND_SPY);
+               if (!nrecon)    /* unless you have a recon unit */
+                   continue;   /* no report from caught spy */
            }
+
+           /* spy report */
+           insert(table, &t_len, nx, ny);
+           spyline(&dsect);
+           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)
+               setcont(player->cnum, own, FOUND_SPY);
        }
        /* subtract any military if necessary */
        if ((savemil != military) && (savemil > 0)) {