]> git.pond.sub.org Git - empserver/blob - src/lib/subs/list.c
Add some missing declarations to headers. Remove some redundant
[empserver] / src / lib / subs / list.c
1 /*
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
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  list.c: List ships, planes, units at a given x,y
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "news.h"
38 #include "ship.h"
39 #include "land.h"
40 #include "sect.h"
41 #include "nuke.h"
42 #include "plane.h"
43 #include "nat.h"
44 #include "item.h"
45 #include "xy.h"
46 #include "nsc.h"
47 #include "file.h"
48 #include "prototypes.h"
49
50 int
51 shipsatxy(coord x, coord y, int wantflags, int nowantflags)
52 {
53     int first;
54     int ships;
55     struct nstr_item ni;
56     struct mchrstr *mp;
57     struct shpstr ship;
58
59     first = 1;
60     ships = 0;
61     snxtitem_xy(&ni, EF_SHIP, x, y);
62     while (nxtitem(&ni, (s_char *)&ship)) {
63         if (player->owner)
64             continue;
65         if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
66             continue;
67         mp = &mchr[(int)ship.shp_type];
68         if (wantflags) {
69             if ((mp->m_flags & wantflags) == 0)
70                 continue;
71         }
72         if (nowantflags) {
73             if (mp->m_flags & nowantflags)
74                 continue;
75         }
76         if (first) {
77             pr(" #          owner           eff       type\n");
78             first = 0;
79         }
80         pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
81            cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
82         ships++;
83     }
84     return ships;
85 }
86
87 /* This one only shows owned or allied ships */
88
89 int
90 carriersatxy(coord x, coord y, int wantflags, int nowantflags, natid own)
91 {
92     int first;
93     int ships;
94     struct nstr_item ni;
95     struct mchrstr *mp;
96     struct shpstr ship;
97     int allied;
98
99     first = 1;
100     ships = 0;
101     snxtitem_xy(&ni, EF_SHIP, x, y);
102     while (nxtitem(&ni, (s_char *)&ship)) {
103         if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
104             continue;
105         allied = (getrel(getnatp(ship.shp_own), own) == ALLIED);
106         if ((ship.shp_own != own) & !allied)
107             continue;
108         mp = &mchr[(int)ship.shp_type];
109         if (wantflags) {
110             if ((mp->m_flags & wantflags) == 0)
111                 continue;
112         }
113         if (nowantflags) {
114             if (mp->m_flags & nowantflags)
115                 continue;
116         }
117         if (first) {
118             pr(" #          owner           eff       type\n");
119             first = 0;
120         }
121         pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
122            cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
123         ships++;
124     }
125     return ships;
126 }
127
128 int
129 unitsatxy(coord x, coord y, int wantflags, int nowantflags)
130 {
131     int first;
132     int units;
133     struct nstr_item ni;
134     struct lchrstr *lp;
135     struct lndstr land;
136
137     first = 1;
138     units = 0;
139     snxtitem_xy(&ni, EF_LAND, x, y);
140     while (nxtitem(&ni, (s_char *)&land)) {
141         if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
142             continue;
143         /* Can't bomb units on ships or other units */
144         if (land.lnd_ship >= 0 || land.lnd_land >= 0)
145             continue;
146         lp = &lchr[(int)land.lnd_type];
147
148         if (wantflags) {
149             if ((lp->l_flags & wantflags) == 0)
150                 continue;
151         }
152         if (nowantflags) {
153             if (lp->l_flags & nowantflags)
154                 continue;
155         }
156
157         if (lp->l_flags & L_SPY) {
158             if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
159                 continue;
160         }
161
162         if (first) {
163             pr(" #          owner           eff       type\n");
164             first = 0;
165         }
166         pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
167            cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
168         units++;
169     }
170     return units;
171 }
172
173 int
174 planesatxy(coord x, coord y, int wantflags, int nowantflags,
175            struct emp_qelem *list)
176 {
177     int first;
178     int planes;
179     struct plnstr plane;
180     struct nstr_item ni;
181     struct plchrstr *plp;
182
183     planes = 0;
184     first = 1;
185     snxtitem_xy(&ni, EF_PLANE, x, y);
186     while (nxtitem(&ni, (s_char *)&plane)) {
187         if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
188             continue;
189         if (plane.pln_flags & PLN_LAUNCHED)
190             continue;
191         /* Is this plane one of the ones flying somewhere? */
192         if (ac_isflying(&plane, list))
193             continue;
194         plp = &plchr[(int)plane.pln_type];
195         if (first) {
196             pr(" #          owner           eff       type\n");
197             first = 0;
198         }
199         if (wantflags) {
200             if ((plp->pl_flags & wantflags) == 0)
201                 continue;
202         }
203         if (nowantflags) {
204             if (plp->pl_flags & nowantflags)
205                 continue;
206         }
207         pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
208            cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane));
209         planes++;
210     }
211     return planes;
212 }
213
214 int
215 asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
216               struct plnstr *pp, struct shiplook *head)
217 {
218     int first;
219     int ships;
220     struct nstr_item ni;
221     struct mchrstr *mp;
222     struct shpstr ship;
223
224     first = 1;
225     ships = 0;
226     snxtitem_xy(&ni, EF_SHIP, x, y);
227     while (nxtitem(&ni, (s_char *)&ship)) {
228         if (player->owner)
229             continue;
230         if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
231             continue;
232         mp = &mchr[(int)ship.shp_type];
233         if (wantflags) {
234             if ((mp->m_flags & wantflags) == 0)
235                 continue;
236         }
237         if (nowantflags) {
238             if (mp->m_flags & nowantflags)
239                 continue;
240         }
241         if (mp->m_flags & M_SUB) {
242             if (roll(100) > pln_hitchance(pp,
243                                           shp_hardtarget(&ship), EF_SHIP))
244                 continue;
245         }
246         set_have_found(ship.shp_uid, head);
247         if (first) {
248             pr(" #          owner           eff       type\n");
249             first = 0;
250         }
251         pr("(#%3d) %10.10s  %12.12s  %s\n", ni.cur,
252            cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
253         ships++;
254     }
255     return ships;
256 }
257
258 int
259 num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
260 {
261     int ships;
262     struct nstr_item ni;
263     struct mchrstr *mp;
264     struct shpstr ship;
265
266     ships = 0;
267     snxtitem_xy(&ni, EF_SHIP, x, y);
268     while (nxtitem(&ni, (s_char *)&ship)) {
269         if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
270             continue;
271         mp = &mchr[(int)ship.shp_type];
272         if (wantflags) {
273             if ((mp->m_flags & wantflags) == 0)
274                 continue;
275         }
276         if (nowantflags) {
277             if (mp->m_flags & nowantflags)
278                 continue;
279         }
280         ships++;
281     }
282     return ships;
283 }
284
285 /*
286  * is p a list of ships/planes/units?
287  *
288  */
289
290 int
291 islist(s_char *p)
292 {
293     register int x;
294
295     x = 0;
296
297     while (*(p + x)) {
298         if (!isdigit(*(p + x)) && (*(p + x) != '/'))
299             return 0;
300
301         x++;
302     }
303
304     return 1;
305 }