]> git.pond.sub.org Git - empserver/blob - src/lib/subs/show.c
(lookup): Rename lookup() to symbol_by_value(), make it public
[empserver] / src / lib / subs / show.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  show.c: General show routines
29  * 
30  *  Known contributors to this file:
31  *     Julian Onions, 1988
32  *     Jeff Bailey, 1990
33  *     Steve McClure, 1996
34  */
35
36 /*
37  * general routines that are callable to give info on things.
38  * currently, planes, ships, nukes and bridges. Tanks & regiments one day?
39  *
40  * Added nuke_flags to be consistent. Jeff Bailey 12/15/90
41  *                                    (bailey@mcs.kent.edu)
42  */
43
44 #include <math.h>
45 #include "misc.h"
46 #include "player.h"
47 #include "nuke.h"
48 #include "ship.h"
49 #include "land.h"
50 #include "item.h"
51 #include "plane.h"
52 #include "sect.h"
53 #include "optlist.h"
54 #include "file.h"
55 #include "nat.h"
56 #include "prototypes.h"
57 #include "nsc.h"
58
59 struct look_list {
60     union {
61         struct lchrstr *lp;
62         struct plchrstr *pp;
63         struct mchrstr *mp;
64     } l_u;
65     int tech;
66 } lookup_list[200];             /* Change this if there are ever more than 200 planes, ships
67                                    or land units. */
68 static int lookup_list_cnt = 0;
69
70 static void
71 sort_lookup_list(void)
72 {
73     struct natstr *np = getnatp(player->cnum);
74     struct look_list tmp;
75     int i;
76     int j;
77
78     if (!(np->nat_flags & NF_TECHLISTS))
79         return;
80     for (i = 0; i < lookup_list_cnt; i++) {
81         for (j = i; j < lookup_list_cnt; j++) {
82             if (lookup_list[j].tech < lookup_list[i].tech) {
83                 tmp = lookup_list[j];
84                 lookup_list[j] = lookup_list[i];
85                 lookup_list[i] = tmp;
86             }
87         }
88     }
89 }
90
91 static void
92 make_new_list(int tlev, int type)
93 {
94     struct plchrstr *pp;
95     struct lchrstr *lp;
96     struct mchrstr *mp;
97
98     lookup_list_cnt = 0;
99     if (type == EF_PLANE) {
100         for (pp = plchr; pp->pl_name; pp++) {
101             if (pp->pl_tech > tlev)
102                 continue;
103             lookup_list[lookup_list_cnt].l_u.pp = pp;
104             lookup_list[lookup_list_cnt].tech = pp->pl_tech;
105             lookup_list_cnt++;
106         }
107     } else if (type == EF_SHIP) {
108         for (mp = mchr; mp->m_name; mp++) {
109             if (mp->m_tech > tlev)
110                 continue;
111             lookup_list[lookup_list_cnt].l_u.mp = mp;
112             lookup_list[lookup_list_cnt].tech = mp->m_tech;
113             lookup_list_cnt++;
114         }
115     } else if (type == EF_LAND) {
116         for (lp = lchr; lp->l_name; lp++) {
117             if (lp->l_tech > tlev)
118                 continue;
119             lookup_list[lookup_list_cnt].l_u.lp = lp;
120             lookup_list[lookup_list_cnt].tech = lp->l_tech;
121             lookup_list_cnt++;
122         }
123     } else
124         return;
125
126     sort_lookup_list();
127 }
128
129 void
130 show_bridge(int tlev)
131 {
132     if (tlev < buil_bt)
133         return;
134     pr("Bridges require %g tech,", buil_bt);
135     pr(" %d hcm,", buil_bh);
136     pr(" %d workers,\n", 0);
137     pr("%d available workforce, and cost $%g\n",
138        (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
139        buil_bc);
140 }
141
142 void
143 show_tower(int tlev)
144 {
145     if (tlev < buil_tower_bt)
146         return;
147     pr("Bridge Towers require %g tech,", buil_tower_bt);
148     pr(" %d hcm,", buil_tower_bh);
149     pr(" %d workers,\n", 0);
150     pr("%d available workforce, and cost $%g\n",
151        (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
152        buil_tower_bc);
153 }
154
155 void
156 show_nuke_stats(int tlev)
157 {
158     show_nuke_capab(tlev);
159 }
160
161 void
162 show_nuke_build(int tlev)
163 {
164     struct nchrstr *np;
165     int avail;
166
167     if (opt_DRNUKE)
168         pr("%13s lcm hcm  oil  rad avail tech res $\n", "");
169     else
170         pr("%13s lcm hcm  oil  rad avail tech $\n", "");
171
172     for (np = nchr; np->n_name; np++) {
173         avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
174         if (np->n_tech > tlev)
175             continue;
176         if (opt_DRNUKE)
177             pr("%-13.13s %3d %3d %4d %4d %5d %4d %3d $%6d\n",
178                np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
179                np->n_rad, avail, np->n_tech,
180                (int)(np->n_tech * drnuke_const) + 1, np->n_cost);
181         else
182             pr("%-13.13s %3d %3d %4d %4d %5d %4d $%6d\n",
183                np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
184                np->n_rad, avail, np->n_tech, np->n_cost);
185     }
186 }
187
188 void
189 show_nuke_capab(int tlev)
190 {
191     struct nchrstr *np;
192     int i, j;
193     char *p;
194
195     if (opt_DRNUKE)
196         pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
197     else
198         pr("%13s blst dam lbs tech $%7s abilities\n", "", "");
199
200     for (np = nchr; np->n_name; np++) {
201         if (np->n_tech > tlev)
202             continue;
203         if (opt_DRNUKE)
204             pr("%-13.13s %4d %3d %3d %4d %3d $%7d ",
205                np->n_name, np->n_blast, np->n_dam,
206                np->n_weight, np->n_tech,
207                (int)(np->n_tech * drnuke_const) + 1, np->n_cost);
208         else                    /* not DRNUKE */
209             pr("%-13.13s %4d %3d %3d %4d $%7d ",
210                np->n_name, np->n_blast, np->n_dam,
211                np->n_weight, np->n_tech, np->n_cost);
212
213         for (i = j = 0; i < 32; i++) {
214             if (!(np->n_flags & bit(i)))
215                 continue;
216             if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
217                 if (j++ > 0)
218                     pr(" ");
219                 pr(p);
220             }
221         }
222         pr("\n");
223     }
224 }
225
226 void
227 show_ship_build(int tlev)
228 {
229     struct mchrstr *mp;
230     int n;
231
232     pr("%25s lcm hcm avail tech $\n", "");
233     make_new_list(tlev, EF_SHIP);
234     for (n = 0; n < lookup_list_cnt; n++) {
235         mp = (struct mchrstr *)lookup_list[n].l_u.mp;
236         /* Can't show trade ships unless it's turned on */
237         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
238             continue;
239
240         pr("%-25.25s %3d %3d %5d %4d $%d\n",
241            mp->m_name, mp->m_lcm, mp->m_hcm,
242            SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
243     }
244 }
245
246 void
247 show_ship_stats(int tlev)
248 {
249     struct mchrstr *mp;
250     int scount;
251     int techdiff;
252
253     pr("%25s      s  v  s  r  f  l  p", "");
254     pr("  h");
255     pr("  x");
256     if (opt_FUEL)
257         pr("  fuel");
258     pr("\n");
259
260     pr("%25s      p  i  p  n  i  n  l", "");
261     pr("  e");
262     pr("  p");
263     if (opt_FUEL)
264         pr("   c/u");
265     pr("\n");
266
267     pr("%25s def  d  s  y  g  r  d  n", "");
268     pr("  l");
269     pr("  l");
270     if (opt_FUEL)
271         pr("      ");
272     pr("\n");
273
274
275     make_new_list(tlev, EF_SHIP);
276     for (scount = 0; scount < lookup_list_cnt; scount++) {
277         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
278         /* Can't show trade ships unless it's turned on */
279         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
280             continue;
281
282         techdiff = (int)(tlev - mp->m_tech);
283         pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
284            mp->m_name,
285            (short)SHP_DEF(mp->m_armor, techdiff),
286            (short)SHP_SPD(mp->m_speed, techdiff),
287            (short)SHP_VIS(mp->m_visib, techdiff),
288            mp->m_vrnge,
289            (short)SHP_RNG(mp->m_frnge, techdiff),
290            (short)SHP_FIR(mp->m_glim, techdiff));
291
292         pr("%2d ", mp->m_nland);
293         pr("%2d ", mp->m_nplanes);
294         pr("%2d ", mp->m_nchoppers);
295         pr("%2d ", mp->m_nxlight);
296         if (opt_FUEL)
297             pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
298         pr("\n");
299     }
300 }
301
302 void
303 show_ship_capab(int tlev)
304 {
305     struct mchrstr *mp;
306     i_type i;
307     int j;
308     int scount;
309     int n;
310     char *p;
311
312     pr("%25s cargos & capabilities\n", "");
313
314     make_new_list(tlev, EF_SHIP);
315     for (scount = 0; scount < lookup_list_cnt; scount++) {
316         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
317         /* Can't show trade ships unless it's turned on */
318         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
319             continue;
320
321         pr("%-25.25s ", mp->m_name);
322
323         for (i = I_NONE + 1; i <= I_MAX; ++i)
324             if (mp->m_item[i])
325                 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
326         pr(" ");
327         for (j = n = 0; j < 32; j++) {
328             if (!(mp->m_flags & bit(j)))
329                 continue;
330             if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
331                 if (n++ > 0)
332                     pr(" ");
333                 pr(p);
334             }
335         }
336         pr("\n");
337     }
338 }
339
340 void
341 show_plane_stats(int tlev)
342 {
343     struct plchrstr *pp;
344     int pcount;
345
346     pr("%25s acc load att def ran fuel stlth\n", "");
347     make_new_list(tlev, EF_PLANE);
348     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
349         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
350         pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
351            pp->pl_name,
352            (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
353            (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
354            (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
355            (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
356            (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
357            pp->pl_fuel);
358         pr("%4d%% ", pp->pl_stealth);
359         pr("\n");
360     }
361 }
362
363 void
364 show_plane_capab(int tlev)
365 {
366     struct plchrstr *pp;
367     int i;
368     int pcount;
369     int n;
370     char *p;
371
372     pr("%25s capabilities\n", "");
373     make_new_list(tlev, EF_PLANE);
374     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
375         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
376         pr("%-25.25s  ", pp->pl_name);
377
378         for (i = n = 0; i < 32; i++) {
379             if (!(pp->pl_flags & bit(i)))
380                 continue;
381             if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
382                 if (n++ > 0)
383                     pr(" ");
384                 pr(p);
385             }
386         }
387         pr("\n");
388     }
389 }
390
391 void
392 show_plane_build(int tlev)
393 {
394     struct plchrstr *pp;
395     int pcount;
396
397     pr("%25s lcm hcm crew avail tech $\n", "");
398     make_new_list(tlev, EF_PLANE);
399     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
400         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
401         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
402            pp->pl_name, pp->pl_lcm,
403            pp->pl_hcm, pp->pl_crew,
404            PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
405     }
406 }
407
408 void
409 show_land_build(int tlev)
410 {
411     struct lchrstr *lp;
412     int n;
413
414     pr("%25s lcm hcm guns avail tech $\n", "");
415     make_new_list(tlev, EF_LAND);
416     for (n = 0; n < lookup_list_cnt; n++) {
417         lp = (struct lchrstr *)lookup_list[n].l_u.lp;
418         if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
419             continue;
420         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
421            lp->l_name, lp->l_lcm,
422            lp->l_hcm,
423            lp->l_gun,
424            LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
425     }
426 }
427
428 void
429 show_land_capab(int tlev)
430 {
431     struct lchrstr *lcp;
432     int lcount;
433     i_type i;
434     int j, n;
435     char *p;
436
437     pr("%25s capabilities\n", "");
438
439     make_new_list(tlev, EF_LAND);
440     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
441         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
442         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
443             continue;
444
445         pr("%-25s ", lcp->l_name);
446
447         for (i = I_NONE + 1; i <= I_MAX; ++i)
448             if (lcp->l_item[i])
449                 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
450         pr(" ");
451         for (j = n = 0; j < 32; j++) {
452             if (!(lcp->l_flags & bit(j)))
453                 continue;
454             if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
455                 if (n++ > 0)
456                     pr(" ");
457                 pr(p);
458             }
459         }
460         pr("\n");
461     }
462 }
463
464 void
465 show_land_stats(int tlev)
466 {
467     struct lchrstr *lcp;
468     int lcount;
469     int ourtlev;
470
471     pr("%25s              s  v  s  r  r  a  f  a  a        x  l\n", "");
472     pr("%25s              p  i  p  a  n  c  i  m  a  f  f  p  n\n", "");
473     pr("%25s att def vul  d  s  y  d  g  c  r  m  f  c  u  l  d\n", "");
474
475     make_new_list(tlev, EF_LAND);
476     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
477         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
478         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
479             continue;
480
481         ourtlev = (int)(tlev - lcp->l_tech);
482         pr("%-25s %1.1f %1.1f %3d ",
483            lcp->l_name, (float)LND_ATTDEF(lcp->l_att, ourtlev),
484            (float)LND_ATTDEF(lcp->l_def, ourtlev),
485            (int)LND_VUL(lcp->l_vul, ourtlev));
486         pr("%2d %2d %2d %2d ",
487            (int)LND_SPD(lcp->l_spd, ourtlev),
488            (int)LND_VIS(lcp->l_vis, ourtlev),
489            (int)LND_SPY(lcp->l_spy, ourtlev),
490            (int)LND_RAD(lcp->l_rad, ourtlev));
491         pr("%2d %2d %2d %2d %2d ",
492            (int)LND_FRG(lcp->l_frg, ourtlev),
493            (int)LND_ACC(lcp->l_acc, ourtlev),
494            (int)LND_DAM(lcp->l_dam, ourtlev),
495            (int)LND_AMM(lcp->l_ammo, lcp->l_dam, ourtlev),
496            (int)LND_AAF(lcp->l_aaf, ourtlev));
497         pr("%2d %2d %2d %2d ",
498            (int)LND_FC(lcp->l_fuelc, ourtlev),
499            (int)LND_FU(lcp->l_fuelu, ourtlev),
500            (int)LND_XPL(lcp->l_nxlight, ourtlev),
501            (int)LND_MXL(lcp->l_mxland, ourtlev));
502
503         pr("\n");
504     }
505 }
506
507 void
508 show_sect_build(int foo)
509 {
510     int x, first = 1;
511
512     for (x = 0; x <= SCT_MAXDEF; x++) {
513         if (dchr[x].d_mnem == 0)
514             continue;
515         if (dchr[x].d_cost < 0)
516             continue;
517         if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
518             (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
519             if (first) {
520                 pr("sector type    cost to des    cost for 1%% eff   lcms for 1%%    hcms for 1%%\n");
521                 first = 0;
522             }
523             pr("%-14c %-14d %-17d %-14d %d\n",
524                dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
525                dchr[x].d_lcms, dchr[x].d_hcms);
526         }
527     }
528     pr("\n");
529     pr("Infrastructure building - adding 1 point of efficiency costs:\n");
530     pr("       type          lcms    hcms    mobility    $$$$\n");
531     for (x = 0; intrchr[x].in_name; x++) {
532         pr("%-20s %4d    %4d    %8d    %4d\n", intrchr[x].in_name,
533            intrchr[x].in_lcms, intrchr[x].in_hcms,
534            intrchr[x].in_mcost, intrchr[x].in_dcost);
535     }
536 }
537
538 void
539 show_sect_stats(int foo)
540 {
541     int x, first = 1;
542     struct natstr *natp;
543
544     natp = getnatp(player->cnum);
545     for (x = 0; x <= SCT_MAXDEF; x++) {
546         if (dchr[x].d_mnem == 0)
547             continue;
548         if (first) {
549             pr("                        base     max   max   --  packing bonus  --   max\n");
550             pr("  sector type           mcost    off   def   mil  uw civ bar other   pop\n");
551             first = 0;
552         }
553         pr("%c %-23s %3d  %5.2f %5.2f   %3d %3d %3d %3d %5d %5d\n",
554            dchr[x].d_mnem, dchr[x].d_name,
555            dchr[x].d_mcst, dchr[x].d_ostr,
556            dchr[x].d_dstr,
557            ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
558            ichr[I_UW].i_pkg[dchr[x].d_pkg],
559            ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
560            ichr[I_BAR].i_pkg[dchr[x].d_pkg],
561            ichr[I_LCM].i_pkg[dchr[x].d_pkg],
562            max_population(natp->nat_level[NAT_RLEV], x, 100));
563     }
564 }
565
566 void
567 show_sect_capab(int foo)
568 {
569     int x, first = 1, i, j;
570     char *tmpstr;
571
572     for (x = 0; x <= SCT_MAXDEF; x++) {
573         if ((dchr[x].d_mnem == 0) || (dchr[x].d_prd == 0))
574             continue;
575         if (first) {
576             pr("                                                 --- level ---          reso \n");
577             pr("  sector type             product use1 use2 use3 level min lag eff%% $$$ dep c\n");
578             first = 0;
579         }
580
581         j = dchr[x].d_prd;
582
583         pr("%c %-23s %-7s ", dchr[x].d_mnem, dchr[x].d_name,
584            pchr[j].p_sname);
585         (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
586         for (i = 0; i < 3; i++) {
587             if (i < MAXPRCON
588                 && pchr[j].p_camt[i]
589                 && pchr[j].p_ctype[i] > I_NONE
590                 && pchr[j].p_ctype[i] <= I_MAX) {
591                 pr("%2d %c ", pchr[j].p_camt[i],
592                    ichr[pchr[j].p_ctype[i]].i_name[0]);
593             } else {
594                 pr("     ");
595             }
596         }
597         switch (pchr[j].p_nlndx) {
598         case NAT_TLEV:
599             tmpstr = "tech";
600             break;
601         case NAT_ELEV:
602             tmpstr = "edu";
603             break;
604         case NAT_RLEV:
605             tmpstr = "res";
606             break;
607         case NAT_HLEV:
608             tmpstr = "hap";
609             break;
610         default:
611             tmpstr = " ";
612             break;
613         }
614         pr("%-5s %3d %3d %4d %3d %3d %c",
615            tmpstr,
616            pchr[j].p_nlmin,
617            pchr[j].p_nllag,
618            pchr[j].p_effic, pchr[j].p_cost, pchr[j].p_nrdep,
619            pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
620
621         pr("\n");
622     }
623 }