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
56 #include "prototypes.h"
61 static char *fmttime2822(time_t);
73 * Change this if there are ever more than 200 ships, plane or land
76 static struct look_list lookup_list[200];
77 static int lookup_list_cnt = 0;
80 sort_lookup_list(void)
82 struct natstr *np = getnatp(player->cnum);
87 if (!(np->nat_flags & NF_TECHLISTS))
89 for (i = 0; i < lookup_list_cnt; i++) {
90 for (j = i; j < lookup_list_cnt; j++) {
91 if (lookup_list[j].tech < lookup_list[i].tech) {
93 lookup_list[j] = lookup_list[i];
101 make_new_list(int tlev, int type)
108 if (type == EF_PLANE) {
109 for (pp = plchr; pp->pl_name; pp++) {
110 if (pp->pl_tech > tlev)
112 lookup_list[lookup_list_cnt].l_u.pp = pp;
113 lookup_list[lookup_list_cnt].tech = pp->pl_tech;
116 } else if (type == EF_SHIP) {
117 for (mp = mchr; mp->m_name; mp++) {
118 if (mp->m_tech > tlev)
120 lookup_list[lookup_list_cnt].l_u.mp = mp;
121 lookup_list[lookup_list_cnt].tech = mp->m_tech;
124 } else if (type == EF_LAND) {
125 for (lp = lchr; lp->l_name; lp++) {
126 if (lp->l_tech > tlev)
128 lookup_list[lookup_list_cnt].l_u.lp = lp;
129 lookup_list[lookup_list_cnt].tech = lp->l_tech;
139 show_bridge(int tlev)
143 pr("Bridges require %g tech,", buil_bt);
144 pr(" %d hcm,", buil_bh);
145 pr(" %d workers,\n", 0);
146 pr("%d available workforce, and cost $%g\n",
147 (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
154 if (tlev < buil_tower_bt)
156 pr("Bridge Towers require %g tech,", buil_tower_bt);
157 pr(" %d hcm,", buil_tower_bh);
158 pr(" %d workers,\n", 0);
159 pr("%d available workforce, and cost $%g\n",
160 (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
165 show_nuke_stats(int tlev)
167 show_nuke_capab(tlev);
171 show_nuke_build(int tlev)
176 pr("%13s lcm hcm oil rad avail tech res $\n", "");
178 for (np = nchr; np->n_name; np++) {
179 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
180 if (np->n_tech > tlev)
182 pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
183 np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
184 np->n_rad, avail, np->n_tech,
185 drnuke_const > MIN_DRNUKE_CONST ?
186 ceil(np->n_tech * drnuke_const) : 0.0,
192 show_nuke_capab(int tlev)
198 pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
200 for (np = nchr; np->n_name; np++) {
201 if (np->n_tech > tlev)
203 pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
204 np->n_name, np->n_blast, np->n_dam,
205 np->n_weight, np->n_tech,
206 drnuke_const > MIN_DRNUKE_CONST ?
207 ceil(np->n_tech * drnuke_const) : 0.0,
209 for (i = j = 0; i < 32; i++) {
210 if (!(np->n_flags & bit(i)))
212 if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
223 show_ship_build(int tlev)
228 pr("%25s lcm hcm avail tech $\n", "");
229 make_new_list(tlev, EF_SHIP);
230 for (n = 0; n < lookup_list_cnt; n++) {
231 mp = (struct mchrstr *)lookup_list[n].l_u.mp;
232 /* Can't show trade ships unless it's turned on */
233 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
236 pr("%-25.25s %3d %3d %5d %4d $%d\n",
237 mp->m_name, mp->m_lcm, mp->m_hcm,
238 SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
243 show_ship_stats(int tlev)
249 pr("%25s s v s r f l p", "");
256 pr("%25s p i p n i n l", "");
263 pr("%25s def d s y g r d n", "");
271 make_new_list(tlev, EF_SHIP);
272 for (scount = 0; scount < lookup_list_cnt; scount++) {
273 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
274 /* Can't show trade ships unless it's turned on */
275 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
278 techdiff = (int)(tlev - mp->m_tech);
279 pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
281 (short)SHP_DEF(mp->m_armor, techdiff),
282 (short)SHP_SPD(mp->m_speed, techdiff),
283 (short)SHP_VIS(mp->m_visib, techdiff),
285 (short)SHP_RNG(mp->m_frnge, techdiff),
286 (short)SHP_FIR(mp->m_glim, techdiff));
288 pr("%2d ", mp->m_nland);
289 pr("%2d ", mp->m_nplanes);
290 pr("%2d ", mp->m_nchoppers);
291 pr("%2d ", mp->m_nxlight);
293 pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
299 show_ship_capab(int tlev)
308 pr("%25s cargos & capabilities\n", "");
310 make_new_list(tlev, EF_SHIP);
311 for (scount = 0; scount < lookup_list_cnt; scount++) {
312 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
313 /* Can't show trade ships unless it's turned on */
314 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
317 pr("%-25.25s ", mp->m_name);
319 for (i = I_NONE + 1; i <= I_MAX; ++i)
321 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
323 for (j = n = 0; j < 32; j++) {
324 if (!(mp->m_flags & bit(j)))
326 if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
337 show_plane_stats(int tlev)
342 pr("%25s acc load att def ran fuel stlth\n", "");
343 make_new_list(tlev, EF_PLANE);
344 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
345 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
346 pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
348 (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
349 (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
350 (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
351 (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
352 (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
354 pr("%4d%% ", pp->pl_stealth);
360 show_plane_capab(int tlev)
368 pr("%25s capabilities\n", "");
369 make_new_list(tlev, EF_PLANE);
370 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
371 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
372 pr("%-25.25s ", pp->pl_name);
374 for (i = n = 0; i < 32; i++) {
375 if (!(pp->pl_flags & bit(i)))
377 if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
388 show_plane_build(int tlev)
393 pr("%25s lcm hcm crew avail tech $\n", "");
394 make_new_list(tlev, EF_PLANE);
395 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
396 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
397 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
398 pp->pl_name, pp->pl_lcm,
399 pp->pl_hcm, pp->pl_crew,
400 PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
405 show_land_build(int tlev)
410 pr("%25s lcm hcm guns avail tech $\n", "");
411 make_new_list(tlev, EF_LAND);
412 for (n = 0; n < lookup_list_cnt; n++) {
413 lp = (struct lchrstr *)lookup_list[n].l_u.lp;
414 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
416 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
417 lp->l_name, lp->l_lcm,
420 LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
425 show_land_capab(int tlev)
433 pr("%25s capabilities\n", "");
435 make_new_list(tlev, EF_LAND);
436 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
437 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
438 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
441 pr("%-25s ", lcp->l_name);
443 for (i = I_NONE + 1; i <= I_MAX; ++i)
445 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
447 for (j = n = 0; j < 32; j++) {
448 if (!(lcp->l_flags & bit(j)))
450 if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
461 show_land_stats(int tlev)
467 pr("%25s s v s r r a f a a x l\n", "");
468 pr("%25s p i p a n c i m a f f p n\n", "");
469 pr("%25s att def vul d s y d g c r m f c u l d\n", "");
471 make_new_list(tlev, EF_LAND);
472 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
473 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
474 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
477 ourtlev = (int)(tlev - lcp->l_tech);
478 pr("%-25s %1.1f %1.1f %3d ",
480 LND_ATTDEF(lcp->l_att, ourtlev),
481 LND_ATTDEF(lcp->l_def, ourtlev),
482 (int)LND_VUL(lcp->l_vul, ourtlev));
483 pr("%2d %2d %2d %2d ",
484 (int)LND_SPD(lcp->l_spd, ourtlev),
485 (int)LND_VIS(lcp->l_vis, ourtlev),
486 (int)LND_SPY(lcp->l_spy, ourtlev),
487 (int)LND_RAD(lcp->l_rad, ourtlev));
488 pr("%2d %2d %2d %2d %2d ",
489 (int)LND_FRG(lcp->l_frg, ourtlev),
490 (int)LND_ACC(lcp->l_acc, ourtlev),
491 (int)LND_DAM(lcp->l_dam, ourtlev),
492 (int)LND_AMM(lcp->l_ammo, ourtlev),
493 (int)LND_AAF(lcp->l_aaf, ourtlev));
494 pr("%2d %2d %2d %2d ",
495 (int)LND_FC(lcp->l_fuelc, ourtlev),
496 (int)LND_FU(lcp->l_fuelu, ourtlev),
497 (int)LND_XPL(lcp->l_nxlight, ourtlev),
498 (int)LND_MXL(lcp->l_nland, ourtlev));
505 show_sect_build(int foo)
510 for (x = 0; dchr[x].d_name; x++) {
511 if (dchr[x].d_mnem == 0)
513 if (dchr[x].d_cost < 0)
515 if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
516 (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
518 pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
521 pr("%-14c %-14d %-17d %-14d %d\n",
522 dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
523 dchr[x].d_lcms, dchr[x].d_hcms);
528 for (x = 0; intrchr[x].in_name; x++) {
529 if (!intrchr[x].in_enable)
532 pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
533 " type lcms hcms mobility $$$$\n");
534 pr("%-20s %4d %4d %8d %4d\n",
535 intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
536 intrchr[x].in_mcost, intrchr[x].in_dcost);
542 show_sect_stats(int foo)
547 natp = getnatp(player->cnum);
548 for (x = 0; dchr[x].d_name; x++) {
549 if (dchr[x].d_mnem == 0)
552 pr(" mob cost max max -- packing bonus -- max\n");
553 pr(" sector type 0%% 100%% off def mil uw civ bar other pop\n");
556 pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
557 if (dchr[x].d_mob0 < 0)
560 pr(" %3.1f %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
561 pr(" %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n",
562 dchr[x].d_ostr, dchr[x].d_dstr,
563 ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
564 ichr[I_UW].i_pkg[dchr[x].d_pkg],
565 ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
566 ichr[I_BAR].i_pkg[dchr[x].d_pkg],
567 ichr[I_LCM].i_pkg[dchr[x].d_pkg],
568 max_population(natp->nat_level[NAT_RLEV], x, 100));
573 show_sect_capab(int foo)
575 int x, first = 1, i, j;
578 for (x = 0; dchr[x].d_name; x++) {
579 if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
582 pr(" --- level --- reso \n");
583 pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n");
590 dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
591 (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
592 for (i = 0; i < 3; i++) {
595 && pchr[j].p_ctype[i] > I_NONE
596 && pchr[j].p_ctype[i] <= I_MAX) {
597 pr("%2d %c ", pchr[j].p_camt[i],
598 ichr[pchr[j].p_ctype[i]].i_name[0]);
603 switch (pchr[j].p_nlndx) {
620 pr("%-5s %3d %3d %4d %3d %3d %c",
624 dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
625 pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
636 pr("item value sell lbs packing melt item\n");
637 pr("mnem in rg wh ur bk deno name\n");
639 for (ip = ichr; ip->i_name; ip++) {
640 pr(" %c %5d %4s %3d %2d %2d %2d %2d %2d %4d %s\n",
641 ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
642 ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
643 ip->i_pkg[UPKG], ip->i_pkg[BPKG],
644 ip->i_melt_denom, ip->i_name);
653 pr("id category good will\n");
656 for (i = 1; i < N_MAX_VERB + 1; i++) {
657 if (rpt[i].r_newspage == N_NOTUSED)
659 pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
660 page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
661 for (j = 0; j < NUM_RPTS; j++)
662 pr(" %s\n", rpt[i].r_newstory[j]);
667 * Show update policy and up to N scheduled updates.
672 struct gamestr *game = game_tick_tick();
676 pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
677 game->game_turn, game->game_tick);
679 if (update_time[0]) {
680 if (update_demand == UPD_DEMAND_SCHED) {
681 pr("Demand updates occur according to schedule:\n");
684 pr("Updates occur according to schedule:\n");
685 for (i = 0; i < n && update_time[i]; i++)
686 pr("%3d. %s\n", game->game_turn + i,
687 fmttime2822(update_time[i]));
689 pr("Updates occur within %d seconds after the scheduled time\n",
693 pr("There are no updates scheduled.\n");
695 if (update_demand == UPD_DEMAND_ASYNC) {
696 pr("Demand updates occur right after the demand is set.\n");
697 if (*update_demandtimes != 0) {
698 pr("Demand updates are allowed during: %s\n",
705 pr("Demand updates require %d country(s) to want one.\n",
709 if (updates_disabled())
710 pr("\nUPDATES ARE DISABLED!\n");
714 * Return T formatted according to RFC 2822.
715 * The return value is statically allocated and overwritten on
719 fmttime2822(time_t t)
725 TIME_ZONE_INFORMATION tzi;
729 localtime_s(&time, &t);
731 n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", &time);
732 if (CANT_HAPPEN(n == 0)) {
736 GetTimeZoneInformation(&tzi);
737 time_offset = -(tzi.Bias +
738 (time.tm_isdst ? tzi.DaylightBias : tzi.StandardBias));
740 nn = _snprintf_s(buf + n, sizeof(buf) - n, sizeof(buf) - n -1,
741 " %+03d%02d", time_offset/60, abs(time_offset) % 60);
742 if (CANT_HAPPEN(nn <= 0))
745 size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
747 if (CANT_HAPPEN(n == 0))