]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sdump.c
Remove a bunch of redundant casts.
[empserver] / src / lib / commands / sdump.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  sdump.c: Dump ship information
29  * 
30  *  Known contributors to this file:
31  *     John Yockey, 1997
32  *     Steve McClure, 1998
33  */
34
35 #include "misc.h"
36 #include "player.h"
37 #include "xy.h"
38 #include "sect.h"
39 #include "ship.h"
40 #include "nat.h"
41 #include "nsc.h"
42 #include "file.h"
43 #include "optlist.h"
44 #include "commands.h"
45
46 int
47 sdump(void)
48 {
49     int nships;
50     struct nstr_item ni;
51     struct shpstr ship;
52     int field[128];
53     struct natstr *np;
54     int n, i;
55     time_t now;
56
57     if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
58         return RET_SYN;
59     prdate();
60
61     if (!player->argp[2]) {
62         for (n = 1; n <= 34; n++)
63             field[n - 1] = n;
64         field[n - 1] = 0;
65     } else {
66         n = 2;
67         i = 0;
68         while (player->argp[n]) {
69             if (!strcmp("type", player->argp[n])) {
70                 field[i++] = 1;
71             } else if (!strcmp("x", player->argp[n])) {
72                 field[i++] = 2;
73             } else if (!strcmp("y", player->argp[n])) {
74                 field[i++] = 3;
75             } else if (!strcmp("flt", player->argp[n])) {
76                 field[i++] = 4;
77             } else if (!strcmp("eff", player->argp[n])) {
78                 field[i++] = 5;
79             } else if (!strcmp("civ", player->argp[n])) {
80                 field[i++] = 6;
81             } else if (!strcmp("mil", player->argp[n])) {
82                 field[i++] = 7;
83             } else if (!strcmp("uw", player->argp[n])) {
84                 field[i++] = 8;
85             } else if (!strcmp("food", player->argp[n])) {
86                 field[i++] = 9;
87             } else if (!strcmp("pln", player->argp[n])) {
88                 field[i++] = 10;
89             } else if (!strcmp("he", player->argp[n])) {
90                 field[i++] = 11;
91             } else if (!strcmp("xl", player->argp[n])) {
92                 field[i++] = 12;
93             } else if (!strcmp("land", player->argp[n])) {
94                 field[i++] = 13;
95             } else if (!strcmp("mob", player->argp[n])) {
96                 field[i++] = 14;
97             } else if (!strcmp("fuel", player->argp[n])) {
98                 field[i++] = 15;
99             } else if (!strcmp("tech", player->argp[n])) {
100                 field[i++] = 16;
101             } else if (!strcmp("shell", player->argp[n])) {
102                 field[i++] = 17;
103             } else if (!strcmp("gun", player->argp[n])) {
104                 field[i++] = 18;
105             } else if (!strcmp("petrol", player->argp[n])) {
106                 field[i++] = 19;
107             } else if (!strcmp("iron", player->argp[n])) {
108                 field[i++] = 20;
109             } else if (!strcmp("dust", player->argp[n])) {
110                 field[i++] = 21;
111             } else if (!strcmp("bar", player->argp[n])) {
112                 field[i++] = 22;
113             } else if (!strcmp("oil", player->argp[n])) {
114                 field[i++] = 23;
115             } else if (!strcmp("lcm", player->argp[n])) {
116                 field[i++] = 24;
117             } else if (!strcmp("hcm", player->argp[n])) {
118                 field[i++] = 25;
119             } else if (!strcmp("rad", player->argp[n])) {
120                 field[i++] = 26;
121             } else if (!strcmp("def", player->argp[n])) {
122                 field[i++] = 27;
123             } else if (!strcmp("spd", player->argp[n])) {
124                 field[i++] = 28;
125             } else if (!strcmp("vis", player->argp[n])) {
126                 field[i++] = 29;
127             } else if (!strcmp("rng", player->argp[n])) {
128                 field[i++] = 30;
129             } else if (!strcmp("fir", player->argp[n])) {
130                 field[i++] = 31;
131             } else if (!strcmp("origx", player->argp[n])) {
132                 field[i++] = 32;
133             } else if (!strcmp("origy", player->argp[n])) {
134                 field[i++] = 33;
135             } else if (!strcmp("name", player->argp[n])) {
136                 field[i++] = 34;
137             } else {
138                 pr("Unrecognized field %s\n", player->argp[n]);
139             }
140             if (n++ > 100) {
141                 pr("Too many fields\n");
142                 return RET_FAIL;
143             }
144         }
145         field[i] = 0;
146     }
147
148     if (player->god)
149         pr("   ");
150     time(&now);
151     pr("DUMP SHIPS %ld\n", (long)now);
152     if (player->god)
153         pr("own ");
154     pr("id");
155     n = 0;
156     while (field[n]) {
157         switch (field[n]) {
158         case 1:
159             pr(" type");
160             break;
161         case 2:
162             pr(" x");
163             break;
164         case 3:
165             pr(" y");
166             break;
167         case 4:
168             pr(" flt");
169             break;
170         case 5:
171             pr(" eff");
172             break;
173         case 6:
174             pr(" civ");
175             break;
176         case 7:
177             pr(" mil");
178             break;
179         case 8:
180             pr(" uw");
181             break;
182         case 9:
183             pr(" food");
184             break;
185         case 10:
186             pr(" pln");
187             break;
188         case 11:
189             pr(" he");
190             break;
191         case 12:
192             pr(" xl");
193             break;
194         case 13:
195             pr(" land");
196             break;
197         case 14:
198             pr(" mob");
199             break;
200         case 15:
201             pr(" fuel");
202             break;
203         case 16:
204             pr(" tech");
205             break;
206         case 17:
207             pr(" shell");
208             break;
209         case 18:
210             pr(" gun");
211             break;
212         case 19:
213             pr(" petrol");
214             break;
215         case 20:
216             pr(" iron");
217             break;
218         case 21:
219             pr(" dust");
220             break;
221         case 22:
222             pr(" bar");
223             break;
224         case 23:
225             pr(" oil");
226             break;
227         case 24:
228             pr(" lcm");
229             break;
230         case 25:
231             pr(" hcm");
232             break;
233         case 26:
234             pr(" rad");
235             break;
236         case 27:
237             pr(" def");
238             break;
239         case 28:
240             pr(" spd");
241             break;
242         case 29:
243             pr(" vis");
244             break;
245         case 30:
246             pr(" rng");
247             break;
248         case 31:
249             pr(" fir");
250             break;
251         case 32:
252             pr(" origx");
253             break;
254         case 33:
255             pr(" origy");
256             break;
257         case 34:
258             pr(" name");
259             break;
260         }
261         n++;
262     }
263     pr("\n");
264
265     nships = 0;
266     np = getnatp(player->cnum);
267     while (nxtitem(&ni, &ship)) {
268         if (!player->owner || ship.shp_own == 0)
269             continue;
270         if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
271             pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur);
272             continue;
273         }
274         count_planes(&ship);
275         count_units(&ship);
276         nships++;
277         if (player->god)
278             pr("%d ", ship.shp_own);
279         pr("%d", ni.cur);
280         n = 0;
281         while (field[n]) {
282             switch (field[n++]) {
283             case 1:
284                 pr(" %.4s", mchr[(int)ship.shp_type].m_name);
285                 break;
286             case 2:
287                 pr(" %d", xrel(np, ship.shp_x));
288                 break;
289             case 3:
290                 pr(" %d", yrel(np, ship.shp_y));
291                 break;
292             case 4:
293                 if (ship.shp_fleet == ' ')
294                     pr(" ~");
295                 else
296                     pr(" %c", ship.shp_fleet);
297                 break;
298             case 5:
299                 pr(" %d", ship.shp_effic);
300                 break;
301             case 6:
302                 pr(" %d", ship.shp_item[I_CIVIL]);
303                 break;
304             case 7:
305                 pr(" %d", ship.shp_item[I_MILIT]);
306                 break;
307             case 8:
308                 pr(" %d", ship.shp_item[I_UW]);
309                 break;
310             case 9:
311                 pr(" %d", ship.shp_item[I_FOOD]);
312                 break;
313             case 10:
314                 pr(" %d", ship.shp_nplane);
315                 break;
316             case 11:
317                 pr(" %d", ship.shp_nchoppers);
318                 break;
319             case 12:
320                 pr(" %d", ship.shp_nxlight);
321                 break;
322             case 13:
323                 pr(" %d", ship.shp_nland);
324                 break;
325             case 14:
326                 pr(" %d", ship.shp_mobil);
327                 break;
328             case 15:
329                 if (opt_FUEL)
330                     pr(" %d", ship.shp_fuel);
331                 else
332                     pr(" 0");
333                 break;
334             case 16:
335                 pr(" %d", ship.shp_tech);
336                 break;
337             case 17:
338                 pr(" %d", ship.shp_item[I_SHELL]);
339                 break;
340             case 18:
341                 pr(" %d", ship.shp_item[I_GUN]);
342                 break;
343             case 19:
344                 pr(" %d", ship.shp_item[I_PETROL]);
345                 break;
346             case 20:
347                 pr(" %d", ship.shp_item[I_IRON]);
348                 break;
349             case 21:
350                 pr(" %d", ship.shp_item[I_DUST]);
351                 break;
352             case 22:
353                 pr(" %d", ship.shp_item[I_BAR]);
354                 break;
355             case 23:
356                 pr(" %d", ship.shp_item[I_OIL]);
357                 break;
358             case 24:
359                 pr(" %d", ship.shp_item[I_LCM]);
360                 break;
361             case 25:
362                 pr(" %d", ship.shp_item[I_HCM]);
363                 break;
364             case 26:
365                 pr(" %d", ship.shp_item[I_RAD]);
366                 break;
367             case 27:
368                 pr(" %d", ship.shp_armor);
369                 break;
370             case 28:
371                 pr(" %d", ship.shp_speed);
372                 break;
373             case 29:
374                 pr(" %d", ship.shp_visib);
375                 break;
376             case 30:
377                 pr(" %d", ship.shp_frnge);
378                 break;
379             case 31:
380                 pr(" %d", ship.shp_glim);
381                 break;
382             case 32:
383                 /*
384                  * Disclosing construction site allows pirates to find
385                  * harbors.  Disclose it only to the original owner
386                  * and to deities.  Else dump illegal coordinates
387                  * 1,0
388                  */
389                 if (ship.shp_own == ship.shp_orig_own || player->god)
390                     pr(" %d", xrel(np, ship.shp_orig_x));
391                 else
392                     pr(" 1");
393                 break;
394             case 33:
395                 /* see case 32 */
396                 if (ship.shp_own == ship.shp_orig_own || player->god)
397                     pr(" %d", yrel(np, ship.shp_orig_y));
398                 else
399                     pr(" 0");
400                 break;
401             case 34:
402                 pr(" %c%s%c", '"', ship.shp_name, '"');
403                 break;
404             }
405         }
406         pr("\n");
407     }
408     if (nships == 0) {
409         if (player->argp[1])
410             pr("%s: No ship(s)\n", player->argp[1]);
411         else
412             pr("%s: No ship(s)\n", "");
413         return RET_FAIL;
414     } else
415         pr("%d ship%s\n", nships, splur(nships));
416     return RET_OK;
417 }