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:
parent
68c7c08a58
commit
da05484d8b
17 changed files with 79 additions and 100 deletions
|
@ -213,9 +213,7 @@ build_ship(struct sctstr *sp, int type, int tlev)
|
|||
short mat[I_MAX+1];
|
||||
struct shpstr ship;
|
||||
|
||||
memset(mat, 0, sizeof(mat));
|
||||
mat[I_LCM] = mp->m_lcm;
|
||||
mat[I_HCM] = mp->m_hcm;
|
||||
memcpy(mat, mp->m_mat, sizeof(mat));
|
||||
|
||||
if (sp->sct_type != SCT_HARBR && !player->god) {
|
||||
pr("Ships must be built in harbours.\n");
|
||||
|
@ -264,9 +262,7 @@ build_land(struct sctstr *sp, int type, int tlev)
|
|||
short mat[I_MAX+1];
|
||||
struct lndstr land;
|
||||
|
||||
memset(mat, 0, sizeof(mat));
|
||||
mat[I_LCM] = lp->l_lcm;
|
||||
mat[I_HCM] = lp->l_hcm;
|
||||
memcpy(mat, lp->l_mat, sizeof(mat));
|
||||
|
||||
if (sp->sct_type != SCT_HEADQ && !player->god) {
|
||||
pr("Land units must be built in headquarters.\n");
|
||||
|
@ -323,11 +319,7 @@ build_nuke(struct sctstr *sp, int type, int tlev)
|
|||
* make them start at 20%. Since they don't have efficiency
|
||||
* now, we charge all the work right away.
|
||||
*/
|
||||
memset(mat, 0, sizeof(mat));
|
||||
mat[I_LCM] = np->n_lcm;
|
||||
mat[I_HCM] = np->n_hcm;
|
||||
mat[I_OIL] = np->n_oil;
|
||||
mat[I_RAD] = np->n_rad;
|
||||
memcpy(mat, np->n_mat, sizeof(mat));
|
||||
|
||||
if (!sector_can_build(sp, mat, np->n_bwork, 100, np->n_name))
|
||||
return 0;
|
||||
|
@ -358,10 +350,7 @@ build_plane(struct sctstr *sp, int type, int tlev)
|
|||
short mat[I_MAX+1];
|
||||
struct plnstr plane;
|
||||
|
||||
memset(mat, 0, sizeof(mat));
|
||||
mat[I_MILIT] = pp->pl_crew;
|
||||
mat[I_LCM] = pp->pl_lcm;
|
||||
mat[I_HCM] = pp->pl_hcm;
|
||||
memcpy(mat, pp->pl_mat, sizeof(mat));
|
||||
|
||||
if (sp->sct_type != SCT_AIRPT && !player->god) {
|
||||
pr("Planes must be built in airports.\n");
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* Dave Pare
|
||||
* Ken Stevens, 1995
|
||||
* Steve McClure, 1998-2000
|
||||
* Markus Armbruster, 2004-2013
|
||||
* Markus Armbruster, 2004-2016
|
||||
* Ron Koenderink, 2005-2008
|
||||
*/
|
||||
|
||||
|
@ -244,8 +244,10 @@ gen_power(struct powstr *powbuf, int save)
|
|||
continue;
|
||||
pow = &powbuf[land.lnd_own];
|
||||
addtopow(land.lnd_item, pow);
|
||||
f = (lchr[(int)land.lnd_type].l_lcm / 10.0) * (land.lnd_effic / 100.0);
|
||||
f += (lchr[(int)land.lnd_type].l_hcm / 10.0) * (land.lnd_effic / 100.0);
|
||||
f = (lchr[land.lnd_type].l_mat[I_LCM] / 10.0)
|
||||
* (land.lnd_effic / 100.0);
|
||||
f += (lchr[land.lnd_type].l_mat[I_HCM] / 10.0)
|
||||
* (land.lnd_effic / 100.0);
|
||||
pow->p_power += f * 2;
|
||||
if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
|
||||
pow->p_units += 1.0;
|
||||
|
@ -256,8 +258,10 @@ gen_power(struct powstr *powbuf, int save)
|
|||
continue;
|
||||
pow = &powbuf[ship.shp_own];
|
||||
addtopow(ship.shp_item, pow);
|
||||
f = (mchr[(int)ship.shp_type].m_lcm / 10.0) * (ship.shp_effic / 100.0);
|
||||
f += (mchr[(int)ship.shp_type].m_hcm / 10.0) * (ship.shp_effic / 100.0);
|
||||
f = (mchr[ship.shp_type].m_mat[I_LCM] / 10.0)
|
||||
* (ship.shp_effic / 100.0);
|
||||
f += (mchr[ship.shp_type].m_mat[I_HCM] / 10.0)
|
||||
* (ship.shp_effic / 100.0);
|
||||
pow->p_power += f * 2;
|
||||
pow->p_ships += 1.0;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Steve McClure, 2000
|
||||
* Markus Armbruster, 2004-2014
|
||||
* Markus Armbruster, 2004-2016
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -55,6 +55,8 @@ scra(void)
|
|||
char prompt[128];
|
||||
char buf[1024];
|
||||
float eff;
|
||||
short *mvec;
|
||||
int amt;
|
||||
|
||||
if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
|
||||
return RET_SYN;
|
||||
|
@ -148,8 +150,7 @@ scra(void)
|
|||
-item.ship.shp_item[i]))
|
||||
sect.sct_item[i] += item.ship.shp_item[i];
|
||||
}
|
||||
sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
|
||||
sect.sct_item[I_HCM] += mp->m_hcm * 2 / 3 * eff;
|
||||
mvec = mp->m_mat;
|
||||
if (item.ship.shp_pstage == PLG_INFECT
|
||||
&& sect.sct_pstage == PLG_HEALTHY)
|
||||
sect.sct_pstage = PLG_EXPOSED;
|
||||
|
@ -161,23 +162,25 @@ scra(void)
|
|||
-item.land.lnd_item[i]))
|
||||
sect.sct_item[i] += item.land.lnd_item[i];
|
||||
}
|
||||
sect.sct_item[I_LCM] += lp->l_lcm * 2 / 3 * eff;
|
||||
sect.sct_item[I_HCM] += lp->l_hcm * 2 / 3 * eff;
|
||||
mvec = lp->l_mat;
|
||||
if (item.land.lnd_pstage == PLG_INFECT
|
||||
&& sect.sct_pstage == PLG_HEALTHY)
|
||||
sect.sct_pstage = PLG_EXPOSED;
|
||||
} else {
|
||||
eff = item.land.lnd_effic / 100.0;
|
||||
pp = &plchr[(int)item.plane.pln_type];
|
||||
sect.sct_item[I_LCM] += pp->pl_lcm * 2 / 3 * eff;
|
||||
sect.sct_item[I_HCM] += pp->pl_hcm * 2 / 3 * eff;
|
||||
sect.sct_item[I_MILIT] += roundavg(pp->pl_crew * eff);
|
||||
mvec = pp->pl_mat;
|
||||
}
|
||||
item.gen.effic = 0;
|
||||
put_empobj(type, item.gen.uid, &item.gen);
|
||||
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
||||
if (sect.sct_item[i] > ITEM_MAX)
|
||||
sect.sct_item[i] = ITEM_MAX;
|
||||
if (i == I_CIVIL || i == I_MILIT || i == I_UW)
|
||||
amt = sect.sct_item[i] + mvec[i] * eff;
|
||||
else
|
||||
amt = sect.sct_item[i] + mvec[i] * 2 / 3 * eff;
|
||||
if (amt > ITEM_MAX)
|
||||
amt = ITEM_MAX;
|
||||
sect.sct_item[i] = amt;
|
||||
}
|
||||
putsect(§);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Steve McClure, 2000
|
||||
* Markus Armbruster, 2006-2011
|
||||
* Markus Armbruster, 2006-2016
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -193,7 +193,7 @@ tran_plane(void)
|
|||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
|
||||
weight += plchr[type].pl_mat[I_LCM] + (plchr[type].pl_mat[I_HCM] * 2);
|
||||
++count;
|
||||
}
|
||||
if (count == 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue