]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/list.c
License upgrade to GPL version 3 or later
[empserver] / src / lib / subs / list.c
index 3c9574c151644ae8eba8c83e6fbfe95574522feb..13eb92cf7f07986b18e23ad9aadaedc7e5a8863c 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2011, 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/>.
  *
  *  ---
  *
@@ -26,7 +25,7 @@
  *  ---
  *
  *  list.c: List ships, planes, units at a given x,y
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  */
@@ -48,7 +47,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 +72,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;
@@ -100,8 +101,7 @@ carriersatxy(coord x, coord y, natid own)
     while (nxtitem(&ni, &ship)) {
        if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
            continue;
-       if (ship.shp_own != own
-           && getrel(getnatp(ship.shp_own), own) != ALLIED)
+       if (relations_with(ship.shp_own, own) != ALLIED)
            continue;
        if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
            continue;
@@ -176,6 +176,8 @@ planesatxy(coord x, coord y, int wantflags, int nowantflags)
     while (nxtitem(&ni, &plane)) {
        if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
            continue;
+       if (plane.pln_ship >= 0 || plane.pln_land >= 0)
+           continue;
        if (plane.pln_flags & PLN_LAUNCHED)
            continue;
        plp = &plchr[(int)plane.pln_type];
@@ -242,33 +244,6 @@ asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
     return ships;
 }
 
-int
-num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
-{
-    int ships;
-    struct nstr_item ni;
-    struct mchrstr *mp;
-    struct shpstr ship;
-
-    ships = 0;
-    snxtitem_xy(&ni, EF_SHIP, x, y);
-    while (nxtitem(&ni, &ship)) {
-       if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
-           continue;
-       mp = &mchr[(int)ship.shp_type];
-       if (wantflags) {
-           if ((mp->m_flags & wantflags) == 0)
-               continue;
-       }
-       if (nowantflags) {
-           if (mp->m_flags & nowantflags)
-               continue;
-       }
-       ships++;
-    }
-    return ships;
-}
-
 int
 adj_units(coord x, coord y, natid own)
 {
@@ -277,7 +252,7 @@ adj_units(coord x, coord y, natid own)
 
     for (i = DIR_FIRST; i <= DIR_LAST; i++) {
        getsect(x + diroff[i][0], y + diroff[i][1], &sect);
-       if (has_units(sect.sct_x, sect.sct_y, own, 0))
+       if (has_units(sect.sct_x, sect.sct_y, own, NULL))
            return 1;
     }
     return 0;