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