]> git.pond.sub.org Git - empserver/commitdiff
update: Track levels in nat_budget[]
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Jun 2016 12:32:33 +0000 (14:32 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:08:30 +0000 (20:08 +0200)
Replace levels[][] by nat_budget[].level[].

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/update.h
src/lib/update/nat.c
src/lib/update/prepare.c
src/lib/update/produce.c

index edb9bd79c5720129ea88be7f37c62f4f3fb57fa3..f0129191f3c74d5e0c1255df3e20bb062167c123 100644 (file)
@@ -60,6 +60,8 @@ struct budg_item {
 struct budget {
     /* production by sector type */
     struct budg_item prod[SCT_TYPE_MAX + 1];
+    /* level production output */
+    float level[4];
     /* building and maintenance */
     struct budg_item bm[BUDG_BLD_MAX + 1];
     /* population, taxes, military payroll, bank interest */
@@ -73,8 +75,6 @@ struct budget {
 
 /* main.c */
 extern struct budget nat_budget[MAXNOC];
-/* nat.c */
-extern float levels[MAXNOC][4];
 
 /* age.c */
 extern int age_people(int, int);
index 952354af34a24492a36eedea9f6c9d1ff7ecbb51..1300cba025a0582cd70ef20fbd19efbdb32cc69c 100644 (file)
@@ -73,8 +73,6 @@ static void share_incr(double[], double[]);
 static float level_easy[4] = { 0.75, 0.75, 5.00, 5.00 };
 static float level_log[4] = { 1.75, 2.00, 4.00, 6.00 };
 
-float levels[MAXNOC][4];
-
 /*
  * technique to limit the sharpers who turn entire countries
  * into tech plants overnight...
@@ -124,6 +122,7 @@ void
 prod_nat(int etu)
 {
     struct natstr *np;
+    float *level;
     float hap;
     float edu;
     float hap_edu;
@@ -143,6 +142,7 @@ prod_nat(int etu)
        grant_btus(np, game_reset_tick(&np->nat_access));
        if (np->nat_stat < STAT_ACTIVE)
            continue;
+       level = nat_budget[n].level;
        /*
         * hap_edu: the more education people have, the
         * more happiness they want.
@@ -155,11 +155,11 @@ prod_nat(int etu)
         * see what the total per-civilian production is
         * for this time period.
         */
-       hap = levels[n][NAT_HLEV] * hap_edu * hap_cons /
+       hap = level[NAT_HLEV] * hap_edu * hap_cons /
            ((float)pop * etu);
-       edu = levels[n][NAT_ELEV] * edu_cons / ((float)pop * etu);
+       edu = level[NAT_ELEV] * edu_cons / ((float)pop * etu);
        wu(0, n, "%3.0f happiness, %3.0f education produced\n",
-          levels[n][NAT_HLEV], levels[n][NAT_ELEV]);
+          level[NAT_HLEV], level[NAT_ELEV]);
        hap = limit_level(hap, NAT_HLEV, 1);
        edu = limit_level(edu, NAT_ELEV, 1);
        /*
@@ -176,10 +176,10 @@ prod_nat(int etu)
        /*
         * limit tech/research production
         */
-       levels[n][NAT_TLEV] =
-           limit_level(levels[n][NAT_TLEV] / 1, NAT_TLEV, 0) * 1;
-       levels[n][NAT_RLEV] =
-           limit_level(levels[n][NAT_RLEV] / 1, NAT_RLEV, 0) * 1;
+       level[NAT_TLEV] =
+           limit_level(level[NAT_TLEV] / 1, NAT_TLEV, 0) * 1;
+       level[NAT_RLEV] =
+           limit_level(level[NAT_RLEV] / 1, NAT_RLEV, 0) * 1;
        wu(0, n, "total pop was %d, yielding %4.2f hap, %4.2f edu\n",
           pop - 1, hap, edu);
     }
@@ -192,8 +192,9 @@ prod_nat(int etu)
     for (n = 0; NULL != (np = getnatp(n)); n++) {
        if (np->nat_stat < STAT_ACTIVE)
            continue;
-       tlev = levels[n][NAT_TLEV];
-       rlev = levels[n][NAT_RLEV];
+       level = nat_budget[n].level;
+       tlev = level[NAT_TLEV];
+       rlev = level[NAT_RLEV];
        if (tech[n] != 0.0 || res[n] != 0.0) {
            wu(0, n, "%5.4f technology (%5.4f + %5.4f), "
               "%5.4f research (%5.4f + %5.4f) produced\n",
@@ -258,8 +259,8 @@ share_incr(double res[], double tech[])
                    continue;
            }
 
-           other_tlev = levels[j][NAT_TLEV];
-           other_rlev = levels[j][NAT_RLEV];
+           other_tlev = nat_budget[j].level[NAT_TLEV];
+           other_rlev = nat_budget[j].level[NAT_RLEV];
 
            if (!opt_ALL_BLEED) {
                if (relations_with(i, j) != ALLIED)
index e5683a89cded05444420efeadbb5fc098fab40dc..3ce126c3f1e9c593aa0b8168d9baa5a6ed954451 100644 (file)
@@ -53,8 +53,6 @@ prepare_sects(int etu)
     struct natstr *np;
     int n;
 
-    memset(levels, 0, sizeof(levels));
-
 /* Process all the fallout. */
     if (opt_FALLOUT) {
        if (!player->simulation) {
index 2ecf467a9866aa176b67fac0a560f6b71303b901..b02e94c7a93ec581180daf7f80895f4e849d4604 100644 (file)
@@ -73,6 +73,8 @@ produce(struct natstr *np, struct sctstr *sp)
        }
     }
 
+    if (product->p_level >= 0)
+       budget->level[product->p_level] += output;
     budget->prod[sp->sct_type].count += ldround(output, 1);
     budget->prod[sp->sct_type].money -= cost;
     budget->money -= cost;
@@ -134,7 +136,6 @@ prod_output(struct sctstr *sp, double prodeff)
     output = material_consume * prodeff;
     if (item == I_NONE) {
        if (!player->simulation) {
-           levels[sp->sct_own][product->p_level] += output;
            wu(0, sp->sct_own, "%s (%.2f) produced in %s\n",
               product->p_name, output, ownxy(sp));
        }