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