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