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