]> git.pond.sub.org Git - empserver/blob - src/lib/commands/comm.c
Import of Empire 4.2.12
[empserver] / src / lib / commands / comm.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "var.h"
37 #include "sect.h"
38 #include "xy.h"
39 #include "nsc.h"
40 #include "path.h"
41 #include "nat.h"
42 #include "deity.h"
43 #include "file.h"
44 #include "commands.h"
45
46 static  void prthresh(s_char *format, int val);
47
48 int
49 comm(void)
50 {
51     struct      sctstr sect;
52     s_char      dirstr[12];
53     int nsect;
54     int n;
55     struct      nstr_sect nstr;
56     int del[I_MAX+1];
57     int dist[I_MAX+1];
58     int item[I_MAX+1];
59     
60     if (!snxtsct(&nstr, player->argp[1]))
61         return RET_SYN;
62     prdate();
63     (void) strcpy(dirstr, ".      $");
64     n = 1;
65     for (n = 1; n <= 6; n++)
66         dirstr[n] = dirch[n];
67     nsect = 0;
68     while (nxtsct(&nstr, &sect)) {
69         if (!player->owner)
70             continue;
71         if (nsect++ == 0) {
72             if (player->god)
73                 pr("   ");
74             pr("COMMODITIES deliver--  distribute\n");
75             if (player->god)
76                 pr("   ");
77             pr("  sect      sgpidbolhr sgpidbolhr  sh gun  pet iron dust bar  oil  lcm  hcm rad\n");
78         }
79         if (player->god)
80             pr("%3d", sect.sct_own);
81         getvec(VT_DEL, del, (s_char *)&sect, EF_SECTOR);
82         getvec(VT_DIST, dist, (s_char *)&sect, EF_SECTOR);
83         getvec(VT_ITEM, item, (s_char *)&sect, EF_SECTOR);
84         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
85         pr(" %c", dchr[sect.sct_type].d_mnem);
86         pr(" %c", dirstr[del[I_SHELL] & 0x7]);
87         pr("%c", dirstr[del[I_GUN] & 0x7]);
88         pr("%c", dirstr[del[I_PETROL] & 0x7]);
89         pr("%c", dirstr[del[I_IRON] & 0x7]);
90         pr("%c", dirstr[del[I_DUST] & 0x7]);
91         pr("%c", dirstr[del[I_BAR] & 0x7]);
92         pr("%c", dirstr[del[I_OIL] & 0x7]);
93         pr("%c", dirstr[del[I_LCM] & 0x7]);
94         pr("%c", dirstr[del[I_HCM] & 0x7]);
95         pr("%c", dirstr[del[I_RAD] & 0x7]);
96         prthresh(" %c", dist[I_SHELL]);
97         prthresh("%c", dist[I_GUN]);
98         prthresh("%c", dist[I_PETROL]);
99         prthresh("%c", dist[I_IRON]);
100         prthresh("%c", dist[I_DUST]);
101         prthresh("%c", dist[I_BAR]);
102         prthresh("%c", dist[I_OIL]);
103         prthresh("%c", dist[I_LCM]);
104         prthresh("%c", dist[I_HCM]);
105         prthresh("%c", dist[I_RAD]);
106         pr("%4d", item[I_SHELL]);
107         pr("%4d", item[I_GUN]);
108         pr("%5d", item[I_PETROL]);
109         pr("%5d", item[I_IRON]);
110         pr("%5d", item[I_DUST]);
111         pr("%4d", item[I_BAR]);
112         pr("%5d", item[I_OIL]);
113         pr("%5d", item[I_LCM]);
114         pr("%5d", item[I_HCM]);
115         pr("%4d", item[I_RAD]);
116         pr("\n");
117     }
118     if (nsect == 0) {
119         if (player->argp[1])
120             pr("%s: No sector(s)\n", player->argp[1]);
121         else
122             pr("%s: No sector(s)\n", "");
123         return RET_FAIL;
124     }else
125         pr("%d sector%s\n", nsect, splur(nsect));
126     return 0;
127 }
128
129 static void
130 prthresh(s_char *format, int val)
131 {
132     if (val >= 1000)
133         val = 'a';
134     else if (val > 0)
135         val = val / 100 + '0';
136     else
137         val = '.';
138     pr(format, val);
139 }
140
141