]> git.pond.sub.org Git - empserver/blob - src/lib/commands/cens.c
Update copyright notice.
[empserver] / src / lib / commands / cens.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  *  cens.c: Do a census report
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 2000
32  *     
33  */
34
35 #include "misc.h"
36 #include "player.h"
37 #include "var.h"
38 #include "xy.h"
39 #include "sect.h"
40 #include "nsc.h"
41 #include "nat.h"
42 #include "path.h"
43 #include "file.h"
44 #include "commands.h"
45 #include "optlist.h"
46
47 static void cens_hdr(void);
48
49 int
50 cens(void)
51 {
52     struct sctstr sect;
53     int nsect;
54     int n;
55     struct nstr_sect nstr;
56     s_char dirstr[20];
57
58     if (!snxtsct(&nstr, player->argp[1]))
59         return RET_SYN;
60     prdate();
61     for (n = 1; n <= 6; n++)
62         dirstr[n] = dirch[n];
63     dirstr[0] = '.';
64     dirstr[7] = '$';
65     dirstr[8] = '\0';
66     nsect = 0;
67     while (nxtsct(&nstr, &sect)) {
68         if (!player->owner)
69             continue;
70         if (nsect++ == 0)
71             cens_hdr();
72         if (player->god)
73             pr("%3d ", sect.sct_own);
74         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
75         pr(" %c", dchr[sect.sct_type].d_mnem);
76         if (sect.sct_newtype != sect.sct_type)
77             pr("%c", dchr[sect.sct_newtype].d_mnem);
78         else
79             pr(" ");
80         pr("%4d%%", sect.sct_effic);
81         if (sect.sct_off)
82             pr(" no ");
83         else
84             pr("    ");
85         pr("%4d", sect.sct_mobil);
86
87         pr(" %c", dirstr[sect.sct_del[I_UW] & 0x7]);
88         pr("%c", dirstr[sect.sct_del[I_FOOD] & 0x7]);
89
90         n = sect.sct_dist[I_UW] % 1000;
91         pr(" %c", n == 0 ? '.' : '0' + (n / 100));
92         n = sect.sct_dist[I_FOOD] % 1000;
93         pr("%c ", n == 0 ? '.' : '0' + (n / 100));
94         pr("%c", sect.sct_own != sect.sct_oldown ? '*' : ' ');
95
96         pr("%5d", sect.sct_item[I_CIVIL]);
97         pr("%5d", sect.sct_item[I_MILIT]);
98         pr("%5d", sect.sct_item[I_UW]);
99         pr("%5d", sect.sct_item[I_FOOD]);
100         pr("%4d%%", sect.sct_work);
101         pr("%5d", sect.sct_avail);
102         if (!player->god) {
103             if (sect.sct_terr)
104                 pr("%4d", sect.sct_terr);
105             else
106                 pr("    ");
107         }
108         if (opt_FALLOUT) {
109             pr("%5d", sect.sct_fallout);
110         }
111         set_coastal(&sect);
112         if (sect.sct_coastal)
113             pr("%4d", sect.sct_coastal);
114         pr("\n");
115     }
116     if (nsect == 0) {
117         if (player->argp[1])
118             pr("%s: No sector(s)\n", player->argp[1]);
119         else
120             pr("%s: No sector(s)\n", "");
121         return RET_FAIL;
122     } else
123         pr("%d sector%s\n", nsect, splur(nsect));
124     return 0;
125 }
126
127 static void
128 cens_hdr(void)
129 {
130     if (player->god)
131         pr("    ");
132     pr("CENSUS                   del dst\n");
133     if (player->god)
134         pr("own ");
135     pr("  sect        eff ");
136     pr("prd ");
137     pr("mob uf uf *  civ  mil   uw food work avail ");
138     if (!player->god)
139         pr("ter ");
140     if (opt_FALLOUT)
141         pr("fall ");
142     pr("coa");
143     pr("\n");
144 }
145
146 void
147 set_coastal(struct sctstr *sp)
148 {
149     int n;
150     struct sctstr sect;
151     u_char start_flags = sp->sct_coastal;
152
153     /* It's already been set, it didn't change (you can't fill
154        in water, even with bridge spans they are still coastal.) */
155     if (sp->sct_coastal)
156         return;
157     for (n = 1; n <= 6; ++n) {  /* Directions */
158         getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
159         if (sect.sct_type == SCT_WATER ||
160             sect.sct_type == SCT_BTOWER || sect.sct_type == SCT_BSPAN) {
161             sp->sct_coastal = 1;
162             if (start_flags != sp->sct_coastal)
163                 putsect(sp);
164             return;
165         }
166     }
167     sp->sct_coastal = 0;
168     if (start_flags != sp->sct_coastal)
169         putsect(sp);
170 }