2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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, %d hcm, 0 workers,\n",
145 pr("%d available workforce, and cost $%g\n",
146 (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
153 if (tlev < buil_tower_bt)
155 pr("Bridge Towers require %g tech, %d hcm, 0 workers,\n",
156 buil_tower_bt, buil_tower_bh);
157 pr("%d available workforce, and cost $%g\n",
158 (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
163 show_nuke_stats(int tlev)
165 show_nuke_capab(tlev);
169 show_nuke_build(int tlev)
174 pr("%13s lcm hcm oil rad avail tech res $\n", "");
176 for (np = nchr; np->n_name; np++) {
177 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
178 if (np->n_tech > tlev)
180 pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
181 np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
182 np->n_rad, avail, np->n_tech,
183 drnuke_const > MIN_DRNUKE_CONST ?
184 ceil(np->n_tech * drnuke_const) : 0.0,
190 show_nuke_capab(int tlev)
196 pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
198 for (np = nchr; np->n_name; np++) {
199 if (np->n_tech > tlev)
201 pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
202 np->n_name, np->n_blast, np->n_dam,
203 np->n_weight, np->n_tech,
204 drnuke_const > MIN_DRNUKE_CONST ?
205 ceil(np->n_tech * drnuke_const) : 0.0,
207 for (i = j = 0; i < 32; i++) {
208 if (!(np->n_flags & bit(i)))
210 if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
221 show_ship_build(int tlev)
226 pr("%25s lcm hcm avail tech $\n", "");
227 make_new_list(tlev, EF_SHIP);
228 for (n = 0; n < lookup_list_cnt; n++) {
229 mp = (struct mchrstr *)lookup_list[n].l_u.mp;
230 /* Can't show trade ships unless it's turned on */
231 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
234 pr("%-25.25s %3d %3d %5d %4d $%d\n",
235 mp->m_name, mp->m_lcm, mp->m_hcm,
236 SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
241 show_ship_stats(int tlev)
246 pr("%25s s v s r f l p h x", "");
251 pr("%25s p i p n i n l e p", "");
256 pr("%25s def d s y g r d n l l", "");
262 make_new_list(tlev, EF_SHIP);
263 for (scount = 0; scount < lookup_list_cnt; scount++) {
264 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
265 /* Can't show trade ships unless it's turned on */
266 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
269 pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
270 mp->m_name, m_armor(mp, tlev), m_speed(mp, tlev),
271 m_visib(mp, tlev), mp->m_vrnge,
272 m_frnge(mp, tlev), m_glim(mp, tlev));
274 pr("%2d ", mp->m_nland);
275 pr("%2d ", mp->m_nplanes);
276 pr("%2d ", mp->m_nchoppers);
277 pr("%2d ", mp->m_nxlight);
279 pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
285 show_ship_capab(int tlev)
294 pr("%25s cargos & capabilities\n", "");
296 make_new_list(tlev, EF_SHIP);
297 for (scount = 0; scount < lookup_list_cnt; scount++) {
298 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
299 /* Can't show trade ships unless it's turned on */
300 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
303 pr("%-25.25s ", mp->m_name);
305 for (i = I_NONE + 1; i <= I_MAX; ++i)
307 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
309 for (j = n = 0; j < 32; j++) {
310 if (!(mp->m_flags & bit(j)))
312 if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
323 show_plane_stats(int tlev)
328 pr("%25s acc load att def ran fuel stlth\n", "");
329 make_new_list(tlev, EF_PLANE);
330 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
331 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
332 pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
333 pp->pl_name, pl_acc(pp, tlev), pl_load(pp, tlev),
334 pl_att(pp, tlev), pl_def(pp, tlev), pl_range(pp, tlev),
336 pr("%4d%% ", pp->pl_stealth);
342 show_plane_capab(int tlev)
350 pr("%25s capabilities\n", "");
351 make_new_list(tlev, EF_PLANE);
352 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
353 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
354 pr("%-25.25s ", pp->pl_name);
356 for (i = n = 0; i < 32; i++) {
357 if (!(pp->pl_flags & bit(i)))
359 if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
370 show_plane_build(int tlev)
375 pr("%25s lcm hcm crew avail tech $\n", "");
376 make_new_list(tlev, EF_PLANE);
377 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
378 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
379 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
380 pp->pl_name, pp->pl_lcm,
381 pp->pl_hcm, pp->pl_crew,
382 PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
387 show_land_build(int tlev)
392 pr("%25s lcm hcm guns avail tech $\n", "");
393 make_new_list(tlev, EF_LAND);
394 for (n = 0; n < lookup_list_cnt; n++) {
395 lp = (struct lchrstr *)lookup_list[n].l_u.lp;
396 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
398 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
399 lp->l_name, lp->l_lcm,
402 LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
407 show_land_capab(int tlev)
415 pr("%25s capabilities\n", "");
417 make_new_list(tlev, EF_LAND);
418 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
419 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
420 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
423 pr("%-25s ", lcp->l_name);
425 for (i = I_NONE + 1; i <= I_MAX; ++i)
427 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
429 for (j = n = 0; j < 32; j++) {
430 if (!(lcp->l_flags & bit(j)))
432 if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
443 show_land_stats(int tlev)
448 pr("%25s s v s r r a f a a x l\n", "");
449 pr("%25s p i p a n c i m a f f p n\n", "");
450 pr("%25s att def vul d s y d g c r m f c u l d\n", "");
452 make_new_list(tlev, EF_LAND);
453 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
454 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
455 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
458 pr("%-25s %1.1f %1.1f %3d ",
460 l_att(lcp, tlev), l_def(lcp, tlev), l_vul(lcp, tlev));
461 pr("%2d %2d %2d %2d ",
462 l_spd(lcp, tlev), lcp->l_vis, lcp->l_spy, lcp->l_rad);
463 pr("%2d %2d %2d %2d %2d ",
464 l_frg(lcp, tlev), l_acc(lcp, tlev), l_dam(lcp, tlev),
465 lcp->l_ammo, lcp->l_aaf);
466 pr("%2d %2d %2d %2d ",
467 lcp->l_fuelc, lcp->l_fuelu, lcp->l_nxlight, lcp->l_nland);
474 show_sect_build(int foo)
479 for (x = 0; dchr[x].d_name; x++) {
480 if (dchr[x].d_mnem == 0)
482 if (dchr[x].d_cost < 0)
484 if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
485 (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
487 pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
490 pr("%-14c %-14d %-17d %-14d %d\n",
491 dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
492 dchr[x].d_lcms, dchr[x].d_hcms);
497 for (x = 0; intrchr[x].in_name; x++) {
498 if (!intrchr[x].in_enable)
501 pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
502 " type lcms hcms mobility $$$$\n");
503 pr("%-20s %4d %4d %8d %4d\n",
504 intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
505 intrchr[x].in_mcost, intrchr[x].in_dcost);
511 show_sect_stats(int foo)
516 natp = getnatp(player->cnum);
517 for (x = 0; dchr[x].d_name; x++) {
518 if (dchr[x].d_mnem == 0)
521 pr(" mob cost max max -- packing bonus -- max\n");
522 pr(" sector type 0%% 100%% off def mil uw civ bar other pop\n");
525 pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
526 if (dchr[x].d_mob0 < 0)
529 pr(" %3.1f %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
530 pr(" %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n",
531 dchr[x].d_ostr, dchr[x].d_dstr,
532 ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
533 ichr[I_UW].i_pkg[dchr[x].d_pkg],
534 ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
535 ichr[I_BAR].i_pkg[dchr[x].d_pkg],
536 ichr[I_LCM].i_pkg[dchr[x].d_pkg],
537 max_population(natp->nat_level[NAT_RLEV], x, 100));
542 show_sect_capab(int foo)
544 int x, first = 1, i, j;
547 for (x = 0; dchr[x].d_name; x++) {
548 if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
551 pr(" --- level --- reso \n");
552 pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n");
559 dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
560 (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
561 for (i = 0; i < 3; i++) {
564 && pchr[j].p_ctype[i] > I_NONE
565 && pchr[j].p_ctype[i] <= I_MAX) {
566 pr("%2d %c ", pchr[j].p_camt[i],
567 ichr[pchr[j].p_ctype[i]].i_name[0]);
572 switch (pchr[j].p_nlndx) {
589 pr("%-5s %3d %3d %4d %3d %3d %c",
593 dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
594 pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
605 pr("item value sell lbs packing melt item\n");
606 pr("mnem in rg wh ur bk deno name\n");
608 for (ip = ichr; ip->i_name; ip++) {
609 pr(" %c %5d %4s %3d %2d %2d %2d %2d %2d %4d %s\n",
610 ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
611 ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
612 ip->i_pkg[UPKG], ip->i_pkg[BPKG],
613 ip->i_melt_denom, ip->i_name);
622 pr("id category good will\n");
625 for (i = 1; i < N_MAX_VERB + 1; i++) {
626 if (rpt[i].r_newspage == N_NOTUSED)
628 pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
629 page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
630 for (j = 0; j < NUM_RPTS; j++)
631 pr(" %s\n", rpt[i].r_newstory[j]);
636 * Show update policy and up to N scheduled updates.
641 struct gamestr *game = game_tick_tick();
645 pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
646 game->game_turn, game->game_tick);
648 if (update_time[0]) {
649 if (update_demand == UPD_DEMAND_SCHED) {
650 pr("Demand updates occur according to schedule:\n");
653 pr("Updates occur according to schedule:\n");
654 for (i = 0; i < n && update_time[i]; i++)
655 pr("%3d. %s\n", game->game_turn + i,
656 fmttime2822(update_time[i]));
658 pr("Updates occur within %d seconds after the scheduled time\n",
662 pr("There are no updates scheduled.\n");
664 if (update_demand == UPD_DEMAND_ASYNC) {
665 pr("Demand updates occur right after the demand is set.\n");
666 if (*update_demandtimes != 0) {
667 pr("Demand updates are allowed during: %s\n",
674 pr("Demand updates require %d country(s) to want one.\n",
678 if (updates_disabled())
679 pr("\nUPDATES ARE DISABLED!\n");
683 * Return T formatted according to RFC 2822.
684 * The return value is statically allocated and overwritten on
688 fmttime2822(time_t t)
694 TIME_ZONE_INFORMATION tzi;
698 time = localtime(&t);
700 n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", time);
701 if (CANT_HAPPEN(n == 0)) {
705 GetTimeZoneInformation(&tzi);
706 time_offset = -(tzi.Bias +
707 (time->tm_isdst ? tzi.DaylightBias : tzi.StandardBias));
709 nn = _snprintf(buf + n, sizeof(buf) - n, " %+03d%02d",
710 time_offset/60, abs(time_offset) % 60);
711 if (CANT_HAPPEN(nn <= 0 || nn + n >= sizeof(buf)))
714 size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
716 if (CANT_HAPPEN(n == 0))