2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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, int wantflags, int nowantflags, natid own)
98 snxtitem_xy(&ni, EF_SHIP, x, y);
99 while (nxtitem(&ni, &ship)) {
100 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
102 if (ship.shp_own != own
103 && getrel(getnatp(ship.shp_own), own) != ALLIED)
105 if (ship.shp_effic < SHP_AIROPS_EFF)
107 mp = &mchr[(int)ship.shp_type];
109 if ((mp->m_flags & wantflags) == 0)
113 if (mp->m_flags & nowantflags)
117 pr(" # owner eff type\n");
120 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
121 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
128 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
138 snxtitem_xy(&ni, EF_LAND, x, y);
139 while (nxtitem(&ni, &land)) {
140 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
142 /* Can't bomb units on ships or other units */
143 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
145 lp = &lchr[(int)land.lnd_type];
148 if ((lp->l_flags & wantflags) == 0)
152 if (lp->l_flags & nowantflags)
156 if (lp->l_flags & L_SPY) {
157 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
162 pr(" # owner eff type\n");
165 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
166 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
173 planesatxy(coord x, coord y, int wantflags, int nowantflags,
174 struct emp_qelem *list)
180 struct plchrstr *plp;
184 snxtitem_xy(&ni, EF_PLANE, x, y);
185 while (nxtitem(&ni, &plane)) {
186 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
188 if (plane.pln_flags & PLN_LAUNCHED)
190 /* Is this plane one of the ones flying somewhere? */
191 if (ac_isflying(&plane, list))
193 plp = &plchr[(int)plane.pln_type];
195 pr(" # owner eff type\n");
199 if ((plp->pl_flags & wantflags) == 0)
203 if (plp->pl_flags & nowantflags)
206 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
207 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
214 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
215 struct plnstr *pp, struct shiplist **head)
225 snxtitem_xy(&ni, EF_SHIP, x, y);
226 while (nxtitem(&ni, &ship)) {
229 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
231 mp = &mchr[(int)ship.shp_type];
233 if ((mp->m_flags & wantflags) == 0)
237 if (mp->m_flags & nowantflags)
240 if (mp->m_flags & M_SUB) {
241 if (roll(100) > pln_hitchance(pp,
242 shp_hardtarget(&ship), EF_SHIP))
245 add_shiplist(ship.shp_uid, head);
247 pr(" # owner eff type\n");
250 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
251 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
258 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
266 snxtitem_xy(&ni, EF_SHIP, x, y);
267 while (nxtitem(&ni, &ship)) {
268 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
270 mp = &mchr[(int)ship.shp_type];
272 if ((mp->m_flags & wantflags) == 0)
276 if (mp->m_flags & nowantflags)
285 * is p a list of ships/planes/units?
292 if (!isdigit(*p) && *p != '/')