2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * list.c: List ships, planes, units at a given x,y
29 * Known contributors to this file:
31 * Markus Armbruster, 2003-2014
46 #include "prototypes.h"
52 shipsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
62 snxtitem_xy(&ni, EF_SHIP, x, y);
63 while (nxtitem(&ni, &ship)) {
66 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
68 mp = &mchr[(int)ship.shp_type];
70 if ((mp->m_flags & wantflags) == 0)
74 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));
90 /* This one only shows owned or allied ships */
93 carriersatxy(coord x, coord y, natid own)
102 snxtitem_xy(&ni, EF_SHIP, x, y);
103 while (nxtitem(&ni, &ship)) {
104 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
106 if (relations_with(ship.shp_own, own) != ALLIED)
108 if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
111 pr(" # owner eff type\n");
114 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
115 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
122 unitsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
132 snxtitem_xy(&ni, EF_LAND, x, y);
133 while (nxtitem(&ni, &land)) {
134 if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
136 /* Can't bomb units on ships or other units */
137 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
139 lp = &lchr[(int)land.lnd_type];
142 if ((lp->l_flags & wantflags) == 0)
146 if (lp->l_flags & nowantflags)
150 if (lp->l_flags & L_SPY) {
151 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
157 pr(" # owner eff type\n");
160 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
161 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
169 planesatxy(coord x, coord y, int wantflags, int nowantflags)
175 struct plchrstr *plp;
179 snxtitem_xy(&ni, EF_PLANE, x, y);
180 while (nxtitem(&ni, &plane)) {
181 if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
183 if (plane.pln_ship >= 0 || plane.pln_land >= 0)
185 if (plane.pln_flags & PLN_LAUNCHED)
187 plp = &plchr[(int)plane.pln_type];
189 pr(" # owner eff type\n");
193 if ((plp->pl_flags & wantflags) == 0)
197 if (plp->pl_flags & nowantflags)
200 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
201 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
208 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
209 struct plnstr *pp, struct shiplist **head)
219 snxtitem_xy(&ni, EF_SHIP, x, y);
220 while (nxtitem(&ni, &ship)) {
223 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
225 mp = &mchr[(int)ship.shp_type];
227 if ((mp->m_flags & wantflags) == 0)
231 if (mp->m_flags & nowantflags)
234 if (mp->m_flags & M_SUB) {
235 if (!pct_chance(pln_hitchance(pp,
236 shp_hardtarget(&ship), EF_SHIP)))
239 add_shiplist(ship.shp_uid, head);
241 pr(" # owner eff type\n");
244 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
245 cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
252 adj_units(coord x, coord y, natid own)
257 for (i = DIR_FIRST; i <= DIR_LAST; i++) {
258 getsect(x + diroff[i][0], y + diroff[i][1], §);
259 if (has_units(sect.sct_x, sect.sct_y, own))
266 has_units(coord x, coord y, natid cn)
271 for (n = 0; ef_read(EF_LAND, n, &land); n++) {
272 if (land.lnd_x != x || land.lnd_y != y)
274 if (land.lnd_own == cn)
282 * is p a list of ships/planes/units?
289 if (!isdigit(*p) && *p != '/')