update: Saner rounding of sector building money and work

buildeff() rounds work and money up.  Until recently, fractions could
only occur on tear-down, but with customized costs they can now also
occur on build-up.

The previous commit changed unit building to round money and work
randomly.  Before, money was rounded down, and work was rounded up.

Round them randomly for sectors as well, for consistency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-07 21:10:18 +02:00
parent ae2ae938b5
commit 8b1cc6cb47
6 changed files with 466 additions and 466 deletions

View file

@ -44,15 +44,15 @@
#include "ship.h"
#include "update.h"
int
double
buildeff(struct sctstr *sp)
{
int avail = sp->sct_avail / 2 * 100;
int cost;
double cost;
int delta, build;
struct dchrstr *dcp;
cost = 0;
cost = 0.0;
if (sp->sct_type != sp->sct_newtype) {
/*
@ -68,8 +68,8 @@ buildeff(struct sctstr *sp)
sp->sct_effic = 0;
sp->sct_type = sp->sct_newtype;
}
avail -= (build + 3) / 4 * dcp->d_bwork;
cost += (build + 3) / 4;
avail -= roundavg(build / 4.0 * dcp->d_bwork);
cost += build / 4.0;
}
if (sp->sct_type == sp->sct_newtype) {
@ -80,7 +80,7 @@ buildeff(struct sctstr *sp)
build = get_materials(sp, dcp->d_mat, delta);
sp->sct_effic += build;
avail -= build * dcp->d_bwork;
cost += (build * dcp->d_cost + 99) / 100;
cost += build * dcp->d_cost / 100.0;
}
sp->sct_avail = (sp->sct_avail + 1) / 2 + avail / 100;
@ -270,7 +270,7 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2])
if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
np->nat_money >= 0) {
cost = buildeff(sp);
cost = roundavg(buildeff(sp));
p_sect[SCT_EFFIC][0]++;
p_sect[SCT_EFFIC][1] += cost;
if (!player->simulation)