2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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:
48 #include "prototypes.h"
50 extern s_char *effadv(int);
53 shipsatxy(coord x, coord y, int wantflags, int nowantflags)
63 snxtitem_xy(&ni, EF_SHIP, x, y);
64 while (nxtitem(&ni, (s_char *)&ship)) {
67 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
69 mp = &mchr[(int)ship.shp_type];
71 if ((mp->m_flags & wantflags) == 0)
75 if (mp->m_flags & nowantflags)
79 pr(" # owner eff type\n");
82 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
84 effadv(ship.shp_effic), prship(&ship));
90 /* This one only shows owned or allied ships */
93 carriersatxy(coord x, coord y, int wantflags, int nowantflags, natid own)
104 snxtitem_xy(&ni, EF_SHIP, x, y);
105 while (nxtitem(&ni, (s_char *)&ship)) {
106 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
108 allied = (getrel(getnatp(ship.shp_own), own) == ALLIED);
109 if ((ship.shp_own != own) & !allied)
111 mp = &mchr[(int)ship.shp_type];
113 if ((mp->m_flags & wantflags) == 0)
117 if (mp->m_flags & nowantflags)
121 pr(" # owner eff type\n");
124 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
126 effadv(ship.shp_effic),
134 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
145 snxtitem_xy(&ni, EF_LAND, x, y);
146 while (nxtitem(&ni, (s_char *)&land)) {
147 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
149 /* Can't bomb units on ships or other units */
150 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
152 lp = &lchr[(int)land.lnd_type];
155 if ((lp->l_flags & wantflags) == 0)
159 if (lp->l_flags & nowantflags)
163 if (lp->l_flags & L_SPY) {
164 odds = (double)(100 - land.lnd_effic) + 0.10;
170 pr(" # owner eff type\n");
173 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
175 effadv(land.lnd_effic), prland(&land));
182 planesatxy(coord x, coord y, int wantflags, int nowantflags, struct emp_qelem *list)
188 struct plchrstr *plp;
192 snxtitem_xy(&ni, EF_PLANE, x, y);
193 while (nxtitem(&ni, (s_char *)&plane)) {
194 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
196 if (plane.pln_flags & PLN_LAUNCHED)
198 /* Is this plane one of the ones flying somewhere? */
199 if (ac_isflying(&plane, list))
201 plp = &plchr[(int)plane.pln_type];
203 pr(" # owner eff type\n");
207 if ((plp->pl_flags & wantflags) == 0)
211 if (plp->pl_flags & nowantflags)
214 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
215 cname(plane.pln_own),
216 effadv(plane.pln_effic), prplane(&plane));
223 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags, struct plnstr *pp, struct shiplook *head)
233 snxtitem_xy(&ni, EF_SHIP, x, y);
234 while (nxtitem(&ni, (s_char *)&ship)) {
237 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
239 mp = &mchr[(int)ship.shp_type];
241 if ((mp->m_flags & wantflags) == 0)
245 if (mp->m_flags & nowantflags)
248 if (mp->m_flags & M_SUB){
249 if (roll(100) > pln_hitchance(pp,
250 shp_hardtarget(&ship),
254 set_have_found(ship.shp_uid,head);
256 pr(" # owner eff type\n");
259 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
261 effadv(ship.shp_effic), prship(&ship));
268 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
276 snxtitem_xy(&ni, EF_SHIP, x, y);
277 while (nxtitem(&ni, (s_char *)&ship)) {
278 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
280 mp = &mchr[(int)ship.shp_type];
282 if ((mp->m_flags & wantflags) == 0)
286 if (mp->m_flags & nowantflags)
295 * is p a list of ships/planes/units?
307 if (!isdigit(*(p+x)) && (*(p+x) != '/'))