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