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];
/* building and maintenance */
struct budg_item bm[BUDG_BLD_MAX + 1];
/* population, taxes, military payroll */
struct budg_item civ, mil, uw;
/* population, taxes, military payroll, bank interest */
struct budg_item civ, mil, uw, bars;
};
/* main.c */
@ -130,7 +130,7 @@ extern int total_work(int, int, int, int, int, int);
extern void prepare_sects(int);
extern void tax(struct sctstr *, int, int *);
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);
/* produce.c */
extern int produce(struct natstr *, struct sctstr *, int *);

View file

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

View file

@ -94,10 +94,9 @@ prepare_sects(int etu)
guerrilla(sp);
do_plague(sp, etu);
populace(sp, etu);
np = getnatp(sp->sct_own);
tax(sp, etu, &pops[sp->sct_own]);
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++) {
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].civ.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;
}
int
void
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