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