2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * budg.c: Calculate production levels, prioritize
29 * Known contributors to this file:
30 * Thomas Ruschak, 1992
31 * Ville Virrankoski, 1995
32 * Steve McClure, 1997-2000
33 * Markus Armbruster, 2004-2016
45 static struct budget *calc_all(void);
46 static char *dotsprintf(char *buf, char *format, int data);
55 { "Ship building", "ship" },
56 { "Ship maintenance", "ship" },
57 { "Plane building", "plane" },
58 { "Plane maintenance", "plane" },
59 { "Unit building", "unit" },
60 { "Unit maintenance", "unit" },
61 { "Sector building", "sector" },
62 { "Sector maintenance", "sector" }
65 struct budget *budget;
66 int income, expenses, taxes;
70 np = getnatp(player->cnum);
72 player->simulation = 1;
74 player->simulation = 0;
76 income = expenses = 0;
78 pr("Sector Type\t\t\tProduction\t\t\t Cost\n");
79 for (i = 0; i <= SCT_TYPE_MAX; i++) {
80 if (!budget->prod[i].money)
82 pr("%-17s\t\t", dchr[i].d_name);
84 pr("%d mil \t", budget->prod[i].count);
85 else if (dchr[i].d_prd >= 0)
86 pr("%d %-7s\t", budget->prod[i].count,
87 pchr[dchr[i].d_prd].p_sname);
90 pr("\t\t%8.0f\n", -budget->prod[i].money);
91 expenses -= budget->prod[i].money;
94 for (i = 0; i <= BUDG_BLD_MAX; i++) {
95 if (!budget->bm[i].money)
97 snprintf(buf, sizeof(buf), "%d %s%s",
98 budget->bm[i].count, bm_name[i].object,
99 splur(budget->bm[i].count));
100 pr("%-20s\t\t%-16s\t\t%8.0f\n",
101 bm_name[i].activity, buf, -budget->bm[i].money);
102 expenses -= budget->bm[i].money;
105 if (budget->mil.money) {
106 snprintf(buf, sizeof(buf), "%d mil, %d res",
107 budget->mil.count, np->nat_reserve);
108 pr("Military payroll\t\t%-32s%8.0f\n",
109 buf, -budget->mil.money);
110 expenses -= budget->mil.money;
113 pr("Total expenses%s\n", dotsprintf(buf, "%58d", expenses));
114 taxes = budget->civ.money + budget->uw.money;
116 snprintf(buf, sizeof(buf), "%d civ%s, %d uw%s",
117 budget->civ.count, splur(budget->civ.count),
118 budget->uw.count, splur(budget->uw.count));
119 pr("Income from taxes\t\t%-32s%+8d\n", buf, taxes);
122 if (budget->bars.money) {
123 snprintf(buf, sizeof(buf), "%d bar%s",
124 budget->bars.count, splur(budget->bars.count));
125 pr("Income from bars\t\t%-32s%+8.0f\n",
126 buf, budget->bars.money);
127 income += budget->bars.money;
129 pr("Total income%s\n", dotsprintf(buf, "%+60d", income));
130 pr("Balance forward\t\t\t\t\t\t %10d\n", np->nat_money);
131 pr("Estimated delta\t\t\t\t\t\t %+10d\n", income - expenses);
132 pr("Estimated new treasury%s\n",
133 dotsprintf(buf, "%50d", np->nat_money + income - expenses));
134 if (np->nat_money + income - expenses < 0 && !player->god) {
135 pr("After processing sectors, you will be broke!\n");
136 pr("Sectors will not produce, distribute, or deliver!\n\n");
142 static struct budget *
145 struct budget *budget = &nat_budget[player->cnum];
149 int etu = etu_per_update;
151 memset(nat_budget, 0, sizeof(nat_budget));
152 np = getnatp(player->cnum);
153 /* Take care not to disclose others going broke: */
154 for (i = 0; i < MAXNOC; i++)
155 nat_budget[i].start_money = nat_budget[i].money = INT_MAX;
156 budget->start_money = budget->money = np->nat_money;
160 prep_planes(etu, bp);
162 prepare_sects(etu, bp);
163 pay_reserve(np, etu);
165 /* Maintain ships, planes and land units */
166 prod_ship(etu, bp, 0);
167 prod_plane(etu, bp, 0);
168 prod_land(etu, bp, 0);
171 produce_sect(etu, bp);
173 /* Build ships, planes and land units */
174 prod_ship(etu, bp, 1);
175 prod_plane(etu, bp, 1);
176 prod_land(etu, bp, 1);
178 if (CANT_HAPPEN(np->nat_money != budget->start_money))
179 np->nat_money = budget->start_money;
186 dotsprintf(char *buf, char *format, int data)
188 sprintf(buf, format, data);
189 return memset(buf, '.', strspn(buf, " "));