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 <armbru@pond.sub.org>
This commit is contained in:
parent
4daf98a160
commit
d30de533d7
3 changed files with 8 additions and 11 deletions
|
@ -664,7 +664,7 @@ extern int dodistribute(struct sctstr *, int, double);
|
||||||
extern void finish_sects(int);
|
extern void finish_sects(int);
|
||||||
/* human.c */
|
/* human.c */
|
||||||
extern int new_work(struct sctstr *, int);
|
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 int feed_people(short *, int);
|
||||||
extern double food_needed(short *, int);
|
extern double food_needed(short *, int);
|
||||||
extern int famine_victims(short *, int);
|
extern int famine_victims(short *, int);
|
||||||
|
|
|
@ -52,7 +52,7 @@ static int babies(int, int, double, int, int);
|
||||||
* feed the individual sector
|
* feed the individual sector
|
||||||
*/
|
*/
|
||||||
int
|
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 work_avail;
|
||||||
int starved, sctwork;
|
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;
|
sp->sct_item[I_FOOD] = 0;
|
||||||
} else
|
} else
|
||||||
sctwork = 100;
|
sctwork = 100;
|
||||||
|
|
||||||
/* Here is where we truncate extra people, always */
|
/* Here is where we truncate extra people, always */
|
||||||
trunc_people(sp, np);
|
trunc_people(sp, np);
|
||||||
|
|
||||||
*workp = work_avail;
|
|
||||||
if (!player->simulation)
|
|
||||||
sp->sct_work = sctwork;
|
sp->sct_work = sctwork;
|
||||||
return sctwork;
|
return work_avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -284,9 +284,8 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
|
||||||
}
|
}
|
||||||
|
|
||||||
sp->sct_updated = 1;
|
sp->sct_updated = 1;
|
||||||
work = 0;
|
|
||||||
|
|
||||||
do_feed(sp, np, &work, etu);
|
work = do_feed(sp, np, etu);
|
||||||
bp_put_items(bp, sp);
|
bp_put_items(bp, sp);
|
||||||
|
|
||||||
if (sp->sct_off || np->nat_money < 0)
|
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);
|
bp_put_items(bp, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sp->sct_avail = work;
|
||||||
bp_put_avail(bp, sp, work);
|
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)
|
||||||
sp->sct_avail = work;
|
|
||||||
np->nat_money -= pcost;
|
np->nat_money -= pcost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue