config: Make product work independently configurable

The work required for a product is traditionally the amount of raw
materials, plus 1 for resource usage, or 1 if using neither.  Make it
independently configurable instead, via new product selector bwork,
backed by new struct pchrstr member p_bwork.  Keep the required work
exactly the same in the default configuration.

Clients that compute work from materials need to be updated.  Easy,
since build work is now exposed in xdump.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2021-01-07 07:14:27 +01:00
parent d7a9593f35
commit 9b84153038
10 changed files with 82 additions and 83 deletions

View file

@ -45,6 +45,7 @@ struct pchrstr {
int p_uid;
i_type p_ctype[MAXPRCON]; /* constituent types */
unsigned short p_camt[MAXPRCON]; /* constituent amounts */
int p_bwork; /* work to build one product unit */
i_type p_type; /* product item type, or I_NONE if level */
int p_level; /* level index (NAT_?LEV), or -1 if item */
int p_cost; /* dollars / product unit */

View file

@ -27,7 +27,7 @@
* nsc.c: Empire selection global structures
*
* Known contributors to this file:
* Markus Armbruster, 2004-2020
* Markus Armbruster, 2004-2021
*/
/*
@ -144,6 +144,7 @@ struct castr pchr_ca[] = {
EF_ITEM, 0, CA_DUMP},
{"camt", fldoff(p_camt), NSC_USHORT, MAXPRCON, NULL, EF_BAD, 0,
CA_DUMP},
{"bwork", fldoff(p_bwork), NSC_INT, 0, NULL, EF_BAD, 0, CA_DUMP},
{"type", fldoff(p_type), NSC_SITYPE(i_type), 0, NULL, EF_ITEM, 0,
CA_DUMP},
{"level", fldoff(p_level), NSC_INT, 0, NULL, EF_LEVEL, 0, CA_DUMP},

View file

@ -27,7 +27,7 @@
# product.config: Product characteristics
#
# Known contributors to this file:
# Markus Armbruster, 2006-2016
# Markus Armbruster, 2006-2021
#
# Derived from product.c; no known contributors
#
@ -51,23 +51,23 @@
# econfig key custom_tables.
config product
uid sname ct(0) ct(1) ct(2) ca(0) ca(1) ca(2) type lev cost nrndx nrdep nlndx nlmin nllag name
uid sname ct(0) ct(1) ct(2) ca(0) ca(1) ca(2) bwork type lev cost nrndx nrdep nlndx nlmin nllag name
# Mining natural resources:
0 "iron" -1 -1 -1 0 0 0 i none 0 min 0 none 0 0 "iron ore"
1 "dust" -1 -1 -1 0 0 0 d none 0 gold 20 none 0 0 "gold dust"
2 "food" -1 -1 -1 0 0 0 f none 0 fert 0 tech -10 10 "food"
3 "oil" -1 -1 -1 0 0 0 o none 0 ocon 10 tech -10 10 "oil"
4 "rad" -1 -1 -1 0 0 0 r none 2 uran 35 tech 40 10 "radioactive materials"
0 "iron" -1 -1 -1 0 0 0 1 i none 0 min 0 none 0 0 "iron ore"
1 "dust" -1 -1 -1 0 0 0 1 d none 0 gold 20 none 0 0 "gold dust"
2 "food" -1 -1 -1 0 0 0 1 f none 0 fert 0 tech -10 10 "food"
3 "oil" -1 -1 -1 0 0 0 1 o none 0 ocon 10 tech -10 10 "oil"
4 "rad" -1 -1 -1 0 0 0 1 r none 2 uran 35 tech 40 10 "radioactive materials"
# Processing stuff into different stuff:
5 "shells" l h -1 2 1 0 s none 3 none 0 tech 20 10 "shells"
6 "guns" o l h 1 5 10 g none 30 none 0 tech 20 10 "guns"
7 "petrol" o -1 -1 1 0 0 p none 1 none 0 tech 20 10 "petrol"
8 "bars" d -1 -1 5 0 0 b none 10 none 0 none 0 0 "gold bars"
9 "lcm" i -1 -1 1 0 0 l none 0 none 0 tech -10 10 "light construction materials"
10 "hcm" i -1 -1 2 0 0 h none 0 none 0 tech -10 10 "heavy construction materials"
5 "shells" l h -1 2 1 0 3 s none 3 none 0 tech 20 10 "shells"
6 "guns" o l h 1 5 10 16 g none 30 none 0 tech 20 10 "guns"
7 "petrol" o -1 -1 1 0 0 1 p none 1 none 0 tech 20 10 "petrol"
8 "bars" d -1 -1 5 0 0 5 b none 10 none 0 none 0 0 "gold bars"
9 "lcm" i -1 -1 1 0 0 1 l none 0 none 0 tech -10 10 "light construction materials"
10 "hcm" i -1 -1 2 0 0 2 h none 0 none 0 tech -10 10 "heavy construction materials"
# Producing levels:
11 "tech" d o l 1 5 10 -1 tech 300 none 0 edu 5 10 "technological breakthroughs"
12 "medical" d o l 1 5 10 -1 res 90 none 0 edu 5 10 "medical discoveries"
13 "edu" l -1 -1 1 0 0 -1 edu 9 none 0 none 0 0 "a class of graduates"
14 "happy" l -1 -1 1 0 0 -1 hap 9 none 0 none 0 0 "happy strollers"
11 "tech" d o l 1 5 10 16 -1 tech 300 none 0 edu 5 10 "technological breakthroughs"
12 "medical" d o l 1 5 10 16 -1 res 90 none 0 edu 5 10 "medical discoveries"
13 "edu" l -1 -1 1 0 0 1 -1 edu 9 none 0 none 0 0 "a class of graduates"
14 "happy" l -1 -1 1 0 0 1 -1 hap 9 none 0 none 0 0 "happy strollers"
/config

View file

@ -508,7 +508,7 @@ show_product(int tlev)
int i;
char *lev;
pr("product cost raw materials reso dep level p.e.\n");
pr("product cost raw materials avail reso dep level p.e.\n");
for (pp = pchr; pp->p_sname; pp++) {
if (!pp->p_sname[0])
@ -525,6 +525,7 @@ show_product(int tlev)
else
pr(" ");
}
pr(" %8d", pp->p_bwork);
if (pp->p_nrndx)
pr(" %5.5s %3d ",
symbol_by_value(pp->p_nrndx, resources), pp->p_nrdep);

View file

@ -41,7 +41,7 @@
#include "prototypes.h"
#include "update.h"
static double prod_materials_cost(struct pchrstr *, short[], int *);
static double prod_materials_cost(struct pchrstr *, short[]);
static void materials_charge(struct pchrstr *, short *, double);
static double prod_resource_limit(struct pchrstr *, unsigned char *);
@ -99,17 +99,14 @@ prod_output(struct sctstr *sp, double prodeff)
else
resource = NULL;
material_limit = prod_materials_cost(product, sp->sct_item,
&unit_work);
material_limit = prod_materials_cost(product, sp->sct_item);
unit_work = product->p_bwork;
/* sector p.e. */
p_e = sp->sct_effic / 100.0;
if (resource) {
unit_work++;
p_e *= *resource / 100.0;
}
if (unit_work == 0)
unit_work = 1;
worker_limit = sp->sct_avail * p_e / unit_work;
res_limit = prod_resource_limit(product, resource);
@ -184,16 +181,14 @@ prod_output(struct sctstr *sp, double prodeff)
/*
* Return how much of product @pp can be made from materials @vec[].
* Store amount of work per unit in *@costp.
*/
static double
prod_materials_cost(struct pchrstr *pp, short vec[], int *costp)
prod_materials_cost(struct pchrstr *pp, short vec[])
{
double count, n;
int cost, i;
int i;
count = ITEM_MAX;
cost = 0;
for (i = 0; i < MAXPRCON; ++i) {
if (!pp->p_camt[i])
continue;
@ -202,9 +197,7 @@ prod_materials_cost(struct pchrstr *pp, short vec[], int *costp)
n = (double)vec[pp->p_ctype[i]] / pp->p_camt[i];
if (n < count)
count = n;
cost += pp->p_camt[i];
}
*costp = cost;
return count;
}

View file

@ -20,6 +20,7 @@ tests/empdump/xundump-errors/colhdr-miss:2: header 'camt(0)' ... 'camt(2)' missi
tests/empdump/xundump-errors/colhdr-miss:2: header 'nllag' missing
tests/empdump/xundump-errors/colhdr-miss2:21: header 'ctype(0)' ... 'ctype(2)' missing
tests/empdump/xundump-errors/colhdr-miss2:21: header 'camt(0)' ... 'camt(2)' missing
tests/empdump/xundump-errors/colhdr-miss2:21: header 'bwork' missing
tests/empdump/xundump-errors/colhdr-miss2:21: header 'type' missing
tests/empdump/xundump-errors/colhdr-miss2:21: header 'level' missing
tests/empdump/xundump-errors/colhdr-miss2:21: header 'cost' missing
@ -105,7 +106,7 @@ tests/empdump/xundump-errors/fld-sep:2: bad field separator after field 1
tests/empdump/xundump-errors/fld-strbig:3: field 19 takes at most 9 characters
tests/empdump/xundump-errors/fld-unexpid:6: table's first part doesn't have this row
tests/empdump/xundump-errors/fld-unexpid1:7: value for field 1 must be 2
tests/empdump/xundump-errors/fld-unksym:2: unknown level symbol 'xxx' in field 11
tests/empdump/xundump-errors/fld-unksym:2: unknown type symbol 'xxx' in field 11
tests/empdump/xundump-errors/fld-unparen:2: unmatched '(' in field 19
tests/empdump/xundump-errors/ftr-fewrows:2: expected 34 more rows
tests/empdump/xundump-errors/ftr-fewrows2:4: expected 13 more rows

View file

@ -1,5 +1,5 @@
config product
name sname ctype(0) ctype(1) type level cost nrndx nrdep nlndx nlmin
name sname ctype(0) ctype(1) bwork type level cost nrndx nrdep nlndx nlmin
# header 'uid' missing
# header 'ctype(2)' missing
# header 'camt(0)' ... 'camt(2)' missing

View file

@ -21,6 +21,7 @@ config product
name
# header 'ctype(0)' ... 'ctype(2)' missing
# header 'camt(0)' ... 'camt(2)' missing
# header 'bwork' missing
# header 'type' missing
# header 'level' missing
# header 'cost' missing

View file

@ -1,3 +1,3 @@
XDUMP product 1
0 "iron ore" "iron" 0 0 0 0 0 0 0 xxx
# unknown level symbol 'xxx' in field 11
# unknown type symbol 'xxx' in field 11

View file

@ -601,22 +601,22 @@
Play#0 output Play#0 6 0 640
Play#0 input show product
Play#0 command show
Play#0 output Play#0 1 product cost raw materials reso dep level p.e.
Play#0 output Play#0 1 iron i $0 min 0 1.0
Play#0 output Play#0 1 dust d $0 gold 20 1.0
Play#0 output Play#0 1 food f $0 fert 0 (tech+10)/(tech+20)
Play#0 output Play#0 1 oil o $0 ocont 10 (tech+10)/(tech+20)
Play#0 output Play#0 1 rad r $2 uran 35 (tech-40)/(tech-30)
Play#0 output Play#0 1 shells s $3 2l 1h (tech-20)/(tech-10)
Play#0 output Play#0 1 guns g $30 1o 5l 10h (tech-20)/(tech-10)
Play#0 output Play#0 1 petrol p $1 1o (tech-20)/(tech-10)
Play#0 output Play#0 1 bars b $10 5d 1.0
Play#0 output Play#0 1 lcm l $0 1i (tech+10)/(tech+20)
Play#0 output Play#0 1 hcm h $0 2i (tech+10)/(tech+20)
Play#0 output Play#0 1 tech $300 1d 5o 10l (educ-5)/(educ+5)
Play#0 output Play#0 1 medical $90 1d 5o 10l (educ-5)/(educ+5)
Play#0 output Play#0 1 edu $9 1l 1.0
Play#0 output Play#0 1 happy $9 1l 1.0
Play#0 output Play#0 1 product cost raw materials avail reso dep level p.e.
Play#0 output Play#0 1 iron i $0 1 min 0 1.0
Play#0 output Play#0 1 dust d $0 1 gold 20 1.0
Play#0 output Play#0 1 food f $0 1 fert 0 (tech+10)/(tech+20)
Play#0 output Play#0 1 oil o $0 1 ocont 10 (tech+10)/(tech+20)
Play#0 output Play#0 1 rad r $2 1 uran 35 (tech-40)/(tech-30)
Play#0 output Play#0 1 shells s $3 2l 1h 3 (tech-20)/(tech-10)
Play#0 output Play#0 1 guns g $30 1o 5l 10h 16 (tech-20)/(tech-10)
Play#0 output Play#0 1 petrol p $1 1o 1 (tech-20)/(tech-10)
Play#0 output Play#0 1 bars b $10 5d 5 1.0
Play#0 output Play#0 1 lcm l $0 1i 1 (tech+10)/(tech+20)
Play#0 output Play#0 1 hcm h $0 2i 2 (tech+10)/(tech+20)
Play#0 output Play#0 1 tech $300 1d 5o 10l 16 (educ-5)/(educ+5)
Play#0 output Play#0 1 medical $90 1d 5o 10l 16 (educ-5)/(educ+5)
Play#0 output Play#0 1 edu $9 1l 1 1.0
Play#0 output Play#0 1 happy $9 1l 1 1.0
Play#0 output Play#0 6 0 640
Play#0 input show news
Play#0 command show
@ -1235,6 +1235,7 @@
Play#0 output Play#0 1 "sname" 3 0 0 -1
Play#0 output Play#0 1 "ctype" 1 0 3 19
Play#0 output Play#0 1 "camt" 1 0 3 -1
Play#0 output Play#0 1 "bwork" 1 0 0 -1
Play#0 output Play#0 1 "type" 1 0 0 19
Play#0 output Play#0 1 "level" 1 0 0 34
Play#0 output Play#0 1 "cost" 1 0 0 -1
@ -1243,7 +1244,7 @@
Play#0 output Play#0 1 "nlndx" 1 0 0 34
Play#0 output Play#0 1 "nlmin" 1 0 0 -1
Play#0 output Play#0 1 "nllag" 1 0 0 -1
Play#0 output Play#0 1 /13
Play#0 output Play#0 1 /14
Play#0 output Play#0 6 0 640
Play#0 input xdump meta 21
Play#0 command xdump
@ -1816,21 +1817,21 @@
Play#0 input xdump product *
Play#0 command xdump
Play#0 output Play#0 1 XDUMP product 0
Play#0 output Play#0 1 0 "iron\\040ore" "iron" -1 -1 -1 0 0 0 5 -1 0 0 0 -1 0 0
Play#0 output Play#0 1 1 "gold\\040dust" "dust" -1 -1 -1 0 0 0 6 -1 0 0 20 -1 0 0
Play#0 output Play#0 1 2 "food" "food" -1 -1 -1 0 0 0 8 -1 0 0 0 0 -10 10
Play#0 output Play#0 1 3 "oil" "oil" -1 -1 -1 0 0 0 9 -1 0 0 10 0 -10 10
Play#0 output Play#0 1 4 "radioactive\\040materials" "rad" -1 -1 -1 0 0 0 13 -1 2 0 35 0 40 10
Play#0 output Play#0 1 5 "shells" "shells" 10 11 -1 2 1 0 2 -1 3 0 0 0 20 10
Play#0 output Play#0 1 6 "guns" "guns" 9 10 11 1 5 10 3 -1 30 0 0 0 20 10
Play#0 output Play#0 1 7 "petrol" "petrol" 9 -1 -1 1 0 0 4 -1 1 0 0 0 20 10
Play#0 output Play#0 1 8 "gold\\040bars" "bars" 6 -1 -1 5 0 0 7 -1 10 0 0 -1 0 0
Play#0 output Play#0 1 9 "light\\040construction\\040materials" "lcm" 5 -1 -1 1 0 0 10 -1 0 0 0 0 -10 10
Play#0 output Play#0 1 10 "heavy\\040construction\\040materials" "hcm" 5 -1 -1 2 0 0 11 -1 0 0 0 0 -10 10
Play#0 output Play#0 1 11 "technological\\040breakthroughs" "tech" 6 9 10 1 5 10 -1 0 300 0 0 2 5 10
Play#0 output Play#0 1 12 "medical\\040discoveries" "medical" 6 9 10 1 5 10 -1 1 90 0 0 2 5 10
Play#0 output Play#0 1 13 "a\\040class\\040of\\040graduates" "edu" 10 -1 -1 1 0 0 -1 2 9 0 0 -1 0 0
Play#0 output Play#0 1 14 "happy\\040strollers" "happy" 10 -1 -1 1 0 0 -1 3 9 0 0 -1 0 0
Play#0 output Play#0 1 0 "iron\\040ore" "iron" -1 -1 -1 0 0 0 1 5 -1 0 45 0 -1 0 0
Play#0 output Play#0 1 1 "gold\\040dust" "dust" -1 -1 -1 0 0 0 1 6 -1 0 46 20 -1 0 0
Play#0 output Play#0 1 2 "food" "food" -1 -1 -1 0 0 0 1 8 -1 0 47 0 0 -10 10
Play#0 output Play#0 1 3 "oil" "oil" -1 -1 -1 0 0 0 1 9 -1 0 48 10 0 -10 10
Play#0 output Play#0 1 4 "radioactive\\040materials" "rad" -1 -1 -1 0 0 0 1 13 -1 0 49 35 0 40 10
Play#0 output Play#0 1 5 "shells" "shells" 10 11 -1 2 1 0 3 2 -1 0 0 0 0 20 10
Play#0 output Play#0 1 6 "guns" "guns" 9 10 11 1 5 10 16 3 -1 0 0 0 0 20 10
Play#0 output Play#0 1 7 "petrol" "petrol" 9 -1 -1 1 0 0 1 4 -1 0 0 0 0 20 10
Play#0 output Play#0 1 8 "gold\\040bars" "bars" 6 -1 -1 5 0 0 5 7 -1 0 0 0 -1 0 0
Play#0 output Play#0 1 9 "light\\040construction\\040materials" "lcm" 5 -1 -1 1 0 0 1 10 -1 0 0 0 0 -10 10
Play#0 output Play#0 1 10 "heavy\\040construction\\040materials" "hcm" 5 -1 -1 2 0 0 2 11 -1 0 0 0 0 -10 10
Play#0 output Play#0 1 11 "technological\\040breakthroughs" "tech" 6 9 10 1 5 10 16 -1 0 0 0 0 2 5 10
Play#0 output Play#0 1 12 "medical\\040discoveries" "medical" 6 9 10 1 5 10 16 -1 1 0 0 0 2 5 10
Play#0 output Play#0 1 13 "a\\040class\\040of\\040graduates" "edu" 10 -1 -1 1 0 0 1 -1 2 0 0 0 -1 0 0
Play#0 output Play#0 1 14 "happy\\040strollers" "happy" 10 -1 -1 1 0 0 1 -1 3 0 0 0 -1 0 0
Play#0 output Play#0 1 /15
Play#0 output Play#0 6 0 640
Play#0 input xdump sect-chr *
@ -2532,21 +2533,21 @@
Play#1 input xdump product *
Play#1 command xdump
Play#1 output Play#1 1 XDUMP product 0
Play#1 output Play#1 1 0 "iron\\040ore" "iron" -1 -1 -1 0 0 0 5 -1 0 0 0 -1 0 0
Play#1 output Play#1 1 1 "gold\\040dust" "dust" -1 -1 -1 0 0 0 6 -1 0 0 20 -1 0 0
Play#1 output Play#1 1 2 "food" "food" -1 -1 -1 0 0 0 8 -1 0 0 0 0 -10 10
Play#1 output Play#1 1 3 "oil" "oil" -1 -1 -1 0 0 0 9 -1 0 0 10 0 -10 10
Play#1 output Play#1 1 4 "radioactive\\040materials" "rad" -1 -1 -1 0 0 0 13 -1 2 0 35 0 40 10
Play#1 output Play#1 1 5 "shells" "shells" 10 11 -1 2 1 0 2 -1 3 0 0 0 20 10
Play#1 output Play#1 1 6 "guns" "guns" 9 10 11 1 5 10 3 -1 30 0 0 0 20 10
Play#1 output Play#1 1 7 "petrol" "petrol" 9 -1 -1 1 0 0 4 -1 1 0 0 0 20 10
Play#1 output Play#1 1 8 "gold\\040bars" "bars" 6 -1 -1 5 0 0 7 -1 10 0 0 -1 0 0
Play#1 output Play#1 1 9 "light\\040construction\\040materials" "lcm" 5 -1 -1 1 0 0 10 -1 0 0 0 0 -10 10
Play#1 output Play#1 1 10 "heavy\\040construction\\040materials" "hcm" 5 -1 -1 2 0 0 11 -1 0 0 0 0 -10 10
Play#1 output Play#1 1 11 "technological\\040breakthroughs" "tech" 6 9 10 1 5 10 -1 0 300 0 0 2 5 10
Play#1 output Play#1 1 12 "medical\\040discoveries" "medical" 6 9 10 1 5 10 -1 1 90 0 0 2 5 10
Play#1 output Play#1 1 13 "a\\040class\\040of\\040graduates" "edu" 10 -1 -1 1 0 0 -1 2 9 0 0 -1 0 0
Play#1 output Play#1 1 14 "happy\\040strollers" "happy" 10 -1 -1 1 0 0 -1 3 9 0 0 -1 0 0
Play#1 output Play#1 1 0 "iron\\040ore" "iron" -1 -1 -1 0 0 0 1 5 -1 0 45 0 -1 0 0
Play#1 output Play#1 1 1 "gold\\040dust" "dust" -1 -1 -1 0 0 0 1 6 -1 0 46 20 -1 0 0
Play#1 output Play#1 1 2 "food" "food" -1 -1 -1 0 0 0 1 8 -1 0 47 0 0 -10 10
Play#1 output Play#1 1 3 "oil" "oil" -1 -1 -1 0 0 0 1 9 -1 0 48 10 0 -10 10
Play#1 output Play#1 1 4 "radioactive\\040materials" "rad" -1 -1 -1 0 0 0 1 13 -1 0 49 35 0 40 10
Play#1 output Play#1 1 5 "shells" "shells" 10 11 -1 2 1 0 3 2 -1 0 0 0 0 20 10
Play#1 output Play#1 1 6 "guns" "guns" 9 10 11 1 5 10 16 3 -1 0 0 0 0 20 10
Play#1 output Play#1 1 7 "petrol" "petrol" 9 -1 -1 1 0 0 1 4 -1 0 0 0 0 20 10
Play#1 output Play#1 1 8 "gold\\040bars" "bars" 6 -1 -1 5 0 0 5 7 -1 0 0 0 -1 0 0
Play#1 output Play#1 1 9 "light\\040construction\\040materials" "lcm" 5 -1 -1 1 0 0 1 10 -1 0 0 0 0 -10 10
Play#1 output Play#1 1 10 "heavy\\040construction\\040materials" "hcm" 5 -1 -1 2 0 0 2 11 -1 0 0 0 0 -10 10
Play#1 output Play#1 1 11 "technological\\040breakthroughs" "tech" 6 9 10 1 5 10 16 -1 0 0 0 0 2 5 10
Play#1 output Play#1 1 12 "medical\\040discoveries" "medical" 6 9 10 1 5 10 16 -1 1 0 0 0 2 5 10
Play#1 output Play#1 1 13 "a\\040class\\040of\\040graduates" "edu" 10 -1 -1 1 0 0 1 -1 2 0 0 0 -1 0 0
Play#1 output Play#1 1 14 "happy\\040strollers" "happy" 10 -1 -1 1 0 0 1 -1 3 0 0 0 -1 0 0
Play#1 output Play#1 1 /15
Play#1 output Play#1 6 0 0
Play#1 input xdump sect-chr *