Avoid double rounding materials when limiting products made
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 4 May 2013 15:54:37 +0000 (17:54 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 8 May 2013 04:57:58 +0000 (06:57 +0200)
We can make actual = roundavg(material_consume * prodeff) products.

When we reduce actual, we have to reduce material_consume, too.  Code
does that like this:

    material_consume = roundavg(actual' * material_consume / actual)

Double rounding.  Do this instead:

    material_consume = roundavg(actual' / prodeff)

src/lib/update/produce.c

index 1c09415376151f6b490de9ba7c691607e3d05023..e136d271e02ab4398a0eddd17a5487ff29e05161 100644 (file)
@@ -122,15 +122,14 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
        if (actual <= 0)
            return 0;
        if (actual > 999) {
-           material_consume = roundavg(999.0 * material_consume / actual);
            actual = 999;
+           material_consume = roundavg(actual / prodeff);
        }
        if (vec[item] + actual > ITEM_MAX) {
-           material_consume = roundavg((double)(ITEM_MAX - vec[item])
-                                       * material_consume / actual);
+           actual = ITEM_MAX - vec[item];
+           material_consume = roundavg(actual / prodeff);
            if (material_consume < 0)
                material_consume = 0;
-           actual = ITEM_MAX - vec[item];
            if (sp->sct_own && !player->simulation)
                wu(0, sp->sct_own,
                   "%s production backlog in %s\n",