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