From 0efa8fa7a1c6276a64aacff4d38f34b60223a2af Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 4 Jun 2016 08:12:12 +0200 Subject: [PATCH] update: Drop produce() return value and parameters work, amount 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 --- include/prototypes.h | 3 +-- src/lib/update/produce.c | 17 ++++++++--------- src/lib/update/sect.c | 3 +-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index fbb05e5d..10f39695 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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); diff --git a/src/lib/update/produce.c b/src/lib/update/produce.c index b931a4fc..343a0aaf 100644 --- a/src/lib/update/produce.c +++ b/src/lib/update/produce.c @@ -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; } /* diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index 4585a276..9bfabfe5 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -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); }