]> git.pond.sub.org Git - empserver/blob - src/lib/commands/cens.c
Update known contributors comment.
[empserver] / src / lib / commands / cens.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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  *  cens.c: Do a census report
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 2000
32  */
33
34 #include <config.h>
35
36 #include "prototypes.h"
37 #include "path.h"
38 #include "commands.h"
39 #include "optlist.h"
40
41 static void cens_hdr(void);
42
43 int
44 cens(void)
45 {
46     struct sctstr sect;
47     int nsect;
48     int n;
49     struct nstr_sect nstr;
50     s_char dirstr[20];
51
52     if (!snxtsct(&nstr, player->argp[1]))
53         return RET_SYN;
54     prdate();
55     for (n = 1; n <= 6; n++)
56         dirstr[n] = dirch[n];
57     dirstr[0] = '.';
58     dirstr[7] = '$';
59     dirstr[8] = '\0';
60     nsect = 0;
61     while (nxtsct(&nstr, &sect)) {
62         if (!player->owner)
63             continue;
64         if (nsect++ == 0)
65             cens_hdr();
66         if (player->god)
67             pr("%3d ", sect.sct_own);
68         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
69         pr(" %c", dchr[sect.sct_type].d_mnem);
70         if (sect.sct_newtype != sect.sct_type)
71             pr("%c", dchr[sect.sct_newtype].d_mnem);
72         else
73             pr(" ");
74         pr("%4d%%", sect.sct_effic);
75         if (sect.sct_off)
76             pr(" no ");
77         else
78             pr("    ");
79         pr("%4d", sect.sct_mobil);
80
81         pr(" %c", dirstr[sect.sct_del[I_UW] & 0x7]);
82         pr("%c", dirstr[sect.sct_del[I_FOOD] & 0x7]);
83
84         n = sect.sct_dist[I_UW] % 1000;
85         pr(" %c", n == 0 ? '.' : '0' + (n / 100));
86         n = sect.sct_dist[I_FOOD] % 1000;
87         pr("%c ", n == 0 ? '.' : '0' + (n / 100));
88         if (sect.sct_own != sect.sct_oldown)
89           pr("%3d",  sect.sct_oldown);
90         else
91           pr("   ");
92
93         pr("%5d", sect.sct_item[I_CIVIL]);
94         pr("%5d", sect.sct_item[I_MILIT]);
95         pr("%5d", sect.sct_item[I_UW]);
96         pr("%5d", sect.sct_item[I_FOOD]);
97         pr("%4d%%", sect.sct_work);
98         pr("%5d", sect.sct_avail);
99         if (!player->god) {
100             if (sect.sct_terr)
101                 pr("%4d", sect.sct_terr);
102             else
103                 pr("    ");
104         }
105         pr("%5d", opt_FALLOUT ? sect.sct_fallout : 0);
106         if (sect.sct_coastal)
107             pr("%4d", sect.sct_coastal);
108         pr("\n");
109     }
110     if (nsect == 0) {
111         if (player->argp[1])
112             pr("%s: No sector(s)\n", player->argp[1]);
113         else
114             pr("%s: No sector(s)\n", "");
115         return RET_FAIL;
116     } else
117         pr("%d sector%s\n", nsect, splur(nsect));
118     return 0;
119 }
120
121 static void
122 cens_hdr(void)
123 {
124     if (player->god)
125         pr("    ");
126     pr("CENSUS                   del dst\n");
127     if (player->god)
128         pr("own ");
129     pr("  sect        eff ");
130     pr("prd ");
131     pr("mob uf uf old  civ  mil   uw food work avail ");
132     if (!player->god)
133         pr("ter ");
134     pr("fall coa\n");
135 }
136