]> git.pond.sub.org Git - empserver/commitdiff
update: Drop produce() return value and parameters work, amount
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 4 Jun 2016 06:12:12 +0000 (08:12 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 17:59:57 +0000 (19:59 +0200)
Since changing *sp is safe now, we can move the update of
sp->sct_avail into produce().  This frees the return value; use it to
return the amount produced.  Drop the parameters.

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

index fbb05e5d76ce0a37bd4bf08a2bbc6b1e077ad86d..10f396950c445f1af02b4615cec1da7a33b55965 100644 (file)
@@ -704,8 +704,7 @@ extern int upd_slmilcosts(natid, int);
 extern void prepare_sects(int, struct bp *);
 extern int bank_income(struct sctstr *, int);
 /* produce.c */
-extern int produce(struct natstr *, struct sctstr *, int, int,
-                  int, int *, int *);
+extern int produce(struct natstr *, struct sctstr *, int, int, int *);
 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 b931a4fc87c9c1cc03f67d7e1d188ccdc9deda69..343a0aaf8cdc8255153ea9dacb05f464296cd1d5 100644 (file)
@@ -45,8 +45,8 @@ static char *levelnames[] = {
 };
 
 int
-produce(struct natstr *np, struct sctstr *sp, int work,
-       int desig, int neweff, int *cost, int *amount)
+produce(struct natstr *np, struct sctstr *sp,
+       int desig, int neweff, int *cost)
 {
     struct pchrstr *product;
     double p_e;
@@ -69,7 +69,6 @@ produce(struct natstr *np, struct sctstr *sp, int work,
        resource = (unsigned char *)sp + product->p_nrndx;
     else
        resource = NULL;
-    *amount = 0;
     *cost = 0;
 
     material_limit = prod_materials_cost(product, sp->sct_item,
@@ -86,7 +85,7 @@ produce(struct natstr *np, struct sctstr *sp, int work,
     if (unit_work == 0)
        unit_work = 1;
 
-    worker_limit = work * p_e / unit_work;
+    worker_limit = sp->sct_avail * p_e / unit_work;
     res_limit = prod_resource_limit(product, resource);
 
     material_consume = res_limit;
@@ -150,7 +149,6 @@ produce(struct natstr *np, struct sctstr *sp, int work,
            val = 0;
        *resource = val;
     }
-    *amount = actual;
     *cost = product->p_cost * material_consume;
 
     if (opt_TECH_POP) {
@@ -161,11 +159,12 @@ produce(struct natstr *np, struct sctstr *sp, int work,
     }
 
     if (CANT_HAPPEN(p_e <= 0.0))
-       return 0;
+       return actual;
     work_used = roundavg(unit_work * material_consume / p_e);
-    if (CANT_HAPPEN(work_used > work))
-       return work;
-    return work_used;
+    if (CANT_HAPPEN(work_used > sp->sct_avail))
+       work_used = sp->sct_avail;
+    sp->sct_avail -= work_used;
+    return actual;
 }
 
 /*
index 4585a276042ea9e964b420401961056e93c4bd58..9bfabfe59334bf81f277f48b68e820bc46d3a5f7 100644 (file)
@@ -328,8 +328,7 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
 
        if (sp->sct_effic >= 60) {
            if (np->nat_money >= 0 && dchr[desig].d_prd >= 0)
-               sp->sct_avail -= produce(np, sp, sp->sct_avail, desig,
-                                        sp->sct_effic, &pcost, &amount);
+               amount = produce(np, sp, desig, sp->sct_effic, &pcost);
            bp_put_items(bp, sp);
        }