/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* show.c: General show routines
- *
+ *
* Known contributors to this file:
* Julian Onions, 1988
* Jeff Bailey, 1990
* Steve McClure, 1996
+ * Ron Koenderink, 2005
+ * Markus Armbruster, 2006-2008
*/
-/*
- * general routines that are callable to give info on things.
- * currently, planes, ships, nukes and bridges. Tanks & regiments one day?
- *
- * Added nuke_flags to be consistent. Jeff Bailey 12/15/90
- * (bailey@mcs.kent.edu)
- */
+#include <config.h>
#include <math.h>
-#include "misc.h"
-#include "player.h"
-#include "nuke.h"
-#include "ship.h"
-#include "land.h"
-#include "item.h"
-#include "plane.h"
-#include "sect.h"
-#include "optlist.h"
#include "file.h"
+#include "game.h"
+#include "item.h"
+#include "land.h"
#include "nat.h"
+#include "news.h"
+#include "nuke.h"
+#include "optlist.h"
+#include "plane.h"
+#include "player.h"
+#include "product.h"
#include "prototypes.h"
+#include "sect.h"
+#include "server.h"
+#include "ship.h"
+
+static char *fmttime2822(time_t);
struct look_list {
union {
struct mchrstr *mp;
} l_u;
int tech;
-} lookup_list[200]; /* Change this if there are ever more than 200 planes, ships
- or land units. */
+};
+
+/*
+ * Change this if there are ever more than 200 ships, plane or land
+ * unit types.
+ */
+static struct look_list lookup_list[200];
static int lookup_list_cnt = 0;
static void
sort_lookup_list();
}
-static char *
-lookup(int key, struct symbol *table)
-{
- int i;
-
- for (i = 0; table[i].name; i++)
- if (key == table[i].value)
- return table[i].name;
-
- return NULL;
-}
-
void
show_bridge(int tlev)
{
if (tlev < buil_bt)
return;
- pr("Bridges require %g tech,", buil_bt);
- pr(" %d hcm,", buil_bh);
- pr(" %d workers,\n", 0);
+ pr("Bridges require %g tech, %d hcm, 0 workers,\n",
+ buil_bt, buil_bh);
pr("%d available workforce, and cost $%g\n",
(SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
buil_bc);
{
if (tlev < buil_tower_bt)
return;
- pr("Bridge Towers require %g tech,", buil_tower_bt);
- pr(" %d hcm,", buil_tower_bh);
- pr(" %d workers,\n", 0);
+ pr("Bridge Towers require %g tech, %d hcm, 0 workers,\n",
+ buil_tower_bt, buil_tower_bh);
pr("%d available workforce, and cost $%g\n",
(SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
buil_tower_bc);
struct nchrstr *np;
int avail;
- if (opt_DRNUKE)
- pr("%13s lcm hcm oil rad avail tech res $\n", "");
- else
- pr("%13s lcm hcm oil rad avail tech $\n", "");
+ pr("%13s lcm hcm oil rad avail tech res $\n", "");
for (np = nchr; np->n_name; np++) {
avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
if (np->n_tech > tlev)
continue;
- if (opt_DRNUKE)
- pr("%-13.13s %3d %3d %4d %4d %5d %4d %3d $%6d\n",
- np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
- np->n_rad, avail, np->n_tech,
- (int)(np->n_tech * drnuke_const) + 1, np->n_cost);
- else
- pr("%-13.13s %3d %3d %4d %4d %5d %4d $%6d\n",
- np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
- np->n_rad, avail, np->n_tech, np->n_cost);
+ pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
+ np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
+ np->n_rad, avail, np->n_tech,
+ drnuke_const > MIN_DRNUKE_CONST ?
+ ceil(np->n_tech * drnuke_const) : 0.0,
+ np->n_cost);
}
}
int i, j;
char *p;
- if (opt_DRNUKE)
- pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
- else
- pr("%13s blst dam lbs tech $%7s abilities\n", "", "");
+ pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
for (np = nchr; np->n_name; np++) {
if (np->n_tech > tlev)
continue;
- if (opt_DRNUKE)
- pr("%-13.13s %4d %3d %3d %4d %3d $%7d ",
- np->n_name, np->n_blast, np->n_dam,
- np->n_weight, np->n_tech,
- (int)(np->n_tech * drnuke_const) + 1, np->n_cost);
- else /* not DRNUKE */
- pr("%-13.13s %4d %3d %3d %4d $%7d ",
- np->n_name, np->n_blast, np->n_dam,
- np->n_weight, np->n_tech, np->n_cost);
-
+ pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
+ np->n_name, np->n_blast, np->n_dam,
+ np->n_weight, np->n_tech,
+ drnuke_const > MIN_DRNUKE_CONST ?
+ ceil(np->n_tech * drnuke_const) : 0.0,
+ np->n_cost);
for (i = j = 0; i < 32; i++) {
if (!(np->n_flags & bit(i)))
continue;
- if (NULL != (p = lookup(bit(i), nuke_chr_flags))) {
+ if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
if (j++ > 0)
pr(" ");
- pr(p);
+ pr("%s", p);
}
}
pr("\n");
{
struct mchrstr *mp;
int scount;
- int techdiff;
- pr("%25s s v s r f l p", "");
- pr(" h");
- pr(" x");
- if (opt_FUEL)
- pr(" fuel");
+ pr("%25s s v s r f l p h x", "");
pr("\n");
- pr("%25s p i p n i n l", "");
- pr(" e");
- pr(" p");
- if (opt_FUEL)
- pr(" c/u");
+ pr("%25s p i p n i n l e p", "");
pr("\n");
- pr("%25s def d s y g r d n", "");
- pr(" l");
- pr(" l");
- if (opt_FUEL)
- pr(" ");
+ pr("%25s def d s y g r d n l l", "");
pr("\n");
if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
continue;
- techdiff = (int)(tlev - mp->m_tech);
pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
- mp->m_name,
- (short)SHP_DEF(mp->m_armor, techdiff),
- (short)SHP_SPD(mp->m_speed, techdiff),
- (short)SHP_VIS(mp->m_visib, techdiff),
- mp->m_vrnge,
- (short)SHP_RNG(mp->m_frnge, techdiff),
- (short)SHP_FIR(mp->m_glim, techdiff));
+ mp->m_name, m_armor(mp, tlev), m_speed(mp, tlev),
+ m_visib(mp, tlev), mp->m_vrnge,
+ m_frnge(mp, tlev), m_glim(mp, tlev));
pr("%2d ", mp->m_nland);
pr("%2d ", mp->m_nplanes);
pr("%2d ", mp->m_nchoppers);
pr("%2d ", mp->m_nxlight);
- if (opt_FUEL)
- pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
pr("\n");
}
}
for (j = n = 0; j < 32; j++) {
if (!(mp->m_flags & bit(j)))
continue;
- if (NULL != (p = lookup(bit(j), ship_chr_flags))) {
+ if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
if (n++ > 0)
pr(" ");
- pr(p);
+ pr("%s", p);
}
}
pr("\n");
for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
- pp->pl_name,
- (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
- (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
- (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
- (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
- (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
+ pp->pl_name, pl_acc(pp, tlev), pl_load(pp, tlev),
+ pl_att(pp, tlev), pl_def(pp, tlev), pl_range(pp, tlev),
pp->pl_fuel);
pr("%4d%% ", pp->pl_stealth);
pr("\n");
for (i = n = 0; i < 32; i++) {
if (!(pp->pl_flags & bit(i)))
continue;
- if (NULL != (p = lookup(bit(i), plane_chr_flags))) {
+ if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
if (n++ > 0)
pr(" ");
- pr(p);
+ pr("%s", p);
}
}
pr("\n");
for (j = n = 0; j < 32; j++) {
if (!(lcp->l_flags & bit(j)))
continue;
- if (NULL != (p = lookup(bit(j), land_chr_flags))) {
+ if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
if (n++ > 0)
pr(" ");
- pr(p);
+ pr("%s", p);
}
}
pr("\n");
{
struct lchrstr *lcp;
int lcount;
- int ourtlev;
- pr("%25s s v s r r a f a a x l\n", "");
- pr("%25s p i p a n c i m a f f p n\n", "");
- pr("%25s att def vul d s y d g c r m f c u l d\n", "");
+ pr("%25s s v s r r a f a a x l\n", "");
+ pr("%25s p i p a n c i m a p n\n", "");
+ pr("%25s att def vul d s y d g c r m f l d\n", "");
make_new_list(tlev, EF_LAND);
for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
continue;
- ourtlev = (int)(tlev - lcp->l_tech);
pr("%-25s %1.1f %1.1f %3d ",
- lcp->l_name, (float)LND_ATTDEF(lcp->l_att, ourtlev),
- (float)LND_ATTDEF(lcp->l_def, ourtlev),
- (int)LND_VUL(lcp->l_vul, ourtlev));
+ lcp->l_name,
+ l_att(lcp, tlev), l_def(lcp, tlev), l_vul(lcp, tlev));
pr("%2d %2d %2d %2d ",
- (int)LND_SPD(lcp->l_spd, ourtlev),
- (int)LND_VIS(lcp->l_vis, ourtlev),
- (int)LND_SPY(lcp->l_spy, ourtlev),
- (int)LND_RAD(lcp->l_rad, ourtlev));
+ l_spd(lcp, tlev), lcp->l_vis, lcp->l_spy, lcp->l_rad);
pr("%2d %2d %2d %2d %2d ",
- (int)LND_FRG(lcp->l_frg, ourtlev),
- (int)LND_ACC(lcp->l_acc, ourtlev),
- (int)LND_DAM(lcp->l_dam, ourtlev),
- (int)LND_AMM(lcp->l_ammo, lcp->l_dam, ourtlev),
- (int)LND_AAF(lcp->l_aaf, ourtlev));
- pr("%2d %2d %2d %2d ",
- (int)LND_FC(lcp->l_fuelc, ourtlev),
- (int)LND_FU(lcp->l_fuelu, ourtlev),
- (int)LND_XPL(lcp->l_nxlight, ourtlev),
- (int)LND_MXL(lcp->l_mxland, ourtlev));
-
+ l_frg(lcp, tlev), l_acc(lcp, tlev), l_dam(lcp, tlev),
+ lcp->l_ammo, lcp->l_aaf);
pr("\n");
}
}
void
show_sect_build(int foo)
{
- int x, first = 1;
+ int x, first;
- for (x = 0; x <= SCT_MAXDEF; x++) {
+ pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
+ for (x = 0; dchr[x].d_name; x++) {
if (dchr[x].d_mnem == 0)
continue;
if (dchr[x].d_cost < 0)
continue;
if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
(dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
- if (first) {
- pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n");
- first = 0;
- }
pr("%-14c %-14d %-17d %-14d %d\n",
dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
dchr[x].d_lcms, dchr[x].d_hcms);
}
}
- pr("\n");
- pr("Infrastructure building - adding 1 point of efficiency costs:\n");
- pr(" type lcms hcms mobility $$$$\n");
+ pr("other 0 1 0 0\n");
+
+ first = 1;
for (x = 0; intrchr[x].in_name; x++) {
- pr("%-20s %4d %4d %8d %4d\n", intrchr[x].in_name,
- intrchr[x].in_lcms, intrchr[x].in_hcms,
+ if (!intrchr[x].in_enable)
+ continue;
+ if (first)
+ pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
+ " type lcms hcms mobility $$$$\n");
+ pr("%-20s %4d %4d %8d %4d\n",
+ intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
intrchr[x].in_mcost, intrchr[x].in_dcost);
+ first = 0;
}
}
void
show_sect_stats(int foo)
{
- int x, first = 1;
- struct natstr *natp;
+ int x;
+ struct natstr *natp = getnatp(player->cnum);
+
+ pr(" mob cost max max naviga packing max\n");
+ pr(" sector type 0%% 100%% off def bility bonus pop\n");
- natp = getnatp(player->cnum);
- for (x = 0; x <= SCT_MAXDEF; x++) {
+ for (x = 0; dchr[x].d_name; x++) {
if (dchr[x].d_mnem == 0)
continue;
- if (first) {
- pr(" base max max -- packing bonus -- max\n");
- pr(" sector type mcost off def mil uw civ bar other pop\n");
- first = 0;
- }
- pr("%c %-23s %3d %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n",
- dchr[x].d_mnem, dchr[x].d_name,
- dchr[x].d_mcst, dchr[x].d_ostr,
- dchr[x].d_dstr,
- ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
- ichr[I_UW].i_pkg[dchr[x].d_pkg],
- ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
- ichr[I_BAR].i_pkg[dchr[x].d_pkg],
- ichr[I_LCM].i_pkg[dchr[x].d_pkg],
+ pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
+ if (dchr[x].d_mob0 < 0)
+ pr(" no way ");
+ else
+ pr(" %3.1f %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
+ pr(" %5.2f %5.2f %7.7s %10.10s %5d\n",
+ dchr[x].d_ostr, dchr[x].d_dstr,
+ symbol_by_value(dchr[x].d_nav, sector_navigation),
+ symbol_by_value(dchr[x].d_pkg, packing),
max_population(natp->nat_level[NAT_RLEV], x, 100));
}
}
void
show_sect_capab(int foo)
{
- int x, first = 1, i, j;
- char *tmpstr;
+ int x;
+
+ pr(" sector type product p.e.\n");
- for (x = 0; x <= SCT_MAXDEF; x++) {
- if ((dchr[x].d_mnem == 0) || (dchr[x].d_prd == 0))
+ for (x = 0; dchr[x].d_name; x++) {
+ if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
continue;
- if (first) {
- pr(" --- level --- reso \n");
- pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n");
- first = 0;
- }
+ pr("%c %-23s %-7s %4d%%\n",
+ dchr[x].d_mnem, dchr[x].d_name, pchr[dchr[x].d_prd].p_sname,
+ dchr[x].d_peffic);
+ }
+}
- j = dchr[x].d_prd;
+void
+show_item(int tlev)
+{
+ struct ichrstr *ip;
+
+ pr("item value sell lbs packing melt item\n");
+ pr("mnem in no wh ur bk deno name\n");
+
+ for (ip = ichr; ip->i_name; ip++) {
+ pr(" %c %5d %4s %3d %2d %2d %2d %2d %2d %4d %s\n",
+ ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
+ ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
+ ip->i_pkg[UPKG], ip->i_pkg[BPKG],
+ ip->i_melt_denom, ip->i_name);
+ }
+}
- pr("%c %-23s %-7s ", dchr[x].d_mnem, dchr[x].d_name,
- pchr[j].p_sname);
+void
+show_product(int tlev)
+{
+ struct pchrstr *pp;
+ int i;
+ char *lev;
+
+ pr("product cost raw materials reso dep level p.e.\n");
+
+ for (pp = pchr; pp->p_sname; pp++) {
+ pr("%7.7s %c $%-3d ",
+ pp->p_sname,
+ pp->p_type < 0 ? ' ' : ichr[pp->p_type].i_mnem,
+ pp->p_cost);
(void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
for (i = 0; i < 3; i++) {
- if (i < MAXPRCON
- && pchr[j].p_camt[i]
- && pchr[j].p_ctype[i] > I_NONE
- && pchr[j].p_ctype[i] <= I_MAX) {
- pr("%2d %c ", pchr[j].p_camt[i],
- ichr[pchr[j].p_ctype[i]].i_name[0]);
- } else {
- pr(" ");
- }
+ if (i < MAXPRCON && pp->p_camt[i]
+ && pp->p_ctype[i] > I_NONE && pp->p_ctype[i] <= I_MAX)
+ pr(" %2d%c", pp->p_camt[i], ichr[pp->p_ctype[i]].i_mnem);
+ else
+ pr(" ");
}
- switch (pchr[j].p_nlndx) {
- case NAT_TLEV:
- tmpstr = "tech";
- break;
- case NAT_ELEV:
- tmpstr = "edu";
- break;
- case NAT_RLEV:
- tmpstr = "res";
- break;
- case NAT_HLEV:
- tmpstr = "hap";
- break;
- default:
- tmpstr = " ";
- break;
+ if (pp->p_nrndx)
+ pr(" %5.5s %3d ",
+ symbol_by_value(pp->p_nrndx, resources), pp->p_nrdep);
+ else
+ pr(" ");
+ if (pp->p_nlndx < 0)
+ pr("1.0\n");
+ else {
+ lev = symbol_by_value(pp->p_nlndx, level);
+ pr("(%.4s%+d)/(%.4s%+d)\n",
+ lev, -pp->p_nlmin, lev, pp->p_nllag - pp->p_nlmin);
}
- pr("%-5s %3d %3d %4d %3d %3d %c",
- tmpstr,
- pchr[j].p_nlmin,
- pchr[j].p_nllag,
- pchr[j].p_effic, pchr[j].p_cost, pchr[j].p_nrdep,
- pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
+ }
+}
- pr("\n");
+void
+show_news(int tlev)
+{
+ int i, j;
+
+ pr("id category good will\n");
+ pr(" messsages\n");
+
+ for (i = 1; i < N_MAX_VERB + 1; i++) {
+ if (rpt[i].r_newspage == N_NOTUSED)
+ continue;
+ pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
+ page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
+ for (j = 0; j < NUM_RPTS; j++)
+ pr(" %s\n", rpt[i].r_newstory[j]);
+ }
+}
+
+/*
+ * Show update policy and up to N scheduled updates.
+ */
+void
+show_updates(int n)
+{
+ struct gamestr *game = game_tick_tick();
+ int demand = 0;
+ int i;
+
+ pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
+ game->game_turn, game->game_tick);
+
+ if (update_time[0]) {
+ if (update_demand == UPD_DEMAND_SCHED) {
+ pr("Demand updates occur according to schedule:\n");
+ demand = 1;
+ } else
+ pr("Updates occur according to schedule:\n");
+ for (i = 0; i < n && update_time[i]; i++)
+ pr("%3d. %s\n", game->game_turn + i,
+ fmttime2822(update_time[i]));
+ if (update_window) {
+ pr("Updates occur within %d seconds after the scheduled time\n",
+ update_window);
+ }
+ } else
+ pr("There are no updates scheduled.\n");
+
+ if (update_demand == UPD_DEMAND_ASYNC) {
+ pr("Demand updates occur right after the demand is set.\n");
+ if (*update_demandtimes != 0) {
+ pr("Demand updates are allowed during: %s\n",
+ update_demandtimes);
+ }
+ demand = 1;
+ }
+
+ if (demand) {
+ pr("Demand updates require %d country(s) to want one.\n",
+ update_wantmin);
+ }
+
+ if (updates_disabled())
+ pr("\nUPDATES ARE DISABLED!\n");
+}
+
+/*
+ * Return T formatted according to RFC 2822.
+ * The return value is statically allocated and overwritten on
+ * subsequent calls.
+ */
+static char *
+fmttime2822(time_t t)
+{
+ static char buf[32];
+#if defined(_WIN32)
+ size_t n;
+ int nn;
+ TIME_ZONE_INFORMATION tzi;
+ long time_offset;
+ struct tm *time;
+
+ time = localtime(&t);
+
+ n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", time);
+ if (CANT_HAPPEN(n == 0)) {
+ buf[0] = 0;
+ return buf;
}
+ GetTimeZoneInformation(&tzi);
+ time_offset = -(tzi.Bias +
+ (time->tm_isdst ? tzi.DaylightBias : tzi.StandardBias));
+
+ nn = _snprintf(buf + n, sizeof(buf) - n, " %+03d%02d",
+ time_offset/60, abs(time_offset) % 60);
+ if (CANT_HAPPEN(nn <= 0 || nn + n >= sizeof(buf)))
+ buf[0] = 0;
+#else
+ size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
+ localtime(&t));
+ if (CANT_HAPPEN(n == 0))
+ buf[0] = 0;
+#endif
+ return buf;
}