#include "product.h"
#include "update.h"
-static struct budget *calc_all(int (*p_sect)[2], int *taxes, int *Ncivs,
+static struct budget *calc_all(int *taxes, int *Ncivs,
int *Nuws, int *bars, int *Nbars,
int *ships, int *sbuild, int *nsbuild, int *smaint,
int *units, int *lbuild, int *nlbuild, int *lmaint,
budg(void)
{
int i;
- int p_sect[SCT_BUDG_MAX+1][2];
int taxes, Ncivs, Nuws, bars, Nbars;
int ships, sbuild, nsbuild, smaint;
int units, lbuild, nlbuild, lmaint;
np = getnatp(player->cnum);
player->simulation = 1;
- budget = calc_all(p_sect,
- &taxes, &Ncivs, &Nuws, &bars, &Nbars,
+ budget = calc_all(&taxes, &Ncivs, &Nuws, &bars, &Nbars,
&ships, &sbuild, &nsbuild, &smaint,
&units, &lbuild, &nlbuild, &lmaint,
&planes, &pbuild, &npbuild, &pmaint);
expenses = 0;
pr("Sector Type\t\t\tProduction\t\t\t Cost\n");
for (i = 0; i <= SCT_TYPE_MAX; i++) {
- if (!p_sect[i][1])
+ if (!budget->prod[i].money)
continue;
pr("%-17s\t\t", dchr[i].d_name);
if (i == SCT_ENLIST)
- pr("%d mil \t", p_sect[i][0]);
+ pr("%d mil \t", budget->prod[i].count);
else if (dchr[i].d_prd >= 0)
- pr("%d %-7s\t", p_sect[i][0], pchr[dchr[i].d_prd].p_sname);
+ pr("%d %-7s\t", budget->prod[i].count,
+ pchr[dchr[i].d_prd].p_sname);
else
pr("\t\t");
- pr("\t\t%8d\n", p_sect[i][1]);
- expenses += p_sect[i][1];
+ pr("\t\t%8d\n", -budget->prod[i].money);
+ expenses -= budget->prod[i].money;
}
if (sbuild) {
expenses += -lmaint;
}
- if (p_sect[SCT_EFFIC][1]) {
- sprintf(buf, "%d sector%s",
- p_sect[SCT_EFFIC][0], splur(p_sect[SCT_EFFIC][0]));
+ if (budget->bm[BUDG_SCT_BUILD].money) {
+ snprintf(buf, sizeof(buf), "%d sector%s",
+ budget->bm[BUDG_SCT_BUILD].count,
+ splur(budget->bm[BUDG_SCT_BUILD].count));
pr("Sector building\t\t\t%-16s\t\t%8d\n",
- buf, p_sect[SCT_EFFIC][1]);
- expenses += p_sect[SCT_EFFIC][1];
+ buf, -budget->bm[BUDG_SCT_BUILD].money);
+ expenses -= budget->bm[BUDG_SCT_BUILD].money;
}
- if (p_sect[SCT_MAINT][0]) {
- sprintf(buf, "%d sector%s",
- p_sect[SCT_MAINT][0], splur(p_sect[SCT_MAINT][0]));
+ if (budget->bm[BUDG_SCT_MAINT].count) {
+ snprintf(buf, sizeof(buf), "%d sector%s",
+ budget->bm[BUDG_SCT_MAINT].count,
+ splur(budget->bm[BUDG_SCT_MAINT].count));
pr("Sector maintenance\t\t%-16s\t\t%8d\n",
- buf, p_sect[SCT_MAINT][1]);
- expenses += p_sect[SCT_MAINT][1];
+ buf, -budget->bm[BUDG_SCT_MAINT].money);
+ expenses -= budget->bm[BUDG_SCT_MAINT].money;
}
if (budget->mil.money) {
snprintf(buf, sizeof(buf), "%d mil, %d res",
}
static struct budget *
-calc_all(int p_sect[][2],
- int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars,
+calc_all(int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars,
int *ships, int *sbuild, int *nsbuild, int *smaint,
int *units, int *lbuild, int *nlbuild, int *lmaint,
int *planes, int *pbuild, int *npbuild, int *pmaint)
int etu = etu_per_update;
memset(nat_budget, 0, sizeof(nat_budget));
- memset(p_sect, 0, sizeof(**p_sect) * (SCT_BUDG_MAX+1) * 2);
*taxes = *Ncivs = *Nuws = *bars = *Nbars = 0;
*ships = *sbuild = *nsbuild = *smaint = 0;
*units = *lbuild = *nlbuild = *lmaint = 0;
*lmaint = lnd_money[player->cnum];
/* Produce */
- produce_sect(np, etu, bp, p_sect);
+ produce_sect(np, etu, bp);
/* Build ships */
sea_money[player->cnum] = 0;
* Produce for a specific nation
*/
void
-produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
+produce_sect(struct natstr *np, int etu, struct bp *bp)
{
+ struct budget *budget = &nat_budget[np->nat_cnum];
struct sctstr *sp, scratch_sect;
int cost, ecost, pcost;
int n, amount;
if (dchr[sp->sct_type].d_maint) {
cost = etu * dchr[sp->sct_type].d_maint;
- p_sect[SCT_MAINT][0]++;
- p_sect[SCT_MAINT][1] += cost;
+ budget->bm[BUDG_SCT_MAINT].count++;
+ budget->bm[BUDG_SCT_MAINT].money -= cost;
if (!player->simulation)
np->nat_money -= cost;
}
if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
np->nat_money >= 0) {
cost = roundavg(buildeff(sp));
- p_sect[SCT_EFFIC][0]++;
- p_sect[SCT_EFFIC][1] += cost;
+ budget->bm[BUDG_SCT_BUILD].count++;
+ budget->bm[BUDG_SCT_BUILD].money -= cost;
if (!player->simulation)
np->nat_money -= cost;
}
if (sp->sct_type == SCT_ENLIST && sp->sct_effic >= 60 &&
sp->sct_own == sp->sct_oldown) {
- p_sect[sp->sct_type][0] += enlist(sp->sct_item, etu, &ecost);
- p_sect[sp->sct_type][1] += ecost;
+ budget->prod[sp->sct_type].count
+ += enlist(sp->sct_item, etu, &ecost);
+ budget->prod[sp->sct_type].money -= ecost;
if (!player->simulation)
np->nat_money -= ecost;
}
}
bp_set_from_sect(bp, sp);
- p_sect[sp->sct_type][0] += amount;
- p_sect[sp->sct_type][1] += pcost;
+ budget->prod[sp->sct_type].count += amount;
+ budget->prod[sp->sct_type].money -= pcost;
if (!player->simulation)
np->nat_money -= pcost;
}