2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2020, 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-2016
45 #include "prototypes.h"
51 list_ship(struct shpstr *sp, int first)
54 pr(" # owner eff type\n");
55 pr("(#%3d) %10.10s %12.12s %s\n", sp->shp_uid,
56 cname(sp->shp_own), effadv(sp->shp_effic), prship(sp));
60 shipsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
68 snxtitem_xy(&ni, EF_SHIP, x, y);
69 while (nxtitem(&ni, &ship)) {
74 mp = &mchr[(int)ship.shp_type];
76 if ((mp->m_flags & wantflags) == 0)
80 if (mp->m_flags & nowantflags)
84 list_ship(&ship, !ships);
90 /* This one only shows owned or allied ships */
93 carriersatxy(coord x, coord y, natid own)
100 snxtitem_xy(&ni, EF_SHIP, x, y);
101 while (nxtitem(&ni, &ship)) {
104 if (relations_with(ship.shp_own, own) != ALLIED)
106 if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
108 list_ship(&ship, !ships);
115 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
123 snxtitem_xy(&ni, EF_LAND, x, y);
124 while (nxtitem(&ni, &land)) {
127 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
129 lp = &lchr[(int)land.lnd_type];
132 if ((lp->l_flags & wantflags) == 0)
136 if (lp->l_flags & nowantflags)
141 pr(" # owner eff type\n");
142 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
143 cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
150 planesatxy(coord x, coord y, int wantflags, int nowantflags)
155 struct plchrstr *plp;
158 snxtitem_xy(&ni, EF_PLANE, x, y);
159 while (nxtitem(&ni, &plane)) {
162 if (plane.pln_ship >= 0 || plane.pln_land >= 0)
164 if (plane.pln_flags & PLN_LAUNCHED)
166 plp = &plchr[(int)plane.pln_type];
168 pr(" # owner eff type\n");
170 if ((plp->pl_flags & wantflags) == 0)
174 if (plp->pl_flags & nowantflags)
177 pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
178 cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
185 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
186 struct plnstr *pp, struct shiplist **head)
194 snxtitem_xy(&ni, EF_SHIP, x, y);
195 while (nxtitem(&ni, &ship)) {
200 mp = &mchr[(int)ship.shp_type];
202 if ((mp->m_flags & wantflags) == 0)
206 if (mp->m_flags & nowantflags)
209 if (mp->m_flags & M_SUB) {
210 if (!pct_chance(pln_hitchance(pp,
211 shp_hardtarget(&ship), EF_SHIP)))
214 add_shiplist(ship.shp_uid, head);
215 list_ship(&ship, !ships);
222 print_shiplist(struct shiplist *head)
227 for (s = head; s; s = s->next) {
228 getship(s->uid, &ship);
229 list_ship(&ship, s == head);
234 adj_units(coord x, coord y, natid own)
239 for (i = DIR_FIRST; i <= DIR_LAST; i++) {
240 getsect(x + diroff[i][0], y + diroff[i][1], §);
241 if (has_units(sect.sct_x, sect.sct_y, own))
248 has_units(coord x, coord y, natid cn)
253 for (n = 0; ef_read(EF_LAND, n, &land); n++) {
254 if (land.lnd_x != x || land.lnd_y != y)
256 if (land.lnd_own == cn)