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