src/lib/commands/comm.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  *  comm.c: Do a commodity report
00029  * 
00030  *  Known contributors to this file:
00031  *     
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 #include "path.h"
00038 
00039 static void prthresh(int val);
00040 
00041 int
00042 comm(void)
00043 {
00044     struct sctstr sect;
00045     char dirstr[12];
00046     int nsect;
00047     int n;
00048     struct nstr_sect nstr;
00049 
00050     if (!snxtsct(&nstr, player->argp[1]))
00051         return RET_SYN;
00052     prdate();
00053     (void)strcpy(dirstr, ".      $");
00054     n = 1;
00055     for (n = 1; n <= 6; n++)
00056         dirstr[n] = dirch[n];
00057     nsect = 0;
00058     while (nxtsct(&nstr, &sect)) {
00059         if (!player->owner)
00060             continue;
00061         if (nsect++ == 0) {
00062             if (player->god)
00063                 pr("   ");
00064             pr("COMMODITIES deliver--  distribute\n");
00065             if (player->god)
00066                 pr("   ");
00067             pr("  sect      sgpidbolhr sgpidbolhr  sh gun  pet iron dust bar  oil  lcm  hcm rad\n");
00068         }
00069         if (player->god)
00070             pr("%3d", sect.sct_own);
00071         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
00072         pr(" %c", dchr[sect.sct_type].d_mnem);
00073         pr(" %c", dirstr[sect.sct_del[I_SHELL] & 0x7]);
00074         pr("%c", dirstr[sect.sct_del[I_GUN] & 0x7]);
00075         pr("%c", dirstr[sect.sct_del[I_PETROL] & 0x7]);
00076         pr("%c", dirstr[sect.sct_del[I_IRON] & 0x7]);
00077         pr("%c", dirstr[sect.sct_del[I_DUST] & 0x7]);
00078         pr("%c", dirstr[sect.sct_del[I_BAR] & 0x7]);
00079         pr("%c", dirstr[sect.sct_del[I_OIL] & 0x7]);
00080         pr("%c", dirstr[sect.sct_del[I_LCM] & 0x7]);
00081         pr("%c", dirstr[sect.sct_del[I_HCM] & 0x7]);
00082         pr("%c ", dirstr[sect.sct_del[I_RAD] & 0x7]);
00083         prthresh(sect.sct_dist[I_SHELL]);
00084         prthresh(sect.sct_dist[I_GUN]);
00085         prthresh(sect.sct_dist[I_PETROL]);
00086         prthresh(sect.sct_dist[I_IRON]);
00087         prthresh(sect.sct_dist[I_DUST]);
00088         prthresh(sect.sct_dist[I_BAR]);
00089         prthresh(sect.sct_dist[I_OIL]);
00090         prthresh(sect.sct_dist[I_LCM]);
00091         prthresh(sect.sct_dist[I_HCM]);
00092         prthresh(sect.sct_dist[I_RAD]);
00093         pr("%4d", sect.sct_item[I_SHELL]);
00094         pr("%4d", sect.sct_item[I_GUN]);
00095         pr("%5d", sect.sct_item[I_PETROL]);
00096         pr("%5d", sect.sct_item[I_IRON]);
00097         pr("%5d", sect.sct_item[I_DUST]);
00098         pr("%4d", sect.sct_item[I_BAR]);
00099         pr("%5d", sect.sct_item[I_OIL]);
00100         pr("%5d", sect.sct_item[I_LCM]);
00101         pr("%5d", sect.sct_item[I_HCM]);
00102         pr("%4d", sect.sct_item[I_RAD]);
00103         pr("\n");
00104     }
00105     if (nsect == 0) {
00106         if (player->argp[1])
00107             pr("%s: No sector(s)\n", player->argp[1]);
00108         else
00109             pr("%s: No sector(s)\n", "");
00110         return RET_FAIL;
00111     } else
00112         pr("%d sector%s\n", nsect, splur(nsect));
00113     return 0;
00114 }
00115 
00116 static void
00117 prthresh(int val)
00118 {
00119     if (val >= 1000)
00120         val = 'a';
00121     else if (val > 0)
00122         val = val / 100 + '0';
00123     else
00124         val = '.';
00125     pr("%c", val);
00126 }

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