2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * show.c: General show routines
30 * Known contributors to this file:
37 * general routines that are callable to give info on things.
38 * currently, planes, ships, nukes and bridges. Tanks & regiments one day?
40 * Added nuke_flags to be consistent. Jeff Bailey 12/15/90
41 * (bailey@mcs.kent.edu)
56 #include "prototypes.h"
59 double logx(double, double);
62 * This cruft really belongs in the empglb.c file.
71 struct lookup ship_flags[] = {
86 {M_SEMILAND, "semi-land"},
89 {M_ANTIMISSILE, "anti-missile"},
93 struct lookup land_flags[] = {
95 {L_ENGINEER, "engineer"},
97 {L_SECURITY, "security"},
102 {L_ASSAULT, "assault"},
111 struct lookup plane_flags[] = {
124 {P_H, "half-stealth"},
136 struct lookup nuke_flags[] = {
149 } lookup_list[200]; /* Change this if there are ever more than 200 planes, ships
151 static int lookup_list_cnt = 0;
154 sort_lookup_list(void)
156 struct natstr *np = getnatp(player->cnum);
157 struct look_list tmp;
161 if (!(np->nat_flags & NF_TECHLISTS))
163 for (i = 0; i < lookup_list_cnt; i++) {
164 for (j = i; j < lookup_list_cnt; j++) {
165 if (lookup_list[j].tech < lookup_list[i].tech) {
166 tmp = lookup_list[j];
167 lookup_list[j] = lookup_list[i];
168 lookup_list[i] = tmp;
176 make_new_list(int tlev, int type)
184 if (type == EF_PLANE) {
185 for (pp = plchr, count = 0; count < pln_maxno; count++, pp++) {
186 if (pp->pl_tech > tlev)
188 if (pp->pl_name == 0 || pp->pl_name[0] == '\0')
190 lookup_list[lookup_list_cnt].l_u.pp = pp;
191 lookup_list[lookup_list_cnt].tech = pp->pl_tech;
194 } else if (type == EF_SHIP) {
195 for (mp = mchr, count = 0; count < shp_maxno; count++, mp++) {
196 if (mp->m_tech > tlev)
198 if (mp->m_name == 0 || mp->m_name[0] == '\0')
200 lookup_list[lookup_list_cnt].l_u.mp = mp;
201 lookup_list[lookup_list_cnt].tech = mp->m_tech;
204 } else if (type == EF_LAND) {
205 for (lp = lchr, count = 0; count < lnd_maxno; count++, lp++) {
206 if (lp->l_tech > tlev)
208 if (lp->l_name == 0 || lp->l_name[0] == '\0')
210 lookup_list[lookup_list_cnt].l_u.lp = lp;
211 lookup_list[lookup_list_cnt].tech = lp->l_tech;
222 lookup(int key, struct lookup *table)
226 if ((match = intmatch(key, &table->key, sizeof(*table))) < 0)
228 return table[match].value;
232 show_bridge(int tlev)
234 extern double buil_bt, buil_bc;
239 pr("Bridges require %g tech,", buil_bt);
241 pr(" %d hcm,", buil_bh);
242 else if (!opt_NO_LCMS)
243 pr(" %d lcm,", buil_bh);
244 pr(" %d workers,\n", buil_bh * 2);
245 pr("%d available workforce, and cost $%g\n",
246 1 + (buil_bh * 40 / 100), buil_bc);
252 extern double buil_tower_bt, buil_tower_bc;
253 extern int buil_tower_bh;
255 if (tlev < buil_tower_bt)
257 pr("Bridge Towers require %g tech,", buil_tower_bt);
259 pr(" %d hcm,", buil_tower_bh);
260 else if (!opt_NO_LCMS)
261 pr(" %d lcm,", buil_tower_bh);
262 pr(" %d workers,\n", buil_tower_bh * 2);
263 pr("%d available workforce, and cost $%g\n",
264 1 + (buil_tower_bh * 40 / 100), buil_tower_bc);
268 show_nuke_stats(int tlev)
270 show_nuke_capab(tlev);
274 show_nuke_build(int tlev)
276 register struct nchrstr *np;
279 extern float drnuke_const;
282 pr("%13s lcm hcm oil rad avail tech res $\n", "");
284 pr("%13s lcm hcm oil rad avail tech $\n", "");
288 for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) {
290 (4 + np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2) / 5;
291 if (np->n_tech > tlev)
293 if (np->n_name == 0 || np->n_name[0] == '\0')
295 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
298 pr("%-13.13s %3d %3d %4d %4d %5d %4d %3d $%6d\n",
299 np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
300 np->n_rad, avail, np->n_tech,
301 (int)(np->n_tech * drnuke_const) + 1, np->n_cost);
302 else /* not DRNUKE */
303 pr("%-13.13s %3d %3d %4d %4d %5d %4d $%6d\n",
304 np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
305 np->n_rad, avail, np->n_tech, np->n_cost);
310 show_nuke_capab(int tlev)
312 register struct nchrstr *np;
313 register int i, j, n;
315 extern float drnuke_const;
318 pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
320 pr("%13s blst dam lbs tech $%7s abilities\n", "", "");
324 for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) {
325 if (np->n_tech > tlev)
327 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
329 if (np->n_name == 0 || np->n_name[0] == '\0')
332 pr("%-13.13s %4d %3d %3d %4d %3d $%7d ",
333 np->n_name, np->n_blast, np->n_dam,
334 np->n_weight, np->n_tech,
335 (int)(np->n_tech * drnuke_const) + 1, np->n_cost);
336 else /* not DRNUKE */
337 pr("%-13.13s %4d %3d %3d %4d $%7d ",
338 np->n_name, np->n_blast, np->n_dam,
339 np->n_weight, np->n_tech, np->n_cost);
341 for (i = j = 0; i < 32; i++) {
342 if (!(np->n_flags & bit(i)))
344 if (NULL != (p = lookup(bit(i), nuke_flags))) {
355 show_ship_build(int tlev)
357 register struct mchrstr *mp;
360 pr("%25s lcm hcm avail tech $\n", "");
361 make_new_list(tlev, EF_SHIP);
362 for (n = 0; n < lookup_list_cnt; n++) {
363 mp = (struct mchrstr *)lookup_list[n].l_u.mp;
364 /* Can't show trade ships unless it's turned on */
365 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
368 pr("%-25.25s %3d %3d %5d %4d $%d\n",
369 mp->m_name, mp->m_lcm, mp->m_hcm,
370 20 + mp->m_lcm + mp->m_hcm * 2, mp->m_tech, mp->m_cost);
375 show_ship_stats(int tlev)
377 register struct mchrstr *mp;
381 pr("%25s s v s r f l p", "");
388 pr("%25s p i p n i n l", "");
395 pr("%25s def d s y g r d n", "");
403 make_new_list(tlev, EF_SHIP);
404 for (scount = 0; scount < lookup_list_cnt; scount++) {
405 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
406 /* Can't show trade ships unless it's turned on */
407 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
410 techdiff = (int)(tlev - mp->m_tech);
411 pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
413 (short)SHP_DEF(mp->m_armor, techdiff),
414 (short)SHP_SPD(mp->m_speed, techdiff),
415 (short)SHP_VIS(mp->m_visib, techdiff),
417 (short)SHP_RNG(mp->m_frnge, techdiff),
418 (short)SHP_FIR(mp->m_glim, techdiff));
420 pr("%2d ", mp->m_nland);
421 pr("%2d ", mp->m_nplanes);
422 pr("%2d ", mp->m_nchoppers);
423 pr("%2d ", mp->m_nxlight);
425 pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
431 show_ship_capab(int tlev)
433 register struct mchrstr *mp;
434 register u_short *ap;
435 register u_char *type;
443 pr("%25s cargos & capabilities\n", "");
445 make_new_list(tlev, EF_SHIP);
446 for (scount = 0; scount < lookup_list_cnt; scount++) {
447 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
448 /* Can't show trade ships unless it's turned on */
449 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
452 pr("%-25.25s ", mp->m_name);
455 * should use vector stuff
457 for (ap = mp->m_vamt, type = mp->m_vtype, i = 0;
458 i < mp->m_nv; i++, ap++, type++) {
459 it = unitem((int)*type);
460 if (it > 0 && it <= I_MAX && ichr[it].i_name != 0)
461 c = ichr[it].i_name[0];
467 for (i = n = 0; i < 32; i++) {
468 if (!(mp->m_flags & bit(i)))
470 if (NULL != (p = lookup(bit(i), ship_flags))) {
481 show_plane_stats(int tlev)
483 register struct plchrstr *pp;
486 pr("%25s acc load att def ran fuel stlth\n", "");
487 make_new_list(tlev, EF_PLANE);
488 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
489 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
490 pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
492 (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
493 (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
494 (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
495 (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
496 (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
498 pr("%4d%% ", pp->pl_stealth);
504 show_plane_capab(int tlev)
506 register struct plchrstr *pp;
512 pr("%25s capabilities\n", "");
513 make_new_list(tlev, EF_PLANE);
514 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
515 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
516 pr("%-25.25s ", pp->pl_name);
518 for (i = n = 0; i < 32; i++) {
519 if (!(pp->pl_flags & bit(i)))
521 if (NULL != (p = lookup(bit(i), plane_flags))) {
532 show_plane_build(int tlev)
534 register struct plchrstr *pp;
537 pr("%25s lcm hcm crew avail tech $\n", "");
538 make_new_list(tlev, EF_PLANE);
539 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
540 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
541 pr("%-25.25s %3d %3d %3d %5d %4d $%d\n",
542 pp->pl_name, pp->pl_lcm,
543 pp->pl_hcm, pp->pl_crew,
544 20 + 2 * pp->pl_hcm + pp->pl_lcm, pp->pl_tech, pp->pl_cost);
549 show_land_build(int tlev)
551 register struct lchrstr *lp;
554 pr("%25s lcm hcm guns avail tech $\n", "");
555 make_new_list(tlev, EF_LAND);
556 for (n = 0; n < lookup_list_cnt; n++) {
557 lp = (struct lchrstr *)lookup_list[n].l_u.lp;
558 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
560 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
561 lp->l_name, lp->l_lcm,
564 20 + lp->l_lcm + (lp->l_hcm * 2), lp->l_tech, lp->l_cost);
569 show_land_capab(int tlev)
573 register u_short *ap;
574 register u_char *type;
577 register s_char *p, c;
579 pr("%25s capabilities\n", "");
581 make_new_list(tlev, EF_LAND);
582 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
583 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
584 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
587 pr("%-25s ", lcp->l_name);
590 * should use vector stuff
592 for (ap = lcp->l_vamt, type = lcp->l_vtype, i = 0;
593 i < lcp->l_nv; i++, ap++, type++) {
594 it = unitem((int)*type);
595 if (it > 0 && it <= I_MAX && ichr[it].i_name != 0)
596 c = ichr[it].i_name[0];
602 for (i = n = 0; i < 32; i++) {
603 if (!(lcp->l_flags & bit(i)))
605 if (NULL != (p = lookup(bit(i), land_flags))) {
616 show_land_stats(int tlev)
622 pr("%25s s v s r r a f a a x l\n", "");
623 pr("%25s p i p a n c i m a f f p n\n", "");
624 pr("%25s att def vul d s y d g c r m f c u l d\n", "");
626 make_new_list(tlev, EF_LAND);
627 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
628 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
629 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
632 ourtlev = (int)(tlev - lcp->l_tech);
633 pr("%-25s %1.1f %1.1f %3d ",
634 lcp->l_name, (float)LND_ATTDEF(lcp->l_att, ourtlev),
635 (float)LND_ATTDEF(lcp->l_def, ourtlev),
636 (int)LND_VUL(lcp->l_vul, ourtlev));
637 pr("%2d %2d %2d %2d ",
638 (int)LND_SPD(lcp->l_spd, ourtlev),
639 (int)LND_VIS(lcp->l_vis, ourtlev),
640 (int)LND_SPY(lcp->l_spy, ourtlev),
641 (int)LND_RAD(lcp->l_rad, ourtlev));
642 pr("%2d %2d %2d %2d %2d ",
643 (int)LND_FRG(lcp->l_frg, ourtlev),
644 (int)LND_ACC(lcp->l_acc, ourtlev),
645 (int)LND_DAM(lcp->l_dam, ourtlev),
646 (int)LND_AMM(lcp->l_ammo, lcp->l_dam, ourtlev),
647 (int)LND_AAF(lcp->l_aaf, ourtlev));
648 pr("%2d %2d %2d %2d ",
649 (int)LND_FC(lcp->l_fuelc, ourtlev),
650 (int)LND_FU(lcp->l_fuelu, ourtlev),
651 (int)LND_XPL(lcp->l_nxlight, ourtlev),
652 (int)LND_MXL(lcp->l_mxland, ourtlev));
659 show_sect_build(int foo)
661 register int x, first = 1;
663 for (x = 5; x < SCT_MAXDEF + 2; x++) {
664 if (dchr[x].d_mnem == 0)
666 if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
667 (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
669 pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
672 pr("%-14c %-14d %-17d %-14d %d\n",
673 dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
674 dchr[x].d_lcms, dchr[x].d_hcms);
678 pr("Infrastructure building - adding 1 point of efficiency costs:\n");
679 pr(" type lcms hcms mobility $$$$\n");
680 for (x = 0; intrchr[x].in_name; x++) {
681 pr("%-20s %4d %4d %8d %4d\n", intrchr[x].in_name,
682 intrchr[x].in_lcms, intrchr[x].in_hcms,
683 intrchr[x].in_mcost, intrchr[x].in_dcost);
688 show_sect_stats(int foo)
690 register int x, first = 1;
694 natp = getnatp(player->cnum);
696 sect.sct_effic = 100;
697 for (x = 0; x < SCT_MAXDEF + 2; x++) {
698 if (dchr[x].d_mnem == 0)
701 pr(" base max max -- packing bonus -- max\n");
702 pr(" sector type mcost off def mil uw civ bar other pop\n");
706 pr("%c %-23s %3d %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n",
707 dchr[x].d_mnem, dchr[x].d_name,
708 dchr[x].d_mcst, dchr[x].d_ostr,
710 ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
711 ichr[I_UW].i_pkg[dchr[x].d_pkg],
712 ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
713 ichr[I_BAR].i_pkg[dchr[x].d_pkg],
714 ichr[I_LCM].i_pkg[dchr[x].d_pkg],
715 max_pop(natp->nat_level[NAT_RLEV], §));
720 show_sect_capab(int foo)
722 register int x, first = 1, i, j;
725 char *outputs = " cmsgpidbfolhur";
727 for (x = 0; x < SCT_MAXDEF + 2; x++) {
728 if ((dchr[x].d_mnem == 0) || (dchr[x].d_prd == 0))
731 pr(" --- level --- reso \n");
732 pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n");
738 pr("%c %-23s %-7s ", dchr[x].d_mnem, dchr[x].d_name,
740 /*for(i=0;i<MAXCHRNV;i++) */
741 /* XXX currently no more than 3 items actually used */
742 for (i = 0; i < 3; i++) {
743 if ((i < pchr[j].p_nv) && (pchr[j].p_vamt[i] > 0)) {
744 pr("%2d %c ", pchr[j].p_vamt[i],
745 ichr[pchr[j].p_vtype[i] & (~VT_ITEM)].i_name[0]);
750 switch (pchr[j].p_nlndx) {
768 c = outputs[pchr[j].p_type - VT_ITEM];
771 pr("%-5s %3d %3d %4d %3d %3d %c",
775 pchr[j].p_effic, pchr[j].p_cost, pchr[j].p_nrdep, c);