budget: Track bank interest in nat_budget[]

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-18 22:33:25 +02:00
parent c12d1e137f
commit f27dd4e227
3 changed files with 24 additions and 22 deletions

View file

@ -62,8 +62,8 @@ struct budget {
struct budg_item prod[SCT_TYPE_MAX + 1]; struct budg_item prod[SCT_TYPE_MAX + 1];
/* building and maintenance */ /* building and maintenance */
struct budg_item bm[BUDG_BLD_MAX + 1]; struct budg_item bm[BUDG_BLD_MAX + 1];
/* population, taxes, military payroll */ /* population, taxes, military payroll, bank interest */
struct budg_item civ, mil, uw; struct budg_item civ, mil, uw, bars;
}; };
/* main.c */ /* main.c */
@ -130,7 +130,7 @@ extern int total_work(int, int, int, int, int, int);
extern void prepare_sects(int); extern void prepare_sects(int);
extern void tax(struct sctstr *, int, int *); extern void tax(struct sctstr *, int, int *);
extern void upd_slmilcosts(int, natid); extern void upd_slmilcosts(int, natid);
extern int bank_income(struct sctstr *, int); extern void bank_income(struct sctstr *, int);
extern void pay_reserve(struct natstr *, int); extern void pay_reserve(struct natstr *, int);
/* produce.c */ /* produce.c */
extern int produce(struct natstr *, struct sctstr *, int *); extern int produce(struct natstr *, struct sctstr *, int *);

View file

@ -42,7 +42,7 @@
#include "product.h" #include "product.h"
#include "update.h" #include "update.h"
static struct budget *calc_all(int *bars, int *Nbars); static struct budget *calc_all(void);
static char *dotsprintf(char *buf, char *format, int data); static char *dotsprintf(char *buf, char *format, int data);
int int
@ -62,21 +62,19 @@ budg(void)
{ "Sector maintenance", "sector" } { "Sector maintenance", "sector" }
}; };
int i; int i;
int bars, Nbars;
struct budget *budget; struct budget *budget;
int income, expenses, taxes; int income, expenses, taxes;
struct natstr *np; struct natstr *np;
char buf[1024]; char buf[1024];
char in[80];
np = getnatp(player->cnum); np = getnatp(player->cnum);
player->simulation = 1; player->simulation = 1;
budget = calc_all(&bars, &Nbars); budget = calc_all();
player->simulation = 0; player->simulation = 0;
income = bars; income = expenses = 0;
expenses = 0;
pr("Sector Type\t\t\tProduction\t\t\t Cost\n"); pr("Sector Type\t\t\tProduction\t\t\t Cost\n");
for (i = 0; i <= SCT_TYPE_MAX; i++) { for (i = 0; i <= SCT_TYPE_MAX; i++) {
if (!budget->prod[i].money) if (!budget->prod[i].money)
@ -121,9 +119,12 @@ budg(void)
pr("Income from taxes\t\t%-32s%+8d\n", buf, taxes); pr("Income from taxes\t\t%-32s%+8d\n", buf, taxes);
income += taxes; income += taxes;
} }
if (bars) { if (budget->bars.money) {
sprintf(in, "%d bar%s", Nbars, splur(Nbars)); snprintf(buf, sizeof(buf), "%d bar%s",
pr("Income from bars\t\t%-32s%+8d\n", in, bars); budget->bars.count, splur(budget->bars.count));
pr("Income from bars\t\t%-32s%+8d\n",
buf, budget->bars.money);
income += budget->bars.money;
} }
pr("Total income%s\n", dotsprintf(buf, "%+60d", income)); pr("Total income%s\n", dotsprintf(buf, "%+60d", income));
pr("Balance forward\t\t\t\t\t\t %10d\n", np->nat_money); pr("Balance forward\t\t\t\t\t\t %10d\n", np->nat_money);
@ -139,7 +140,7 @@ budg(void)
} }
static struct budget * static struct budget *
calc_all(int *bars, int *Nbars) calc_all(void)
{ {
struct budget *budget = &nat_budget[player->cnum]; struct budget *budget = &nat_budget[player->cnum];
struct natstr *np; struct natstr *np;
@ -150,7 +151,6 @@ calc_all(int *bars, int *Nbars)
int etu = etu_per_update; int etu = etu_per_update;
memset(nat_budget, 0, sizeof(nat_budget)); memset(nat_budget, 0, sizeof(nat_budget));
*bars = *Nbars = 0;
np = getnatp(player->cnum); np = getnatp(player->cnum);
bp = bp_alloc(); bp = bp_alloc();
@ -159,10 +159,8 @@ calc_all(int *bars, int *Nbars)
if (sp->sct_own == player->cnum) { if (sp->sct_own == player->cnum) {
sp->sct_updated = 0; sp->sct_updated = 0;
tax(sp, etu, &pop); tax(sp, etu, &pop);
if (sp->sct_type == SCT_BANK) { if (sp->sct_type == SCT_BANK)
*bars += bank_income(sp, etu); bank_income(sp, etu);
*Nbars += sp->sct_item[I_BAR];
}
} }
} }
tpops[player->cnum] = pop; tpops[player->cnum] = pop;

View file

@ -94,10 +94,9 @@ prepare_sects(int etu)
guerrilla(sp); guerrilla(sp);
do_plague(sp, etu); do_plague(sp, etu);
populace(sp, etu); populace(sp, etu);
np = getnatp(sp->sct_own);
tax(sp, etu, &pops[sp->sct_own]); tax(sp, etu, &pops[sp->sct_own]);
if (sp->sct_type == SCT_BANK) if (sp->sct_type == SCT_BANK)
np->nat_money += bank_income(sp, etu); bank_income(sp, etu);
} }
for (n = 0; NULL != (np = getnatp(n)); n++) { for (n = 0; NULL != (np = getnatp(n)); n++) {
upd_slmilcosts(etu, np->nat_cnum); upd_slmilcosts(etu, np->nat_cnum);
@ -105,6 +104,7 @@ prepare_sects(int etu)
np->nat_money += nat_budget[n].mil.money; np->nat_money += nat_budget[n].mil.money;
np->nat_money += nat_budget[n].civ.money; np->nat_money += nat_budget[n].civ.money;
np->nat_money += nat_budget[n].uw.money; np->nat_money += nat_budget[n].uw.money;
np->nat_money += nat_budget[n].bars.money;
} }
} }
@ -165,10 +165,14 @@ upd_slmilcosts(int etu, natid n)
nat_budget[n].mil.money += mil * etu * money_mil; nat_budget[n].mil.money += mil * etu * money_mil;
} }
int void
bank_income(struct sctstr *sp, int etu) bank_income(struct sctstr *sp, int etu)
{ {
return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100); int inc;
inc = (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
nat_budget[sp->sct_own].bars.count += sp->sct_item[I_BAR];
nat_budget[sp->sct_own].bars.money += inc;
} }
void void