(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[].
This commit is contained in:
parent
c9c06d4fbe
commit
f1df44dd2c
1 changed files with 27 additions and 17 deletions
|
@ -37,13 +37,22 @@
|
||||||
#include "budg.h"
|
#include "budg.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
|
||||||
struct bp {
|
enum {
|
||||||
int val[6];
|
BP_NONE = -1,
|
||||||
int avail;
|
BP_CIVIL, BP_MILIT, BP_SHELL, BP_GUN, BP_LCM, BP_HCM,
|
||||||
|
BP_MAX = BP_HCM
|
||||||
};
|
};
|
||||||
|
|
||||||
static int bud_key[I_MAX + 1] =
|
struct bp {
|
||||||
{ 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0 };
|
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 *
|
static struct bp *
|
||||||
bp_ref(struct bp *bp, struct sctstr *sp)
|
bp_ref(struct bp *bp, struct sctstr *sp)
|
||||||
|
@ -54,46 +63,47 @@ bp_ref(struct bp *bp, struct sctstr *sp)
|
||||||
int
|
int
|
||||||
bp_get_item(struct bp *bp, struct sctstr *sp, i_type comm)
|
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 sp->sct_item[comm];
|
||||||
return bp_ref(bp, sp)->val[cm - 1];
|
return bp_ref(bp, sp)->bp_item[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bp_put_item(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;
|
int idx = bud_key[comm];
|
||||||
|
|
||||||
if ((cm = bud_key[comm]) != 0)
|
if (idx >= 0)
|
||||||
bp_ref(bp, sp)->val[cm - 1] = amount;
|
bp_ref(bp, sp)->bp_item[idx] = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
bp_get_avail(struct bp *bp, struct sctstr *sp)
|
bp_get_avail(struct bp *bp, struct sctstr *sp)
|
||||||
{
|
{
|
||||||
return bp_ref(bp, sp)->avail;
|
return bp_ref(bp, sp)->bp_avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bp_put_avail(struct bp *bp, struct sctstr *sp, int amount)
|
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
|
void
|
||||||
bp_set_from_sect(struct bp *bp, struct sctstr *sp)
|
bp_set_from_sect(struct bp *bp, struct sctstr *sp)
|
||||||
{
|
{
|
||||||
int k;
|
int idx;
|
||||||
struct bp *p = bp_ref(bp, sp);
|
struct bp *p = bp_ref(bp, sp);
|
||||||
i_type i;
|
i_type i;
|
||||||
|
|
||||||
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
||||||
if ((k = bud_key[i]) != 0)
|
idx = bud_key[i];
|
||||||
p->val[k - 1] = sp->sct_item[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 *
|
struct bp *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue