]> git.pond.sub.org Git - empserver/commitdiff
update: Move work percentage update into do_feed()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 4 Jun 2016 05:30:40 +0000 (07:30 +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_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 <armbru@pond.sub.org>
include/prototypes.h
src/lib/update/human.c
src/lib/update/sect.c

index 3f6fa49594ac37212092bb164de9fd08a89d2e1c..fbb05e5d76ce0a37bd4bf08a2bbc6b1e077ad86d 100644 (file)
@@ -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);
index f86541010ecc0e8f4c7f60e40e7ba7a96fc2bbc5..e05aa6b8d304beb71d6df08c9dbda820e91f270d 100644 (file)
@@ -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
index 2802a4e9baa53cd26085fb9beef9217e5acf0af2..f7f2da46f1f8117d16e4bf1b7f1cbb6f196e60f8 100644 (file)
@@ -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;
-       }
     }
 }