]> git.pond.sub.org Git - empserver/commitdiff
Fix pin bomb not to report subs when there are none
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 11 May 2008 11:43:26 +0000 (13:43 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 11 May 2008 11:44:29 +0000 (13:44 +0200)
pin_bomb() computed the number of foreign subs as number of ships less
number of foreign surface ships.  This counted own surface ships as
subs.

Change it to count foreign subs directly.  Closes #906040.

However, shipsatxy(), the function for counting foreign ships, also
lists them.  Add a parameter to suppress that, and change its callers.

include/prototypes.h
src/lib/commands/bomb.c
src/lib/subs/list.c

index 5edadd9697c3cdeb6d3d55451a3dab19b145f993..9c112a8ffeb771c41495a688df092ed53f0e25bc 100644 (file)
@@ -465,7 +465,7 @@ extern double torprange(struct shpstr *);
 extern double fortrange(struct sctstr *);
 extern int roundrange(double);
 /* list.c */
-extern int shipsatxy(coord, coord, int, int);
+extern int shipsatxy(coord, coord, int, int, int);
 extern int carriersatxy(coord, coord, natid);
 extern int unitsatxy(coord, coord, int, int);
 extern int planesatxy(coord, coord, int, int);
index ac74652a8f03cc74edd134802a27a6537843d0c6..842b60472500c6d82040f68d93d83d386ce61de9 100644 (file)
@@ -209,13 +209,11 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        effadv((int)target->sct_effic), dcp->d_name);
     nsubs = 0;
     plp = (struct plist *)list->q_forw;
+    nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
     if (plp->pcp->pl_flags & P_A) {
-       nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
-       nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
+       nsubs = shipsatxy(target->sct_x, target->sct_y, M_SUB, 0, 1);
        if (nsubs > 0)
            pr("Some subs are present in the sector.\n");
-    } else {
-       nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
     }
     nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
     nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
@@ -481,7 +479,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
                                   &plp->plane, &head);
        else
-           nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
+           nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
        if (nships == 0) {
            pr("%s could not find any ships!\n", prplane(&plp->plane));
            continue;
@@ -501,7 +499,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
                if (plp->pcp->pl_flags & P_A)
                    print_shiplist(head);
                else
-                   shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
+                   shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
                continue;
            }
            if (*q == 'd')
index 3c9574c151644ae8eba8c83e6fbfe95574522feb..6c206e69861c976d45280afd4cbc2321f38d0eaa 100644 (file)
@@ -48,7 +48,7 @@
 #include "xy.h"
 
 int
-shipsatxy(coord x, coord y, int wantflags, int nowantflags)
+shipsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
 {
     int first;
     int ships;
@@ -73,12 +73,14 @@ shipsatxy(coord x, coord y, int wantflags, int nowantflags)
            if (mp->m_flags & nowantflags)
                continue;
        }
-       if (first) {
-           pr(" #          owner           eff       type\n");
-           first = 0;
+       if (!only_count) {
+           if (first) {
+               pr(" #          owner           eff       type\n");
+               first = 0;
+           }
+           pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
+              cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
        }
-       pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
-          cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
        ships++;
     }
     return ships;