diff --git a/include/budg.h b/include/budg.h index 0a5b452e..a8aef7c3 100644 --- a/include/budg.h +++ b/include/budg.h @@ -43,11 +43,6 @@ struct bp *bp_alloc(void); void bp_set_from_sect(struct bp *, struct sctstr *); -int bp_get_item(struct bp *, struct sctstr *, i_type); -void bp_put_item(struct bp *, struct sctstr *, i_type, int); -void bp_put_items(struct bp *, struct sctstr *); -int bp_get_avail(struct bp *, struct sctstr *); -void bp_put_avail(struct bp *, struct sctstr *, int); void bp_to_sect(struct bp *, struct sctstr *); extern int money[MAXNOC]; diff --git a/src/lib/update/bp.c b/src/lib/update/bp.c index 020cf1c2..941e68d9 100644 --- a/src/lib/update/bp.c +++ b/src/lib/update/bp.c @@ -66,70 +66,21 @@ static enum bp_item_idx bud_key[I_MAX + 1] = { BP_LCM, BP_HCM, BP_NONE, BP_NONE }; -/* - * Return the item value tracked in @bp for sector @sp's item @comm. - * @comm must be a tracked item type. - */ -int -bp_get_item(struct bp *bp, struct sctstr *sp, i_type comm) -{ - enum bp_item_idx idx = bud_key[comm]; - - if (CANT_HAPPEN(idx < 0) || !bp) - return sp->sct_item[comm]; - return bp[sp->sct_uid].bp_item[idx]; -} - -/* - * Set item value tracked in @bp for sector @sp's item @comm to @amount. - */ +/* Set the values tracked in @bp for sector @sp to the values in @sp. */ void -bp_put_item(struct bp *bp, struct sctstr *sp, i_type comm, int amount) +bp_set_from_sect(struct bp *bp, struct sctstr *sp) { - enum bp_item_idx idx = bud_key[comm]; - - if (bp && idx >= 0) - bp[sp->sct_uid].bp_item[idx] = amount; -} - -/* Set the item values tracked in @bp from sector @sp. */ -void -bp_put_items(struct bp *bp, struct sctstr *sp) -{ - enum bp_item_idx idx; i_type i; + enum bp_item_idx idx; if (!bp) return; - for (i = I_NONE + 1; i <= I_MAX; i++) { idx = bud_key[i]; if (idx >= 0) bp[sp->sct_uid].bp_item[idx] = sp->sct_item[i]; } -} - -/* Return avail tracked in @bp for sector @sp. */ -int -bp_get_avail(struct bp *bp, struct sctstr *sp) -{ - return bp ? bp[sp->sct_uid].bp_avail : sp->sct_avail; -} - -/* Set avail tracked in @bp for sector @sp to @amount. */ -void -bp_put_avail(struct bp *bp, struct sctstr *sp, int amount) -{ - if (bp) - bp[sp->sct_uid].bp_avail = amount; -} - -/* Set the values tracked in @bp for sector @sp to the values in @sp. */ -void -bp_set_from_sect(struct bp *bp, struct sctstr *sp) -{ - bp_put_items(bp, sp); - bp_put_avail(bp, sp, sp->sct_avail); + bp[sp->sct_uid].bp_avail = sp->sct_avail; } /* Copy the values tracked in @bp for sector @sp back to @sp. */ diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index fb97142f..206c0788 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -270,10 +270,11 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2]) } work = do_feed(sp, np, etu, 0); - bp_put_items(bp, sp); - if (sp->sct_off || np->nat_money < 0) + if (sp->sct_off || np->nat_money < 0) { + bp_set_from_sect(bp, sp); continue; + } sp->sct_avail = work; amount = 0; @@ -290,7 +291,6 @@ 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) && np->nat_money >= 0) { cost = buildeff(sp); - bp_put_items(bp, sp); p_sect[SCT_EFFIC][0]++; p_sect[SCT_EFFIC][1] += cost; if (!player->simulation) @@ -303,7 +303,6 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2]) p_sect[sp->sct_type][1] += ecost; if (!player->simulation) np->nat_money -= ecost; - bp_put_items(bp, sp); } /* @@ -313,10 +312,9 @@ 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[sp->sct_type].d_prd >= 0) amount = produce(np, sp, &pcost); - bp_put_items(bp, sp); } - bp_put_avail(bp, sp, sp->sct_avail); + bp_set_from_sect(bp, sp); p_sect[sp->sct_type][0] += amount; p_sect[sp->sct_type][1] += pcost; if (!player->simulation)