2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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, int only_count)
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)
78 pr(" # owner eff type\n");
81 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
82 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, natid own)
101 snxtitem_xy(&ni, EF_SHIP, x, y);
102 while (nxtitem(&ni, &ship)) {
103 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
105 if (relations_with(ship.shp_own, own) != ALLIED)
107 if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
110 pr(" # owner eff type\n");
113 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
114 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
121 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
131 snxtitem_xy(&ni, EF_LAND, x, y);
132 while (nxtitem(&ni, &land)) {
133 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
135 /* Can't bomb units on ships or other units */
136 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
138 lp = &lchr[(int)land.lnd_type];
141 if ((lp->l_flags & wantflags) == 0)
145 if (lp->l_flags & nowantflags)
149 if (lp->l_flags & L_SPY) {
150 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
155 pr(" # owner eff type\n");
158 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
159 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
166 planesatxy(coord x, coord y, int wantflags, int nowantflags)
172 struct plchrstr *plp;
176 snxtitem_xy(&ni, EF_PLANE, x, y);
177 while (nxtitem(&ni, &plane)) {
178 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
180 if (plane.pln_ship >= 0 || plane.pln_land >= 0)
182 if (plane.pln_flags & PLN_LAUNCHED)
184 plp = &plchr[(int)plane.pln_type];
186 pr(" # owner eff type\n");
190 if ((plp->pl_flags & wantflags) == 0)
194 if (plp->pl_flags & nowantflags)
197 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
198 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
205 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
206 struct plnstr *pp, struct shiplist **head)
216 snxtitem_xy(&ni, EF_SHIP, x, y);
217 while (nxtitem(&ni, &ship)) {
220 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
222 mp = &mchr[(int)ship.shp_type];
224 if ((mp->m_flags & wantflags) == 0)
228 if (mp->m_flags & nowantflags)
231 if (mp->m_flags & M_SUB) {
232 if (roll(100) > pln_hitchance(pp,
233 shp_hardtarget(&ship), EF_SHIP))
236 add_shiplist(ship.shp_uid, head);
238 pr(" # owner eff type\n");
241 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
242 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
249 adj_units(coord x, coord y, natid own)
254 for (i = DIR_FIRST; i <= DIR_LAST; i++) {
255 getsect(x + diroff[i][0], y + diroff[i][1], §);
256 if (has_units(sect.sct_x, sect.sct_y, own, NULL))
263 has_units(coord x, coord y, natid cn, struct lndstr *lp)
268 for (n = 0; ef_read(EF_LAND, n, &land); n++) {
269 if (land.lnd_x != x || land.lnd_y != y)
272 /* Check this unit. If it is this one, we don't want
273 it included in the count. */
274 if (lp->lnd_uid == land.lnd_uid)
277 if (land.lnd_own == cn)
285 * is p a list of ships/planes/units?
292 if (!isdigit(*p) && *p != '/')