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