bomb: Fix ship list header for ASW planes
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 10 Jan 2015 06:22:05 +0000 (07:22 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Mar 2015 07:20:49 +0000 (08:20 +0100)
The code to list ships got triplicated in Chainsaw.  Empire 2 screwed
up one copy in its global replace of owner by player->owner.

Fix it by de-duplicating.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/plane.h
include/prototypes.h
src/lib/subs/aswplnsubs.c
src/lib/subs/list.c

index bbf2709f4bb08193e4e446404eb21a5ee866df49..242c933dd89ebcd218bb33895375f16a0a180f93 100644 (file)
@@ -171,6 +171,5 @@ extern int ac_damage_plane(struct plnstr *, natid, int, int, char *);
 extern int on_shiplist(int, struct shiplist *);
 extern void add_shiplist(int, struct shiplist **);
 extern void free_shiplist(struct shiplist **);
-extern void print_shiplist(struct shiplist *);
 
 #endif
index a9e4556d72620040dd89253e2a6d128afdd9fdb7..ecb014bfc353056d72e094bc2fe079d0df1d0458 100644 (file)
@@ -450,6 +450,7 @@ extern int unitsatxy(coord, coord, int, int, int);
 extern int planesatxy(coord, coord, int, int);
 extern int asw_shipsatxy(coord, coord, int, int, struct plnstr *,
                         struct shiplist **);
+extern void print_shiplist(struct shiplist *);
 extern int has_units(coord, coord, natid);
 extern int adj_units(coord, coord, natid);
 extern int islist(char *);
index f9827c844a409ced61cfa9d39a0c9ebe5fca0e94..4e93ebf98cef9a2f2e7290a84f90ef46f1bb2945 100644 (file)
@@ -92,25 +92,3 @@ free_shiplist(struct shiplist **head)
     }
     *head = NULL;
 }
-
-void
-print_shiplist(struct shiplist *head)
-{
-    struct shiplist *s;
-    int first;
-    struct shpstr ship;
-
-    s = head;
-    first = 1;
-
-    while (s != NULL) {
-       getship(s->uid, &ship);
-       if (first) {
-           pr(" #          player->owner           eff        type\n");
-           first = 0;
-       }
-       pr("(#%3d) %10.10s  %12.12s  %s\n", ship.shp_uid,
-          cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
-       s = s->next;
-    }
-}
index 728bc7d9e9735921563fc83a9f011b932876d42c..02a712094b8860806bf8e31d26a35328edda86cf 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Dave Pare, 1986
- *     Markus Armbruster, 2003-2014
+ *     Markus Armbruster, 2003-2015
  */
 
 #include <config.h>
 #include "ship.h"
 #include "xy.h"
 
+static void
+list_ship(struct shpstr *sp, int first)
+{
+    if (first)
+       pr(" #          owner           eff       type\n");
+    pr("(#%3d) %10.10s  %12.12s  %s\n", sp->shp_uid,
+       cname(sp->shp_own), effadv(sp->shp_effic), prship(sp));
+}
+
 int
 shipsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
 {
@@ -72,12 +81,8 @@ shipsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
            if (mp->m_flags & nowantflags)
                continue;
        }
-       if (!only_count) {
-           if (!ships)
-               pr(" #          owner           eff       type\n");
-           pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
-              cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
-       }
+       if (!only_count)
+           list_ship(&ship, !ships);
        ships++;
     }
     return ships;
@@ -101,10 +106,7 @@ carriersatxy(coord x, coord y, natid own)
            continue;
        if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
            continue;
-       if (!ships)
-           pr(" #          owner           eff       type\n");
-       pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
-          cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
+       list_ship(&ship, !ships);
        ships++;
     }
     return ships;
@@ -219,15 +221,24 @@ asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
                continue;
        }
        add_shiplist(ship.shp_uid, head);
-       if (!ships)
-           pr(" #          owner           eff       type\n");
-       pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
-          cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
+       list_ship(&ship, !ships);
        ships++;
     }
     return ships;
 }
 
+void
+print_shiplist(struct shiplist *head)
+{
+    struct shiplist *s;
+    struct shpstr ship;
+
+    for (s = head; s; s = s->next) {
+       getship(s->uid, &ship);
+       list_ship(&ship, s == head);
+    }
+}
+
 int
 adj_units(coord x, coord y, natid own)
 {