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