]> git.pond.sub.org Git - empserver/blob - src/lib/subs/show.c
(LND_AMM): Became weird in 4.2.3: ammo use depends on l_dam if l_ammo
[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  *     Markus Armbruster, 2006
36  */
37
38 #include <config.h>
39
40 #include <math.h>
41 #include "misc.h"
42 #include "player.h"
43 #include "nuke.h"
44 #include "ship.h"
45 #include "land.h"
46 #include "item.h"
47 #include "plane.h"
48 #include "sect.h"
49 #include "optlist.h"
50 #include "file.h"
51 #include "nat.h"
52 #include "prototypes.h"
53 #include "nsc.h"
54 #include "news.h"
55
56 struct look_list {
57     union {
58         struct lchrstr *lp;
59         struct plchrstr *pp;
60         struct mchrstr *mp;
61     } l_u;
62     int tech;
63 };
64
65 /*
66  * Change this if there are ever more than 200 ships, plane or land
67  * unit types.
68  */
69 static struct look_list lookup_list[200];
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     pr("%13s lcm hcm  oil  rad avail tech res $\n", "");
170
171     for (np = nchr; np->n_name; np++) {
172         avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
173         if (np->n_tech > tlev)
174             continue;
175         pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
176            np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
177            np->n_rad, avail, np->n_tech,
178            drnuke_const > MIN_DRNUKE_CONST ?
179                 (np->n_tech * drnuke_const) + 1.0 : 0.0,
180            np->n_cost);
181     }
182 }
183
184 void
185 show_nuke_capab(int tlev)
186 {
187     struct nchrstr *np;
188     int i, j;
189     char *p;
190
191     pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
192
193     for (np = nchr; np->n_name; np++) {
194         if (np->n_tech > tlev)
195             continue;
196         pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
197            np->n_name, np->n_blast, np->n_dam,
198            np->n_weight, np->n_tech,
199            drnuke_const > MIN_DRNUKE_CONST ?
200                 (np->n_tech * drnuke_const) + 1.0 : 0.0,
201            np->n_cost);
202         for (i = j = 0; i < 32; i++) {
203             if (!(np->n_flags & bit(i)))
204                 continue;
205             if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
206                 if (j++ > 0)
207                     pr(" ");
208                 pr("%s", p);
209             }
210         }
211         pr("\n");
212     }
213 }
214
215 void
216 show_ship_build(int tlev)
217 {
218     struct mchrstr *mp;
219     int n;
220
221     pr("%25s lcm hcm avail tech $\n", "");
222     make_new_list(tlev, EF_SHIP);
223     for (n = 0; n < lookup_list_cnt; n++) {
224         mp = (struct mchrstr *)lookup_list[n].l_u.mp;
225         /* Can't show trade ships unless it's turned on */
226         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
227             continue;
228
229         pr("%-25.25s %3d %3d %5d %4d $%d\n",
230            mp->m_name, mp->m_lcm, mp->m_hcm,
231            SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
232     }
233 }
234
235 void
236 show_ship_stats(int tlev)
237 {
238     struct mchrstr *mp;
239     int scount;
240     int techdiff;
241
242     pr("%25s      s  v  s  r  f  l  p", "");
243     pr("  h");
244     pr("  x");
245     if (opt_FUEL)
246         pr("  fuel");
247     pr("\n");
248
249     pr("%25s      p  i  p  n  i  n  l", "");
250     pr("  e");
251     pr("  p");
252     if (opt_FUEL)
253         pr("   c/u");
254     pr("\n");
255
256     pr("%25s def  d  s  y  g  r  d  n", "");
257     pr("  l");
258     pr("  l");
259     if (opt_FUEL)
260         pr("      ");
261     pr("\n");
262
263
264     make_new_list(tlev, EF_SHIP);
265     for (scount = 0; scount < lookup_list_cnt; scount++) {
266         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
267         /* Can't show trade ships unless it's turned on */
268         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
269             continue;
270
271         techdiff = (int)(tlev - mp->m_tech);
272         pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
273            mp->m_name,
274            (short)SHP_DEF(mp->m_armor, techdiff),
275            (short)SHP_SPD(mp->m_speed, techdiff),
276            (short)SHP_VIS(mp->m_visib, techdiff),
277            mp->m_vrnge,
278            (short)SHP_RNG(mp->m_frnge, techdiff),
279            (short)SHP_FIR(mp->m_glim, techdiff));
280
281         pr("%2d ", mp->m_nland);
282         pr("%2d ", mp->m_nplanes);
283         pr("%2d ", mp->m_nchoppers);
284         pr("%2d ", mp->m_nxlight);
285         if (opt_FUEL)
286             pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
287         pr("\n");
288     }
289 }
290
291 void
292 show_ship_capab(int tlev)
293 {
294     struct mchrstr *mp;
295     i_type i;
296     int j;
297     int scount;
298     int n;
299     char *p;
300
301     pr("%25s cargos & capabilities\n", "");
302
303     make_new_list(tlev, EF_SHIP);
304     for (scount = 0; scount < lookup_list_cnt; scount++) {
305         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
306         /* Can't show trade ships unless it's turned on */
307         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
308             continue;
309
310         pr("%-25.25s ", mp->m_name);
311
312         for (i = I_NONE + 1; i <= I_MAX; ++i)
313             if (mp->m_item[i])
314                 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
315         pr(" ");
316         for (j = n = 0; j < 32; j++) {
317             if (!(mp->m_flags & bit(j)))
318                 continue;
319             if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
320                 if (n++ > 0)
321                     pr(" ");
322                 pr("%s", p);
323             }
324         }
325         pr("\n");
326     }
327 }
328
329 void
330 show_plane_stats(int tlev)
331 {
332     struct plchrstr *pp;
333     int pcount;
334
335     pr("%25s acc load att def ran fuel stlth\n", "");
336     make_new_list(tlev, EF_PLANE);
337     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
338         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
339         pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
340            pp->pl_name,
341            (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
342            (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
343            (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
344            (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
345            (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
346            pp->pl_fuel);
347         pr("%4d%% ", pp->pl_stealth);
348         pr("\n");
349     }
350 }
351
352 void
353 show_plane_capab(int tlev)
354 {
355     struct plchrstr *pp;
356     int i;
357     int pcount;
358     int n;
359     char *p;
360
361     pr("%25s capabilities\n", "");
362     make_new_list(tlev, EF_PLANE);
363     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
364         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
365         pr("%-25.25s  ", pp->pl_name);
366
367         for (i = n = 0; i < 32; i++) {
368             if (!(pp->pl_flags & bit(i)))
369                 continue;
370             if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
371                 if (n++ > 0)
372                     pr(" ");
373                 pr("%s", p);
374             }
375         }
376         pr("\n");
377     }
378 }
379
380 void
381 show_plane_build(int tlev)
382 {
383     struct plchrstr *pp;
384     int pcount;
385
386     pr("%25s lcm hcm crew avail tech $\n", "");
387     make_new_list(tlev, EF_PLANE);
388     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
389         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
390         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
391            pp->pl_name, pp->pl_lcm,
392            pp->pl_hcm, pp->pl_crew,
393            PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
394     }
395 }
396
397 void
398 show_land_build(int tlev)
399 {
400     struct lchrstr *lp;
401     int n;
402
403     pr("%25s lcm hcm guns avail tech $\n", "");
404     make_new_list(tlev, EF_LAND);
405     for (n = 0; n < lookup_list_cnt; n++) {
406         lp = (struct lchrstr *)lookup_list[n].l_u.lp;
407         if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
408             continue;
409         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
410            lp->l_name, lp->l_lcm,
411            lp->l_hcm,
412            lp->l_gun,
413            LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
414     }
415 }
416
417 void
418 show_land_capab(int tlev)
419 {
420     struct lchrstr *lcp;
421     int lcount;
422     i_type i;
423     int j, n;
424     char *p;
425
426     pr("%25s capabilities\n", "");
427
428     make_new_list(tlev, EF_LAND);
429     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
430         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
431         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
432             continue;
433
434         pr("%-25s ", lcp->l_name);
435
436         for (i = I_NONE + 1; i <= I_MAX; ++i)
437             if (lcp->l_item[i])
438                 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
439         pr(" ");
440         for (j = n = 0; j < 32; j++) {
441             if (!(lcp->l_flags & bit(j)))
442                 continue;
443             if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
444                 if (n++ > 0)
445                     pr(" ");
446                 pr("%s", p);
447             }
448         }
449         pr("\n");
450     }
451 }
452
453 void
454 show_land_stats(int tlev)
455 {
456     struct lchrstr *lcp;
457     int lcount;
458     int ourtlev;
459
460     pr("%25s              s  v  s  r  r  a  f  a  a        x  l\n", "");
461     pr("%25s              p  i  p  a  n  c  i  m  a  f  f  p  n\n", "");
462     pr("%25s att def vul  d  s  y  d  g  c  r  m  f  c  u  l  d\n", "");
463
464     make_new_list(tlev, EF_LAND);
465     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
466         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
467         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
468             continue;
469
470         ourtlev = (int)(tlev - lcp->l_tech);
471         pr("%-25s %1.1f %1.1f %3d ",
472            lcp->l_name,
473            LND_ATTDEF(lcp->l_att, ourtlev),
474            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, 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;
501
502     first = 1;
503     for (x = 0; dchr[x].d_name; x++) {
504         if (dchr[x].d_mnem == 0)
505             continue;
506         if (dchr[x].d_cost < 0)
507             continue;
508         if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
509             (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
510             if (first) {
511                 pr("sector type    cost to des    cost for 1%% eff   lcms for 1%%    hcms for 1%%\n");
512                 first = 0;
513             }
514             pr("%-14c %-14d %-17d %-14d %d\n",
515                dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
516                dchr[x].d_lcms, dchr[x].d_hcms);
517         }
518     }
519
520     first = 1;
521     for (x = 0; intrchr[x].in_name; x++) {
522         if (!intrchr[x].in_enable)
523             continue;
524         if (first)
525             pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
526                "       type          lcms    hcms    mobility    $$$$\n");
527         pr("%-20s %4d    %4d    %8d    %4d\n",
528            intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
529            intrchr[x].in_mcost, intrchr[x].in_dcost);
530         first = 0;
531     }
532 }
533
534 void
535 show_sect_stats(int foo)
536 {
537     int x, first = 1;
538     struct natstr *natp;
539
540     natp = getnatp(player->cnum);
541     for (x = 0; dchr[x].d_name; x++) {
542         if (dchr[x].d_mnem == 0)
543             continue;
544         if (first) {
545             pr("                        mob cost   max   max   --  packing bonus  --   max\n");
546             pr("  sector type            0%% 100%%   off   def   mil  uw civ bar other   pop\n");
547             first = 0;
548         }
549         pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
550         if (dchr[x].d_mob0 < 0)
551             pr("  no way ");
552         else
553             pr(" %3.1f  %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
554         pr("  %5.2f %5.2f   %3d %3d %3d %3d %5d %5d\n",
555            dchr[x].d_ostr, dchr[x].d_dstr,
556            ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
557            ichr[I_UW].i_pkg[dchr[x].d_pkg],
558            ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
559            ichr[I_BAR].i_pkg[dchr[x].d_pkg],
560            ichr[I_LCM].i_pkg[dchr[x].d_pkg],
561            max_population(natp->nat_level[NAT_RLEV], x, 100));
562     }
563 }
564
565 void
566 show_sect_capab(int foo)
567 {
568     int x, first = 1, i, j;
569     char *tmpstr;
570
571     for (x = 0; dchr[x].d_name; x++) {
572         if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
573             continue;
574         if (first) {
575             pr("                                                 --- level ---          reso \n");
576             pr("  sector type             product use1 use2 use3 level min lag eff%% $$$ dep c\n");
577             first = 0;
578         }
579
580         j = dchr[x].d_prd;
581
582         pr("%c %-23s %-7s ",
583            dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
584         (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
585         for (i = 0; i < 3; i++) {
586             if (i < MAXPRCON
587                 && pchr[j].p_camt[i]
588                 && pchr[j].p_ctype[i] > I_NONE
589                 && pchr[j].p_ctype[i] <= I_MAX) {
590                 pr("%2d %c ", pchr[j].p_camt[i],
591                    ichr[pchr[j].p_ctype[i]].i_name[0]);
592             } else {
593                 pr("     ");
594             }
595         }
596         switch (pchr[j].p_nlndx) {
597         case NAT_TLEV:
598             tmpstr = "tech";
599             break;
600         case NAT_ELEV:
601             tmpstr = "edu";
602             break;
603         case NAT_RLEV:
604             tmpstr = "res";
605             break;
606         case NAT_HLEV:
607             tmpstr = "hap";
608             break;
609         default:
610             tmpstr = " ";
611             break;
612         }
613         pr("%-5s %3d %3d %4d %3d %3d %c",
614            tmpstr,
615            pchr[j].p_nlmin,
616            pchr[j].p_nllag,
617            dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
618            pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
619
620         pr("\n");
621     }
622 }
623
624 void
625 show_item(int tlev)
626 {
627     struct ichrstr *ip;
628
629     pr("item value sell lbs    packing     melt  item\n");
630     pr("mnem                in rg wh ur bk deno  name\n");
631
632     for (ip = ichr; ip->i_name; ip++) {
633         pr("   %c %5d %4s %3d %2d %2d %2d %2d %2d %4d  %s\n",
634            ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
635            ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
636            ip->i_pkg[UPKG], ip->i_pkg[BPKG],
637            ip->i_melt_denom, ip->i_name);
638     }
639 }
640
641 void
642 show_news(int tlev)
643 {
644     int i, j;
645     
646     pr("id category           good will\n");
647     pr("    messsages\n");
648
649     for (i = 1; i < N_MAX_VERB + 1; i++) {
650         pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
651             page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
652
653         for (j = 0; j < NUM_RPTS; j++)
654             pr("    %s\n", rpt[i].r_newstory[j]);
655     }
656 }