From 7f4e59fb8d147fb4a5670df69e1c73daa6595269 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 10 May 2004 20:30:38 +0000 Subject: [PATCH] (new_work, do_feed, prod, newe): Factor out calculation of work into 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 | 1 + include/prototypes.h | 1 + src/lib/commands/newe.c | 9 +-------- src/lib/commands/prod.c | 8 +------- src/lib/commands/vers.c | 2 ++ src/lib/gen/emp_config.c | 2 ++ src/lib/global/constants.c | 1 + src/lib/global/options.c | 7 ------- src/lib/update/human.c | 16 ++++++++++------ 9 files changed, 19 insertions(+), 28 deletions(-) diff --git a/include/optlist.h b/include/optlist.h index 6dde076f..3b91c15b 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -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; diff --git a/include/prototypes.h b/include/prototypes.h index 7def4d6f..da972dac 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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 *); diff --git a/src/lib/commands/newe.c b/src/lib/commands/newe.c index a13735f7..fa6cfc92 100644 --- a/src/lib/commands/newe.c +++ b/src/lib/commands/newe.c @@ -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(§, wforce * etu_per_update / 100); bwork = work / 2; type = sect.sct_type; diff --git a/src/lib/commands/prod.c b/src/lib/commands/prod.c index d2fbc754..b25266fb 100644 --- a/src/lib/commands/prod.c +++ b/src/lib/commands/prod.c @@ -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(§, wforce * etu_per_update / 100); bwork = work / 2; if (sect.sct_off) diff --git a/src/lib/commands/vers.c b/src/lib/commands/vers.c index 2acbd826..34cea2d9 100644 --- a/src/lib/commands/vers.c +++ b/src/lib/commands/vers.c @@ -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", diff --git a/src/lib/gen/emp_config.c b/src/lib/gen/emp_config.c index e6e0561b..dfc46c78 100644 --- a/src/lib/gen/emp_config.c +++ b/src/lib/gen/emp_config.c @@ -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, diff --git a/src/lib/global/constants.c b/src/lib/global/constants.c index fc6a7c03..5b721e72 100644 --- a/src/lib/global/constants.c +++ b/src/lib/global/constants.c @@ -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 */ diff --git a/src/lib/global/options.c b/src/lib/global/options.c index d8dba9f5..4eaf9808 100644 --- a/src/lib/global/options.c +++ b/src/lib/global/options.c @@ -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}, diff --git a/src/lib/update/human.c b/src/lib/update/human.c index 5c4cda16..62ba9299 100644 --- a/src/lib/update/human.c +++ b/src/lib/update/human.c @@ -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) {