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