]> git.pond.sub.org Git - empserver/commitdiff
update neweff production: Limit work in big cities
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 1 Jun 2016 19:35:24 +0000 (21:35 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 17:59:56 +0000 (19:59 +0200)
Civilians, military and uw work only up to their sector's population
limit.  The population limit depends on the sector type's maximum
population, research if RES_POP is enabled, and the sector's
efficiency for big cities.

The population limit may decrease between computation of work in
do_feed() and the end of the update:

* Research declines (only relevant with RES_POP).  Work is not
  corrected.  The declined research will apply at the next update.

  Since levels age after production is done, any work corrections
  could only affect leftover available work.  Wouldn't make sense.

  The effect is negligible anyway.  Even with an insanely fast decline
  of 60% (level_age_rate = 1, etu_per_update = 60), the population
  limit decreases by less than 10% in the worst case.

* upd_buildeff() changes sector type and efficiency.  Work is
  corrected only when this changes the sector type from big city to
  not big city.

  It isn't corrected on other sector type changes.  These can affect
  maximum population since the sector type's maximum became
  configurable in commit 153527a (v4.2.20).  Sane configurations don't
  let players redesignate sectors to a type with different maximum
  population.  The server doesn't enforce this, though.

  It isn't corrected when a big city's efficiency decreases, but
  sector type change isn't achieved.  Harmless, because tearing down a
  city takes very little work (25 for 100%), so efficiency decrease
  without type change means the work we have must be safely below any
  sane population limit's work.

Good enough.  However, the code implementing the work correction for
big cities is unclean.  Get rid of it by tweaking the rules: a big
city's extra population does not work.  City slickers, tsk, tsk, tsk.
At least they still pay their taxes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/prototypes.h
src/lib/commands/newe.c
src/lib/commands/prod.c
src/lib/common/res_pop.c
src/lib/update/human.c
src/lib/update/populace.c
src/lib/update/sect.c
tests/update/final.xdump
tests/update/journal.log

index 389f30664873606feb900ffc9fd48522fd4a0e9f..600e321f1301c8ee0d6e4b27b5f56c1851e632af 100644 (file)
@@ -270,6 +270,7 @@ extern int read_schedule(char *, time_t[], int, time_t, time_t);
 /* res_pop.c */
 extern int max_population(float, int, int);
 extern int max_pop(float, struct sctstr *);
+extern int max_workers(float, struct sctstr *);
 /* stmtch.c */
 /* in match.h */
 /* type.c */
index 6951e25ea88a9383c83b1d20c366bef798c4eb26..04cc24a6b8c7305bc6a62129f769c82de26e31a7 100644 (file)
@@ -28,6 +28,7 @@
  *
  *  Known contributors to this file:
  *     Thomas Ruschak, 1993
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -50,7 +51,7 @@ newe(void)
     int twork;
     int type;
     int eff;
-    int maxpop;
+    int maxworkers;
 
     if (!snxtsct(&nstr, player->argp[1]))
        return RET_SYN;
@@ -64,11 +65,11 @@ newe(void)
            civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
            uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
            natp = getnatp(sect.sct_own);
-           maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
+           maxworkers = max_workers(natp->nat_level[NAT_RLEV], &sect);
            work = new_work(&sect,
                            total_work(sect.sct_work, etu_per_update,
                                       civs, sect.sct_item[I_MILIT], uws,
-                                      maxpop));
+                                      maxworkers));
            bwork = work / 2;
 
            type = sect.sct_type;
index 0b1d546946080c11083ddf8569c3d00fcd129c51..2f5527100d3f451f309133d4706b3d3bfd882587 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     David Muir Sharnoff, 1987
  *     Steve McClure, 1997-2000
- *     Markus Armbruster, 2004-2013
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -95,8 +95,7 @@ prod(void)
     int twork;
     int type;
     int eff;
-    int maxpop;
-    int otype;
+    int maxworkers;
     char mnem;
 
     if (!snxtsct(&nstr, player->argp[1]))
@@ -111,12 +110,12 @@ prod(void)
        civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
        uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
        natp = getnatp(sect.sct_own);
-       maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
+       maxworkers = max_workers(natp->nat_level[NAT_RLEV], &sect);
 
        work = new_work(&sect,
                        total_work(sect.sct_work, etu_per_update,
                                   civs, sect.sct_item[I_MILIT], uws,
-                                  maxpop));
+                                  maxworkers));
        bwork = work / 2;
 
        if (sect.sct_off)
@@ -130,20 +129,10 @@ prod(void)
            }
            bwork -= twork;
            eff -= twork * 4;
-           otype = type;
            if (eff <= 0) {
                type = sect.sct_newtype;
                eff = 0;
            }
-           if (!eff && IS_BIG_CITY(otype) && !IS_BIG_CITY(type)) {
-               maxpop = max_population(natp->nat_level[NAT_RLEV],
-                                       type, eff);
-               work = new_work(&sect,
-                               total_work(sect.sct_work, etu_per_update,
-                                          civs, sect.sct_item[I_MILIT],
-                                          uws, maxpop));
-               bwork = MIN(work / 2, bwork);
-           }
            twork = 100 - eff;
            if (twork > bwork) {
                twork = bwork;
@@ -175,6 +164,7 @@ prod(void)
            continue;
 
        if (type == SCT_ENLIST) {
+           int maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
            int maxmil;
            int enlisted;
 
index 91fcb89f5d1d52191063ce5a707e782d3fdb1595..4034965af115b4d85b4d0b88f29f8969203c3970 100644 (file)
@@ -29,6 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2005-2016
  */
 
 #include <config.h>
@@ -71,3 +72,9 @@ max_pop(float research, struct sctstr *sp)
 {
     return max_population(research, sp->sct_type, sp->sct_effic);
 }
+
+int
+max_workers(float research, struct sctstr *sp)
+{
+    return max_population(research, sp->sct_type, 0);
+}
index 8f606e87229ab96a0efb17babd7929d16ffdd30c..5acb18cc594ce71f8ad38d836481585c28919da6 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1996
- *     Markus Armbruster, 2004-2012
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -59,17 +59,17 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
     int work_avail;
     int starved, sctwork;
     int needed;
-    int maxpop;
+    int maxworkers;
     int manna;
 
     /* grow people & stuff */
     sctwork = sp->sct_work;
 
-    maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
+    maxworkers = max_workers(np->nat_level[NAT_RLEV], sp);
     work_avail = new_work(sp,
                          total_work(sctwork, etu,
                                     vec[I_CIVIL], vec[I_MILIT], vec[I_UW],
-                                    maxpop));
+                                    maxworkers));
 
     if (sp->sct_type != SCT_SANCT) {
        manna = 0;
index 0f3e2afcb2ce79f39c2fda5ffb07a6dfd041ef4f..04c501bb8f471e85e356bce77f7a88e8d296c52a 100644 (file)
@@ -115,14 +115,15 @@ populace(struct natstr *np, struct sctstr *sp, int etu)
 }
 
 int
-total_work(int sctwork, int etu, int civil, int milit, int uw, int maxpop)
+total_work(int sctwork, int etu, int civil, int milit, int uw,
+          int maxworkers)
 {
-    if (civil > maxpop)
-       civil = maxpop;
-    if (milit > maxpop)
-       milit = maxpop;
-    if (uw > maxpop)
-       uw = maxpop;
+    if (civil > maxworkers)
+       civil = maxworkers;
+    if (milit > maxworkers)
+       milit = maxworkers;
+    if (uw > maxworkers)
+       uw = maxworkers;
 
     return (civil * sctwork / 100.0 + milit / 2.5 + uw) * etu / 100.0;
 }
index 4251e65bf74428b8a0d95663831644e1c9ffe6c1..1249cf22aaa464cb55bd4c03f3ddb6c5d3df7c18 100644 (file)
@@ -51,7 +51,7 @@
  */
 static int
 upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
-            short *vec, int etu, int *desig, int sctwork, int *cost)
+            short *vec, int etu, int *desig, int *cost)
 {
     int work_cost = 0;
     int buildeff_work = *workp / 2;
@@ -78,17 +78,12 @@ upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
        neweff = n;
        *cost += work_cost;
        if (!n && IS_BIG_CITY(old_type) && !IS_BIG_CITY(*desig)) {
-           /* FIXME use trunc_people() and total_work() */
+           /* FIXME use trunc_people() */
            int maxpop = max_population(np->nat_level[NAT_RLEV], *desig, n);
            if (vec[I_CIVIL] > maxpop)
                vec[I_CIVIL] = maxpop;
            if (vec[I_UW] > maxpop)
                vec[I_UW] = maxpop;
-           *workp = (vec[I_CIVIL] * sctwork) / 100.0
-               + (vec[I_MILIT] * 2 / 5.0) + vec[I_UW];
-           *workp = roundavg((etu * *workp) / 100.0);
-
-           buildeff_work = MIN((int)(*workp / 2), buildeff_work);
        }
     }
     if (*desig == sp->sct_newtype) {
@@ -262,7 +257,7 @@ produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2])
     struct natstr *np;
     short buf[I_MAX + 1];
     short *vec;
-    int work, cost, ecost, pcost, sctwork;
+    int work, cost, ecost, pcost;
     int n, desig, neweff, amount;
 
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
@@ -307,7 +302,7 @@ produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2])
        sp->sct_updated = 1;
        work = 0;
 
-       sctwork = do_feed(sp, np, vec, &work, etu);
+       do_feed(sp, np, vec, &work, etu);
        bp_put_items(bp, sp, vec);
 
        if (sp->sct_off || np->nat_money < 0)
@@ -329,8 +324,7 @@ produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2])
 
        if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
            np->nat_money >= 0) {
-           neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
-                                 &cost);
+           neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, &cost);
            bp_put_items(bp, sp, vec);
            p_sect[SCT_EFFIC][0]++;
            p_sect[SCT_EFFIC][1] += cost;
index 16b8e98d679c5872abb10ddf53ec4e21bd4a1ad9..c950c1abf492fcc00bc276642c0f4ce6ead4c02c 100644 (file)
@@ -259,7 +259,7 @@ owner xloc yloc des effic mobil off loyal terr0 terr1 terr2 terr3 dterr xdist yd
 4 -6 -2 4 39 120 0 0 0 0 0 0 0 -6 -2 39 0 100 0 4 0 0 0 0 0 4 130 0 0 0 0 0 0 0 97 0 0 0 0 0 0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0 0 0 healthy 0 0 0 0 0 0 0 0
 3 7 -1 4 39 120 0 0 0 0 0 0 0 7 -1 39 0 100 0 4 0 0 0 0 0 3 130 0 0 0 0 0 0 0 96 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
index 200259a601d7ff0618d054f7c93e6ac4453be4b7..cd036c9849cdeaf407b8789d441853f1af137569 100644 (file)
     Play#0 output Play#0 1   3   10,-2   w   14%     120 .. ..      130    0    0   97 100%   39    0
     Play#0 output Play#0 1   3   12,-2   -   39%     120 .. ..      130    0    0   97 100%   39    0
     Play#0 output Play#0 1   3   14,-2   -   39%     120 .. ..      130    0    0   96 100%   39    0   1
-    Play#0 output Play#0 1   3    1,-1   c  100%     120 .. ..     9999    0    0  100 100% 5999    0
+    Play#0 output Play#0 1   3    1,-1   c  100%     120 .. ..     9999    0    0  100 100%  600    0
     Play#0 output Play#0 1   3    3,-1   -   39%     120 .. ..      130    0    0   97 100%   39    0
     Play#0 output Play#0 1   3    5,-1   u  100%     120 .. ..      130    0    0   96 100%    0    0
     Play#0 output Play#0 1   3    7,-1   -   39%     120 .. ..      130    0    0   96 100%   39    0