From ff67d93711a99187fc28ce247c29c6250362161a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Feb 2005 21:04:08 +0000 Subject: [PATCH] (max_population): New, factored out of max_pop(). (max_pop): Use it. Don't support null argument anymore. (nati, gen_power): Use max_population() instead of max_pop() with null argument. (show_sect_stats): Use max_population() to simplify the code. (prod, upd_buildeff): Use max_population() to get correct new maximum population for limiting work when tearing down a big city. Previously, this was broken in upd_buildeff(). In prod(), it was broken when the new designation had odd maximum population, which should not occur. --- include/prototypes.h | 1 + src/lib/commands/nati.c | 2 +- src/lib/commands/powe.c | 2 +- src/lib/commands/prod.c | 6 ++++-- src/lib/common/res_pop.c | 15 +++++++++++---- src/lib/subs/show.c | 6 +----- src/lib/update/sect.c | 2 +- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index b084a08d..5caf8404 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -330,6 +330,7 @@ extern s_char *BestShipPath(s_char *, int, int, int, int, int); extern s_char *BestAirPath(s_char *, int, int, int, int); extern double pathcost(struct sctstr *, s_char *, int); /* res_pop.c */ +extern int max_population(float, int, int); extern int max_pop(float, struct sctstr *); /* sectdamage.c */ extern int sect_damage(struct sctstr *, int, struct emp_qelem *); diff --git a/src/lib/commands/nati.c b/src/lib/commands/nati.c index 7f6b88b4..b63c3db9 100644 --- a/src/lib/commands/nati.c +++ b/src/lib/commands/nati.c @@ -95,7 +95,7 @@ nati(void) pr(" Plague factor : %6.2f%%\n", pfac); pr("\n"); - poplimit = max_pop(natp->nat_level[NAT_RLEV], 0); + poplimit = max_population(natp->nat_level[NAT_RLEV], SCT_MINE, 0); pr("Max population : %d\n", poplimit); safepop = diff --git a/src/lib/commands/powe.c b/src/lib/commands/powe.c index bf8cab64..834f718d 100644 --- a/src/lib/commands/powe.c +++ b/src/lib/commands/powe.c @@ -329,7 +329,7 @@ gen_power(void) if (opt_RES_POP) { np = getnatp(i); - maxpop = max_pop(np->nat_level[NAT_RLEV], 0); + maxpop = max_population(np->nat_level[NAT_RLEV], SCT_MINE, 0); f = 1.0 + (((float)maxpop) / 10000.0); } powbuf[i].p_power *= f; diff --git a/src/lib/commands/prod.c b/src/lib/commands/prod.c index f022bccd..16494b39 100644 --- a/src/lib/commands/prod.c +++ b/src/lib/commands/prod.c @@ -144,8 +144,10 @@ prod(void) if (!eff && dchr[otype].d_pkg == UPKG && dchr[type].d_pkg != UPKG) { natp = getnatp(sect.sct_own); - civs = min(civs, max_pop(natp->nat_level[NAT_RLEV], 0)); - uws = min(uws, max_pop(natp->nat_level[NAT_RLEV], 0)); + maxpop = max_population(natp->nat_level[NAT_RLEV], + type, eff); + civs = min(civs, maxpop); + uws = min(uws, maxpop); wforce = (int)(((double)civs * sect.sct_work) / 100.0 + uws + sect.sct_item[I_MILIT] * 2 / 5.0); diff --git a/src/lib/common/res_pop.c b/src/lib/common/res_pop.c index 5b3428f6..298c8ea6 100644 --- a/src/lib/common/res_pop.c +++ b/src/lib/common/res_pop.c @@ -41,9 +41,9 @@ #include "common.h" int -max_pop(float research, struct sctstr *sp) +max_population(float research, int desig, int eff) { - int maxpop = dchr[sp ? sp->sct_type : SCT_MINE].d_maxpop; + int maxpop = dchr[desig].d_maxpop; if (opt_RES_POP) { /* research limits maximum population */ @@ -55,10 +55,17 @@ max_pop(float research, struct sctstr *sp) if (opt_BIG_CITY) { /* city efficiency limits maximum population */ - if (sp && dchr[sp->sct_type].d_pkg == UPKG) - maxpop = (int)(maxpop * ((9.0 * sp->sct_effic) / 100 + 1)); + if (dchr[desig].d_pkg == UPKG) + maxpop *= 1 + 9.0 * eff / 100; if (CANT_HAPPEN(maxpop > 9999)) maxpop = 9999; } + return maxpop; } + +int +max_pop(float research, struct sctstr *sp) +{ + return max_population(research, sp->sct_type, sp->sct_effic); +} diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index 1f850dba..d8366c05 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -655,12 +655,9 @@ void show_sect_stats(int foo) { int x, first = 1; - struct sctstr sect; struct natstr *natp; natp = getnatp(player->cnum); - /* We fake this */ - sect.sct_effic = 100; for (x = 0; x <= SCT_MAXDEF; x++) { if (dchr[x].d_mnem == 0) continue; @@ -669,7 +666,6 @@ show_sect_stats(int foo) pr(" sector type mcost off def mil uw civ bar other pop\n"); first = 0; } - sect.sct_type = x; pr("%c %-23s %3d %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n", dchr[x].d_mnem, dchr[x].d_name, dchr[x].d_mcst, dchr[x].d_ostr, @@ -679,7 +675,7 @@ show_sect_stats(int foo) ichr[I_CIVIL].i_pkg[dchr[x].d_pkg], ichr[I_BAR].i_pkg[dchr[x].d_pkg], ichr[I_LCM].i_pkg[dchr[x].d_pkg], - max_pop(natp->nat_level[NAT_RLEV], §)); + max_population(natp->nat_level[NAT_RLEV], x, 100)); } } diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index ad1dd41e..7f3de4c8 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -87,7 +87,7 @@ upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp, if (opt_BIG_CITY) { if (!n && dchr[old_type].d_pkg == UPKG && dchr[*desig].d_pkg != UPKG) { - int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); + 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)