(get_wp, bp_ref): Replace function returning pointer into a struct bp

by function returning to struct bp.  Leave member access to callers.
Callers changed.
This commit is contained in:
Markus Armbruster 2007-01-13 12:01:12 +00:00
parent 7db3523f62
commit ec203e88ad

View file

@ -44,52 +44,43 @@ struct bp {
static int bud_key[I_MAX + 2] = static int bud_key[I_MAX + 2] =
{ 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 7 }; { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 7 };
static int * static struct bp *
get_wp(struct bp *bp, struct sctstr *sp, int cm) bp_ref(struct bp *bp, struct sctstr *sp)
{ {
return &bp[sp->sct_x + sp->sct_y * WORLD_X].val[cm - 1]; return &bp[sp->sct_x + sp->sct_y * WORLD_X];
} }
int int
gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm) gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm)
{ {
int *wp;
int cm; int cm;
if ((cm = bud_key[comm]) == 0) { if ((cm = bud_key[comm]) == 0)
return sp->sct_item[comm]; return sp->sct_item[comm];
} else { return bp_ref(bp, sp)->val[cm - 1];
wp = get_wp(bp, sp, cm);
return *wp;
}
} }
void void
pt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm, int amount) pt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm, int amount)
{ {
int *wp;
int cm; int cm;
if ((cm = bud_key[comm]) != 0) { if ((cm = bud_key[comm]) != 0)
wp = get_wp(bp, sp, cm); bp_ref(bp, sp)->val[cm - 1] = amount;
*wp = amount;
}
} }
void void
fill_update_array(struct bp *bp, struct sctstr *sp) fill_update_array(struct bp *bp, struct sctstr *sp)
{ {
int k; int k;
int *wp; 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) { if ((k = bud_key[i]) != 0)
wp = get_wp(bp, sp, k); p->val[k - 1] = sp->sct_item[i];
*wp = sp->sct_item[i]; }
} p->val[bud_key[I_MAX + 1] - 1] = sp->sct_avail;
wp = get_wp(bp, sp, bud_key[I_MAX + 1]);
*wp = sp->sct_avail;
} }
struct bp * struct bp *