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