config: Generalize infrastructure build materials storage

Infrastructure requires lcms and hcms to build.  The build materials
are exposed as infrastructure columns lcms, hcms (struct sctintrins
members in_lcms, in_hcms).  They are per point of efficiency.  In
contrast, sector and unit build materials are defined for 100%.

We want to define build materials for 100% now, for flexibility and
consistency, and we want to optionally support more build materials in
the future.  Replace members in_lcms and in_hcms by array in_mat[],
and provide selectors l_build and h_build.

Additionally provide selectors for all other item types, with value
zero, to help clients prepare for future additional materials.  Use
CA_DUMP_ONLY to keep them out of configuration tables until they
actually work.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-08-17 21:01:32 +02:00
parent c8b51ec1a8
commit 5d3abc9917
8 changed files with 52 additions and 50 deletions

View file

@ -216,8 +216,8 @@ extern struct dchrstr dchr[SCT_TYPE_MAX + 2];
/* Each cost is per point of efficency */ /* Each cost is per point of efficency */
struct sctintrins { struct sctintrins {
char *in_name; char *in_name;
unsigned char in_lcms; /* construction materials */ short in_mat[I_MAX+1]; /* materials to build 100% */
unsigned char in_hcms; /* non-zero only for I_LCM and I_HCM */
short in_bmobil; /* mobility to build 100% */ short in_bmobil; /* mobility to build 100% */
int in_cost; /* cost to build 100% */ int in_cost; /* cost to build 100% */
unsigned char in_enable; /* enabled iff non-zero */ unsigned char in_enable; /* enabled iff non-zero */

View file

@ -49,10 +49,8 @@ improve(void)
int type; int type;
int value; int value;
int ovalue; int ovalue;
int maxup, lim; int maxup, i, lim;
struct natstr *natp; struct natstr *natp;
int lneeded;
int hneeded;
int wanted; int wanted;
p = getstarg(player->argp[1], p = getstarg(player->argp[1],
@ -104,26 +102,6 @@ improve(void)
maxup = wanted; maxup = wanted;
if (!maxup) if (!maxup)
continue; continue;
lneeded = incp->in_lcms * maxup;
if (sect.sct_item[I_LCM] < lneeded) {
lneeded = sect.sct_item[I_LCM];
maxup = lneeded / incp->in_lcms;
if (maxup <= 0) {
pr("Not enough lcms in %s\n",
xyas(sect.sct_x, sect.sct_y, player->cnum));
continue;
}
}
hneeded = incp->in_hcms * maxup;
if (sect.sct_item[I_HCM] < hneeded) {
hneeded = sect.sct_item[I_HCM];
maxup = hneeded / incp->in_hcms;
if (maxup <= 0) {
pr("Not enough hcms in %s\n",
xyas(sect.sct_x, sect.sct_y, player->cnum));
continue;
}
}
lim = (sect. sct_mobil - 1) * 100 / incp->in_bmobil; lim = (sect. sct_mobil - 1) * 100 / incp->in_bmobil;
if (lim <= 0) { if (lim <= 0) {
@ -134,6 +112,21 @@ improve(void)
if (maxup > lim) if (maxup > lim)
maxup = lim; maxup = lim;
for (i = I_NONE + 1; i <= I_MAX; i++) {
if (!incp->in_mat[i])
continue;
lim = sect.sct_item[i] * 100 / incp->in_mat[i];
if (lim <= 0) {
pr("Not enough %s in %s\n",
ichr[i].i_name,
xyas(sect.sct_x, sect.sct_y, player->cnum));
}
if (maxup > lim)
maxup = lim;
}
if (maxup <= 0)
continue;
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
lim = (natp->nat_money - player->dolcost) * 100 / incp->in_cost; lim = (natp->nat_money - player->dolcost) * 100 / incp->in_cost;
if (lim <= 0) { if (lim <= 0) {
@ -144,10 +137,8 @@ improve(void)
if (maxup > lim) if (maxup > lim)
maxup = lim; maxup = lim;
lneeded = incp->in_lcms * maxup; for (i = I_NONE + 1; i <= I_MAX; i++)
hneeded = incp->in_hcms * maxup; sect.sct_item[i] -= roundavg(maxup * incp->in_mat[i] / 100.0);
sect.sct_item[I_LCM] -= lneeded;
sect.sct_item[I_HCM] -= hneeded;
sect.sct_mobil -= roundavg(maxup * incp->in_bmobil / 100.0); sect.sct_mobil -= roundavg(maxup * incp->in_bmobil / 100.0);
player->dolcost += maxup * incp->in_cost / 100.0; player->dolcost += maxup * incp->in_cost / 100.0;
ovalue = value; ovalue = value;

View file

@ -688,8 +688,7 @@ struct castr intrchr_ca[] = {
/* no need for uid as long as it's not referenced from other tables */ /* no need for uid as long as it's not referenced from other tables */
{"name", fldoff(in_name), NSC_STRING, 0, NULL, EF_BAD, 0, {"name", fldoff(in_name), NSC_STRING, 0, NULL, EF_BAD, 0,
CA_DUMP_CONST}, CA_DUMP_CONST},
{"lcms", fldoff(in_lcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, NSC_MVEC(fldoff(in_mat), CA_DUMP_ONLY, CA_DUMP_ONLY, CA_DUMP_ONLY),
{"hcms", fldoff(in_hcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
{"bmobil", fldoff(in_bmobil), NSC_SHORT, 0, NULL, EF_BAD, 0, CA_DUMP}, {"bmobil", fldoff(in_bmobil), NSC_SHORT, 0, NULL, EF_BAD, 0, CA_DUMP},
{"cost", fldoff(in_cost), NSC_INT, 0, NULL, EF_BAD, 0, CA_DUMP}, {"cost", fldoff(in_cost), NSC_INT, 0, NULL, EF_BAD, 0, CA_DUMP},
{"enable", fldoff(in_enable), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, {"enable", fldoff(in_enable), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},

View file

@ -45,8 +45,8 @@
# econfig key custom_tables. # econfig key custom_tables.
config infrastructure config infrastructure
name lcm hcm bmob cost enab name l_b h_b bmob cost enab
"road network" 2 2 100 200 1 "road network" 200 200 100 200 1
"rail network" 1 1 100 100 1 "rail network" 100 100 100 100 1
"defense factor" 1 1 100 100 0 "defense factor" 100 100 100 100 0
/config /config

View file

@ -429,7 +429,7 @@ show_sect_build(int foo)
"infrastructure type lcm hcm mobil $\n"); "infrastructure type lcm hcm mobil $\n");
pr("%-23.23s %4d %4d %5d %5d\n", pr("%-23.23s %4d %4d %5d %5d\n",
intrchr[i].in_name, intrchr[i].in_name,
intrchr[i].in_lcms * 100, intrchr[i].in_hcms * 100, intrchr[i].in_mat[I_LCM], intrchr[i].in_mat[I_HCM],
intrchr[i].in_bmobil, intrchr[i].in_cost); intrchr[i].in_bmobil, intrchr[i].in_cost);
first = 0; first = 0;
} }

View file

@ -1,4 +1,4 @@
config infrastructure config infrastructure
name lcms hcms bmobil cost enable name l_b h_b bmobil cost enable
"lala" 1 1 1 1 1 "lala" 1 1 1 1 1
# value for field 1 must be "road network" # value for field 1 must be "road network"

View file

@ -1,7 +1,7 @@
config infrastructure config infrastructure
name lcm hcm bmob cost enab name l_b h_b bmob cost enab
"road network" 2 2 100 200 1 "road network" 200 200 100 200 1
"rail network" 1 1 100 100 1 "rail network" 100 100 100 100 1
"defense factor" 1 1 100 100 0 "defense factor" 100 100 100 100 0
/con /con
# malformed table footer # malformed table footer

View file

@ -1194,12 +1194,24 @@
Play#0 command xdump Play#0 command xdump
Play#0 output Play#0 1 XDUMP meta infrastructure 0 Play#0 output Play#0 1 XDUMP meta infrastructure 0
Play#0 output Play#0 1 "name" 3 0 0 -1 Play#0 output Play#0 1 "name" 3 0 0 -1
Play#0 output Play#0 1 "lcms" 1 0 0 -1 Play#0 output Play#0 1 "c_build" 1 0 0 -1
Play#0 output Play#0 1 "hcms" 1 0 0 -1 Play#0 output Play#0 1 "m_build" 1 0 0 -1
Play#0 output Play#0 1 "s_build" 1 0 0 -1
Play#0 output Play#0 1 "g_build" 1 0 0 -1
Play#0 output Play#0 1 "p_build" 1 0 0 -1
Play#0 output Play#0 1 "i_build" 1 0 0 -1
Play#0 output Play#0 1 "d_build" 1 0 0 -1
Play#0 output Play#0 1 "b_build" 1 0 0 -1
Play#0 output Play#0 1 "f_build" 1 0 0 -1
Play#0 output Play#0 1 "o_build" 1 0 0 -1
Play#0 output Play#0 1 "l_build" 1 0 0 -1
Play#0 output Play#0 1 "h_build" 1 0 0 -1
Play#0 output Play#0 1 "u_build" 1 0 0 -1
Play#0 output Play#0 1 "r_build" 1 0 0 -1
Play#0 output Play#0 1 "bmobil" 1 0 0 -1 Play#0 output Play#0 1 "bmobil" 1 0 0 -1
Play#0 output Play#0 1 "cost" 1 0 0 -1 Play#0 output Play#0 1 "cost" 1 0 0 -1
Play#0 output Play#0 1 "enable" 1 0 0 -1 Play#0 output Play#0 1 "enable" 1 0 0 -1
Play#0 output Play#0 1 /6 Play#0 output Play#0 1 /18
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input xdump meta 25 Play#0 input xdump meta 25
Play#0 command xdump Play#0 command xdump
@ -1801,9 +1813,9 @@
Play#0 input xdump infrastructure * Play#0 input xdump infrastructure *
Play#0 command xdump Play#0 command xdump
Play#0 output Play#0 1 XDUMP infrastructure 0 Play#0 output Play#0 1 XDUMP infrastructure 0
Play#0 output Play#0 1 "road\\040network" 2 2 100 200 1 Play#0 output Play#0 1 "road\\040network" 0 0 0 0 0 0 0 0 0 0 200 200 0 0 100 200 1
Play#0 output Play#0 1 "rail\\040network" 1 1 100 100 0 Play#0 output Play#0 1 "rail\\040network" 0 0 0 0 0 0 0 0 0 0 100 100 0 0 100 100 0
Play#0 output Play#0 1 "defense\\040factor" 1 1 100 100 0 Play#0 output Play#0 1 "defense\\040factor" 0 0 0 0 0 0 0 0 0 0 100 100 0 0 100 100 0
Play#0 output Play#0 1 /3 Play#0 output Play#0 1 /3
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input xdump updates * Play#0 input xdump updates *
@ -2451,9 +2463,9 @@
Play#1 input xdump infrastructure * Play#1 input xdump infrastructure *
Play#1 command xdump Play#1 command xdump
Play#1 output Play#1 1 XDUMP infrastructure 0 Play#1 output Play#1 1 XDUMP infrastructure 0
Play#1 output Play#1 1 "road\\040network" 2 2 100 200 1 Play#1 output Play#1 1 "road\\040network" 0 0 0 0 0 0 0 0 0 0 200 200 0 0 100 200 1
Play#1 output Play#1 1 "rail\\040network" 1 1 100 100 0 Play#1 output Play#1 1 "rail\\040network" 0 0 0 0 0 0 0 0 0 0 100 100 0 0 100 100 0
Play#1 output Play#1 1 "defense\\040factor" 1 1 100 100 0 Play#1 output Play#1 1 "defense\\040factor" 0 0 0 0 0 0 0 0 0 0 100 100 0 0 100 100 0
Play#1 output Play#1 1 /3 Play#1 output Play#1 1 /3
Play#1 output Play#1 6 0 0 Play#1 output Play#1 6 0 0
Play#1 input xdump updates * Play#1 input xdump updates *