config: Define infra build cost and mobility use per 100%

Infrastructure build cost is defined by infra column dcost (struct
sctintrins member in_dcost).  It's the cost per point of efficiency.
In contrast, sector and unit build cost is defined for 100%, by
sect-chr, ship-chr, plane-chr, land-chr, nuke-chr column cost.

Switch to build cost per 100%, for flexibility and consistency:
replace struct sctintrins member in_dcost by in_cost, and selector
dcost by cost.

With cost values that aren't multiple of 100, the build cost may have
to be rounded.  Do this exactly like we round sector build cost: the
amount is limited to money * 100 / cost rounded down, but the money
charged is actual amount * money / 100 rounded randomly.

Do the same for mobility use: replace struct sctintrins member
in_mcost by in_bmobil, and selector mcost by bmobil, with similar
rounding.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-08-17 20:00:02 +02:00
parent f9114aecd8
commit c8b51ec1a8
8 changed files with 42 additions and 43 deletions

View file

@ -218,8 +218,8 @@ struct sctintrins {
char *in_name; char *in_name;
unsigned char in_lcms; /* construction materials */ unsigned char in_lcms; /* construction materials */
unsigned char in_hcms; unsigned char in_hcms;
unsigned char in_dcost; /* dollars */ short in_bmobil; /* mobility to build 100% */
unsigned char in_mcost; /* mobility */ 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

@ -28,10 +28,12 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Steve McClure, 1996-2000 * Steve McClure, 1996-2000
* Markus Armbruster, 2004-2016
*/ */
#include <config.h> #include <config.h>
#include "chance.h"
#include "commands.h" #include "commands.h"
int int
@ -47,12 +49,10 @@ improve(void)
int type; int type;
int value; int value;
int ovalue; int ovalue;
int maxup; int maxup, lim;
struct natstr *natp; struct natstr *natp;
int lneeded; int lneeded;
int hneeded; int hneeded;
int mneeded;
int dneeded;
int wanted; int wanted;
p = getstarg(player->argp[1], p = getstarg(player->argp[1],
@ -124,33 +124,32 @@ improve(void)
continue; continue;
} }
} }
mneeded = incp->in_mcost * maxup;
if ((sect.sct_mobil - 1) < mneeded) { lim = (sect. sct_mobil - 1) * 100 / incp->in_bmobil;
mneeded = sect.sct_mobil - 1; if (lim <= 0) {
if (mneeded < 0)
mneeded = 0;
maxup = mneeded / incp->in_mcost;
if (maxup <= 0) {
pr("Not enough mobility in %s\n", pr("Not enough mobility in %s\n",
xyas(sect.sct_x, sect.sct_y, player->cnum)); xyas(sect.sct_x, sect.sct_y, player->cnum));
continue; continue;
} }
} if (maxup > lim)
dneeded = incp->in_dcost * maxup; maxup = lim;
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
if (player->dolcost + dneeded > natp->nat_money) { lim = (natp->nat_money - player->dolcost) * 100 / incp->in_cost;
if (lim <= 0) {
pr("Not enough money left to improve %s by %d%%\n", pr("Not enough money left to improve %s by %d%%\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), maxup); xyas(sect.sct_x, sect.sct_y, player->cnum), maxup);
break; break;
} }
if (maxup > lim)
maxup = lim;
lneeded = incp->in_lcms * maxup; lneeded = incp->in_lcms * maxup;
hneeded = incp->in_hcms * maxup; hneeded = incp->in_hcms * maxup;
mneeded = incp->in_mcost * maxup;
dneeded = incp->in_dcost * maxup;
player->dolcost += dneeded;
sect.sct_item[I_LCM] -= lneeded; sect.sct_item[I_LCM] -= lneeded;
sect.sct_item[I_HCM] -= hneeded; sect.sct_item[I_HCM] -= hneeded;
sect.sct_mobil -= mneeded; sect.sct_mobil -= roundavg(maxup * incp->in_bmobil / 100.0);
player->dolcost += maxup * incp->in_cost / 100.0;
ovalue = value; ovalue = value;
value += maxup; value += maxup;
if (CANT_HAPPEN(value > 100)) if (CANT_HAPPEN(value > 100))

View file

@ -690,8 +690,8 @@ struct castr intrchr_ca[] = {
CA_DUMP_CONST}, CA_DUMP_CONST},
{"lcms", fldoff(in_lcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, {"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}, {"hcms", fldoff(in_hcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
{"dcost", fldoff(in_dcost), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP}, {"bmobil", fldoff(in_bmobil), NSC_SHORT, 0, NULL, EF_BAD, 0, CA_DUMP},
{"mcost", fldoff(in_mcost), NSC_UCHAR, 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},
{NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP} {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
#undef CURSTR #undef CURSTR

View file

@ -27,7 +27,7 @@
# infra.config: Infrastructure characteristics # infra.config: Infrastructure characteristics
# #
# Known contributors to this file: # Known contributors to this file:
# Markus Armbruster, 2006-2011 # Markus Armbruster, 2006-2016
# #
# Derived from sect.c; known contributors: # Derived from sect.c; known contributors:
# Dave Pare, 1986 # Dave Pare, 1986
@ -45,8 +45,8 @@
# econfig key custom_tables. # econfig key custom_tables.
config infrastructure config infrastructure
name lcm hcm dcost mcost enab name lcm hcm bmob cost enab
"road network" 2 2 2 1 1 "road network" 2 2 100 200 1
"rail network" 1 1 1 1 1 "rail network" 1 1 100 100 1
"defense factor" 1 1 1 1 0 "defense factor" 1 1 100 100 0
/config /config

View file

@ -430,7 +430,7 @@ show_sect_build(int foo)
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_lcms * 100, intrchr[i].in_hcms * 100,
intrchr[i].in_mcost * 100, intrchr[i].in_dcost * 100); 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 dcost mcost enable name lcms hcms 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 dcost mcost enab name lcm hcm bmob cost enab
"road network" 2 2 2 1 1 "road network" 2 2 100 200 1
"rail network" 1 1 1 1 1 "rail network" 1 1 100 100 1
"defense factor" 1 1 1 1 0 "defense factor" 1 1 100 100 0
/con /con
# malformed table footer # malformed table footer

View file

@ -1196,8 +1196,8 @@
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 "lcms" 1 0 0 -1
Play#0 output Play#0 1 "hcms" 1 0 0 -1 Play#0 output Play#0 1 "hcms" 1 0 0 -1
Play#0 output Play#0 1 "dcost" 1 0 0 -1 Play#0 output Play#0 1 "bmobil" 1 0 0 -1
Play#0 output Play#0 1 "mcost" 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 /6
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
@ -1801,9 +1801,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 2 1 1 Play#0 output Play#0 1 "road\\040network" 2 2 100 200 1
Play#0 output Play#0 1 "rail\\040network" 1 1 1 1 0 Play#0 output Play#0 1 "rail\\040network" 1 1 100 100 0
Play#0 output Play#0 1 "defense\\040factor" 1 1 1 1 0 Play#0 output Play#0 1 "defense\\040factor" 1 1 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 +2451,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 2 1 1 Play#1 output Play#1 1 "road\\040network" 2 2 100 200 1
Play#1 output Play#1 1 "rail\\040network" 1 1 1 1 0 Play#1 output Play#1 1 "rail\\040network" 1 1 100 100 0
Play#1 output Play#1 1 "defense\\040factor" 1 1 1 1 0 Play#1 output Play#1 1 "defense\\040factor" 1 1 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 *