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