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