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,
83 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
89 /* This one only shows owned or allied ships */
92 carriersatxy(coord x, coord y, int wantflags, int nowantflags, natid own)
103 snxtitem_xy(&ni, EF_SHIP, x, y);
104 while (nxtitem(&ni, (s_char *)&ship)) {
105 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
107 allied = (getrel(getnatp(ship.shp_own), own) == ALLIED);
108 if ((ship.shp_own != own) & !allied)
110 mp = &mchr[(int)ship.shp_type];
112 if ((mp->m_flags & wantflags) == 0)
116 if (mp->m_flags & nowantflags)
120 pr(" # owner eff type\n");
123 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
124 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
131 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
141 snxtitem_xy(&ni, EF_LAND, x, y);
142 while (nxtitem(&ni, (s_char *)&land)) {
143 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
145 /* Can't bomb units on ships or other units */
146 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
148 lp = &lchr[(int)land.lnd_type];
151 if ((lp->l_flags & wantflags) == 0)
155 if (lp->l_flags & nowantflags)
159 if (lp->l_flags & L_SPY) {
160 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
165 pr(" # owner eff type\n");
168 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
169 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
176 planesatxy(coord x, coord y, int wantflags, int nowantflags,
177 struct emp_qelem *list)
183 struct plchrstr *plp;
187 snxtitem_xy(&ni, EF_PLANE, x, y);
188 while (nxtitem(&ni, (s_char *)&plane)) {
189 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
191 if (plane.pln_flags & PLN_LAUNCHED)
193 /* Is this plane one of the ones flying somewhere? */
194 if (ac_isflying(&plane, list))
196 plp = &plchr[(int)plane.pln_type];
198 pr(" # owner eff type\n");
202 if ((plp->pl_flags & wantflags) == 0)
206 if (plp->pl_flags & nowantflags)
209 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
210 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
217 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
218 struct plnstr *pp, struct shiplook *head)
228 snxtitem_xy(&ni, EF_SHIP, x, y);
229 while (nxtitem(&ni, (s_char *)&ship)) {
232 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
234 mp = &mchr[(int)ship.shp_type];
236 if ((mp->m_flags & wantflags) == 0)
240 if (mp->m_flags & nowantflags)
243 if (mp->m_flags & M_SUB) {
244 if (roll(100) > pln_hitchance(pp,
245 shp_hardtarget(&ship), EF_SHIP))
248 set_have_found(ship.shp_uid, head);
250 pr(" # owner eff type\n");
253 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
254 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
261 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
269 snxtitem_xy(&ni, EF_SHIP, x, y);
270 while (nxtitem(&ni, (s_char *)&ship)) {
271 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
273 mp = &mchr[(int)ship.shp_type];
275 if ((mp->m_flags & wantflags) == 0)
279 if (mp->m_flags & nowantflags)
288 * is p a list of ships/planes/units?
300 if (!isdigit(*(p + x)) && (*(p + x) != '/'))