2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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 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.
28 * show.c: General show routines
30 * Known contributors to this file:
34 * Ron Koenderink, 2005
35 * Markus Armbruster, 2006-2007
52 #include "prototypes.h"
57 static char *fmttime2822(time_t);
69 * Change this if there are ever more than 200 ships, plane or land
72 static struct look_list lookup_list[200];
73 static int lookup_list_cnt = 0;
76 sort_lookup_list(void)
78 struct natstr *np = getnatp(player->cnum);
83 if (!(np->nat_flags & NF_TECHLISTS))
85 for (i = 0; i < lookup_list_cnt; i++) {
86 for (j = i; j < lookup_list_cnt; j++) {
87 if (lookup_list[j].tech < lookup_list[i].tech) {
89 lookup_list[j] = lookup_list[i];
97 make_new_list(int tlev, int type)
104 if (type == EF_PLANE) {
105 for (pp = plchr; pp->pl_name; pp++) {
106 if (pp->pl_tech > tlev)
108 lookup_list[lookup_list_cnt].l_u.pp = pp;
109 lookup_list[lookup_list_cnt].tech = pp->pl_tech;
112 } else if (type == EF_SHIP) {
113 for (mp = mchr; mp->m_name; mp++) {
114 if (mp->m_tech > tlev)
116 lookup_list[lookup_list_cnt].l_u.mp = mp;
117 lookup_list[lookup_list_cnt].tech = mp->m_tech;
120 } else if (type == EF_LAND) {
121 for (lp = lchr; lp->l_name; lp++) {
122 if (lp->l_tech > tlev)
124 lookup_list[lookup_list_cnt].l_u.lp = lp;
125 lookup_list[lookup_list_cnt].tech = lp->l_tech;
135 show_bridge(int tlev)
139 pr("Bridges require %g tech,", buil_bt);
140 pr(" %d hcm,", buil_bh);
141 pr(" %d workers,\n", 0);
142 pr("%d available workforce, and cost $%g\n",
143 (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
150 if (tlev < buil_tower_bt)
152 pr("Bridge Towers require %g tech,", buil_tower_bt);
153 pr(" %d hcm,", buil_tower_bh);
154 pr(" %d workers,\n", 0);
155 pr("%d available workforce, and cost $%g\n",
156 (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
161 show_nuke_stats(int tlev)
163 show_nuke_capab(tlev);
167 show_nuke_build(int tlev)
172 pr("%13s lcm hcm oil rad avail tech res $\n", "");
174 for (np = nchr; np->n_name; np++) {
175 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
176 if (np->n_tech > tlev)
178 pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
179 np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
180 np->n_rad, avail, np->n_tech,
181 drnuke_const > MIN_DRNUKE_CONST ?
182 ceil(np->n_tech * drnuke_const) : 0.0,
188 show_nuke_capab(int tlev)
194 pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
196 for (np = nchr; np->n_name; np++) {
197 if (np->n_tech > tlev)
199 pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
200 np->n_name, np->n_blast, np->n_dam,
201 np->n_weight, np->n_tech,
202 drnuke_const > MIN_DRNUKE_CONST ?
203 ceil(np->n_tech * drnuke_const) : 0.0,
205 for (i = j = 0; i < 32; i++) {
206 if (!(np->n_flags & bit(i)))
208 if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
219 show_ship_build(int tlev)
224 pr("%25s lcm hcm avail tech $\n", "");
225 make_new_list(tlev, EF_SHIP);
226 for (n = 0; n < lookup_list_cnt; n++) {
227 mp = (struct mchrstr *)lookup_list[n].l_u.mp;
228 /* Can't show trade ships unless it's turned on */
229 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
232 pr("%-25.25s %3d %3d %5d %4d $%d\n",
233 mp->m_name, mp->m_lcm, mp->m_hcm,
234 SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
239 show_ship_stats(int tlev)
245 pr("%25s s v s r f l p", "");
252 pr("%25s p i p n i n l", "");
259 pr("%25s def d s y g r d n", "");
267 make_new_list(tlev, EF_SHIP);
268 for (scount = 0; scount < lookup_list_cnt; scount++) {
269 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
270 /* Can't show trade ships unless it's turned on */
271 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
274 techdiff = (int)(tlev - mp->m_tech);
275 pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
277 (short)SHP_DEF(mp->m_armor, techdiff),
278 (short)SHP_SPD(mp->m_speed, techdiff),
279 (short)SHP_VIS(mp->m_visib, techdiff),
281 (short)SHP_RNG(mp->m_frnge, techdiff),
282 (short)SHP_FIR(mp->m_glim, techdiff));
284 pr("%2d ", mp->m_nland);
285 pr("%2d ", mp->m_nplanes);
286 pr("%2d ", mp->m_nchoppers);
287 pr("%2d ", mp->m_nxlight);
289 pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
295 show_ship_capab(int tlev)
304 pr("%25s cargos & capabilities\n", "");
306 make_new_list(tlev, EF_SHIP);
307 for (scount = 0; scount < lookup_list_cnt; scount++) {
308 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
309 /* Can't show trade ships unless it's turned on */
310 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
313 pr("%-25.25s ", mp->m_name);
315 for (i = I_NONE + 1; i <= I_MAX; ++i)
317 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
319 for (j = n = 0; j < 32; j++) {
320 if (!(mp->m_flags & bit(j)))
322 if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
333 show_plane_stats(int tlev)
338 pr("%25s acc load att def ran fuel stlth\n", "");
339 make_new_list(tlev, EF_PLANE);
340 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
341 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
342 pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
344 (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
345 (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
346 (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
347 (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
348 (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
350 pr("%4d%% ", pp->pl_stealth);
356 show_plane_capab(int tlev)
364 pr("%25s capabilities\n", "");
365 make_new_list(tlev, EF_PLANE);
366 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
367 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
368 pr("%-25.25s ", pp->pl_name);
370 for (i = n = 0; i < 32; i++) {
371 if (!(pp->pl_flags & bit(i)))
373 if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
384 show_plane_build(int tlev)
389 pr("%25s lcm hcm crew avail tech $\n", "");
390 make_new_list(tlev, EF_PLANE);
391 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
392 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
393 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
394 pp->pl_name, pp->pl_lcm,
395 pp->pl_hcm, pp->pl_crew,
396 PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
401 show_land_build(int tlev)
406 pr("%25s lcm hcm guns avail tech $\n", "");
407 make_new_list(tlev, EF_LAND);
408 for (n = 0; n < lookup_list_cnt; n++) {
409 lp = (struct lchrstr *)lookup_list[n].l_u.lp;
410 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
412 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
413 lp->l_name, lp->l_lcm,
416 LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
421 show_land_capab(int tlev)
429 pr("%25s capabilities\n", "");
431 make_new_list(tlev, EF_LAND);
432 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
433 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
434 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
437 pr("%-25s ", lcp->l_name);
439 for (i = I_NONE + 1; i <= I_MAX; ++i)
441 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
443 for (j = n = 0; j < 32; j++) {
444 if (!(lcp->l_flags & bit(j)))
446 if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
457 show_land_stats(int tlev)
463 pr("%25s s v s r r a f a a x l\n", "");
464 pr("%25s p i p a n c i m a f f p n\n", "");
465 pr("%25s att def vul d s y d g c r m f c u l d\n", "");
467 make_new_list(tlev, EF_LAND);
468 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
469 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
470 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
473 ourtlev = (int)(tlev - lcp->l_tech);
474 pr("%-25s %1.1f %1.1f %3d ",
476 LND_ATTDEF(lcp->l_att, ourtlev),
477 LND_ATTDEF(lcp->l_def, ourtlev),
478 (int)LND_VUL(lcp->l_vul, ourtlev));
479 pr("%2d %2d %2d %2d ",
480 (int)LND_SPD(lcp->l_spd, ourtlev),
481 (int)LND_VIS(lcp->l_vis, ourtlev),
482 (int)LND_SPY(lcp->l_spy, ourtlev),
483 (int)LND_RAD(lcp->l_rad, ourtlev));
484 pr("%2d %2d %2d %2d %2d ",
485 (int)LND_FRG(lcp->l_frg, ourtlev),
486 (int)LND_ACC(lcp->l_acc, ourtlev),
487 (int)LND_DAM(lcp->l_dam, ourtlev),
488 (int)LND_AMM(lcp->l_ammo, ourtlev),
489 (int)LND_AAF(lcp->l_aaf, ourtlev));
490 pr("%2d %2d %2d %2d ",
491 (int)LND_FC(lcp->l_fuelc, ourtlev),
492 (int)LND_FU(lcp->l_fuelu, ourtlev),
493 (int)LND_XPL(lcp->l_nxlight, ourtlev),
494 (int)LND_MXL(lcp->l_nland, ourtlev));
501 show_sect_build(int foo)
506 for (x = 0; dchr[x].d_name; x++) {
507 if (dchr[x].d_mnem == 0)
509 if (dchr[x].d_cost < 0)
511 if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
512 (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
514 pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
517 pr("%-14c %-14d %-17d %-14d %d\n",
518 dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
519 dchr[x].d_lcms, dchr[x].d_hcms);
524 for (x = 0; intrchr[x].in_name; x++) {
525 if (!intrchr[x].in_enable)
528 pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
529 " type lcms hcms mobility $$$$\n");
530 pr("%-20s %4d %4d %8d %4d\n",
531 intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
532 intrchr[x].in_mcost, intrchr[x].in_dcost);
538 show_sect_stats(int foo)
543 natp = getnatp(player->cnum);
544 for (x = 0; dchr[x].d_name; x++) {
545 if (dchr[x].d_mnem == 0)
548 pr(" mob cost max max -- packing bonus -- max\n");
549 pr(" sector type 0%% 100%% off def mil uw civ bar other pop\n");
552 pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
553 if (dchr[x].d_mob0 < 0)
556 pr(" %3.1f %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
557 pr(" %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n",
558 dchr[x].d_ostr, dchr[x].d_dstr,
559 ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
560 ichr[I_UW].i_pkg[dchr[x].d_pkg],
561 ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
562 ichr[I_BAR].i_pkg[dchr[x].d_pkg],
563 ichr[I_LCM].i_pkg[dchr[x].d_pkg],
564 max_population(natp->nat_level[NAT_RLEV], x, 100));
569 show_sect_capab(int foo)
571 int x, first = 1, i, j;
574 for (x = 0; dchr[x].d_name; x++) {
575 if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
578 pr(" --- level --- reso \n");
579 pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n");
586 dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
587 (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
588 for (i = 0; i < 3; i++) {
591 && pchr[j].p_ctype[i] > I_NONE
592 && pchr[j].p_ctype[i] <= I_MAX) {
593 pr("%2d %c ", pchr[j].p_camt[i],
594 ichr[pchr[j].p_ctype[i]].i_name[0]);
599 switch (pchr[j].p_nlndx) {
616 pr("%-5s %3d %3d %4d %3d %3d %c",
620 dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
621 pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
632 pr("item value sell lbs packing melt item\n");
633 pr("mnem in rg wh ur bk deno name\n");
635 for (ip = ichr; ip->i_name; ip++) {
636 pr(" %c %5d %4s %3d %2d %2d %2d %2d %2d %4d %s\n",
637 ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
638 ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
639 ip->i_pkg[UPKG], ip->i_pkg[BPKG],
640 ip->i_melt_denom, ip->i_name);
649 pr("id category good will\n");
652 for (i = 1; i < N_MAX_VERB + 1; i++) {
653 if (rpt[i].r_newspage == N_NOTUSED)
655 pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
656 page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
657 for (j = 0; j < NUM_RPTS; j++)
658 pr(" %s\n", rpt[i].r_newstory[j]);
663 * Show update policy and up to N scheduled updates.
668 struct gamestr *game = game_tick_tick();
672 pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
673 game->game_turn, game->game_tick);
675 if (update_time[0]) {
676 if (update_demand == UPD_DEMAND_SCHED) {
677 pr("Demand updates occur according to schedule:\n");
680 pr("Updates occur according to schedule:\n");
681 for (i = 0; i < n && update_time[i]; i++)
682 pr("%3d. %s\n", game->game_turn + i,
683 fmttime2822(update_time[i]));
685 pr("Updates occur within %d seconds after the scheduled time\n",
689 pr("There are no updates scheduled.\n");
691 if (update_demand == UPD_DEMAND_ASYNC) {
692 pr("Demand updates occur right after the demand is set.\n");
693 if (*update_demandtimes != 0) {
694 pr("Demand updates are allowed during: %s\n",
701 pr("Demand updates require %d country(s) to want one.\n",
705 if (updates_disabled())
706 pr("\nUPDATES ARE DISABLED!\n");
710 * Return T formatted according to RFC 2822.
711 * The return value is statically allocated and overwritten on
715 fmttime2822(time_t t)
718 int n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
720 if (CANT_HAPPEN(n == 0))