]> git.pond.sub.org Git - empserver/blob - src/lib/commands/pdump.c
Import of Empire 4.2.12
[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 "deity.h"
45 #include "optlist.h"
46 #include "commands.h"
47
48 int
49 pdump(void)
50 {
51         int nplanes;
52         struct nstr_item np;
53         struct plnstr plane;
54         int     field[128];
55         struct  natstr *natp;
56         int     n,i;
57         time_t  now;
58
59         if (!snxtitem(&np, EF_PLANE, player->argp[1]))
60                 return RET_SYN;
61         prdate();
62
63         if (!player->argp[2]) {
64                 for (n = 1; n <= 32; n++) 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 %d\n", 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: pr(" type"); break;
135                 case 2: pr(" x"); break;
136                 case 3: pr(" y"); break;
137                 case 4: pr(" wing"); break;
138                 case 5: pr(" eff"); break;
139                 case 6: pr(" mob"); break;
140                 case 7: pr(" tech"); break;
141                 case 8: pr(" att"); break;
142                 case 9: pr(" def"); break;
143                 case 10: pr(" acc"); break;
144                 case 11: pr(" react"); break;
145                 case 12: pr(" range"); break;
146                 case 13: pr(" load"); break;
147                 case 14: pr(" fuel"); break;
148                 case 15: pr(" hard"); break;
149                 case 16: pr(" ship"); break;
150                 case 17: pr(" land"); break;
151                 case 18: pr(" laun"); break;
152                 case 19: pr(" orb"); break;
153                 case 20: pr(" nuke"); break;
154                 case 21: pr(" grd"); break;
155                 }
156                 n++;
157         }
158         pr("\n");
159
160         nplanes = 0;
161         natp = getnatp(player->cnum);
162         while (nxtitem(&np, (s_char *)&plane)) {
163                 if (!player->owner || plane.pln_own == 0)
164                         continue;
165                 nplanes++;
166                 if (player->god)
167                         pr("%3d ", plane.pln_own);
168                 pr("%d", np.cur);
169                 n = 0;
170                 while (field[n]) {
171                         switch (field[n++]) {
172                         case 1: pr(" %0.4s", plchr[(int)plane.pln_type].pl_name); break;
173                         case 2: pr(" %d", xrel(natp, plane.pln_x)); break;
174                         case 3: pr(" %d", yrel(natp, plane.pln_y)); break;
175                         case 4: if (plane.pln_wing == ' ') 
176                                         pr(" ~");
177                                 else
178                                         pr(" %c", plane.pln_wing);
179                                 break;
180                         case 5: pr(" %d", plane.pln_effic); break;
181                         case 6: pr(" %d", plane.pln_mobil); break;
182                         case 7: pr(" %d", plane.pln_tech); break;
183                         case 8: pr(" %d", plane.pln_att); break;
184                         case 9: pr(" %d", plane.pln_def); break;
185                         case 10: pr(" %d", plane.pln_acc); break;
186                         case 11: pr(" %d", plane.pln_range); break;
187                         case 12: pr(" %d", plane.pln_range_max); break;
188                         case 13: pr(" %d", plane.pln_load); break;
189                         case 14: pr(" %d", plane.pln_fuel); break;
190                         case 15: pr(" %d", plane.pln_harden); break;
191                         case 16: pr(" %d", plane.pln_ship); break;
192                         case 17: pr(" %d", plane.pln_land); break;
193                         case 18: if ((plchr[(int)plane.pln_type].pl_flags & (P_O|P_M)) == P_O) {
194                                         pr(" %c", (plane.pln_flags & PLN_LAUNCHED)?'Y':'N');
195                                  } else pr (" N"); break;
196                         case 19: if ((plchr[(int)plane.pln_type].pl_flags & (P_O|P_M)) == P_O) {
197                                         pr(" %c", opt_ORBIT?(plane.pln_flags & PLN_SYNCHRONOUS)?'Y':'N':'N');
198                                  } else pr (" N"); break;
199                         case 20: if (plane.pln_nuketype != -1) {
200                                         pr(" %0.5s", nchr[(int)plane.pln_nuketype].n_name); break;
201                                  } else pr(" N/A"); break;
202
203                         case 21: pr(" %c", plane.pln_flags & PLN_AIRBURST?'A':'G'); break;
204                         }
205                 }
206                 pr("\n");
207         }
208         if (nplanes == 0) {
209                 if (player->argp[1])
210                         pr("%s: No plane(s)\n", player->argp[1]);
211                 else
212                         pr("%s: No plane(s)\n", "");
213                 return RET_FAIL;
214         }else
215                 pr("%d plane%s\n", nplanes, splur(nplanes));
216
217         return RET_OK;
218 }