]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sdump.c
(carg, lcarg, fort, land, ldump, lsta, orde, payo, retr, lretr)
[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         count_planes(&ship);
271         count_units(&ship);
272         nships++;
273         if (player->god)
274             pr("%d ", ship.shp_own);
275         pr("%d", ni.cur);
276         n = 0;
277         while (field[n]) {
278             switch (field[n++]) {
279             case 1:
280                 pr(" %.4s", mchr[(int)ship.shp_type].m_name);
281                 break;
282             case 2:
283                 pr(" %d", xrel(np, ship.shp_x));
284                 break;
285             case 3:
286                 pr(" %d", yrel(np, ship.shp_y));
287                 break;
288             case 4:
289                 if (ship.shp_fleet == ' ')
290                     pr(" ~");
291                 else
292                     pr(" %c", ship.shp_fleet);
293                 break;
294             case 5:
295                 pr(" %d", ship.shp_effic);
296                 break;
297             case 6:
298                 pr(" %d", ship.shp_item[I_CIVIL]);
299                 break;
300             case 7:
301                 pr(" %d", ship.shp_item[I_MILIT]);
302                 break;
303             case 8:
304                 pr(" %d", ship.shp_item[I_UW]);
305                 break;
306             case 9:
307                 pr(" %d", ship.shp_item[I_FOOD]);
308                 break;
309             case 10:
310                 pr(" %d", ship.shp_nplane);
311                 break;
312             case 11:
313                 pr(" %d", ship.shp_nchoppers);
314                 break;
315             case 12:
316                 pr(" %d", ship.shp_nxlight);
317                 break;
318             case 13:
319                 pr(" %d", ship.shp_nland);
320                 break;
321             case 14:
322                 pr(" %d", ship.shp_mobil);
323                 break;
324             case 15:
325                 if (opt_FUEL)
326                     pr(" %d", ship.shp_fuel);
327                 else
328                     pr(" 0");
329                 break;
330             case 16:
331                 pr(" %d", ship.shp_tech);
332                 break;
333             case 17:
334                 pr(" %d", ship.shp_item[I_SHELL]);
335                 break;
336             case 18:
337                 pr(" %d", ship.shp_item[I_GUN]);
338                 break;
339             case 19:
340                 pr(" %d", ship.shp_item[I_PETROL]);
341                 break;
342             case 20:
343                 pr(" %d", ship.shp_item[I_IRON]);
344                 break;
345             case 21:
346                 pr(" %d", ship.shp_item[I_DUST]);
347                 break;
348             case 22:
349                 pr(" %d", ship.shp_item[I_BAR]);
350                 break;
351             case 23:
352                 pr(" %d", ship.shp_item[I_OIL]);
353                 break;
354             case 24:
355                 pr(" %d", ship.shp_item[I_LCM]);
356                 break;
357             case 25:
358                 pr(" %d", ship.shp_item[I_HCM]);
359                 break;
360             case 26:
361                 pr(" %d", ship.shp_item[I_RAD]);
362                 break;
363             case 27:
364                 pr(" %d", ship.shp_armor);
365                 break;
366             case 28:
367                 pr(" %d", ship.shp_speed);
368                 break;
369             case 29:
370                 pr(" %d", ship.shp_visib);
371                 break;
372             case 30:
373                 pr(" %d", ship.shp_frnge);
374                 break;
375             case 31:
376                 pr(" %d", ship.shp_glim);
377                 break;
378             case 32:
379                 /*
380                  * Disclosing construction site allows pirates to find
381                  * harbors.  Disclose it only to the original owner
382                  * and to deities.  Else dump illegal coordinates
383                  * 1,0
384                  */
385                 if (ship.shp_own == ship.shp_orig_own || player->god)
386                     pr(" %d", xrel(np, ship.shp_orig_x));
387                 else
388                     pr(" 1");
389                 break;
390             case 33:
391                 /* see case 32 */
392                 if (ship.shp_own == ship.shp_orig_own || player->god)
393                     pr(" %d", yrel(np, ship.shp_orig_y));
394                 else
395                     pr(" 0");
396                 break;
397             case 34:
398                 pr(" %c%s%c", '"', ship.shp_name, '"');
399                 break;
400             }
401         }
402         pr("\n");
403     }
404     if (nships == 0) {
405         if (player->argp[1])
406             pr("%s: No ship(s)\n", player->argp[1]);
407         else
408             pr("%s: No ship(s)\n", "");
409         return RET_FAIL;
410     } else
411         pr("%d ship%s\n", nships, splur(nships));
412     return RET_OK;
413 }