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