8
|
1 /*--------------------------------------------------------------------------
|
|
2 NETREK II -- Paradise
|
|
3
|
|
4 Permission to use, copy, modify, and distribute this software and its
|
|
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
|
|
6 purpose and without fee is hereby granted, provided that this copyright
|
|
7 notice appear in all copies. No representations are made about the
|
|
8 suitability of this software for any purpose. This software is provided
|
|
9 "as is" without express or implied warranty.
|
|
10
|
|
11 Xtrek Copyright 1986 Chris Guthrie
|
|
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
|
|
13 Scott Silvey
|
|
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
|
|
15 Kurt Olsen
|
|
16 Brandon Gillespie
|
|
17 --------------------------------------------------------------------------*/
|
|
18
|
|
19 #include "config.h"
|
|
20 #include "shmem.h"
|
|
21 #include "structdesc.h"
|
|
22 #include "data.h"
|
|
23
|
|
24 /* ----------------[ prototypes because I like main first ]---------------- */
|
|
25 void dump_ship_sysdef(void);
|
|
26 void dump_ship_Ccode(void);
|
|
27 void dump_ships_to_table(void);
|
|
28 void describe_ship(int ship);
|
|
29 void usage(char name[]);
|
|
30
|
|
31 /* --[ rather than duplicate it 3 times make the macro from hell (shrug) ]-- */
|
|
32 #define Print_value(place) { \
|
|
33 switch (ship_fields[place].type) { \
|
|
34 case FT_CHAR: \
|
|
35 printf("%c", *(char *) temp); \
|
|
36 break; \
|
|
37 case FT_SHORT: \
|
|
38 printf("%d", *(short *) temp); \
|
|
39 break; \
|
|
40 case FT_INT: \
|
|
41 printf("%d", *(int *) temp); \
|
|
42 break; \
|
|
43 case FT_LONG: \
|
|
44 printf("%ld", *(long *) temp); \
|
|
45 break; \
|
|
46 case FT_FLOAT: \
|
|
47 printf("%g", *(float *) temp); \
|
|
48 break; \
|
|
49 case FT_STRING: \
|
|
50 printf("%s", (char *) temp); \
|
|
51 break; \
|
|
52 case FT_LONGFLAGS: \
|
|
53 { \
|
|
54 int zz = 0; \
|
|
55 char **names = (char **) ship_fields[place].aux; \
|
|
56 long flag = *(long *) temp; \
|
|
57 int first = 1; \
|
|
58 for (zz = 0; names[zz]; zz++) { \
|
|
59 if (flag & (1 << zz)) { \
|
|
60 printf("%s%s", first ? "" : ",", names[zz]); \
|
|
61 first = 0; \
|
|
62 } \
|
|
63 } \
|
|
64 } \
|
|
65 break; \
|
|
66 default: \
|
|
67 printf("unknown type"); \
|
|
68 break; \
|
|
69 } \
|
|
70 }
|
|
71
|
|
72 char *shipTYPES[] = {
|
|
73 "SCOUT",
|
|
74 "DESTROYER",
|
|
75 "CRUISER",
|
|
76 "BATTLESHIP",
|
|
77 "ASSAULT",
|
|
78 "STARBASE",
|
|
79 "ATT",
|
|
80 "JUMPSHIP",
|
|
81 "FRIGATE",
|
|
82 "WARBASE",
|
|
83 "LIGHTCRUISER",
|
|
84 "CARRIER"
|
|
85 };
|
|
86
|
|
87 struct nflags_desc_
|
|
88 {
|
|
89 int flag;
|
|
90 char *meaning;
|
|
91 } nflags_desc[] =
|
|
92 {
|
|
93 {
|
|
94 SFNUNDOCKABLE, "can not dock with another ship"
|
|
95 },
|
|
96 {
|
|
97 SFNCANORBIT, "can orbit hostile worlds"
|
|
98 },
|
|
99 {
|
|
100 SFNCANWARP, "has warp engines"
|
|
101 },
|
|
102 {
|
|
103 SFNCANFUEL, "can transfer fuel to docked ships"
|
|
104 },
|
|
105 {
|
|
106 SFNCANREPAIR, "can speed repair of docked ships"
|
|
107 },
|
|
108 {
|
|
109 SFNCANREFIT, "can let docked ships refit"
|
|
110 },
|
|
111 {
|
|
112 SFNARMYNEEDKILL, "needs kills to carry armies"
|
|
113 },
|
|
114 {
|
|
115 SFNHASPHASERS, "is armed with phasers"
|
|
116 },
|
|
117 {
|
|
118 SFNPLASMASTYLE, "360 arc of fire for plasmas"
|
|
119 },
|
|
120 {
|
|
121 SFNPLASMAARMED, "is armed with plasmas by default"
|
|
122 },
|
|
123 {
|
|
124 SFNHASMISSILE, "is armed with missiles by default"
|
|
125 },
|
|
126 {
|
|
127 SFNHASFIGHTERS, "has a fighter bay"
|
|
128 },
|
|
129 {
|
|
130 0, 0
|
|
131 }
|
|
132 };
|
|
133
|
|
134 /* ==============================[ Functions ]============================== */
|
|
135
|
|
136 int
|
|
137 main(int argc, char **argv)
|
|
138 {
|
|
139 int i, droutine = 0;
|
|
140 char *name;
|
|
141
|
|
142 name = *argv++;
|
|
143 argc--;
|
|
144
|
|
145 if (argc != 1)
|
|
146 usage(name);
|
|
147
|
|
148 while (*argv)
|
|
149 {
|
|
150 if (**argv == '-')
|
|
151 ++* argv;
|
|
152 else
|
|
153 break;
|
|
154 switch (**argv)
|
|
155 {
|
|
156 case 's': /* sysdef */
|
|
157 droutine = 1;
|
|
158 break;
|
|
159 case 'c': /* C Code */
|
|
160 droutine = 2;
|
|
161 break;
|
|
162 case 't': /* table */
|
|
163 droutine = 3;
|
|
164 break;
|
|
165 case 'v': /* verbose */
|
|
166 droutine = 4;
|
|
167 break;
|
|
168 default:
|
|
169 printf("! %s: Unknown option '-%c'\n", name, **argv);
|
|
170 usage(name);
|
|
171 }
|
|
172 }
|
|
173
|
|
174 /* start up a daemon if we need to */
|
|
175 openmem(1, 0);
|
|
176
|
|
177 /*
|
|
178 * do this with two switches because we don't want to fire up the daemon if
|
|
179 * we don't need to
|
|
180 */
|
|
181 switch (droutine)
|
|
182 {
|
|
183 case 1: /* Sysdef */
|
|
184 dump_ship_sysdef();
|
|
185 break;
|
|
186 case 2: /* C Code */
|
|
187 dump_ship_Ccode();
|
|
188 break;
|
|
189 case 3: /* Table */
|
|
190 dump_ships_to_table();
|
|
191 break;
|
|
192 case 4:
|
|
193 { /* Verbose */
|
|
194 ++*argv;
|
|
195 if (!**argv)
|
|
196 {
|
|
197 for (i = 0; i < NUM_TYPES; i++)
|
|
198 describe_ship(i);
|
|
199 }
|
|
200 else
|
|
201 {
|
|
202 describe_ship(atoi(*argv));
|
|
203 }
|
|
204 break; /* for old times sake */
|
|
205 } /* case 4 (Braces on this one because it
|
|
206 * looks nice, thats all */
|
|
207 } /* switch */
|
|
208 }
|
|
209
|
|
210 /* ------------------[ Print ship stats in sysdef format ]------------------ */
|
|
211 void
|
|
212 dump_ship_sysdef(void)
|
|
213 {
|
|
214 int j, i;
|
|
215
|
|
216 for (i = 0; i < NUM_TYPES; i++)
|
|
217 {
|
|
218 struct ship *shp = &shipvals[i];
|
|
219 printf("SHIP=%d\n", i);
|
|
220 for (j = 0; ship_fields[j].name; j++)
|
|
221 {
|
|
222 void *temp = ship_fields[j].offset + (char *) shp;
|
|
223
|
|
224 printf("%c%c %-24s",
|
|
225 shp->s_desig1, shp->s_desig2, ship_fields[j].name);
|
|
226 Print_value(j);
|
|
227 printf("\n");
|
|
228 }
|
|
229 printf("end\n");
|
|
230 }
|
|
231 }
|
|
232
|
|
233 /* ----------------[ Print ship stats in a C syntax format ]---------------- */
|
|
234 void
|
|
235 dump_ship_Ccode(void)
|
|
236 {
|
|
237 int j, i;
|
|
238
|
|
239 for (i = 0; i < NUM_TYPES; i++)
|
|
240 {
|
|
241 struct ship *shp = &shipvals[i];
|
|
242 printf(" /* comprehensive definition of %s */\n", shipTYPES[i]);
|
|
243 for (j = 0; ship_fields[j].name; j++)
|
|
244 {
|
|
245 void *temp = ship_fields[j].offset + (char *) shp;
|
|
246
|
|
247 if (ship_fields[j].type == FT_STRING)
|
|
248 {
|
|
249 printf(" strcpy(shipvals[%s].s_%s, \"%s\")", shipTYPES[i],
|
|
250 ship_fields[j].name, (char *) temp);
|
|
251 }
|
|
252 else
|
|
253 {
|
|
254 printf(" shipvals[%s].s_%s = ",
|
|
255 shipTYPES[i], ship_fields[j].name);
|
|
256 Print_value(j);
|
|
257 }
|
|
258 printf(";\n");
|
|
259 }
|
|
260 printf("\n");
|
|
261 }
|
|
262 }
|
|
263
|
|
264 /* -----------------[ Print ship stats in a table format ]----------------- */
|
|
265 void
|
|
266 dump_ships_to_table(void)
|
|
267 {
|
|
268 int x, j, i;
|
|
269
|
|
270 /*
|
|
271 * we have to find the max element of the ship fields, this is the only way
|
|
272 * I know of so far (BG)
|
|
273 */
|
|
274
|
|
275 printf("Ship Statistics:\n");
|
|
276 for (i = 0; ship_fields[i].name; i++)
|
|
277 {
|
|
278 printf("%-13s ", ship_fields[i].name);
|
|
279 for (j = 0; j < NUM_TYPES; j++)
|
|
280 {
|
|
281 struct ship *shp = &shipvals[j];
|
|
282 void *temp = (ship_fields[i].offset + (char *) shp);
|
|
283
|
|
284 /* we do this one differently so don't use Print_value() */
|
|
285 switch (ship_fields[i].type)
|
|
286 {
|
|
287 case FT_CHAR:
|
|
288 printf("%6c ", *(char *) temp);
|
|
289 break;
|
|
290 case FT_SHORT:
|
|
291 printf("%6d ", *(short *) temp);
|
|
292 break;
|
|
293 case FT_INT:
|
|
294 printf("%6d ", *(int *) temp);
|
|
295 break;
|
|
296 case FT_LONG:
|
|
297 printf("%6ld ", *(long *) temp);
|
|
298 break;
|
|
299 case FT_FLOAT:
|
|
300 printf("%6g ", *(float *) temp);
|
|
301 break;
|
|
302 case FT_STRING:
|
|
303 printf("%6s ", (char *) temp);
|
|
304 break;
|
|
305 default:
|
|
306 break;
|
|
307 }
|
|
308 }
|
|
309 printf("\n");
|
|
310 }
|
|
311 }
|
|
312
|
|
313
|
|
314 /* -------------------------[ Verbose description ]------------------------- */
|
|
315 void
|
|
316 describe_ship(int s_no)
|
|
317 {
|
|
318 struct ship *sp = &shipvals[s_no];
|
|
319 int i;
|
|
320
|
|
321 printf("The %s\n", sp->s_name);
|
|
322 for (i = 0; nflags_desc[i].flag; i++)
|
|
323 {
|
|
324 if ((sp->s_nflags & nflags_desc[i].flag) != nflags_desc[i].flag)
|
|
325 continue;
|
|
326 printf("\t%s\n", nflags_desc[i].meaning);
|
|
327 }
|
|
328 }
|
|
329
|
|
330
|
|
331 /* ----------------------------[ Prints usage ]---------------------------- */
|
|
332 void
|
|
333 usage(char name[])
|
|
334 {
|
|
335 int x;
|
|
336
|
|
337 char errmsg[][255] = {
|
|
338 "\n\t'%s <format option>'\n\n",
|
|
339 "This tool will dump all ship values, configurable to 3 formats:\n",
|
|
340 "\t-s -- .sysdef Format\n",
|
|
341 "\t-c -- C code Format\n",
|
|
342 "\t-t -- Table Format (best printed with 8 point font)\n",
|
|
343 "\t-v# -- Verbose Format (optional ship number)\n",
|
|
344 ""
|
|
345 };
|
|
346
|
|
347 printf("-- NetrekII (Paradise), %s --\n", PARAVERS);
|
|
348 for (x = 0; *errmsg[x] != NULL; x++)
|
|
349 printf(errmsg[x], name);
|
|
350
|
|
351 exit(1);
|
|
352 }
|