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
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.
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.
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
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.
28 * budg.c: Calculate production levels, prioritize
30 * Known contributors to this file:
31 * Thomas Ruschak, 1992
32 * Ville Virrankoski, 1995
33 * Steve McClure, 1997-2000
34 * Markus Armbruster, 2004-2006
56 static void calc_all(long (*p_sect)[2], int *taxes, int *Ncivs,
57 int *Nuws, int *bars, int *Nbars, int *mil,
58 int *ships, int *sbuild, int *nsbuild, int *smaint,
59 int *units, int *lbuild, int *nlbuild, int *lmaint,
60 int *planes, int *pbuild, int *npbuild, int *pmaint);
61 static char *dotsprintf(char *buf, char *format, int data);
67 long p_sect[SCT_MAXDEF+1][2];
68 int taxes, Ncivs, Nuws, bars, Nbars, mil;
69 int ships, sbuild, nsbuild, smaint;
70 int units, lbuild, nlbuild, lmaint;
71 int planes, pbuild, npbuild, pmaint;
80 np = getnatp(player->cnum);
82 player->simulation = 1;
84 &taxes, &Ncivs, &Nuws, &bars, &Nbars, &mil,
85 &ships, &sbuild, &nsbuild, &smaint,
86 &units, &lbuild, &nlbuild, &lmaint,
87 &planes, &pbuild, &npbuild, &pmaint);
88 player->simulation = 0;
90 income = taxes + bars;
92 pr("Sector Type\t\t\tProduction\t\t\t Cost\n");
93 for (i = 0; i <= SCT_MAXDEF; i++) {
94 if (!p_sect[i][1] || i == SCT_CAPIT)
96 pr("%-17s\t\t", dchr[i].d_name);
98 pr("%ld mil \t", p_sect[i][0]);
99 else if (dchr[i].d_prd >= 0)
100 pr("%ld %-7s\t", p_sect[i][0], pchr[dchr[i].d_prd].p_sname);
103 pr("\t\t%8ld\n", p_sect[i][1]);
104 expenses += p_sect[i][1];
108 sprintf(buf, "%d ship%s", nsbuild, splur(nsbuild));
109 pr("Ship building\t\t\t%-16s\t\t%8d\n", buf, -sbuild);
114 sprintf(buf, "%d ship%s", ships, splur(ships));
115 pr("Ship maintenance\t\t%-16s\t\t%8d\n", buf, -smaint);
120 sprintf(buf, "%d plane%s", npbuild, splur(npbuild));
121 pr("Plane building\t\t\t%-16s\t\t%8d\n", buf, -pbuild);
126 sprintf(buf, "%d plane%s", planes, splur(planes));
127 pr("Plane maintenance\t\t%-16s\t\t%8d\n", buf, -pmaint);
131 sprintf(buf, "%d unit%s", nlbuild, splur(nlbuild));
132 pr("Unit building\t\t\t%-16s\t\t%8d\n", buf, -lbuild);
137 sprintf(buf, "%d unit%s", units, splur(units));
138 pr("Unit maintenance\t\t%-16s\t\t%8d\n", buf, -lmaint);
142 if (p_sect[SCT_EFFIC][1]) {
143 pr("Sector building\t\t\t\t%8ld sct(s)\t\t%8ld\n",
144 p_sect[SCT_EFFIC][0], p_sect[SCT_EFFIC][1]);
145 expenses += p_sect[SCT_EFFIC][1];
148 n = (mil - np->nat_reserve * money_res * etu) / (etu * money_mil);
149 sprintf(in, "%d mil, %d res", n, (int)np->nat_reserve);
150 pr("Military payroll\t\t%-32s%8d\n", in, -mil);
153 if (p_sect[SCT_CAPIT][0]) {
154 pr("%c%s maintenance\t\t",
155 toupper(dchr[SCT_CAPIT].d_name[0]),
156 dchr[SCT_CAPIT].d_name + 1);
157 n = p_sect[SCT_CAPIT][0];
158 sprintf(in, "%d %s", n, dchr[SCT_CAPIT].d_name);
159 plurize(in, sizeof(in), n);
160 pr("%-32s%8ld\n", in, p_sect[SCT_CAPIT][1]);
161 expenses += p_sect[SCT_CAPIT][1];
163 pr("Total expenses%s\n", dotsprintf(buf, "%58d", expenses));
165 sprintf(in, "%d civ%s, %d uw%s",
166 Ncivs, splur(Ncivs), Nuws, splur(Nuws));
167 pr("Income from taxes\t\t%-32s%+8d\n", in, taxes);
170 sprintf(in, "%d bar%s", Nbars, splur(Nbars));
171 pr("Income from bars\t\t%-32s%+8d\n", in, bars);
173 pr("Total income%s\n", dotsprintf(buf, "%+60d", income));
174 pr("Balance forward\t\t\t\t\t\t %10ld\n", np->nat_money);
175 pr("Estimated delta\t\t\t\t\t\t %+10d\n", income - expenses);
176 pr("Estimated new treasury%s\n",
177 dotsprintf(buf, "%50d", np->nat_money + income - expenses));
178 if (((np->nat_money + income - expenses) < 0) && !player->god) {
179 pr("After processsing sectors, you will be broke!\n");
180 pr("Sectors will not produce, distribute, or deliver!\n\n");
187 calc_all(long p_sect[][2],
188 int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars, int *mil,
189 int *ships, int *sbuild, int *nsbuild, int *smaint,
190 int *units, int *lbuild, int *nlbuild, int *lmaint,
191 int *planes, int *pbuild, int *npbuild, int *pmaint)
196 int n, civ_tax, uw_tax, mil_pay;
198 int etu = etu_per_update;
201 memset(p_sect, 0, sizeof(**p_sect) * (SCT_MAXDEF+1) * 2);
202 *taxes = *Ncivs = *Nuws = *bars = *Nbars = *mil = 0;
203 *ships = *sbuild = *nsbuild = *smaint = 0;
204 *units = *lbuild = *nlbuild = *lmaint = 0;
205 *planes = *pbuild = *npbuild = *pmaint = 0;
207 np = getnatp(player->cnum);
208 bp = calloc(WORLD_X * WORLD_Y * 8, sizeof(int));
209 for (n = 0; NULL != (sp = getsectid(n)); n++) {
210 fill_update_array(bp, sp);
211 if (sp->sct_own == player->cnum) {
213 tax(sp, np, etu, &pop, &civ_tax, &uw_tax, &mil_pay);
214 *Ncivs += sp->sct_item[I_CIVIL];
215 *Nuws += sp->sct_item[I_UW];
216 *taxes += civ_tax + uw_tax;
218 if (sp->sct_type == SCT_BANK) {
219 *bars += bank_income(sp, etu);
220 *Nbars += sp->sct_item[I_BAR];
224 tpops[player->cnum] = pop;
225 *mil += (int)(np->nat_reserve * money_res * etu);
227 *mil += upd_slmilcosts(np->nat_cnum, etu);
229 /* Maintain and build ships */
230 sea_money[player->cnum] = 0;
231 *ships = prod_ship(etu, player->cnum, bp, 0);
232 *smaint = sea_money[player->cnum];
233 sea_money[player->cnum] = 0;
234 *nsbuild = prod_ship(etu, player->cnum, bp, 1);
235 *sbuild = sea_money[player->cnum];
236 sea_money[player->cnum] = 0;
238 /* Maintain and build planes */
239 air_money[player->cnum] = 0;
240 *planes = prod_plane(etu, player->cnum, bp, 0);
241 *pmaint = air_money[player->cnum];
242 air_money[player->cnum] = 0;
243 *npbuild = prod_plane(etu, player->cnum, bp, 1);
244 *pbuild = air_money[player->cnum];
245 air_money[player->cnum] = 0;
247 /* Maintain and build land units */
248 lnd_money[player->cnum] = 0;
249 *units = prod_land(etu, player->cnum, bp, 0);
250 *lmaint = lnd_money[player->cnum];
251 lnd_money[player->cnum] = 0;
252 *nlbuild = prod_land(etu, player->cnum, bp, 1);
253 *lbuild = lnd_money[player->cnum];
254 lnd_money[player->cnum] = 0;
257 produce_sect(player->cnum, etu, bp, p_sect);
263 dotsprintf(char *buf, char *format, int data)
265 sprintf(buf, format, data);
266 return memset(buf, '.', strspn(buf, " "));