From c9c06d4fbefd793228965b4ba0754dadbfb5c021 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 13 Jan 2007 17:11:17 +0000 Subject: [PATCH] (alloc_bp, bp_alloc): Rename. (fill_update_array, bp_set_from_sect): Rename. (gt_bg_nmbr, pt_bg_nmbr, bp_get_item, bp_get_avail, bp_put_item, bp_put_avail): Separate accessor functions for item and avail. --- include/budg.h | 11 +++++++---- src/lib/commands/budg.c | 4 ++-- src/lib/update/bp.c | 29 +++++++++++++++++++++-------- src/lib/update/human.c | 8 ++++---- src/lib/update/land.c | 4 ++-- src/lib/update/main.c | 2 +- src/lib/update/material.c | 6 +++--- src/lib/update/plane.c | 6 +++--- src/lib/update/prepare.c | 2 +- src/lib/update/sect.c | 6 +++--- src/lib/update/ship.c | 6 +++--- 11 files changed, 50 insertions(+), 34 deletions(-) diff --git a/include/budg.h b/include/budg.h index f33c3167..8e8f8a2c 100644 --- a/include/budg.h +++ b/include/budg.h @@ -39,10 +39,13 @@ #define SCT_EFFIC (SCT_TYPE_MAX + 1) -struct bp *alloc_bp(void); -void fill_update_array(struct bp *, struct sctstr *); -int gt_bg_nmbr(struct bp *, struct sctstr *, i_type); -void pt_bg_nmbr(struct bp *, struct sctstr *, i_type, int); +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); +int bp_get_avail(struct bp *, struct sctstr *); +void bp_put_avail(struct bp *, struct sctstr *, int); + int get_materials(struct sctstr *, struct bp *, int *, int); extern long money[MAXNOC]; diff --git a/src/lib/commands/budg.c b/src/lib/commands/budg.c index 6befd205..c14ae533 100644 --- a/src/lib/commands/budg.c +++ b/src/lib/commands/budg.c @@ -197,9 +197,9 @@ calc_all(long p_sect[][2], *planes = *pbuild = *npbuild = *pmaint = 0; np = getnatp(player->cnum); - bp = alloc_bp(); + bp = bp_alloc(); for (n = 0; NULL != (sp = getsectid(n)); n++) { - fill_update_array(bp, sp); + bp_set_from_sect(bp, sp); if (sp->sct_own == player->cnum) { sp->sct_updated = 0; tax(sp, np, etu, &pop, &civ_tax, &uw_tax, &mil_pay); diff --git a/src/lib/update/bp.c b/src/lib/update/bp.c index d6bd3f0b..e0702e62 100644 --- a/src/lib/update/bp.c +++ b/src/lib/update/bp.c @@ -38,11 +38,12 @@ #include "update.h" struct bp { - int val[7]; + int val[6]; + int avail; }; -static int bud_key[I_MAX + 2] = - { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 7 }; +static int bud_key[I_MAX + 1] = + { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0 }; static struct bp * bp_ref(struct bp *bp, struct sctstr *sp) @@ -51,7 +52,7 @@ bp_ref(struct bp *bp, struct sctstr *sp) } int -gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm) +bp_get_item(struct bp *bp, struct sctstr *sp, i_type comm) { int cm; @@ -61,7 +62,7 @@ gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm) } void -pt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm, int amount) +bp_put_item(struct bp *bp, struct sctstr *sp, i_type comm, int amount) { int cm; @@ -69,8 +70,20 @@ pt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm, int amount) bp_ref(bp, sp)->val[cm - 1] = amount; } +int +bp_get_avail(struct bp *bp, struct sctstr *sp) +{ + return bp_ref(bp, sp)->avail; +} + void -fill_update_array(struct bp *bp, struct sctstr *sp) +bp_put_avail(struct bp *bp, struct sctstr *sp, int amount) +{ + bp_ref(bp, sp)->avail = amount; +} + +void +bp_set_from_sect(struct bp *bp, struct sctstr *sp) { int k; struct bp *p = bp_ref(bp, sp); @@ -80,11 +93,11 @@ fill_update_array(struct bp *bp, struct sctstr *sp) if ((k = bud_key[i]) != 0) p->val[k - 1] = sp->sct_item[i]; } - p->val[bud_key[I_MAX + 1] - 1] = sp->sct_avail; + p->avail = sp->sct_avail; } struct bp * -alloc_bp(void) +bp_alloc(void) { return calloc(WORLD_X * WORLD_Y, sizeof(struct bp)); } diff --git a/src/lib/update/human.c b/src/lib/update/human.c index 43c0b1a3..cf5a788a 100644 --- a/src/lib/update/human.c +++ b/src/lib/update/human.c @@ -78,7 +78,7 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec, /* need to grow "emergency rations" */ work_avail -= 2 * growfood(sp, vec, work_avail / 2, etu); /* It's twice as hard to grow those than norm */ - pt_bg_nmbr(bp, sp, I_MAX + 1, work_avail); + bp_put_avail(bp, sp, work_avail); if (!player->simulation) sp->sct_avail = work_avail; } @@ -118,9 +118,9 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec, /* Here is where we truncate extra people, always */ trunc_people(sp, np, vec); - pt_bg_nmbr(bp, sp, I_CIVIL, vec[I_CIVIL]); - pt_bg_nmbr(bp, sp, I_UW, vec[I_UW]); - pt_bg_nmbr(bp, sp, I_MILIT, vec[I_MILIT]); + bp_put_item(bp, sp, I_CIVIL, vec[I_CIVIL]); + bp_put_item(bp, sp, I_UW, vec[I_UW]); + bp_put_item(bp, sp, I_MILIT, vec[I_MILIT]); *workp = work_avail; return sctwork; } diff --git a/src/lib/update/land.c b/src/lib/update/land.c index a6d3566c..eb9fbc60 100644 --- a/src/lib/update/land.c +++ b/src/lib/update/land.c @@ -244,7 +244,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus) if (!player->simulation) avail = sp->sct_avail * 100; else - avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; + avail = bp_get_avail(bp, sp) * 100; w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm); delta = roundavg((double)avail / w_p_eff); @@ -269,7 +269,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus) if (!player->simulation) sp->sct_avail = avail / 100; else - pt_bg_nmbr(bp, sp, I_MAX + 1, avail / 100); + bp_put_avail(bp, sp, avail / 100); if (build < 0) logerror("land unit %d building %d ! \n", land->lnd_uid, build); diff --git a/src/lib/update/main.c b/src/lib/update/main.c index 65ebb573..3564460e 100644 --- a/src/lib/update/main.c +++ b/src/lib/update/main.c @@ -92,7 +92,7 @@ update_main(void *unused) memset(air_money, 0, sizeof(air_money)); memset(sea_money, 0, sizeof(sea_money)); memset(lnd_money, 0, sizeof(lnd_money)); - bp = alloc_bp(); + bp = bp_alloc(); for (n = 0; n < MAXNOC; n++) { money[n] = 0; if (!(np = getnatp(n))) diff --git a/src/lib/update/material.c b/src/lib/update/material.c index 8ccd09b3..e5bb927c 100644 --- a/src/lib/update/material.c +++ b/src/lib/update/material.c @@ -55,7 +55,7 @@ get_materials(struct sctstr *sp, struct bp *bp, int *mvec, int pct) for (i = I_NONE + 1; i <= I_MAX; i++) { if (mvec[i] == 0) continue; - amt = gt_bg_nmbr(bp, sp, i); + amt = bp_get_item(bp, sp, i); if (amt * 100 < mvec[i] * pct) pct = amt * 100 / mvec[i]; } @@ -63,11 +63,11 @@ get_materials(struct sctstr *sp, struct bp *bp, int *mvec, int pct) for (i = I_NONE + 1; i <= I_MAX; i++) { if (mvec[i] == 0) continue; - amt = gt_bg_nmbr(bp, sp, i); + amt = bp_get_item(bp, sp, i); amt -= roundavg(mvec[i] * pct / 100.0); if (CANT_HAPPEN(amt < 0)) amt = 0; - pt_bg_nmbr(bp, sp, i, amt); + bp_put_item(bp, sp, i, amt); if (!player->simulation) sp->sct_item[i] = amt; } diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index 82e2d91b..de7324c9 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -168,7 +168,7 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus) if (!player->simulation) avail = sp->sct_avail * 100; else - avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; + avail = bp_get_avail(bp, sp) * 100; if (carrier) avail += etus * carrier->shp_item[I_MILIT] / 2; @@ -198,14 +198,14 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus) if (!player->simulation) avail = (sp->sct_avail * 100 - used) / 100; else - avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 - used) / 100; + avail = (bp_get_avail(bp, sp) * 100 - used) / 100; if (avail < 0) avail = 0; if (!player->simulation) sp->sct_avail = avail; else - pt_bg_nmbr(bp, sp, I_MAX + 1, avail); + bp_put_avail(bp, sp, avail); if (sp->sct_type != SCT_AIRPT) build /= 3; diff --git a/src/lib/update/prepare.c b/src/lib/update/prepare.c index cd0afb11..6ae06959 100644 --- a/src/lib/update/prepare.c +++ b/src/lib/update/prepare.c @@ -77,7 +77,7 @@ prepare_sects(int etu, struct bp *bp) if (sp->sct_type == SCT_WATER) continue; - fill_update_array(bp, sp); + bp_set_from_sect(bp, sp); np = getnatp(sp->sct_own); #ifdef DEBUG diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index ccc36371..91996a80 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -329,8 +329,8 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2]) np->nat_money > 0) { neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork, &cost); - pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]); - pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]); + bp_put_item(bp, sp, I_LCM, vec[I_LCM]); + bp_put_item(bp, sp, I_HCM, vec[I_HCM]); p_sect[SCT_EFFIC][0]++; p_sect[SCT_EFFIC][1] += cost; if (!player->simulation) { @@ -358,7 +358,7 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2]) &pcost, &amount); } - pt_bg_nmbr(bp, sp, I_MAX + 1, work); + bp_put_avail(bp, sp, work); p_sect[desig][0] += amount; p_sect[desig][1] += pcost; if (!player->simulation) { diff --git a/src/lib/update/ship.c b/src/lib/update/ship.c index 54c18ec3..92a938f9 100644 --- a/src/lib/update/ship.c +++ b/src/lib/update/ship.c @@ -303,7 +303,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus) if (!player->simulation) avail = wf + sp->sct_avail * 100; else - avail = wf + gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; + avail = wf + bp_get_avail(bp, sp) * 100; } w_p_eff = SHP_BLD_WORK(mp->m_lcm, mp->m_hcm); @@ -345,13 +345,13 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus) if (!player->simulation) avail = (sp->sct_avail * 100 + wf) / 100; else - avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 + wf) / 100; + avail = (bp_get_avail(bp, sp) * 100 + wf) / 100; if (avail < 0) avail = 0; if (!player->simulation) sp->sct_avail = avail; else - pt_bg_nmbr(bp, sp, I_MAX + 1, avail); + bp_put_avail(bp, sp, avail); } if (sp->sct_type != SCT_HARBR) if ((build + ship->shp_effic) > 80) {