2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * list.c: List ships, planes, units at a given x,y
30 * Known contributors to this file:
44 #include "prototypes.h"
49 shipsatxy(coord x, coord y, int wantflags, int nowantflags)
59 snxtitem_xy(&ni, EF_SHIP, x, y);
60 while (nxtitem(&ni, &ship)) {
63 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
65 mp = &mchr[(int)ship.shp_type];
67 if ((mp->m_flags & wantflags) == 0)
71 if (mp->m_flags & nowantflags)
75 pr(" # owner eff type\n");
78 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
79 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
85 /* This one only shows owned or allied ships */
88 carriersatxy(coord x, coord y, natid own)
97 snxtitem_xy(&ni, EF_SHIP, x, y);
98 while (nxtitem(&ni, &ship)) {
99 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
101 if (ship.shp_own != own
102 && getrel(getnatp(ship.shp_own), own) != ALLIED)
104 if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
107 pr(" # owner eff type\n");
110 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
111 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
118 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
128 snxtitem_xy(&ni, EF_LAND, x, y);
129 while (nxtitem(&ni, &land)) {
130 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
132 /* Can't bomb units on ships or other units */
133 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
135 lp = &lchr[(int)land.lnd_type];
138 if ((lp->l_flags & wantflags) == 0)
142 if (lp->l_flags & nowantflags)
146 if (lp->l_flags & L_SPY) {
147 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
152 pr(" # owner eff type\n");
155 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
156 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
163 planesatxy(coord x, coord y, int wantflags, int nowantflags,
164 struct emp_qelem *list)
170 struct plchrstr *plp;
174 snxtitem_xy(&ni, EF_PLANE, x, y);
175 while (nxtitem(&ni, &plane)) {
176 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
178 if (plane.pln_flags & PLN_LAUNCHED)
180 /* Is this plane one of the ones flying somewhere? */
181 if (ac_isflying(&plane, list))
183 plp = &plchr[(int)plane.pln_type];
185 pr(" # owner eff type\n");
189 if ((plp->pl_flags & wantflags) == 0)
193 if (plp->pl_flags & nowantflags)
196 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
197 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
204 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
205 struct plnstr *pp, struct shiplist **head)
215 snxtitem_xy(&ni, EF_SHIP, x, y);
216 while (nxtitem(&ni, &ship)) {
219 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
221 mp = &mchr[(int)ship.shp_type];
223 if ((mp->m_flags & wantflags) == 0)
227 if (mp->m_flags & nowantflags)
230 if (mp->m_flags & M_SUB) {
231 if (roll(100) > pln_hitchance(pp,
232 shp_hardtarget(&ship), EF_SHIP))
235 add_shiplist(ship.shp_uid, head);
237 pr(" # owner eff type\n");
240 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
241 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
248 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
256 snxtitem_xy(&ni, EF_SHIP, x, y);
257 while (nxtitem(&ni, &ship)) {
258 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
260 mp = &mchr[(int)ship.shp_type];
262 if ((mp->m_flags & wantflags) == 0)
266 if (mp->m_flags & nowantflags)
275 * is p a list of ships/planes/units?
282 if (!isdigit(*p) && *p != '/')