]> git.pond.sub.org Git - empserver/commitdiff
(new_work, do_feed, prod, newe): Factor out calculation of work into
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 10 May 2004 20:30:38 +0000 (20:30 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 10 May 2004 20:30:38 +0000 (20:30 +0000)
new_work().

(ROLLOVER_AVAIL, opt_ROLLOVER_AVAIL, opt_ROLLOVER_AVAIL, Options,
rollover_avail_max, configkeys, vers, new_work): Replace option
ROLLOVER_AVAIL by configuration parameter rollover_avail_max.

include/optlist.h
include/prototypes.h
src/lib/commands/newe.c
src/lib/commands/prod.c
src/lib/commands/vers.c
src/lib/gen/emp_config.c
src/lib/global/constants.c
src/lib/global/options.c
src/lib/update/human.c

index 6dde076f172b90229fdb7ce250aa0c5c3f674dc4..3b91c15bf77a2e8c0357199febff731f8780edd2 100644 (file)
@@ -177,6 +177,7 @@ extern double eatrate;
 extern double fcrate;
 extern double fgrate;
 extern double obrate;
+extern int rollover_avail_max;
 extern double decay_per_etu;
 extern double fallout_spread;
 extern float drnuke_const;
index 7def4d6f58088db8044c3fe5d3d8019f72c26db0..da972dac93199f9fd4cc5a4d38b2fbad8a285125 100644 (file)
@@ -551,6 +551,7 @@ extern int dodistribute(struct sctstr *, int, s_char *, double, double);
 /* finish.c */
 extern void finish_sects(int);
 /* human.c */
+extern int new_work(struct sctstr *, int);
 extern int do_feed(register struct sctstr *, register struct natstr *,
                   short *, int *, int *, int);
 extern int feed_people(short *, int, int *);
index a13735f71ca0b0f194598ba438292b3dc1bcbfb5..fa6cfc926658f03cca19167afcfe0611c14df386 100644 (file)
@@ -82,14 +82,7 @@ newe(void)
            wforce = (int)((civs * sect.sct_work) / 100.0
                           + uws + sect.sct_item[I_MILIT] * 2 / 5.0);
 
-           work = etu_per_update * wforce / 100.0;
-           if (opt_ROLLOVER_AVAIL) {
-               if (sect.sct_type == sect.sct_newtype) {
-                   work += sect.sct_avail;
-               }
-               if (work > 999) work = 999;
-           }
-
+           work = new_work(&sect, wforce * etu_per_update / 100);
            bwork = work / 2;
 
            type = sect.sct_type;
index d2fbc75474088c9968be25b6ddb85087dd39fb0c..b25266fb037d7248264124913e3149cc279d0d7c 100644 (file)
@@ -134,13 +134,7 @@ prod(void)
        wforce = (int)(((double)civs * sect.sct_work) / 100.0
                       + uws
                       + sect.sct_item[I_MILIT] * 2.0 / 5.0);
-       work = (double)etu_per_update *(double)wforce / 100.0;
-       if (opt_ROLLOVER_AVAIL) {
-           if (sect.sct_type == sect.sct_newtype) {
-               work += sect.sct_avail;
-           }
-           if (work > 999) work = 999;
-       }
+       work = new_work(&sect, wforce * etu_per_update / 100);
        bwork = work / 2;
 
        if (sect.sct_off)
index 2acbd8261235b205c3c4ce4ca22025f6240c3a26..34cea2d92be3b93c17e4439eb514992bfce51ada 100644 (file)
@@ -95,6 +95,8 @@ vers(void)
     pr("1000 civilians generate $%.2f, uncompensated workers $%.2f each time unit.\n", 1000.0 * money_civ, 1000.0 * money_uw);
     pr("1000 active military cost $%.2f, reserves cost $%.2f.\n",
        -money_mil * 1000.0, -money_res * 1000.0);
+    if (rollover_avail_max)
+       pr("Up to %d avail can roll over an update.\n", rollover_avail_max);
     if (opt_SLOW_WAR)
        pr("Declaring war will cost you $%i\n\n", War_Cost);
     pr("Happiness p.e. requires 1 happy stroller per %d civ.\n",
index e6e0561b091280af7bed59daaf45a63b5a882eaa..dfc46c78d461ca2a9d9c5febf54a3768860013d0 100644 (file)
@@ -285,6 +285,8 @@ struct keymatch configkeys[] = {
      "Food growth rate (* fertility of sector)"},
     {"obrate", doubleset, (caddr_t)&obrate, 0,
      "Civilian birth rate"},
+    {"rollover_avail_max", intset, (caddr_t)&rollover_avail_max, 0,
+     "Maximum avail that can roll over an update"},
 
     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Nukes"},
     {"decay_per_etu", doubleset, (caddr_t)&decay_per_etu, 0,
index fc6a7c03e97889c84fdf37b55b7013c13ceff8ca..5b721e72c3cddbf56ae7aa800cb31d6a23b9f004 100644 (file)
@@ -119,6 +119,7 @@ double babyeat = 0.0060;    /* food to mature 1 baby into a civilian */
 double obrate = 0.005;         /* other sectors birth rate */
 double uwbrate = 0.0025;       /* uncompensated worker birth rate */
                                /* values > 0.25 for either will overflow */
+int rollover_avail_max = 0;    /* max. avail that can roll over an update */
 
 /* opt_FALLOUT */
 /* these are the radioactive decay constants */
index d8dba9f5a52549ca3d82c411db51978ce4ed550c..4eaf980812d7720c9e2289a2c268632b73e4f602 100644 (file)
@@ -297,12 +297,6 @@ int opt_TECH_POP = 1;
 int opt_TECH_POP = 0;
 #endif
 
-#ifdef ROLLOVER_AVAIL
-int opt_ROLLOVER_AVAIL = 1;
-#else
-int opt_ROLLOVER_AVAIL = 0;
-#endif
-
 struct option_list Options[] = {
     {"ALL_BLEED", &opt_ALL_BLEED},
     {"BIG_CITY", &opt_BIG_CITY},
@@ -337,7 +331,6 @@ struct option_list Options[] = {
     {"PINPOINTMISSILE", &opt_PINPOINTMISSILE},
     {"PLANENAMES", &opt_PLANENAMES},
     {"RES_POP", &opt_RES_POP},
-    {"ROLLOVER_AVAIL", &opt_ROLLOVER_AVAIL},
     {"SAIL", &opt_SAIL},
     {"SHIPNAMES", &opt_SHIPNAMES},
     {"SHOWPLANE", &opt_SHOWPLANE},
index 5c4cda1600c76e5750b3d91813293c8152876262..62ba92990ff54ecf02f0b40ed8f00af6a1e78baa 100644 (file)
@@ -80,12 +80,7 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
     civvies = (vec[I_CIVIL] > maxpop) ? maxpop : vec[I_CIVIL];
     uws = (vec[I_UW] > maxpop) ? maxpop : vec[I_UW];
     mil = (vec[I_MILIT] > maxpop) ? maxpop : vec[I_MILIT];
-    work_avail = total_work(sctwork, etu, civvies, mil, uws);
-    if (opt_ROLLOVER_AVAIL) {
-       if (sp->sct_type == sp->sct_newtype) {
-           work_avail += sp->sct_avail;
-       }
-    }
+    work_avail = new_work(sp, total_work(sctwork, etu, civvies, mil, uws));
 
     people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
     if (sp->sct_type != SCT_SANCT) {
@@ -149,6 +144,15 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
     return sctwork;
 }
 
+int
+new_work(struct sctstr *sp, int delta)
+{
+    if (sp->sct_type == sp->sct_newtype)
+       return min(rollover_avail_max, sp->sct_avail) + delta;
+
+    return delta;
+}
+
 static int
 growfood(struct sctstr *sp, short *vec, int work, int etu)
 {