config: Generalize unit build materials storage

Use a single array member instead of multiple scalar members.  Only
the array elements that replace scalar members are can be non-zero for
now.

This is a first step to permitting more build materials.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-05-27 14:17:08 +02:00
parent 68c7c08a58
commit da05484d8b
17 changed files with 79 additions and 100 deletions

View file

@ -200,7 +200,6 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
int build;
int avail;
int mult;
int mvec[I_MAX + 1];
lp = &lchr[(int)land->lnd_type];
sp = getsectp(land->lnd_x, land->lnd_y);
@ -230,10 +229,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
if (delta > 100 - land->lnd_effic)
delta = 100 - land->lnd_effic;
memset(mvec, 0, sizeof(mvec));
mvec[I_LCM] = lp->l_lcm;
mvec[I_HCM] = lp->l_hcm;
build = get_materials(sp, bp, mvec, delta);
build = get_materials(sp, bp, lp->l_mat, delta);
if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
build /= 3;

View file

@ -28,7 +28,7 @@
*
* Known contributors to this file:
* Ville Virrankoski, 1996
* Markus Armbruster, 2007
* Markus Armbruster, 2007-2016
*/
#include <config.h>
@ -41,14 +41,14 @@
/*
* Get build materials from sector @sp.
* @bp is the sector's build pointer.
* @mvec[] defines the materials needed to build 100%.
* Array @mvec[ITEM_MAX+1] defines the materials needed to build 100%.
* @pct is the percentage to build.
* Adjust build percentage downwards so that available materials
* suffice. Remove the materials.
* Return adjusted build percentage.
*/
int
get_materials(struct sctstr *sp, struct bp *bp, int *mvec, int pct)
get_materials(struct sctstr *sp, struct bp *bp, short mvec[], int pct)
{
int i, amt;

View file

@ -116,7 +116,7 @@ upd_plane(struct plnstr *pp, int etus,
np->nat_money -= cost;
}
/* flight pay is 5x the pay received by other military */
np->nat_money += etus * pcp->pl_crew * money_mil * 5;
np->nat_money += etus * pcp->pl_mat[I_MILIT] * money_mil * 5;
}
}
@ -124,7 +124,6 @@ static void
planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
{
int build;
int mvec[I_MAX + 1];
struct shpstr *carrier;
struct plchrstr *pcp = &plchr[(int)pp->pln_type];
struct sctstr *sp = getsectp(pp->pln_x, pp->pln_y);
@ -173,11 +172,7 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
if (delta > 100 - pp->pln_effic)
delta = 100 - pp->pln_effic;
memset(mvec, 0, sizeof(mvec));
mvec[I_MILIT] = pcp->pl_crew;
mvec[I_LCM] = pcp->pl_lcm;
mvec[I_HCM] = pcp->pl_hcm;
build = get_materials(sp, bp, mvec, delta);
build = get_materials(sp, bp, pcp->pl_mat, delta);
if (carrier)
build = delta;

View file

@ -248,7 +248,6 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
int wf;
int avail;
int mult;
int mvec[I_MAX + 1];
mp = &mchr[(int)ship->shp_type];
sp = getsectp(ship->shp_x, ship->shp_y);
@ -293,10 +292,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
if (delta > 100 - ship->shp_effic)
delta = 100 - ship->shp_effic;
memset(mvec, 0, sizeof(mvec));
mvec[I_LCM] = mp->m_lcm;
mvec[I_HCM] = mp->m_hcm;
build = get_materials(sp, bp, mvec, delta);
build = get_materials(sp, bp, mp->m_mat, delta);
if (sp->sct_type != SCT_HARBR)
build = delta;