From: Markus Armbruster Date: Wed, 17 Aug 2016 19:01:32 +0000 (+0200) Subject: config: Generalize infrastructure build materials storage X-Git-Tag: v4.4.0~106 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=5d3abc9917964b9ba4551ae7a1f9c675388ba1b0 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 --- diff --git a/include/sect.h b/include/sect.h index a02d21d99..700ced300 100644 --- a/include/sect.h +++ b/include/sect.h @@ -216,8 +216,8 @@ extern struct dchrstr dchr[SCT_TYPE_MAX + 2]; /* Each cost is per point of efficency */ struct sctintrins { char *in_name; - unsigned char in_lcms; /* construction materials */ - unsigned char in_hcms; + short in_mat[I_MAX+1]; /* materials to build 100% */ + /* non-zero only for I_LCM and I_HCM */ short in_bmobil; /* mobility to build 100% */ int in_cost; /* cost to build 100% */ unsigned char in_enable; /* enabled iff non-zero */ diff --git a/src/lib/commands/improve.c b/src/lib/commands/improve.c index b84b7d4a3..a8f5227bd 100644 --- a/src/lib/commands/improve.c +++ b/src/lib/commands/improve.c @@ -49,10 +49,8 @@ improve(void) int type; int value; int ovalue; - int maxup, lim; + int maxup, i, lim; struct natstr *natp; - int lneeded; - int hneeded; int wanted; p = getstarg(player->argp[1], @@ -104,26 +102,6 @@ improve(void) maxup = wanted; if (!maxup) 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; if (lim <= 0) { @@ -134,6 +112,21 @@ improve(void) if (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); lim = (natp->nat_money - player->dolcost) * 100 / incp->in_cost; if (lim <= 0) { @@ -144,10 +137,8 @@ improve(void) if (maxup > lim) maxup = lim; - lneeded = incp->in_lcms * maxup; - hneeded = incp->in_hcms * maxup; - sect.sct_item[I_LCM] -= lneeded; - sect.sct_item[I_HCM] -= hneeded; + for (i = I_NONE + 1; i <= I_MAX; i++) + sect.sct_item[i] -= roundavg(maxup * incp->in_mat[i] / 100.0); sect.sct_mobil -= roundavg(maxup * incp->in_bmobil / 100.0); player->dolcost += maxup * incp->in_cost / 100.0; ovalue = value; diff --git a/src/lib/common/nsc.c b/src/lib/common/nsc.c index 98836286b..91d21028e 100644 --- a/src/lib/common/nsc.c +++ b/src/lib/common/nsc.c @@ -688,8 +688,7 @@ struct castr intrchr_ca[] = { /* 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, CA_DUMP_CONST}, - {"lcms", fldoff(in_lcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, - {"hcms", fldoff(in_hcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, + NSC_MVEC(fldoff(in_mat), CA_DUMP_ONLY, CA_DUMP_ONLY, CA_DUMP_ONLY), {"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}, {"enable", fldoff(in_enable), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, diff --git a/src/lib/global/infra.config b/src/lib/global/infra.config index 3f76bfe9d..18e7a2c9b 100644 --- a/src/lib/global/infra.config +++ b/src/lib/global/infra.config @@ -45,8 +45,8 @@ # econfig key custom_tables. config infrastructure -name lcm hcm bmob cost enab -"road network" 2 2 100 200 1 -"rail network" 1 1 100 100 1 -"defense factor" 1 1 100 100 0 +name l_b h_b bmob cost enab +"road network" 200 200 100 200 1 +"rail network" 100 100 100 100 1 +"defense factor" 100 100 100 100 0 /config diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index 45e912613..e251d3da4 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -429,7 +429,7 @@ show_sect_build(int foo) "infrastructure type lcm hcm mobil $\n"); pr("%-23.23s %4d %4d %5d %5d\n", 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); first = 0; } diff --git a/tests/empdump/xundump-errors/fld-conststr b/tests/empdump/xundump-errors/fld-conststr index 787c1fd96..044004ed1 100644 --- a/tests/empdump/xundump-errors/fld-conststr +++ b/tests/empdump/xundump-errors/fld-conststr @@ -1,4 +1,4 @@ config infrastructure -name lcms hcms bmobil cost enable +name l_b h_b bmobil cost enable "lala" 1 1 1 1 1 # value for field 1 must be "road network" diff --git a/tests/empdump/xundump-errors/ftr-mal2 b/tests/empdump/xundump-errors/ftr-mal2 index 700e0d91c..636f45514 100644 --- a/tests/empdump/xundump-errors/ftr-mal2 +++ b/tests/empdump/xundump-errors/ftr-mal2 @@ -1,7 +1,7 @@ config infrastructure -name lcm hcm bmob cost enab -"road network" 2 2 100 200 1 -"rail network" 1 1 100 100 1 -"defense factor" 1 1 100 100 0 +name l_b h_b bmob cost enab +"road network" 200 200 100 200 1 +"rail network" 100 100 100 100 1 +"defense factor" 100 100 100 100 0 /con # malformed table footer diff --git a/tests/version/journal.log b/tests/version/journal.log index e3b2f1d27..1bfe5e1bd 100644 --- a/tests/version/journal.log +++ b/tests/version/journal.log @@ -1194,12 +1194,24 @@ Play#0 command xdump 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 "lcms" 1 0 0 -1 - Play#0 output Play#0 1 "hcms" 1 0 0 -1 + Play#0 output Play#0 1 "c_build" 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 "cost" 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 input xdump meta 25 Play#0 command xdump @@ -1801,9 +1813,9 @@ Play#0 input xdump infrastructure * Play#0 command xdump 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 "rail\\040network" 1 1 100 100 0 - Play#0 output Play#0 1 "defense\\040factor" 1 1 100 100 0 + 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" 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" 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 6 0 640 Play#0 input xdump updates * @@ -2451,9 +2463,9 @@ Play#1 input xdump infrastructure * Play#1 command xdump 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 "rail\\040network" 1 1 100 100 0 - Play#1 output Play#1 1 "defense\\040factor" 1 1 100 100 0 + 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" 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" 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 6 0 0 Play#1 input xdump updates *