]> git.pond.sub.org Git - empserver/blob - src/lib/commands/comm.c
70664a5665bdbe6d62e125f125e0df3adb101686
[empserver] / src / lib / commands / comm.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2010, 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 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.
25  *
26  *  ---
27  *
28  *  comm.c: Do a commodity report
29  *
30  *  Known contributors to this file:
31  *
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "path.h"
38
39 static void prthresh(int val);
40
41 int
42 comm(void)
43 {
44     struct sctstr sect;
45     char dirstr[12];
46     int nsect;
47     int n;
48     struct nstr_sect nstr;
49
50     if (!snxtsct(&nstr, player->argp[1]))
51         return RET_SYN;
52     prdate();
53     (void)strcpy(dirstr, ".      $");
54     for (n = 1; n <= 6; n++)
55         dirstr[n] = dirch[n];
56     nsect = 0;
57     while (nxtsct(&nstr, &sect)) {
58         if (!player->owner)
59             continue;
60         if (nsect++ == 0) {
61             if (player->god)
62                 pr("   ");
63             pr("COMMODITIES deliver--  distribute\n");
64             if (player->god)
65                 pr("   ");
66             pr("  sect      sgpidbolhr sgpidbolhr  sh gun  pet iron dust bar  oil  lcm  hcm rad\n");
67         }
68         if (player->god)
69             pr("%3d", sect.sct_own);
70         prxy("%4d,%-4d", nstr.x, nstr.y);
71         pr(" %c", dchr[sect.sct_type].d_mnem);
72         pr(" %c", dirstr[sect.sct_del[I_SHELL] & 0x7]);
73         pr("%c", dirstr[sect.sct_del[I_GUN] & 0x7]);
74         pr("%c", dirstr[sect.sct_del[I_PETROL] & 0x7]);
75         pr("%c", dirstr[sect.sct_del[I_IRON] & 0x7]);
76         pr("%c", dirstr[sect.sct_del[I_DUST] & 0x7]);
77         pr("%c", dirstr[sect.sct_del[I_BAR] & 0x7]);
78         pr("%c", dirstr[sect.sct_del[I_OIL] & 0x7]);
79         pr("%c", dirstr[sect.sct_del[I_LCM] & 0x7]);
80         pr("%c", dirstr[sect.sct_del[I_HCM] & 0x7]);
81         pr("%c ", dirstr[sect.sct_del[I_RAD] & 0x7]);
82         prthresh(sect.sct_dist[I_SHELL]);
83         prthresh(sect.sct_dist[I_GUN]);
84         prthresh(sect.sct_dist[I_PETROL]);
85         prthresh(sect.sct_dist[I_IRON]);
86         prthresh(sect.sct_dist[I_DUST]);
87         prthresh(sect.sct_dist[I_BAR]);
88         prthresh(sect.sct_dist[I_OIL]);
89         prthresh(sect.sct_dist[I_LCM]);
90         prthresh(sect.sct_dist[I_HCM]);
91         prthresh(sect.sct_dist[I_RAD]);
92         pr("%4d", sect.sct_item[I_SHELL]);
93         pr("%4d", sect.sct_item[I_GUN]);
94         pr("%5d", sect.sct_item[I_PETROL]);
95         pr("%5d", sect.sct_item[I_IRON]);
96         pr("%5d", sect.sct_item[I_DUST]);
97         pr("%4d", sect.sct_item[I_BAR]);
98         pr("%5d", sect.sct_item[I_OIL]);
99         pr("%5d", sect.sct_item[I_LCM]);
100         pr("%5d", sect.sct_item[I_HCM]);
101         pr("%4d", sect.sct_item[I_RAD]);
102         pr("\n");
103     }
104     if (nsect == 0) {
105         if (player->argp[1])
106             pr("%s: No sector(s)\n", player->argp[1]);
107         else
108             pr("%s: No sector(s)\n", "");
109         return RET_FAIL;
110     } else
111         pr("%d sector%s\n", nsect, splur(nsect));
112     return 0;
113 }
114
115 static void
116 prthresh(int val)
117 {
118     if (val >= 1000)
119         val = 'a';
120     else if (val > 0)
121         val = val / 100 + '0';
122     else
123         val = '.';
124     pr("%c", val);
125 }