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