From d30de533d795628b179e3b8d5e6550f46adabf69 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 4 Jun 2016 07:30:40 +0200 Subject: [PATCH] update: Move work percentage update into do_feed() Since changing *sp is safe now, we can move the update of sp->sct_work into do_feed(), use the return value for work, and drop parameter workp. The sp->sct_avail update looks similar, but there's a subtle difference: it's skipped when the sector is stopped or its owner is broke. The caller already checks that, so leave the update there. Signed-off-by: Markus Armbruster --- include/prototypes.h | 2 +- src/lib/update/human.c | 9 ++++----- src/lib/update/sect.c | 8 +++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index 3f6fa4959..fbb05e5d7 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -664,7 +664,7 @@ extern int dodistribute(struct sctstr *, int, double); extern void finish_sects(int); /* human.c */ extern int new_work(struct sctstr *, int); -extern int do_feed(struct sctstr *, struct natstr *, int *, int); +extern int do_feed(struct sctstr *, struct natstr *, int); extern int feed_people(short *, int); extern double food_needed(short *, int); extern int famine_victims(short *, int); diff --git a/src/lib/update/human.c b/src/lib/update/human.c index f86541010..e05aa6b8d 100644 --- a/src/lib/update/human.c +++ b/src/lib/update/human.c @@ -52,7 +52,7 @@ static int babies(int, int, double, int, int); * feed the individual sector */ int -do_feed(struct sctstr *sp, struct natstr *np, int *workp, int etu) +do_feed(struct sctstr *sp, struct natstr *np, int etu) { int work_avail; int starved, sctwork; @@ -116,13 +116,12 @@ do_feed(struct sctstr *sp, struct natstr *np, int *workp, int etu) sp->sct_item[I_FOOD] = 0; } else sctwork = 100; + /* Here is where we truncate extra people, always */ trunc_people(sp, np); - *workp = work_avail; - if (!player->simulation) - sp->sct_work = sctwork; - return sctwork; + sp->sct_work = sctwork; + return work_avail; } int diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index 2802a4e9b..f7f2da46f 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -284,9 +284,8 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2]) } sp->sct_updated = 1; - work = 0; - do_feed(sp, np, &work, etu); + work = do_feed(sp, np, etu); bp_put_items(bp, sp); if (sp->sct_off || np->nat_money < 0) @@ -337,12 +336,11 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2]) bp_put_items(bp, sp); } + sp->sct_avail = work; bp_put_avail(bp, sp, work); p_sect[desig][0] += amount; p_sect[desig][1] += pcost; - if (!player->simulation) { - sp->sct_avail = work; + if (!player->simulation) np->nat_money -= pcost; - } } } -- 2.43.0