(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.
This commit is contained in:
parent
ec203e88ad
commit
c9c06d4fbe
11 changed files with 50 additions and 34 deletions
|
@ -39,10 +39,13 @@
|
||||||
|
|
||||||
#define SCT_EFFIC (SCT_TYPE_MAX + 1)
|
#define SCT_EFFIC (SCT_TYPE_MAX + 1)
|
||||||
|
|
||||||
struct bp *alloc_bp(void);
|
struct bp *bp_alloc(void);
|
||||||
void fill_update_array(struct bp *, struct sctstr *);
|
void bp_set_from_sect(struct bp *, struct sctstr *);
|
||||||
int gt_bg_nmbr(struct bp *, struct sctstr *, i_type);
|
int bp_get_item(struct bp *, struct sctstr *, i_type);
|
||||||
void pt_bg_nmbr(struct bp *, struct sctstr *, i_type, int);
|
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);
|
int get_materials(struct sctstr *, struct bp *, int *, int);
|
||||||
|
|
||||||
extern long money[MAXNOC];
|
extern long money[MAXNOC];
|
||||||
|
|
|
@ -197,9 +197,9 @@ calc_all(long p_sect[][2],
|
||||||
*planes = *pbuild = *npbuild = *pmaint = 0;
|
*planes = *pbuild = *npbuild = *pmaint = 0;
|
||||||
|
|
||||||
np = getnatp(player->cnum);
|
np = getnatp(player->cnum);
|
||||||
bp = alloc_bp();
|
bp = bp_alloc();
|
||||||
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
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) {
|
if (sp->sct_own == player->cnum) {
|
||||||
sp->sct_updated = 0;
|
sp->sct_updated = 0;
|
||||||
tax(sp, np, etu, &pop, &civ_tax, &uw_tax, &mil_pay);
|
tax(sp, np, etu, &pop, &civ_tax, &uw_tax, &mil_pay);
|
||||||
|
|
|
@ -38,11 +38,12 @@
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
|
||||||
struct bp {
|
struct bp {
|
||||||
int val[7];
|
int val[6];
|
||||||
|
int avail;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int bud_key[I_MAX + 2] =
|
static int bud_key[I_MAX + 1] =
|
||||||
{ 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 };
|
||||||
|
|
||||||
static struct bp *
|
static struct bp *
|
||||||
bp_ref(struct bp *bp, struct sctstr *sp)
|
bp_ref(struct bp *bp, struct sctstr *sp)
|
||||||
|
@ -51,7 +52,7 @@ bp_ref(struct bp *bp, struct sctstr *sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
int cm;
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
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;
|
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
|
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;
|
int k;
|
||||||
struct bp *p = bp_ref(bp, sp);
|
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)
|
if ((k = bud_key[i]) != 0)
|
||||||
p->val[k - 1] = sp->sct_item[i];
|
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 *
|
struct bp *
|
||||||
alloc_bp(void)
|
bp_alloc(void)
|
||||||
{
|
{
|
||||||
return calloc(WORLD_X * WORLD_Y, sizeof(struct bp));
|
return calloc(WORLD_X * WORLD_Y, sizeof(struct bp));
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
|
||||||
/* need to grow "emergency rations" */
|
/* need to grow "emergency rations" */
|
||||||
work_avail -= 2 * growfood(sp, vec, work_avail / 2, etu);
|
work_avail -= 2 * growfood(sp, vec, work_avail / 2, etu);
|
||||||
/* It's twice as hard to grow those than norm */
|
/* 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)
|
if (!player->simulation)
|
||||||
sp->sct_avail = work_avail;
|
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 */
|
/* Here is where we truncate extra people, always */
|
||||||
trunc_people(sp, np, vec);
|
trunc_people(sp, np, vec);
|
||||||
|
|
||||||
pt_bg_nmbr(bp, sp, I_CIVIL, vec[I_CIVIL]);
|
bp_put_item(bp, sp, I_CIVIL, vec[I_CIVIL]);
|
||||||
pt_bg_nmbr(bp, sp, I_UW, vec[I_UW]);
|
bp_put_item(bp, sp, I_UW, vec[I_UW]);
|
||||||
pt_bg_nmbr(bp, sp, I_MILIT, vec[I_MILIT]);
|
bp_put_item(bp, sp, I_MILIT, vec[I_MILIT]);
|
||||||
*workp = work_avail;
|
*workp = work_avail;
|
||||||
return sctwork;
|
return sctwork;
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
avail = sp->sct_avail * 100;
|
avail = sp->sct_avail * 100;
|
||||||
else
|
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);
|
w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm);
|
||||||
delta = roundavg((double)avail / w_p_eff);
|
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)
|
if (!player->simulation)
|
||||||
sp->sct_avail = avail / 100;
|
sp->sct_avail = avail / 100;
|
||||||
else
|
else
|
||||||
pt_bg_nmbr(bp, sp, I_MAX + 1, avail / 100);
|
bp_put_avail(bp, sp, avail / 100);
|
||||||
|
|
||||||
if (build < 0)
|
if (build < 0)
|
||||||
logerror("land unit %d building %d ! \n", land->lnd_uid, build);
|
logerror("land unit %d building %d ! \n", land->lnd_uid, build);
|
||||||
|
|
|
@ -92,7 +92,7 @@ update_main(void *unused)
|
||||||
memset(air_money, 0, sizeof(air_money));
|
memset(air_money, 0, sizeof(air_money));
|
||||||
memset(sea_money, 0, sizeof(sea_money));
|
memset(sea_money, 0, sizeof(sea_money));
|
||||||
memset(lnd_money, 0, sizeof(lnd_money));
|
memset(lnd_money, 0, sizeof(lnd_money));
|
||||||
bp = alloc_bp();
|
bp = bp_alloc();
|
||||||
for (n = 0; n < MAXNOC; n++) {
|
for (n = 0; n < MAXNOC; n++) {
|
||||||
money[n] = 0;
|
money[n] = 0;
|
||||||
if (!(np = getnatp(n)))
|
if (!(np = getnatp(n)))
|
||||||
|
|
|
@ -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++) {
|
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
||||||
if (mvec[i] == 0)
|
if (mvec[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
amt = gt_bg_nmbr(bp, sp, i);
|
amt = bp_get_item(bp, sp, i);
|
||||||
if (amt * 100 < mvec[i] * pct)
|
if (amt * 100 < mvec[i] * pct)
|
||||||
pct = amt * 100 / mvec[i];
|
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++) {
|
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
||||||
if (mvec[i] == 0)
|
if (mvec[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
amt = gt_bg_nmbr(bp, sp, i);
|
amt = bp_get_item(bp, sp, i);
|
||||||
amt -= roundavg(mvec[i] * pct / 100.0);
|
amt -= roundavg(mvec[i] * pct / 100.0);
|
||||||
if (CANT_HAPPEN(amt < 0))
|
if (CANT_HAPPEN(amt < 0))
|
||||||
amt = 0;
|
amt = 0;
|
||||||
pt_bg_nmbr(bp, sp, i, amt);
|
bp_put_item(bp, sp, i, amt);
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
sp->sct_item[i] = amt;
|
sp->sct_item[i] = amt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
avail = sp->sct_avail * 100;
|
avail = sp->sct_avail * 100;
|
||||||
else
|
else
|
||||||
avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
|
avail = bp_get_avail(bp, sp) * 100;
|
||||||
if (carrier)
|
if (carrier)
|
||||||
avail += etus * carrier->shp_item[I_MILIT] / 2;
|
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)
|
if (!player->simulation)
|
||||||
avail = (sp->sct_avail * 100 - used) / 100;
|
avail = (sp->sct_avail * 100 - used) / 100;
|
||||||
else
|
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)
|
if (avail < 0)
|
||||||
avail = 0;
|
avail = 0;
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
sp->sct_avail = avail;
|
sp->sct_avail = avail;
|
||||||
else
|
else
|
||||||
pt_bg_nmbr(bp, sp, I_MAX + 1, avail);
|
bp_put_avail(bp, sp, avail);
|
||||||
|
|
||||||
if (sp->sct_type != SCT_AIRPT)
|
if (sp->sct_type != SCT_AIRPT)
|
||||||
build /= 3;
|
build /= 3;
|
||||||
|
|
|
@ -77,7 +77,7 @@ prepare_sects(int etu, struct bp *bp)
|
||||||
|
|
||||||
if (sp->sct_type == SCT_WATER)
|
if (sp->sct_type == SCT_WATER)
|
||||||
continue;
|
continue;
|
||||||
fill_update_array(bp, sp);
|
bp_set_from_sect(bp, sp);
|
||||||
np = getnatp(sp->sct_own);
|
np = getnatp(sp->sct_own);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -329,8 +329,8 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
|
||||||
np->nat_money > 0) {
|
np->nat_money > 0) {
|
||||||
neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
|
neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
|
||||||
&cost);
|
&cost);
|
||||||
pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]);
|
bp_put_item(bp, sp, I_LCM, vec[I_LCM]);
|
||||||
pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]);
|
bp_put_item(bp, sp, I_HCM, vec[I_HCM]);
|
||||||
p_sect[SCT_EFFIC][0]++;
|
p_sect[SCT_EFFIC][0]++;
|
||||||
p_sect[SCT_EFFIC][1] += cost;
|
p_sect[SCT_EFFIC][1] += cost;
|
||||||
if (!player->simulation) {
|
if (!player->simulation) {
|
||||||
|
@ -358,7 +358,7 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
|
||||||
&pcost, &amount);
|
&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][0] += amount;
|
||||||
p_sect[desig][1] += pcost;
|
p_sect[desig][1] += pcost;
|
||||||
if (!player->simulation) {
|
if (!player->simulation) {
|
||||||
|
|
|
@ -303,7 +303,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
avail = wf + sp->sct_avail * 100;
|
avail = wf + sp->sct_avail * 100;
|
||||||
else
|
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);
|
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)
|
if (!player->simulation)
|
||||||
avail = (sp->sct_avail * 100 + wf) / 100;
|
avail = (sp->sct_avail * 100 + wf) / 100;
|
||||||
else
|
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)
|
if (avail < 0)
|
||||||
avail = 0;
|
avail = 0;
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
sp->sct_avail = avail;
|
sp->sct_avail = avail;
|
||||||
else
|
else
|
||||||
pt_bg_nmbr(bp, sp, I_MAX + 1, avail);
|
bp_put_avail(bp, sp, avail);
|
||||||
}
|
}
|
||||||
if (sp->sct_type != SCT_HARBR)
|
if (sp->sct_type != SCT_HARBR)
|
||||||
if ((build + ship->shp_effic) > 80) {
|
if ((build + ship->shp_effic) > 80) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue