neweff production work: Fix crash for sea sector

The work required for building sea sectors is zero in sect.config.
When a deity runs neweff or production on a sea sector, e.g. with
"neweff *", buildeff() divides by zero.  Same when a player or deity
runs work with an engineer in a sea sector.  Broken in commit
2ffd7b948 "config: Make work to build sectors configurable", v4.4.0

Fix buildeff() to avoid the division.  Change the required work to 100
in sect.config for good measure.

Cover deity use of neweff and production in tests/update.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2021-01-15 07:47:59 +01:00
parent 88bd68b88b
commit 589bc1ed1a
6 changed files with 1108 additions and 5 deletions

View file

@ -65,7 +65,7 @@
config sect-chr
uid mnem prd peff l_b h_b bwork cost maint name ...
0 "." -1 0 0 0 0 0 0 "sea"
0 "." -1 0 0 0 100 0 0 "sea"
1 "^" dust 100 0 0 100 100 0 "mountain"
2 "s" -1 0 0 0 100 0 0 "sanctuary"
3 "\134" -1 0 0 0 100 0 0 "wasteland"

View file

@ -58,7 +58,7 @@ buildeff(struct sctstr *sp)
* Easier to destroy than to build.
*/
dcp = &dchr[sp->sct_type];
build = 4 * avail / dcp->d_bwork;
build = dcp->d_bwork > 0 ? 4 * avail / dcp->d_bwork : 100;
if (build <= sp->sct_effic)
sp->sct_effic -= build;
else {
@ -72,7 +72,7 @@ buildeff(struct sctstr *sp)
if (sp->sct_type == sp->sct_newtype) {
dcp = &dchr[sp->sct_type];
delta = avail / dcp->d_bwork;
delta = dcp->d_bwork > 0 ? avail / dcp->d_bwork : 100;
if (delta > 100 - sp->sct_effic)
delta = 100 - sp->sct_effic;
build = get_materials(sp, dcp->d_mat, delta);

View file

@ -2,6 +2,7 @@ budget
| Note: f1#100 not actually built (plague kills off mil)
| TODO is it accurate?
neweff * ?newd#-
| TODO is it accurate?
production *
| TODO is it accurate?
starvation

View file

@ -1,3 +1,8 @@
production *
| TODO is it accurate?
neweff *
| TODO is it accurate?
__cmd added 2 0 0
force
show updates
power

File diff suppressed because it is too large Load diff

View file

@ -1837,7 +1837,7 @@
Play#0 input xdump sect-chr *
Play#0 command xdump
Play#0 output Play#0 1 XDUMP sect-chr 0
Play#0 output Play#0 1 0 "sea" "." 0 -1 0 -1.00000 -1.00000 1 1 0.00000 0.00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Play#0 output Play#0 1 0 "sea" "." 0 -1 0 -1.00000 -1.00000 1 1 0.00000 0.00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 1
Play#0 output Play#0 1 1 "mountain" "^" 1 1 100 2.40000 1.20000 0 1 1.00000 4.00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 100 0 100 1
Play#0 output Play#0 1 2 "sanctuary" "s" 4 -1 0 -1.00000 -1.00000 0 1 0.00000 99.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 1000 1
Play#0 output Play#0 1 3 "wasteland" "\\134" 3 -1 0 -1.00000 -1.00000 0 1 0.00000 99.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 1
@ -2553,7 +2553,7 @@
Play#1 input xdump sect-chr *
Play#1 command xdump
Play#1 output Play#1 1 XDUMP sect-chr 0
Play#1 output Play#1 1 0 "sea" "." 0 -1 0 -1.00000 -1.00000 1 1 0.00000 0.00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Play#1 output Play#1 1 0 "sea" "." 0 -1 0 -1.00000 -1.00000 1 1 0.00000 0.00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 1
Play#1 output Play#1 1 1 "mountain" "^" 1 1 100 2.40000 1.20000 0 1 1.00000 4.00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 100 0 100 1
Play#1 output Play#1 1 2 "sanctuary" "s" 4 -1 0 -1.00000 -1.00000 0 1 0.00000 99.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 1000 1
Play#1 output Play#1 1 3 "wasteland" "\\134" 3 -1 0 -1.00000 -1.00000 0 1 0.00000 99.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 1