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