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