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