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-2008
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", "");
249 pr("%25s p i p n i n l e p", "");
252 pr("%25s def d s y g r d n l l", "");
256 make_new_list(tlev, EF_SHIP);
257 for (scount = 0; scount < lookup_list_cnt; scount++) {
258 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
259 /* Can't show trade ships unless it's turned on */
260 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
263 pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
264 mp->m_name, m_armor(mp, tlev), m_speed(mp, tlev),
265 m_visib(mp, tlev), mp->m_vrnge,
266 m_frnge(mp, tlev), m_glim(mp, tlev));
268 pr("%2d ", mp->m_nland);
269 pr("%2d ", mp->m_nplanes);
270 pr("%2d ", mp->m_nchoppers);
271 pr("%2d ", mp->m_nxlight);
277 show_ship_capab(int tlev)
286 pr("%25s cargos & capabilities\n", "");
288 make_new_list(tlev, EF_SHIP);
289 for (scount = 0; scount < lookup_list_cnt; scount++) {
290 mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
291 /* Can't show trade ships unless it's turned on */
292 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
295 pr("%-25.25s ", mp->m_name);
297 for (i = I_NONE + 1; i <= I_MAX; ++i)
299 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
301 for (j = n = 0; j < 32; j++) {
302 if (!(mp->m_flags & bit(j)))
304 if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
315 show_plane_stats(int tlev)
320 pr("%25s acc load att def ran fuel stlth\n", "");
321 make_new_list(tlev, EF_PLANE);
322 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
323 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
324 pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
325 pp->pl_name, pl_acc(pp, tlev), pl_load(pp, tlev),
326 pl_att(pp, tlev), pl_def(pp, tlev), pl_range(pp, tlev),
328 pr("%4d%% ", pp->pl_stealth);
334 show_plane_capab(int tlev)
342 pr("%25s capabilities\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 ", pp->pl_name);
348 for (i = n = 0; i < 32; i++) {
349 if (!(pp->pl_flags & bit(i)))
351 if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
362 show_plane_build(int tlev)
367 pr("%25s lcm hcm crew avail tech $\n", "");
368 make_new_list(tlev, EF_PLANE);
369 for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
370 pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
371 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
372 pp->pl_name, pp->pl_lcm,
373 pp->pl_hcm, pp->pl_crew,
374 PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
379 show_land_build(int tlev)
384 pr("%25s lcm hcm guns avail tech $\n", "");
385 make_new_list(tlev, EF_LAND);
386 for (n = 0; n < lookup_list_cnt; n++) {
387 lp = (struct lchrstr *)lookup_list[n].l_u.lp;
388 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
390 pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
391 lp->l_name, lp->l_lcm,
394 LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
399 show_land_capab(int tlev)
407 pr("%25s capabilities\n", "");
409 make_new_list(tlev, EF_LAND);
410 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
411 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
412 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
415 pr("%-25s ", lcp->l_name);
417 for (i = I_NONE + 1; i <= I_MAX; ++i)
419 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
421 for (j = n = 0; j < 32; j++) {
422 if (!(lcp->l_flags & bit(j)))
424 if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
435 show_land_stats(int tlev)
440 pr("%25s s v s r r a f a a x l\n", "");
441 pr("%25s p i p a n c i m a p n\n", "");
442 pr("%25s att def vul d s y d g c r m f l d\n", "");
444 make_new_list(tlev, EF_LAND);
445 for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
446 lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
447 if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
450 pr("%-25s %1.1f %1.1f %3d ",
452 l_att(lcp, tlev), l_def(lcp, tlev), l_vul(lcp, tlev));
453 pr("%2d %2d %2d %2d ",
454 l_spd(lcp, tlev), lcp->l_vis, lcp->l_spy, lcp->l_rad);
455 pr("%2d %2d %2d %2d %2d ",
456 l_frg(lcp, tlev), l_acc(lcp, tlev), l_dam(lcp, tlev),
457 lcp->l_ammo, lcp->l_aaf);
463 show_sect_build(int foo)
467 pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
468 for (x = 0; dchr[x].d_name; x++) {
469 if (dchr[x].d_mnem == 0)
471 if (dchr[x].d_cost < 0)
473 if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
474 (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
475 pr("%-14c %-14d %-17d %-14d %d\n",
476 dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
477 dchr[x].d_lcms, dchr[x].d_hcms);
480 pr("other 0 1 0 0\n");
483 for (x = 0; intrchr[x].in_name; x++) {
484 if (!intrchr[x].in_enable)
487 pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
488 " type lcms hcms mobility $$$$\n");
489 pr("%-20s %4d %4d %8d %4d\n",
490 intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
491 intrchr[x].in_mcost, intrchr[x].in_dcost);
497 show_sect_stats(int foo)
502 natp = getnatp(player->cnum);
503 for (x = 0; dchr[x].d_name; x++) {
504 if (dchr[x].d_mnem == 0)
507 pr(" mob cost max max -- packing bonus -- max\n");
508 pr(" sector type 0%% 100%% off def mil uw civ bar other pop\n");
511 pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
512 if (dchr[x].d_mob0 < 0)
515 pr(" %3.1f %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
516 pr(" %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n",
517 dchr[x].d_ostr, dchr[x].d_dstr,
518 ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
519 ichr[I_UW].i_pkg[dchr[x].d_pkg],
520 ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
521 ichr[I_BAR].i_pkg[dchr[x].d_pkg],
522 ichr[I_LCM].i_pkg[dchr[x].d_pkg],
523 max_population(natp->nat_level[NAT_RLEV], x, 100));
528 show_sect_capab(int foo)
530 int x, first = 1, i, j;
533 for (x = 0; dchr[x].d_name; x++) {
534 if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
537 pr(" --- level --- reso \n");
538 pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n");
545 dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
546 (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
547 for (i = 0; i < 3; i++) {
550 && pchr[j].p_ctype[i] > I_NONE
551 && pchr[j].p_ctype[i] <= I_MAX) {
552 pr("%2d %c ", pchr[j].p_camt[i],
553 ichr[pchr[j].p_ctype[i]].i_name[0]);
558 switch (pchr[j].p_nlndx) {
575 pr("%-5s %3d %3d %4d %3d %3d %c",
579 dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
580 pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
591 pr("item value sell lbs packing melt item\n");
592 pr("mnem in rg wh ur bk deno name\n");
594 for (ip = ichr; ip->i_name; ip++) {
595 pr(" %c %5d %4s %3d %2d %2d %2d %2d %2d %4d %s\n",
596 ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
597 ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
598 ip->i_pkg[UPKG], ip->i_pkg[BPKG],
599 ip->i_melt_denom, ip->i_name);
608 pr("id category good will\n");
611 for (i = 1; i < N_MAX_VERB + 1; i++) {
612 if (rpt[i].r_newspage == N_NOTUSED)
614 pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
615 page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
616 for (j = 0; j < NUM_RPTS; j++)
617 pr(" %s\n", rpt[i].r_newstory[j]);
622 * Show update policy and up to N scheduled updates.
627 struct gamestr *game = game_tick_tick();
631 pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
632 game->game_turn, game->game_tick);
634 if (update_time[0]) {
635 if (update_demand == UPD_DEMAND_SCHED) {
636 pr("Demand updates occur according to schedule:\n");
639 pr("Updates occur according to schedule:\n");
640 for (i = 0; i < n && update_time[i]; i++)
641 pr("%3d. %s\n", game->game_turn + i,
642 fmttime2822(update_time[i]));
644 pr("Updates occur within %d seconds after the scheduled time\n",
648 pr("There are no updates scheduled.\n");
650 if (update_demand == UPD_DEMAND_ASYNC) {
651 pr("Demand updates occur right after the demand is set.\n");
652 if (*update_demandtimes != 0) {
653 pr("Demand updates are allowed during: %s\n",
660 pr("Demand updates require %d country(s) to want one.\n",
664 if (updates_disabled())
665 pr("\nUPDATES ARE DISABLED!\n");
669 * Return T formatted according to RFC 2822.
670 * The return value is statically allocated and overwritten on
674 fmttime2822(time_t t)
680 TIME_ZONE_INFORMATION tzi;
684 time = localtime(&t);
686 n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", time);
687 if (CANT_HAPPEN(n == 0)) {
691 GetTimeZoneInformation(&tzi);
692 time_offset = -(tzi.Bias +
693 (time->tm_isdst ? tzi.DaylightBias : tzi.StandardBias));
695 nn = _snprintf(buf + n, sizeof(buf) - n, " %+03d%02d",
696 time_offset/60, abs(time_offset) % 60);
697 if (CANT_HAPPEN(nn <= 0 || nn + n >= sizeof(buf)))
700 size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
702 if (CANT_HAPPEN(n == 0))