2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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:
45 #include "prototypes.h"
48 shipsatxy(coord x, coord y, int wantflags, int nowantflags)
58 snxtitem_xy(&ni, EF_SHIP, x, y);
59 while (nxtitem(&ni, &ship)) {
62 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
64 mp = &mchr[(int)ship.shp_type];
66 if ((mp->m_flags & wantflags) == 0)
70 if (mp->m_flags & nowantflags)
74 pr(" # owner eff type\n");
77 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
78 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
84 /* This one only shows owned or allied ships */
87 carriersatxy(coord x, coord y, int wantflags, int nowantflags, 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 (ship.shp_effic < SHP_AIROPS_EFF)
106 mp = &mchr[(int)ship.shp_type];
108 if ((mp->m_flags & wantflags) == 0)
112 if (mp->m_flags & nowantflags)
116 pr(" # owner eff type\n");
119 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
120 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
127 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
137 snxtitem_xy(&ni, EF_LAND, x, y);
138 while (nxtitem(&ni, &land)) {
139 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
141 /* Can't bomb units on ships or other units */
142 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
144 lp = &lchr[(int)land.lnd_type];
147 if ((lp->l_flags & wantflags) == 0)
151 if (lp->l_flags & nowantflags)
155 if (lp->l_flags & L_SPY) {
156 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
161 pr(" # owner eff type\n");
164 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
165 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
172 planesatxy(coord x, coord y, int wantflags, int nowantflags,
173 struct emp_qelem *list)
179 struct plchrstr *plp;
183 snxtitem_xy(&ni, EF_PLANE, x, y);
184 while (nxtitem(&ni, &plane)) {
185 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
187 if (plane.pln_flags & PLN_LAUNCHED)
189 /* Is this plane one of the ones flying somewhere? */
190 if (ac_isflying(&plane, list))
192 plp = &plchr[(int)plane.pln_type];
194 pr(" # owner eff type\n");
198 if ((plp->pl_flags & wantflags) == 0)
202 if (plp->pl_flags & nowantflags)
205 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
206 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
213 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
214 struct plnstr *pp, struct shiplist **head)
224 snxtitem_xy(&ni, EF_SHIP, x, y);
225 while (nxtitem(&ni, &ship)) {
228 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
230 mp = &mchr[(int)ship.shp_type];
232 if ((mp->m_flags & wantflags) == 0)
236 if (mp->m_flags & nowantflags)
239 if (mp->m_flags & M_SUB) {
240 if (roll(100) > pln_hitchance(pp,
241 shp_hardtarget(&ship), EF_SHIP))
244 add_shiplist(ship.shp_uid, head);
246 pr(" # owner eff type\n");
249 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
250 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
257 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
265 snxtitem_xy(&ni, EF_SHIP, x, y);
266 while (nxtitem(&ni, &ship)) {
267 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
269 mp = &mchr[(int)ship.shp_type];
271 if ((mp->m_flags & wantflags) == 0)
275 if (mp->m_flags & nowantflags)
284 * is p a list of ships/planes/units?
296 if (!isdigit(*(p + x)) && (*(p + x) != '/'))