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