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