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