]> git.pond.sub.org Git - empserver/commitdiff
budget: Track taxes in nat_budget[]
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Jun 2016 20:26:05 +0000 (22:26 +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 3a20f4b09351c7a6808c5478a722dae27867c96f..8c3f4437786b7b733a0a0dcf03b93bc0b8263902 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];
     struct budg_item prod[SCT_TYPE_MAX + 1];
     /* building and maintenance */
     struct budg_item bm[BUDG_BLD_MAX + 1];
-    /* military payroll */
-    struct budg_item mil;
+    /* population, taxes, military payroll */
+    struct budg_item civ, mil, uw;
 };
 
 /* main.c */
 };
 
 /* main.c */
@@ -128,7 +128,7 @@ extern void populace(struct sctstr *, int);
 extern int total_work(int, int, int, int, int, int);
 /* prepare.c */
 extern void prepare_sects(int);
 extern int total_work(int, int, int, int, int, int);
 /* prepare.c */
 extern void prepare_sects(int);
-extern void tax(struct sctstr *, int, int *, int *, int *);
+extern void tax(struct sctstr *, int, int *);
 extern void upd_slmilcosts(int, natid);
 extern int bank_income(struct sctstr *, int);
 extern void pay_reserve(struct natstr *, int);
 extern void upd_slmilcosts(int, natid);
 extern int bank_income(struct sctstr *, int);
 extern void pay_reserve(struct natstr *, int);
index b6d7ee8caf5411de274561c818137c5454d83db0..397e37ebe42db2b915f3b6b7dda463948f916270 100644 (file)
@@ -42,8 +42,7 @@
 #include "product.h"
 #include "update.h"
 
 #include "product.h"
 #include "update.h"
 
-static struct budget *calc_all(int *taxes, int *Ncivs,
-                              int *Nuws, int *bars, int *Nbars);
+static struct budget *calc_all(int *bars, int *Nbars);
 static char *dotsprintf(char *buf, char *format, int data);
 
 int
 static char *dotsprintf(char *buf, char *format, int data);
 
 int
@@ -63,9 +62,9 @@ budg(void)
        { "Sector maintenance", "sector" }
     };
     int i;
        { "Sector maintenance", "sector" }
     };
     int i;
-    int taxes, Ncivs, Nuws, bars, Nbars;
+    int bars, Nbars;
     struct budget *budget;
     struct budget *budget;
-    int income, expenses;
+    int income, expenses, taxes;
     struct natstr *np;
     char buf[1024];
     char in[80];
     struct natstr *np;
     char buf[1024];
     char in[80];
@@ -73,10 +72,10 @@ budg(void)
     np = getnatp(player->cnum);
 
     player->simulation = 1;
     np = getnatp(player->cnum);
 
     player->simulation = 1;
-    budget = calc_all(&taxes, &Ncivs, &Nuws, &bars, &Nbars);
+    budget = calc_all(&bars, &Nbars);
     player->simulation = 0;
 
     player->simulation = 0;
 
-    income = taxes + bars;
+    income = bars;
     expenses = 0;
     pr("Sector Type\t\t\tProduction\t\t\t    Cost\n");
     for (i = 0; i <= SCT_TYPE_MAX; i++) {
     expenses = 0;
     pr("Sector Type\t\t\tProduction\t\t\t    Cost\n");
     for (i = 0; i <= SCT_TYPE_MAX; i++) {
@@ -114,10 +113,13 @@ budg(void)
     }
 
     pr("Total expenses%s\n", dotsprintf(buf, "%58d", expenses));
     }
 
     pr("Total expenses%s\n", dotsprintf(buf, "%58d", expenses));
+    taxes = budget->civ.money + budget->uw.money;
     if (taxes) {
     if (taxes) {
-       sprintf(in, "%d civ%s, %d uw%s",
-               Ncivs, splur(Ncivs), Nuws, splur(Nuws));
-       pr("Income from taxes\t\t%-32s%+8d\n", in, taxes);
+       snprintf(buf, sizeof(buf), "%d civ%s, %d uw%s",
+                budget->civ.count, splur(budget->civ.count),
+                budget->uw.count, splur(budget->uw.count));
+       pr("Income from taxes\t\t%-32s%+8d\n", buf, taxes);
+       income += taxes;
     }
     if (bars) {
        sprintf(in, "%d bar%s", Nbars, splur(Nbars));
     }
     if (bars) {
        sprintf(in, "%d bar%s", Nbars, splur(Nbars));
@@ -137,18 +139,18 @@ budg(void)
 }
 
 static struct budget *
 }
 
 static struct budget *
-calc_all(int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars)
+calc_all(int *bars, int *Nbars)
 {
     struct budget *budget = &nat_budget[player->cnum];
     struct natstr *np;
     struct bp *bp;
     int pop = 0;
 {
     struct budget *budget = &nat_budget[player->cnum];
     struct natstr *np;
     struct bp *bp;
     int pop = 0;
-    int n, civ_tax, uw_tax;
+    int n;
     struct sctstr *sp;
     int etu = etu_per_update;
 
     memset(nat_budget, 0, sizeof(nat_budget));
     struct sctstr *sp;
     int etu = etu_per_update;
 
     memset(nat_budget, 0, sizeof(nat_budget));
-    *taxes = *Ncivs = *Nuws = *bars = *Nbars = 0;
+    *bars = *Nbars = 0;
 
     np = getnatp(player->cnum);
     bp = bp_alloc();
 
     np = getnatp(player->cnum);
     bp = bp_alloc();
@@ -156,10 +158,7 @@ calc_all(int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars)
        bp_set_from_sect(bp, sp);
        if (sp->sct_own == player->cnum) {
            sp->sct_updated = 0;
        bp_set_from_sect(bp, sp);
        if (sp->sct_own == player->cnum) {
            sp->sct_updated = 0;
-           tax(sp, etu, &pop, &civ_tax, &uw_tax);
-           *Ncivs += sp->sct_item[I_CIVIL];
-           *Nuws += sp->sct_item[I_UW];
-           *taxes += civ_tax + uw_tax;
+           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) {
                *bars += bank_income(sp, etu);
                *Nbars += sp->sct_item[I_BAR];
index ae66966c7b115e5e5e84a255af9f20659db6a707..e3c5bcf55f115079866515fe84156a791c57ae06 100644 (file)
@@ -51,7 +51,7 @@ prepare_sects(int etu)
 {
     struct sctstr *sp;
     struct natstr *np;
 {
     struct sctstr *sp;
     struct natstr *np;
-    int n, civ_tax, uw_tax;
+    int n;
 
     memset(levels, 0, sizeof(levels));
 
 
     memset(levels, 0, sizeof(levels));
 
@@ -95,8 +95,7 @@ prepare_sects(int etu)
        do_plague(sp, etu);
        populace(sp, etu);
        np = getnatp(sp->sct_own);
        do_plague(sp, etu);
        populace(sp, etu);
        np = getnatp(sp->sct_own);
-       tax(sp, etu, &pops[sp->sct_own], &civ_tax, &uw_tax);
-       np->nat_money += civ_tax + uw_tax;
+       tax(sp, etu, &pops[sp->sct_own]);
        if (sp->sct_type == SCT_BANK)
            np->nat_money += bank_income(sp, etu);
     }
        if (sp->sct_type == SCT_BANK)
            np->nat_money += bank_income(sp, etu);
     }
@@ -104,24 +103,31 @@ prepare_sects(int etu)
        upd_slmilcosts(etu, np->nat_cnum);
        pay_reserve(np, etu);
        np->nat_money += nat_budget[n].mil.money;
        upd_slmilcosts(etu, np->nat_cnum);
        pay_reserve(np, 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;
     }
 }
 
 void
     }
 }
 
 void
-tax(struct sctstr *sp, int etu, int *pop, int *civ_tax, int *uw_tax)
+tax(struct sctstr *sp, int etu, int *pop)
 {
     struct budget *budget = &nat_budget[sp->sct_own];
 {
     struct budget *budget = &nat_budget[sp->sct_own];
-    int mil_pay;
+    int civ_tax, uw_tax, mil_pay;
 
 
-    *civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
-                    etu * money_civ / 100);
+    civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
+                   etu * money_civ / 100);
     /*
      * captured civs only pay 1/4 taxes
      */
     if (sp->sct_own != sp->sct_oldown)
     /*
      * captured civs only pay 1/4 taxes
      */
     if (sp->sct_own != sp->sct_oldown)
-       *civ_tax = *civ_tax / 4;
-    *uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
-                   etu * money_uw / 100);
+       civ_tax /= 4;
+    budget->civ.count += sp->sct_item[I_CIVIL];
+    budget->civ.money += civ_tax;
+
+    uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
+                  etu * money_uw / 100);
+    budget->uw.count += sp->sct_item[I_UW];
+    budget->uw.money += uw_tax;
 
     mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
     budget->mil.count += sp->sct_item[I_MILIT];
 
     mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
     budget->mil.count += sp->sct_item[I_MILIT];