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