]> git.pond.sub.org Git - empserver/commitdiff
budget: Track bank interest in nat_budget[]
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Jun 2016 20:33:25 +0000 (22:33 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:00:00 +0000 (20:00 +0200)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/update.h
src/lib/commands/budg.c
src/lib/update/prepare.c

index 8c3f4437786b7b733a0a0dcf03b93bc0b8263902..53d7ec41123d69b2168ec991e1a2e94e996189e2 100644 (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 *);
index 397e37ebe42db2b915f3b6b7dda463948f916270..4f276dddb799752acea1de2bf7da6cb07590a7df 100644 (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;
index e3c5bcf55f115079866515fe84156a791c57ae06..316e14c08fb9c463058629885a56349bcf3297c0 100644 (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