src/lib/subs/show.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  show.c: General show routines
00029  * 
00030  *  Known contributors to this file:
00031  *     Julian Onions, 1988
00032  *     Jeff Bailey, 1990
00033  *     Steve McClure, 1996
00034  *     Ron Koenderink, 2005
00035  *     Markus Armbruster, 2006-2007
00036  */
00037 
00038 #include <config.h>
00039 
00040 #if defined(_WIN32)
00041 #include <Windows.h>
00042 #endif
00043 
00044 #include <math.h>
00045 #include "file.h"
00046 #include "game.h"
00047 #include "item.h"
00048 #include "land.h"
00049 #include "nat.h"
00050 #include "news.h"
00051 #include "nuke.h"
00052 #include "optlist.h"
00053 #include "plane.h"
00054 #include "player.h"
00055 #include "product.h"
00056 #include "prototypes.h"
00057 #include "sect.h"
00058 #include "server.h"
00059 #include "ship.h"
00060 
00061 static char *fmttime2822(time_t);
00062 
00063 struct look_list {
00064     union {
00065         struct lchrstr *lp;
00066         struct plchrstr *pp;
00067         struct mchrstr *mp;
00068     } l_u;
00069     int tech;
00070 };
00071 
00072 /*
00073  * Change this if there are ever more than 200 ships, plane or land
00074  * unit types.
00075  */
00076 static struct look_list lookup_list[200];
00077 static int lookup_list_cnt = 0;
00078 
00079 static void
00080 sort_lookup_list(void)
00081 {
00082     struct natstr *np = getnatp(player->cnum);
00083     struct look_list tmp;
00084     int i;
00085     int j;
00086 
00087     if (!(np->nat_flags & NF_TECHLISTS))
00088         return;
00089     for (i = 0; i < lookup_list_cnt; i++) {
00090         for (j = i; j < lookup_list_cnt; j++) {
00091             if (lookup_list[j].tech < lookup_list[i].tech) {
00092                 tmp = lookup_list[j];
00093                 lookup_list[j] = lookup_list[i];
00094                 lookup_list[i] = tmp;
00095             }
00096         }
00097     }
00098 }
00099 
00100 static void
00101 make_new_list(int tlev, int type)
00102 {
00103     struct plchrstr *pp;
00104     struct lchrstr *lp;
00105     struct mchrstr *mp;
00106 
00107     lookup_list_cnt = 0;
00108     if (type == EF_PLANE) {
00109         for (pp = plchr; pp->pl_name; pp++) {
00110             if (pp->pl_tech > tlev)
00111                 continue;
00112             lookup_list[lookup_list_cnt].l_u.pp = pp;
00113             lookup_list[lookup_list_cnt].tech = pp->pl_tech;
00114             lookup_list_cnt++;
00115         }
00116     } else if (type == EF_SHIP) {
00117         for (mp = mchr; mp->m_name; mp++) {
00118             if (mp->m_tech > tlev)
00119                 continue;
00120             lookup_list[lookup_list_cnt].l_u.mp = mp;
00121             lookup_list[lookup_list_cnt].tech = mp->m_tech;
00122             lookup_list_cnt++;
00123         }
00124     } else if (type == EF_LAND) {
00125         for (lp = lchr; lp->l_name; lp++) {
00126             if (lp->l_tech > tlev)
00127                 continue;
00128             lookup_list[lookup_list_cnt].l_u.lp = lp;
00129             lookup_list[lookup_list_cnt].tech = lp->l_tech;
00130             lookup_list_cnt++;
00131         }
00132     } else
00133         return;
00134 
00135     sort_lookup_list();
00136 }
00137 
00138 void
00139 show_bridge(int tlev)
00140 {
00141     if (tlev < buil_bt)
00142         return;
00143     pr("Bridges require %g tech, %d hcm, 0 workers,\n",
00144        buil_bt, buil_bh);
00145     pr("%d available workforce, and cost $%g\n",
00146        (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100,
00147        buil_bc);
00148 }
00149 
00150 void
00151 show_tower(int tlev)
00152 {
00153     if (tlev < buil_tower_bt)
00154         return;
00155     pr("Bridge Towers require %g tech, %d hcm, 0 workers,\n",
00156        buil_tower_bt, buil_tower_bh);
00157     pr("%d available workforce, and cost $%g\n",
00158        (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100,
00159        buil_tower_bc);
00160 }
00161 
00162 void
00163 show_nuke_stats(int tlev)
00164 {
00165     show_nuke_capab(tlev);
00166 }
00167 
00168 void
00169 show_nuke_build(int tlev)
00170 {
00171     struct nchrstr *np;
00172     int avail;
00173 
00174     pr("%13s lcm hcm  oil  rad avail tech res $\n", "");
00175 
00176     for (np = nchr; np->n_name; np++) {
00177         avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
00178         if (np->n_tech > tlev)
00179             continue;
00180         pr("%-13.13s %3d %3d %4d %4d %5d %4d %3.0f $%6d\n",
00181            np->n_name, np->n_lcm, np->n_hcm, np->n_oil,
00182            np->n_rad, avail, np->n_tech,
00183            drnuke_const > MIN_DRNUKE_CONST ?
00184                 ceil(np->n_tech * drnuke_const) : 0.0,
00185            np->n_cost);
00186     }
00187 }
00188 
00189 void
00190 show_nuke_capab(int tlev)
00191 {
00192     struct nchrstr *np;
00193     int i, j;
00194     char *p;
00195 
00196     pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
00197 
00198     for (np = nchr; np->n_name; np++) {
00199         if (np->n_tech > tlev)
00200             continue;
00201         pr("%-13.13s %4d %3d %3d %4d %3.0f $%7d ",
00202            np->n_name, np->n_blast, np->n_dam,
00203            np->n_weight, np->n_tech,
00204            drnuke_const > MIN_DRNUKE_CONST ?
00205                 ceil(np->n_tech * drnuke_const) : 0.0,
00206            np->n_cost);
00207         for (i = j = 0; i < 32; i++) {
00208             if (!(np->n_flags & bit(i)))
00209                 continue;
00210             if (NULL != (p = symbol_by_value(bit(i), nuke_chr_flags))) {
00211                 if (j++ > 0)
00212                     pr(" ");
00213                 pr("%s", p);
00214             }
00215         }
00216         pr("\n");
00217     }
00218 }
00219 
00220 void
00221 show_ship_build(int tlev)
00222 {
00223     struct mchrstr *mp;
00224     int n;
00225 
00226     pr("%25s lcm hcm avail tech $\n", "");
00227     make_new_list(tlev, EF_SHIP);
00228     for (n = 0; n < lookup_list_cnt; n++) {
00229         mp = (struct mchrstr *)lookup_list[n].l_u.mp;
00230         /* Can't show trade ships unless it's turned on */
00231         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
00232             continue;
00233 
00234         pr("%-25.25s %3d %3d %5d %4d $%d\n",
00235            mp->m_name, mp->m_lcm, mp->m_hcm,
00236            SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost);
00237     }
00238 }
00239 
00240 void
00241 show_ship_stats(int tlev)
00242 {
00243     struct mchrstr *mp;
00244     int scount;
00245     int techdiff;
00246 
00247     pr("%25s      s  v  s  r  f  l  p  h  x", "");
00248     if (opt_FUEL)
00249         pr("  fuel");
00250     pr("\n");
00251 
00252     pr("%25s      p  i  p  n  i  n  l  e  p", "");
00253     if (opt_FUEL)
00254         pr("   c/u");
00255     pr("\n");
00256 
00257     pr("%25s def  d  s  y  g  r  d  n  l  l", "");
00258     if (opt_FUEL)
00259         pr("      ");
00260     pr("\n");
00261 
00262 
00263     make_new_list(tlev, EF_SHIP);
00264     for (scount = 0; scount < lookup_list_cnt; scount++) {
00265         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
00266         /* Can't show trade ships unless it's turned on */
00267         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
00268             continue;
00269 
00270         techdiff = (int)(tlev - mp->m_tech);
00271         pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
00272            mp->m_name,
00273            (short)SHP_DEF(mp->m_armor, techdiff),
00274            (short)SHP_SPD(mp->m_speed, techdiff),
00275            (short)SHP_VIS(mp->m_visib, techdiff),
00276            mp->m_vrnge,
00277            (short)SHP_RNG(mp->m_frnge, techdiff),
00278            (short)SHP_FIR(mp->m_glim, techdiff));
00279 
00280         pr("%2d ", mp->m_nland);
00281         pr("%2d ", mp->m_nplanes);
00282         pr("%2d ", mp->m_nchoppers);
00283         pr("%2d ", mp->m_nxlight);
00284         if (opt_FUEL)
00285             pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu);
00286         pr("\n");
00287     }
00288 }
00289 
00290 void
00291 show_ship_capab(int tlev)
00292 {
00293     struct mchrstr *mp;
00294     i_type i;
00295     int j;
00296     int scount;
00297     int n;
00298     char *p;
00299 
00300     pr("%25s cargos & capabilities\n", "");
00301 
00302     make_new_list(tlev, EF_SHIP);
00303     for (scount = 0; scount < lookup_list_cnt; scount++) {
00304         mp = (struct mchrstr *)lookup_list[scount].l_u.mp;
00305         /* Can't show trade ships unless it's turned on */
00306         if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
00307             continue;
00308 
00309         pr("%-25.25s ", mp->m_name);
00310 
00311         for (i = I_NONE + 1; i <= I_MAX; ++i)
00312             if (mp->m_item[i])
00313                 pr(" %d%c", mp->m_item[i], ichr[i].i_mnem);
00314         pr(" ");
00315         for (j = n = 0; j < 32; j++) {
00316             if (!(mp->m_flags & bit(j)))
00317                 continue;
00318             if (NULL != (p = symbol_by_value(bit(j), ship_chr_flags))) {
00319                 if (n++ > 0)
00320                     pr(" ");
00321                 pr("%s", p);
00322             }
00323         }
00324         pr("\n");
00325     }
00326 }
00327 
00328 void
00329 show_plane_stats(int tlev)
00330 {
00331     struct plchrstr *pp;
00332     int pcount;
00333 
00334     pr("%25s acc load att def ran fuel stlth\n", "");
00335     make_new_list(tlev, EF_PLANE);
00336     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
00337         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
00338         pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
00339            pp->pl_name,
00340            (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
00341            (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
00342            (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
00343            (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
00344            (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
00345            pp->pl_fuel);
00346         pr("%4d%% ", pp->pl_stealth);
00347         pr("\n");
00348     }
00349 }
00350 
00351 void
00352 show_plane_capab(int tlev)
00353 {
00354     struct plchrstr *pp;
00355     int i;
00356     int pcount;
00357     int n;
00358     char *p;
00359 
00360     pr("%25s capabilities\n", "");
00361     make_new_list(tlev, EF_PLANE);
00362     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
00363         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
00364         pr("%-25.25s  ", pp->pl_name);
00365 
00366         for (i = n = 0; i < 32; i++) {
00367             if (!(pp->pl_flags & bit(i)))
00368                 continue;
00369             if (NULL != (p = symbol_by_value(bit(i), plane_chr_flags))) {
00370                 if (n++ > 0)
00371                     pr(" ");
00372                 pr("%s", p);
00373             }
00374         }
00375         pr("\n");
00376     }
00377 }
00378 
00379 void
00380 show_plane_build(int tlev)
00381 {
00382     struct plchrstr *pp;
00383     int pcount;
00384 
00385     pr("%25s lcm hcm crew avail tech $\n", "");
00386     make_new_list(tlev, EF_PLANE);
00387     for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
00388         pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
00389         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
00390            pp->pl_name, pp->pl_lcm,
00391            pp->pl_hcm, pp->pl_crew,
00392            PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost);
00393     }
00394 }
00395 
00396 void
00397 show_land_build(int tlev)
00398 {
00399     struct lchrstr *lp;
00400     int n;
00401 
00402     pr("%25s lcm hcm guns avail tech $\n", "");
00403     make_new_list(tlev, EF_LAND);
00404     for (n = 0; n < lookup_list_cnt; n++) {
00405         lp = (struct lchrstr *)lookup_list[n].l_u.lp;
00406         if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
00407             continue;
00408         pr("%-25.25s %3d %3d %4d %5d %4d $%d\n",
00409            lp->l_name, lp->l_lcm,
00410            lp->l_hcm,
00411            lp->l_gun,
00412            LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost);
00413     }
00414 }
00415 
00416 void
00417 show_land_capab(int tlev)
00418 {
00419     struct lchrstr *lcp;
00420     int lcount;
00421     i_type i;
00422     int j, n;
00423     char *p;
00424 
00425     pr("%25s capabilities\n", "");
00426 
00427     make_new_list(tlev, EF_LAND);
00428     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
00429         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
00430         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
00431             continue;
00432 
00433         pr("%-25s ", lcp->l_name);
00434 
00435         for (i = I_NONE + 1; i <= I_MAX; ++i)
00436             if (lcp->l_item[i])
00437                 pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem);
00438         pr(" ");
00439         for (j = n = 0; j < 32; j++) {
00440             if (!(lcp->l_flags & bit(j)))
00441                 continue;
00442             if (NULL != (p = symbol_by_value(bit(j), land_chr_flags))) {
00443                 if (n++ > 0)
00444                     pr(" ");
00445                 pr("%s", p);
00446             }
00447         }
00448         pr("\n");
00449     }
00450 }
00451 
00452 void
00453 show_land_stats(int tlev)
00454 {
00455     struct lchrstr *lcp;
00456     int lcount;
00457     int ourtlev;
00458 
00459     pr("%25s              s  v  s  r  r  a  f  a  a        x  l\n", "");
00460     pr("%25s              p  i  p  a  n  c  i  m  a  f  f  p  n\n", "");
00461     pr("%25s att def vul  d  s  y  d  g  c  r  m  f  c  u  l  d\n", "");
00462 
00463     make_new_list(tlev, EF_LAND);
00464     for (lcount = 0; lcount < lookup_list_cnt; lcount++) {
00465         lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp;
00466         if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
00467             continue;
00468 
00469         ourtlev = (int)(tlev - lcp->l_tech);
00470         pr("%-25s %1.1f %1.1f %3d ",
00471            lcp->l_name,
00472            LND_ATTDEF(lcp->l_att, ourtlev),
00473            LND_ATTDEF(lcp->l_def, ourtlev),
00474            (int)LND_VUL(lcp->l_vul, ourtlev));
00475         pr("%2d %2d %2d %2d ",
00476            (int)LND_SPD(lcp->l_spd, ourtlev),
00477            (int)LND_VIS(lcp->l_vis, ourtlev),
00478            (int)LND_SPY(lcp->l_spy, ourtlev),
00479            (int)LND_RAD(lcp->l_rad, ourtlev));
00480         pr("%2d %2d %2d %2d %2d ",
00481            (int)LND_FRG(lcp->l_frg, ourtlev),
00482            (int)LND_ACC(lcp->l_acc, ourtlev),
00483            (int)LND_DAM(lcp->l_dam, ourtlev),
00484            (int)LND_AMM(lcp->l_ammo, ourtlev),
00485            (int)LND_AAF(lcp->l_aaf, ourtlev));
00486         pr("%2d %2d %2d %2d ",
00487            (int)LND_FC(lcp->l_fuelc, ourtlev),
00488            (int)LND_FU(lcp->l_fuelu, ourtlev),
00489            (int)LND_XPL(lcp->l_nxlight, ourtlev),
00490            (int)LND_MXL(lcp->l_nland, ourtlev));
00491 
00492         pr("\n");
00493     }
00494 }
00495 
00496 void
00497 show_sect_build(int foo)
00498 {
00499     int x, first;
00500 
00501     first = 1;
00502     for (x = 0; dchr[x].d_name; x++) {
00503         if (dchr[x].d_mnem == 0)
00504             continue;
00505         if (dchr[x].d_cost < 0)
00506             continue;
00507         if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) ||
00508             (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) {
00509             if (first) {
00510                 pr("sector type    cost to des    cost for 1%% eff   lcms for 1%%    hcms for 1%%\n");
00511                 first = 0;
00512             }
00513             pr("%-14c %-14d %-17d %-14d %d\n",
00514                dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build,
00515                dchr[x].d_lcms, dchr[x].d_hcms);
00516         }
00517     }
00518 
00519     first = 1;
00520     for (x = 0; intrchr[x].in_name; x++) {
00521         if (!intrchr[x].in_enable)
00522             continue;
00523         if (first)
00524             pr("\nInfrastructure building - adding 1 point of efficiency costs:\n"
00525                "       type          lcms    hcms    mobility    $$$$\n");
00526         pr("%-20s %4d    %4d    %8d    %4d\n",
00527            intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms,
00528            intrchr[x].in_mcost, intrchr[x].in_dcost);
00529         first = 0;
00530     }
00531 }
00532 
00533 void
00534 show_sect_stats(int foo)
00535 {
00536     int x, first = 1;
00537     struct natstr *natp;
00538 
00539     natp = getnatp(player->cnum);
00540     for (x = 0; dchr[x].d_name; x++) {
00541         if (dchr[x].d_mnem == 0)
00542             continue;
00543         if (first) {
00544             pr("                        mob cost   max   max   --  packing bonus  --   max\n");
00545             pr("  sector type            0%% 100%%   off   def   mil  uw civ bar other   pop\n");
00546             first = 0;
00547         }
00548         pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name);
00549         if (dchr[x].d_mob0 < 0)
00550             pr("  no way ");
00551         else
00552             pr(" %3.1f  %3.1f", dchr[x].d_mob0, dchr[x].d_mob1);
00553         pr("  %5.2f %5.2f   %3d %3d %3d %3d %5d %5d\n",
00554            dchr[x].d_ostr, dchr[x].d_dstr,
00555            ichr[I_MILIT].i_pkg[dchr[x].d_pkg],
00556            ichr[I_UW].i_pkg[dchr[x].d_pkg],
00557            ichr[I_CIVIL].i_pkg[dchr[x].d_pkg],
00558            ichr[I_BAR].i_pkg[dchr[x].d_pkg],
00559            ichr[I_LCM].i_pkg[dchr[x].d_pkg],
00560            max_population(natp->nat_level[NAT_RLEV], x, 100));
00561     }
00562 }
00563 
00564 void
00565 show_sect_capab(int foo)
00566 {
00567     int x, first = 1, i, j;
00568     char *tmpstr;
00569 
00570     for (x = 0; dchr[x].d_name; x++) {
00571         if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
00572             continue;
00573         if (first) {
00574             pr("                                                 --- level ---          reso \n");
00575             pr("  sector type             product use1 use2 use3 level min lag eff%% $$$ dep c\n");
00576             first = 0;
00577         }
00578 
00579         j = dchr[x].d_prd;
00580 
00581         pr("%c %-23s %-7s ",
00582            dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname);
00583         (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */
00584         for (i = 0; i < 3; i++) {
00585             if (i < MAXPRCON
00586                 && pchr[j].p_camt[i]
00587                 && pchr[j].p_ctype[i] > I_NONE
00588                 && pchr[j].p_ctype[i] <= I_MAX) {
00589                 pr("%2d %c ", pchr[j].p_camt[i],
00590                    ichr[pchr[j].p_ctype[i]].i_name[0]);
00591             } else {
00592                 pr("     ");
00593             }
00594         }
00595         switch (pchr[j].p_nlndx) {
00596         case NAT_TLEV:
00597             tmpstr = "tech";
00598             break;
00599         case NAT_ELEV:
00600             tmpstr = "edu";
00601             break;
00602         case NAT_RLEV:
00603             tmpstr = "res";
00604             break;
00605         case NAT_HLEV:
00606             tmpstr = "hap";
00607             break;
00608         default:
00609             tmpstr = " ";
00610             break;
00611         }
00612         pr("%-5s %3d %3d %4d %3d %3d %c",
00613            tmpstr,
00614            pchr[j].p_nlmin,
00615            pchr[j].p_nllag,
00616            dchr[x].d_peffic, pchr[j].p_cost, pchr[j].p_nrdep,
00617            pchr[j].p_type != I_NONE ? ichr[pchr[j].p_type].i_mnem : ' ');
00618 
00619         pr("\n");
00620     }
00621 }
00622 
00623 void
00624 show_item(int tlev)
00625 {
00626     struct ichrstr *ip;
00627 
00628     pr("item value sell lbs    packing     melt  item\n");
00629     pr("mnem                in rg wh ur bk deno  name\n");
00630 
00631     for (ip = ichr; ip->i_name; ip++) {
00632         pr("   %c %5d %4s %3d %2d %2d %2d %2d %2d %4d  %s\n",
00633            ip->i_mnem, ip->i_value, ip->i_sell ? "yes" : "no", ip->i_lbs,
00634            ip->i_pkg[IPKG], ip->i_pkg[NPKG], ip->i_pkg[WPKG],
00635            ip->i_pkg[UPKG], ip->i_pkg[BPKG],
00636            ip->i_melt_denom, ip->i_name);
00637     }
00638 }
00639 
00640 void
00641 show_news(int tlev)
00642 {
00643     int i, j;
00644     
00645     pr("id category           good will\n");
00646     pr("    messsages\n");
00647 
00648     for (i = 1; i < N_MAX_VERB + 1; i++) {
00649         if (rpt[i].r_newspage == N_NOTUSED)
00650             continue;
00651         pr("%-2d %-20.20s %4d\n", rpt[i].r_uid,
00652             page_headings[rpt[i].r_newspage].name, rpt[i].r_good_will);
00653         for (j = 0; j < NUM_RPTS; j++)
00654             pr("    %s\n", rpt[i].r_newstory[j]);
00655     }
00656 }
00657 
00658 /*
00659  * Show update policy and up to N scheduled updates.
00660  */
00661 void
00662 show_updates(int n)
00663 {
00664     struct gamestr *game = game_tick_tick();
00665     int demand = 0;
00666     int i;
00667 
00668     pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
00669        game->game_turn, game->game_tick);
00670 
00671     if (update_time[0]) {
00672         if (update_demand == UPD_DEMAND_SCHED) {
00673             pr("Demand updates occur according to schedule:\n");
00674             demand = 1;
00675         } else
00676             pr("Updates occur according to schedule:\n");
00677         for (i = 0; i < n && update_time[i]; i++)
00678             pr("%3d.  %s\n", game->game_turn + i,
00679                fmttime2822(update_time[i]));
00680         if (update_window) {
00681             pr("Updates occur within %d seconds after the scheduled time\n",
00682                update_window);
00683         }
00684     } else
00685         pr("There are no updates scheduled.\n");
00686 
00687     if (update_demand == UPD_DEMAND_ASYNC) {
00688         pr("Demand updates occur right after the demand is set.\n");
00689         if (*update_demandtimes != 0) {
00690             pr("Demand updates are allowed during: %s\n",
00691                update_demandtimes);
00692         }
00693         demand = 1;
00694     }
00695 
00696     if (demand) {
00697         pr("Demand updates require %d country(s) to want one.\n",
00698            update_wantmin);
00699     }
00700 
00701     if (updates_disabled())
00702         pr("\nUPDATES ARE DISABLED!\n");
00703 }
00704 
00705 /*
00706  * Return T formatted according to RFC 2822.
00707  * The return value is statically allocated and overwritten on
00708  * subsequent calls.
00709  */
00710 static char *
00711 fmttime2822(time_t t)
00712 {
00713     static char buf[32];
00714 #if defined(_WIN32)
00715     size_t n;
00716     int nn;
00717     TIME_ZONE_INFORMATION tzi;
00718     long time_offset;
00719     struct tm *time;
00720     
00721     time = localtime(&t);
00722 
00723     n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", time);
00724     if (CANT_HAPPEN(n == 0)) {
00725         buf[0] = 0;
00726         return buf;
00727     }
00728     GetTimeZoneInformation(&tzi);
00729     time_offset = -(tzi.Bias +
00730         (time->tm_isdst ? tzi.DaylightBias : tzi.StandardBias));
00731 
00732     nn = _snprintf(buf + n, sizeof(buf) - n, " %+03d%02d",
00733         time_offset/60, abs(time_offset) % 60);
00734     if (CANT_HAPPEN(nn <= 0 || nn + n >= sizeof(buf)))
00735         buf[0] = 0;
00736 #else
00737     size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z",
00738                      localtime(&t));
00739     if (CANT_HAPPEN(n == 0))
00740         buf[0] = 0;
00741 #endif
00742     return buf;
00743 }

Generated on Fri Mar 28 11:01:13 2008 for empserver by  doxygen 1.5.2