update: Drop upd_buildeff() parameter workp

Since changing *sp is safe now, we can move the update of
sp->sct_avail into upd_buildeff(), and drop the parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-04 08:07:03 +02:00
parent d30de533d7
commit 688c8b736b

View file

@ -44,16 +44,12 @@
#include "ship.h" #include "ship.h"
#include "update.h" #include "update.h"
/*
* Increase sector efficiency if old type == new type.
* decrease sector efficiency if old type != new type.
* Return amount of work used.
*/
static int static int
upd_buildeff(struct sctstr *sp, int *workp, int *desig, int *cost) upd_buildeff(struct sctstr *sp, int *desig, int *cost)
{ {
int work_cost = 0; int work_cost = 0;
int buildeff_work = *workp / 2; int avail = sp->sct_avail;
int buildeff_work = avail / 2;
int n, hcms, lcms, neweff; int n, hcms, lcms, neweff;
*cost = 0; *cost = 0;
@ -103,7 +99,7 @@ upd_buildeff(struct sctstr *sp, int *workp, int *desig, int *cost)
sp->sct_item[I_HCM] -= work_cost * dchr[*desig].d_hcms; sp->sct_item[I_HCM] -= work_cost * dchr[*desig].d_hcms;
} }
} }
*workp = (*workp + 1) / 2 + buildeff_work; sp->sct_avail = (avail + 1) / 2 + buildeff_work;
return neweff; return neweff;
} }
@ -291,6 +287,7 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
if (sp->sct_off || np->nat_money < 0) if (sp->sct_off || np->nat_money < 0)
continue; continue;
sp->sct_avail = work;
amount = 0; amount = 0;
pcost = cost = ecost = 0; pcost = cost = ecost = 0;
@ -306,7 +303,7 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) && if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
np->nat_money >= 0) { np->nat_money >= 0) {
sp->sct_effic = upd_buildeff(sp, &work, &desig, &cost); sp->sct_effic = upd_buildeff(sp, &desig, &cost);
bp_put_items(bp, sp); bp_put_items(bp, sp);
p_sect[SCT_EFFIC][0]++; p_sect[SCT_EFFIC][0]++;
p_sect[SCT_EFFIC][1] += cost; p_sect[SCT_EFFIC][1] += cost;
@ -331,13 +328,12 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
if (sp->sct_effic >= 60) { if (sp->sct_effic >= 60) {
if (np->nat_money >= 0 && dchr[desig].d_prd >= 0) if (np->nat_money >= 0 && dchr[desig].d_prd >= 0)
work -= produce(np, sp, work, desig, sp->sct_effic, sp->sct_avail -= produce(np, sp, sp->sct_avail, desig,
&pcost, &amount); sp->sct_effic, &pcost, &amount);
bp_put_items(bp, sp); bp_put_items(bp, sp);
} }
sp->sct_avail = work; bp_put_avail(bp, sp, sp->sct_avail);
bp_put_avail(bp, sp, work);
p_sect[desig][0] += amount; p_sect[desig][0] += amount;
p_sect[desig][1] += pcost; p_sect[desig][1] += pcost;
if (!player->simulation) if (!player->simulation)