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:
45 #include "prototypes.h"
51 shipsatxy(coord x, coord y, int wantflags, int nowantflags)
61 snxtitem_xy(&ni, EF_SHIP, x, y);
62 while (nxtitem(&ni, &ship)) {
65 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
67 mp = &mchr[(int)ship.shp_type];
69 if ((mp->m_flags & wantflags) == 0)
73 if (mp->m_flags & nowantflags)
77 pr(" # owner eff type\n");
80 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
81 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
87 /* This one only shows owned or allied ships */
90 carriersatxy(coord x, coord y, natid own)
99 snxtitem_xy(&ni, EF_SHIP, x, y);
100 while (nxtitem(&ni, &ship)) {
101 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
103 if (ship.shp_own != own
104 && getrel(getnatp(ship.shp_own), own) != ALLIED)
106 if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
109 pr(" # owner eff type\n");
112 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
113 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
120 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
130 snxtitem_xy(&ni, EF_LAND, x, y);
131 while (nxtitem(&ni, &land)) {
132 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
134 /* Can't bomb units on ships or other units */
135 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
137 lp = &lchr[(int)land.lnd_type];
140 if ((lp->l_flags & wantflags) == 0)
144 if (lp->l_flags & nowantflags)
148 if (lp->l_flags & L_SPY) {
149 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
154 pr(" # owner eff type\n");
157 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
158 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
165 planesatxy(coord x, coord y, int wantflags, int nowantflags)
171 struct plchrstr *plp;
175 snxtitem_xy(&ni, EF_PLANE, x, y);
176 while (nxtitem(&ni, &plane)) {
177 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
179 if (plane.pln_flags & PLN_LAUNCHED)
181 plp = &plchr[(int)plane.pln_type];
183 pr(" # owner eff type\n");
187 if ((plp->pl_flags & wantflags) == 0)
191 if (plp->pl_flags & nowantflags)
194 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
195 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
202 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
203 struct plnstr *pp, struct shiplist **head)
213 snxtitem_xy(&ni, EF_SHIP, x, y);
214 while (nxtitem(&ni, &ship)) {
217 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
219 mp = &mchr[(int)ship.shp_type];
221 if ((mp->m_flags & wantflags) == 0)
225 if (mp->m_flags & nowantflags)
228 if (mp->m_flags & M_SUB) {
229 if (roll(100) > pln_hitchance(pp,
230 shp_hardtarget(&ship), EF_SHIP))
233 add_shiplist(ship.shp_uid, head);
235 pr(" # owner eff type\n");
238 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
239 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
246 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
254 snxtitem_xy(&ni, EF_SHIP, x, y);
255 while (nxtitem(&ni, &ship)) {
256 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
258 mp = &mchr[(int)ship.shp_type];
260 if ((mp->m_flags & wantflags) == 0)
264 if (mp->m_flags & nowantflags)
273 adj_units(coord x, coord y, natid own)
278 for (i = DIR_FIRST; i <= DIR_LAST; i++) {
279 getsect(x + diroff[i][0], y + diroff[i][1], §);
280 if (has_units(sect.sct_x, sect.sct_y, own, 0))
287 has_units(coord x, coord y, natid cn, struct lndstr *lp)
292 for (n = 0; ef_read(EF_LAND, n, &land); n++) {
293 if (land.lnd_x != x || land.lnd_y != y)
296 /* Check this unit. If it is this one, we don't want
297 it included in the count. */
298 if (lp->lnd_uid == land.lnd_uid)
301 if (land.lnd_own == cn)
309 * is p a list of ships/planes/units?
316 if (!isdigit(*p) && *p != '/')