From f1df44dd2c28f23734b920375bd43ee69cf9ee6b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 13 Jan 2007 17:33:59 +0000 Subject: [PATCH] (bp): Rename member val to bp_item, member avail to bp_avail. Users changed. Switch from int to short, to match struct sctstr members sct_item and sct_avail. Symbolic indexes for struct bp member bp_item[]: (BP_NONE, BP_CIVIL, BP_MILIT, BP_SHELL, BP_GUN, BP_LCM, BP_HCM) (BP_MAX): New. (bug_key): Use them. Values are now array indexes, not indexes + 1. (bp_get_item, bp_put_item, bp_set_from_sect): Update for changed bud_key[]. --- src/lib/update/bp.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/lib/update/bp.c b/src/lib/update/bp.c index e0702e62..aede6f4d 100644 --- a/src/lib/update/bp.c +++ b/src/lib/update/bp.c @@ -37,13 +37,22 @@ #include "budg.h" #include "update.h" -struct bp { - int val[6]; - int avail; +enum { + BP_NONE = -1, + BP_CIVIL, BP_MILIT, BP_SHELL, BP_GUN, BP_LCM, BP_HCM, + BP_MAX = BP_HCM }; -static int bud_key[I_MAX + 1] = - { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0 }; +struct bp { + short bp_item[BP_MAX + 1]; + short bp_avail; +}; + +static int bud_key[I_MAX + 1] = { + BP_CIVIL, BP_MILIT, BP_SHELL, BP_GUN, + BP_NONE, BP_NONE, BP_NONE, BP_NONE, BP_NONE, BP_NONE, + BP_LCM, BP_HCM, BP_NONE, BP_NONE +}; static struct bp * bp_ref(struct bp *bp, struct sctstr *sp) @@ -54,46 +63,47 @@ bp_ref(struct bp *bp, struct sctstr *sp) int bp_get_item(struct bp *bp, struct sctstr *sp, i_type comm) { - int cm; + int idx = bud_key[comm]; - if ((cm = bud_key[comm]) == 0) + if (idx < 0) return sp->sct_item[comm]; - return bp_ref(bp, sp)->val[cm - 1]; + return bp_ref(bp, sp)->bp_item[idx]; } void bp_put_item(struct bp *bp, struct sctstr *sp, i_type comm, int amount) { - int cm; + int idx = bud_key[comm]; - if ((cm = bud_key[comm]) != 0) - bp_ref(bp, sp)->val[cm - 1] = amount; + if (idx >= 0) + bp_ref(bp, sp)->bp_item[idx] = amount; } int bp_get_avail(struct bp *bp, struct sctstr *sp) { - return bp_ref(bp, sp)->avail; + return bp_ref(bp, sp)->bp_avail; } void bp_put_avail(struct bp *bp, struct sctstr *sp, int amount) { - bp_ref(bp, sp)->avail = amount; + bp_ref(bp, sp)->bp_avail = amount; } void bp_set_from_sect(struct bp *bp, struct sctstr *sp) { - int k; + int idx; struct bp *p = bp_ref(bp, sp); i_type i; for (i = I_NONE + 1; i <= I_MAX; i++) { - if ((k = bud_key[i]) != 0) - p->val[k - 1] = sp->sct_item[i]; + idx = bud_key[i]; + if (idx >= 0) + p->bp_item[idx] = sp->sct_item[i]; } - p->avail = sp->sct_avail; + p->bp_avail = sp->sct_avail; } struct bp *