]> git.pond.sub.org Git - empserver/blob - src/lib/commands/comm.c
Cleanup #includes of (mostly a long time) unused header files.
[empserver] / src / lib / commands / comm.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  comm.c: Do a commodity report
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "sect.h"
37 #include "xy.h"
38 #include "nsc.h"
39 #include "path.h"
40 #include "nat.h"
41 #include "commands.h"
42
43 static void prthresh(s_char *format, int val);
44
45 int
46 comm(void)
47 {
48     struct sctstr sect;
49     s_char dirstr[12];
50     int nsect;
51     int n;
52     struct nstr_sect nstr;
53
54     if (!snxtsct(&nstr, player->argp[1]))
55         return RET_SYN;
56     prdate();
57     (void)strcpy(dirstr, ".      $");
58     n = 1;
59     for (n = 1; n <= 6; n++)
60         dirstr[n] = dirch[n];
61     nsect = 0;
62     while (nxtsct(&nstr, &sect)) {
63         if (!player->owner)
64             continue;
65         if (nsect++ == 0) {
66             if (player->god)
67                 pr("   ");
68             pr("COMMODITIES deliver--  distribute\n");
69             if (player->god)
70                 pr("   ");
71             pr("  sect      sgpidbolhr sgpidbolhr  sh gun  pet iron dust bar  oil  lcm  hcm rad\n");
72         }
73         if (player->god)
74             pr("%3d", sect.sct_own);
75         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
76         pr(" %c", dchr[sect.sct_type].d_mnem);
77         pr(" %c", dirstr[sect.sct_del[I_SHELL] & 0x7]);
78         pr("%c", dirstr[sect.sct_del[I_GUN] & 0x7]);
79         pr("%c", dirstr[sect.sct_del[I_PETROL] & 0x7]);
80         pr("%c", dirstr[sect.sct_del[I_IRON] & 0x7]);
81         pr("%c", dirstr[sect.sct_del[I_DUST] & 0x7]);
82         pr("%c", dirstr[sect.sct_del[I_BAR] & 0x7]);
83         pr("%c", dirstr[sect.sct_del[I_OIL] & 0x7]);
84         pr("%c", dirstr[sect.sct_del[I_LCM] & 0x7]);
85         pr("%c", dirstr[sect.sct_del[I_HCM] & 0x7]);
86         pr("%c", dirstr[sect.sct_del[I_RAD] & 0x7]);
87         prthresh(" %c", sect.sct_dist[I_SHELL]);
88         prthresh("%c", sect.sct_dist[I_GUN]);
89         prthresh("%c", sect.sct_dist[I_PETROL]);
90         prthresh("%c", sect.sct_dist[I_IRON]);
91         prthresh("%c", sect.sct_dist[I_DUST]);
92         prthresh("%c", sect.sct_dist[I_BAR]);
93         prthresh("%c", sect.sct_dist[I_OIL]);
94         prthresh("%c", sect.sct_dist[I_LCM]);
95         prthresh("%c", sect.sct_dist[I_HCM]);
96         prthresh("%c", sect.sct_dist[I_RAD]);
97         pr("%4d", sect.sct_item[I_SHELL]);
98         pr("%4d", sect.sct_item[I_GUN]);
99         pr("%5d", sect.sct_item[I_PETROL]);
100         pr("%5d", sect.sct_item[I_IRON]);
101         pr("%5d", sect.sct_item[I_DUST]);
102         pr("%4d", sect.sct_item[I_BAR]);
103         pr("%5d", sect.sct_item[I_OIL]);
104         pr("%5d", sect.sct_item[I_LCM]);
105         pr("%5d", sect.sct_item[I_HCM]);
106         pr("%4d", sect.sct_item[I_RAD]);
107         pr("\n");
108     }
109     if (nsect == 0) {
110         if (player->argp[1])
111             pr("%s: No sector(s)\n", player->argp[1]);
112         else
113             pr("%s: No sector(s)\n", "");
114         return RET_FAIL;
115     } else
116         pr("%d sector%s\n", nsect, splur(nsect));
117     return 0;
118 }
119
120 static void
121 prthresh(s_char *format, int val)
122 {
123     if (val >= 1000)
124         val = 'a';
125     else if (val > 0)
126         val = val / 100 + '0';
127     else
128         val = '.';
129     pr(format, val);
130 }