]> git.pond.sub.org Git - empserver/blob - src/lib/commands/strv.c
Add some missing declarations to headers. Remove some redundant
[empserver] / src / lib / commands / strv.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  *  star.c: Do a starvation 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 "xy.h"
38 #include "sect.h"
39 #include "nsc.h"
40 #include "nat.h"
41 #include "deity.h"
42 #include "path.h"
43 #include "file.h"
44 #include <math.h>
45 #include "item.h"
46 #include "ship.h"
47 #include "optlist.h"
48 #include "land.h"
49 #include "commands.h"
50
51 static void starv_sects(s_char *range);
52 static void starv_ships(s_char *range);
53 static void starv_units(s_char *range);
54 static void sect_hdr(void);
55 static void ship_hdr(void);
56 static void unit_hdr(void);
57
58 int
59 starve(void)
60 {
61     struct nstr_sect nstr;
62     int do_sects = 0;
63     int do_ships = 0;
64     int do_units = 0;
65     s_char range[1024];
66
67     if (opt_NOFOOD) {           /* no food - no work! */
68         pr("No food is required in this game\n");
69         return RET_OK;
70     }
71
72     strcpy(range, "*");
73     if (!player->argp[1]) {
74         do_sects = do_ships = do_units = 1;
75     } else if (*(player->argp[1]) == 's') {
76         do_ships = 1;
77         if (player->argp[2])
78             strcpy(range, player->argp[2]);
79     } else if (*(player->argp[1]) == 'l') {
80         do_units = 1;
81         if (player->argp[2])
82             strcpy(range, player->argp[2]);
83     } else {
84         if (!snxtsct(&nstr, player->argp[1]))
85             return RET_SYN;
86         do_sects = 1;
87         strcpy(range, player->argp[1]);
88     }
89     player->simulation = 1;
90     prdate();
91     if (do_sects)
92         starv_sects(range);
93     if (do_ships)
94         starv_ships(range);
95     if (do_units)
96         starv_units(range);
97     player->simulation = 0;
98     return RET_OK;
99 }
100
101 static void
102 starv_sects(s_char *range)
103 {
104     struct nstr_sect nstr;
105     struct sctstr sect;
106     int nsect = 0;
107     int vec[I_MAX + 1], s, needed;
108
109     if (!snxtsct(&nstr, range))
110         return;
111     while (nxtsct(&nstr, &sect)) {
112         if (!player->owner)
113             continue;
114         if (sect.sct_type == SCT_SANCT)
115             continue;
116
117         getvec(VT_ITEM, vec, (s_char *)&sect, EF_SECTOR);
118 /* This next 2 lines were added to overcompensate for the needy */
119         if (vec[I_FOOD])
120             vec[I_FOOD]--;
121         s = feed_people(vec, etu_per_update, &needed);
122
123         if (s == 0)
124             continue;
125         if (nsect++ == 0)
126             sect_hdr();
127         if (player->god)
128             pr("%3d ", sect.sct_own);
129         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
130         pr(" %c", dchr[sect.sct_type].d_mnem);
131         pr(" %c", (sect.sct_own != sect.sct_oldown ? '*' : ' '));
132         if (sect.sct_newtype != sect.sct_type)
133             pr("%c", dchr[sect.sct_newtype].d_mnem);
134         else
135             pr(" ");
136         pr("%4d%%", sect.sct_effic);
137         pr(" will starve %d people. %d more food needed\n", s, needed);
138     }
139     if (nsect == 0) {
140         if (player->argp[1])
141             pr("%s: No sector(s)\n", player->argp[1]);
142         else
143             pr("%s: No sector(s)\n", "");
144         return;
145     } else
146         pr("%d sector%s\n", nsect, splur(nsect));
147     return;
148 }
149
150 static void
151 sect_hdr(void)
152 {
153     if (player->god)
154         pr("    ");
155     pr("Starvation               \n");
156     if (player->god)
157         pr("own ");
158     pr("  sect         eff ");
159     pr("\n");
160 }
161
162 static void
163 starv_ships(s_char *range)
164 {
165     struct nstr_item ni;
166     struct shpstr ship;
167     int nship = 0;
168     int vec[I_MAX + 1], s, needed;
169
170     if (!snxtitem(&ni, EF_SHIP, range))
171         return;
172
173     while (nxtitem(&ni, (s_char *)&ship)) {
174         if (!player->owner || !ship.shp_own)
175             continue;
176
177         getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP);
178         s = feed_ship(&ship, vec, etu_per_update, &needed, 0);
179
180         if (s == 0)
181             continue;
182         if (nship++ == 0)
183             ship_hdr();
184         if (player->god)
185             pr("%3d ", ship.shp_own);
186         pr("%5d ", ship.shp_uid);
187         pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
188         pr(" will starve %d people. %d more food needed\n", s, needed);
189     }
190     if (nship == 0) {
191         if (range)
192             pr("%s: No ship(s)\n", range);
193         else
194             pr("%s: No ship(s)\n", "");
195         return;
196     } else
197         pr("%d ship%s\n", nship, splur(nship));
198     return;
199 }
200
201 static void
202 ship_hdr(void)
203 {
204     if (player->god)
205         pr("    ");
206     pr("Starvation               \n");
207     if (player->god)
208         pr("own ");
209     pr(" shp#     ship type       \n");
210 }
211
212 static void
213 starv_units(s_char *range)
214 {
215     struct nstr_item ni;
216     struct lndstr land;
217     int nunit = 0;
218     int vec[I_MAX + 1], s, needed;
219
220     if (!snxtitem(&ni, EF_LAND, range))
221         return;
222
223     while (nxtitem(&ni, (s_char *)&land)) {
224         if (!player->owner || !land.lnd_own)
225             continue;
226
227         getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
228         s = feed_land(&land, vec, etu_per_update, &needed, 0);
229
230         if (s == 0)
231             continue;
232         if (nunit++ == 0)
233             unit_hdr();
234         if (player->god)
235             pr("%3d ", land.lnd_own);
236         pr("%5d ", land.lnd_uid);
237         pr("%-16.16s ", lchr[(int)land.lnd_type].l_name);
238         pr(" will starve %d mil. %d more food needed\n", s, needed);
239     }
240     if (nunit == 0) {
241         if (range)
242             pr("%s: No unit(s)\n", range);
243         else
244             pr("%s: No unit(s)\n", "");
245         return;
246     } else
247         pr("%d unit%s\n", nunit, splur(nunit));
248     return;
249 }
250
251 static void
252 unit_hdr(void)
253 {
254     if (player->god)
255         pr("    ");
256     pr("Starvation               \n");
257     if (player->god)
258         pr("own ");
259     pr(" lnd#     unit type       \n");
260 }