]> git.pond.sub.org Git - empserver/blob - src/lib/commands/pdump.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / pdump.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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  *  pdump.c: Dump plane 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 "misc.h"
38 #include "player.h"
39 #include "xy.h"
40 #include "plane.h"
41 #include "nsc.h"
42 #include "nuke.h"
43 #include "file.h"
44 #include "nat.h"
45 #include "optlist.h"
46 #include "commands.h"
47
48 int
49 pdump(void)
50 {
51     int nplanes;
52     struct nstr_item np;
53     struct plnstr plane;
54     int field[128];
55     struct natstr *natp;
56     int n, i;
57     time_t now;
58
59     if (!snxtitem(&np, EF_PLANE, player->argp[1]))
60         return RET_SYN;
61     prdate();
62
63     if (!player->argp[2]) {
64         for (n = 1; n <= 32; n++)
65             field[n - 1] = n;
66         field[n - 1] = 0;
67     } else {
68         n = 2;
69         i = 0;
70         while (player->argp[n]) {
71
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("wing", player->argp[n])) {
79                 field[i++] = 4;
80             } else if (!strcmp("eff", player->argp[n])) {
81                 field[i++] = 5;
82             } else if (!strcmp("mob", player->argp[n])) {
83                 field[i++] = 6;
84             } else if (!strcmp("tech", player->argp[n])) {
85                 field[i++] = 7;
86             } else if (!strcmp("att", player->argp[n])) {
87                 field[i++] = 8;
88             } else if (!strcmp("def", player->argp[n])) {
89                 field[i++] = 9;
90             } else if (!strcmp("acc", player->argp[n])) {
91                 field[i++] = 10;
92             } else if (!strcmp("react", player->argp[n])) {
93                 field[i++] = 11;
94             } else if (!strcmp("range", player->argp[n])) {
95                 field[i++] = 12;
96             } else if (!strcmp("load", player->argp[n])) {
97                 field[i++] = 13;
98             } else if (!strcmp("fuel", player->argp[n])) {
99                 field[i++] = 14;
100             } else if (!strcmp("hard", player->argp[n])) {
101                 field[i++] = 15;
102             } else if (!strcmp("ship", player->argp[n])) {
103                 field[i++] = 16;
104             } else if (!strcmp("land", player->argp[n])) {
105                 field[i++] = 17;
106             } else if (!strcmp("laun", player->argp[n])) {
107                 field[i++] = 18;
108             } else if (!strcmp("orb", player->argp[n])) {
109                 field[i++] = 19;
110             } else if (!strcmp("nuke", player->argp[n])) {
111                 field[i++] = 20;
112             } else if (!strcmp("grd", player->argp[n])) {
113                 field[i++] = 21;
114             } else {
115                 pr("Unrecognized field %s\n", player->argp[n]);
116             }
117             if (n++ > 100) {
118                 pr("Too many fields\n");
119                 return RET_FAIL;
120             }
121         }
122         field[i] = 0;
123     }
124
125     if (player->god)
126         pr("   ");
127     time(&now);
128     pr("DUMP PLANES %ld\n", (long)now);
129     if (player->god)
130         pr("own ");
131     pr("id");
132     n = 0;
133     while (field[n]) {
134         switch (field[n]) {
135         case 1:
136             pr(" type");
137             break;
138         case 2:
139             pr(" x");
140             break;
141         case 3:
142             pr(" y");
143             break;
144         case 4:
145             pr(" wing");
146             break;
147         case 5:
148             pr(" eff");
149             break;
150         case 6:
151             pr(" mob");
152             break;
153         case 7:
154             pr(" tech");
155             break;
156         case 8:
157             pr(" att");
158             break;
159         case 9:
160             pr(" def");
161             break;
162         case 10:
163             pr(" acc");
164             break;
165         case 11:
166             pr(" react");
167             break;
168         case 12:
169             pr(" range");
170             break;
171         case 13:
172             pr(" load");
173             break;
174         case 14:
175             pr(" fuel");
176             break;
177         case 15:
178             pr(" hard");
179             break;
180         case 16:
181             pr(" ship");
182             break;
183         case 17:
184             pr(" land");
185             break;
186         case 18:
187             pr(" laun");
188             break;
189         case 19:
190             pr(" orb");
191             break;
192         case 20:
193             pr(" nuke");
194             break;
195         case 21:
196             pr(" grd");
197             break;
198         }
199         n++;
200     }
201     pr("\n");
202
203     nplanes = 0;
204     natp = getnatp(player->cnum);
205     while (nxtitem(&np, &plane)) {
206         if (!player->owner || plane.pln_own == 0)
207             continue;
208         nplanes++;
209         if (player->god)
210             pr("%d ", plane.pln_own);
211         pr("%d", np.cur);
212         n = 0;
213         while (field[n]) {
214             switch (field[n++]) {
215             case 1:
216                 pr(" %.4s", plchr[(int)plane.pln_type].pl_name);
217                 break;
218             case 2:
219                 pr(" %d", xrel(natp, plane.pln_x));
220                 break;
221             case 3:
222                 pr(" %d", yrel(natp, plane.pln_y));
223                 break;
224             case 4:
225                 if (plane.pln_wing == ' ')
226                     pr(" ~");
227                 else
228                     pr(" %c", plane.pln_wing);
229                 break;
230             case 5:
231                 pr(" %d", plane.pln_effic);
232                 break;
233             case 6:
234                 pr(" %d", plane.pln_mobil);
235                 break;
236             case 7:
237                 pr(" %d", plane.pln_tech);
238                 break;
239             case 8:
240                 pr(" %d", plane.pln_att);
241                 break;
242             case 9:
243                 pr(" %d", plane.pln_def);
244                 break;
245             case 10:
246                 pr(" %d", plane.pln_acc);
247                 break;
248             case 11:
249                 pr(" %d", plane.pln_range);
250                 break;
251             case 12:
252                 pr(" %d", plane.pln_range_max);
253                 break;
254             case 13:
255                 pr(" %d", plane.pln_load);
256                 break;
257             case 14:
258                 pr(" %d", plchr[(int)plane.pln_type].pl_fuel);
259                 break;
260             case 15:
261                 pr(" %d", plane.pln_harden);
262                 break;
263             case 16:
264                 pr(" %d", plane.pln_ship);
265                 break;
266             case 17:
267                 pr(" %d", plane.pln_land);
268                 break;
269             case 18:
270                 if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) ==
271                     P_O) {
272                     pr(" %c",
273                        (plane.pln_flags & PLN_LAUNCHED) ? 'Y' : 'N');
274                 } else
275                     pr(" N");
276                 break;
277             case 19:
278                 if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) ==
279                     P_O) {
280                     pr(" %c", (plane.pln_flags & PLN_SYNCHRONOUS) ? 'Y' : 'N');
281                 } else
282                     pr(" N");
283                 break;
284             case 20:
285                 if (plane.pln_nuketype != -1) {
286                     pr(" %.5s", nchr[(int)plane.pln_nuketype].n_name);
287                     break;
288                 } else
289                     pr(" N/A");
290                 break;
291
292             case 21:
293                 pr(" %c", plane.pln_flags & PLN_AIRBURST ? 'A' : 'G');
294                 break;
295             }
296         }
297         pr("\n");
298     }
299     if (nplanes == 0) {
300         if (player->argp[1])
301             pr("%s: No plane(s)\n", player->argp[1]);
302         else
303             pr("%s: No plane(s)\n", "");
304         return RET_FAIL;
305     } else
306         pr("%d plane%s\n", nplanes, splur(nplanes));
307
308     return RET_OK;
309 }