]> git.pond.sub.org Git - empserver/commitdiff
update: Push budget update into produce(), enlist()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Jun 2016 07:09:46 +0000 (09:09 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:00:00 +0000 (20:00 +0200)
produce() and enlist store the cost through a parameter and return the
amount.  Their caller produce_sect() then updates nat_budget[]
accordingly.  Move the nat_budget[] update into the callees.

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

index ed5c3a8e1b900e6185a778dc2ef10398863f4bbf..14263301834d3ab2ee0d52a15d855a8b8102d282 100644 (file)
@@ -130,7 +130,7 @@ extern void upd_slmilcosts(int, natid);
 extern void bank_income(struct sctstr *, int);
 extern void pay_reserve(struct natstr *, int);
 /* produce.c */
-extern int produce(struct natstr *, struct sctstr *, int *);
+extern void produce(struct natstr *, struct sctstr *);
 extern int prod_materials_cost(struct pchrstr *, short[], int *);
 extern int prod_resource_limit(struct pchrstr *, unsigned char *);
 extern double prod_eff(int, float);
index cc67ece18287dc297112700eeec76ce36807aeae..bc5b31f70e25b283a6b9e8dea12bb4fbe81bd2b9 100644 (file)
@@ -46,9 +46,10 @@ static char *levelnames[] = {
     "Technology", "Research", "Education", "Happiness"
 };
 
-int
-produce(struct natstr *np, struct sctstr *sp, int *cost)
+void
+produce(struct natstr *np, struct sctstr *sp)
 {
+    struct budget *budget = &nat_budget[sp->sct_own];
     struct pchrstr *product;
     double p_e;
     double prodeff;
@@ -61,21 +62,21 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
     int material_limit, res_limit;
     int material_consume;
     int val;
+    int cost;
 
     if (dchr[sp->sct_type].d_prd < 0)
-       return 0;
+       return;
     product = &pchr[dchr[sp->sct_type].d_prd];
     item = product->p_type;
     if (product->p_nrndx)
        resource = (unsigned char *)sp + product->p_nrndx;
     else
        resource = NULL;
-    *cost = 0;
 
     material_limit = prod_materials_cost(product, sp->sct_item,
                                         &unit_work);
     if (material_limit <= 0)
-       return 0;
+       return;
 
     /* sector p.e. */
     p_e = sp->sct_effic / 100.0;
@@ -95,7 +96,7 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
     if (material_consume > material_limit)
        material_consume = material_limit;
     if (material_consume == 0)
-       return 0;
+       return;
 
     prodeff = prod_eff(sp->sct_type, np->nat_level[product->p_nlndx]);
     if (prodeff <= 0.0) {
@@ -103,7 +104,7 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
            wu(0, sp->sct_own,
               "%s level too low to produce in %s (need %d)\n",
               levelnames[product->p_nlndx], ownxy(sp), product->p_nlmin);
-       return 0;
+       return;
     }
     /*
      * Adjust produced amount by commodity production ratio
@@ -119,7 +120,7 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
     } else {
        actual = roundavg(output);
        if (actual <= 0)
-           return 0;
+           return;
        if (actual > 999) {
            actual = 999;
            material_consume = roundavg(actual / prodeff);
@@ -151,22 +152,26 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
            val = 0;
        *resource = val;
     }
-    *cost = product->p_cost * material_consume;
 
+    cost = product->p_cost * material_consume;
     if (opt_TECH_POP) {
        if (product->p_level == NAT_TLEV) {
            if (tpops[sp->sct_own] > 50000)
-               *cost *= tpops[sp->sct_own] / 50000.0;
+               cost *= tpops[sp->sct_own] / 50000.0;
        }
     }
 
+    budget->prod[sp->sct_type].count += actual;
+    budget->prod[sp->sct_type].money -= cost;
+    if (!player->simulation)
+       np->nat_money -= cost;
+
     if (CANT_HAPPEN(p_e <= 0.0))
-       return actual;
+       return;
     work_used = roundavg(unit_work * material_consume / p_e);
     if (CANT_HAPPEN(work_used > sp->sct_avail))
        work_used = sp->sct_avail;
     sp->sct_avail -= work_used;
-    return actual;
 }
 
 /*
index e36eb8c2b87287a20e5c7bcce0d5fcb75552363d..d2afae967c2be5dd51d715096f47c5bb21374ad5 100644 (file)
@@ -96,8 +96,8 @@ buildeff(struct sctstr *sp)
  * Conversion will happen much more slowly without
  * some mil initially.
  */
-static int
-enlist(short *vec, int etu, int *cost)
+static void
+enlist(struct natstr *np, short *vec, int etu)
 {
     int maxmil;
     int enlisted;
@@ -111,8 +111,11 @@ enlist(short *vec, int etu, int *cost)
        vec[I_CIVIL] -= enlisted;
        vec[I_MILIT] += enlisted;
     }
-    *cost = enlisted * 3;
-    return enlisted;
+
+    nat_budget[np->nat_cnum].prod[SCT_ENLIST].count += enlisted;
+    nat_budget[np->nat_cnum].prod[SCT_ENLIST].money -= enlisted * 3;
+    if (!player->simulation)
+       np->nat_money -= enlisted * 3;
 }
 
 /* Fallout is calculated here. */
@@ -227,8 +230,8 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
 {
     struct budget *budget = &nat_budget[np->nat_cnum];
     struct sctstr *sp, scratch_sect;
-    int cost, ecost, pcost;
-    int n, amount;
+    int cost;
+    int n;
 
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
        if (sp->sct_type == SCT_WATER)
@@ -261,9 +264,6 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
            continue;
        }
 
-       amount = 0;
-       pcost = cost = ecost = 0;
-
        if (dchr[sp->sct_type].d_maint) {
            cost = etu * dchr[sp->sct_type].d_maint;
            budget->bm[BUDG_SCT_MAINT].count++;
@@ -283,11 +283,7 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
 
        if (sp->sct_type == SCT_ENLIST && sp->sct_effic >= 60 &&
            sp->sct_own == sp->sct_oldown) {
-           budget->prod[sp->sct_type].count
-               += enlist(sp->sct_item, etu, &ecost);
-           budget->prod[sp->sct_type].money -= ecost;
-           if (!player->simulation)
-               np->nat_money -= ecost;
+           enlist(np, sp->sct_item, etu);
        }
 
        /*
@@ -296,13 +292,9 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
 
        if (sp->sct_effic >= 60) {
            if (np->nat_money >= 0 && dchr[sp->sct_type].d_prd >= 0)
-               amount = produce(np, sp, &pcost);
+               produce(np, sp);
        }
 
        bp_set_from_sect(bp, sp);
-       budget->prod[sp->sct_type].count += amount;
-       budget->prod[sp->sct_type].money -= pcost;
-       if (!player->simulation)
-           np->nat_money -= pcost;
     }
 }