(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.
This commit is contained in:
Markus Armbruster 2005-02-17 21:04:08 +00:00
parent f8b2860ec5
commit ff67d93711
7 changed files with 20 additions and 14 deletions

View file

@ -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 s_char *BestAirPath(s_char *, int, int, int, int);
extern double pathcost(struct sctstr *, s_char *, int); extern double pathcost(struct sctstr *, s_char *, int);
/* res_pop.c */ /* res_pop.c */
extern int max_population(float, int, int);
extern int max_pop(float, struct sctstr *); extern int max_pop(float, struct sctstr *);
/* sectdamage.c */ /* sectdamage.c */
extern int sect_damage(struct sctstr *, int, struct emp_qelem *); extern int sect_damage(struct sctstr *, int, struct emp_qelem *);

View file

@ -95,7 +95,7 @@ nati(void)
pr(" Plague factor : %6.2f%%\n", pfac); pr(" Plague factor : %6.2f%%\n", pfac);
pr("\n"); 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); pr("Max population : %d\n", poplimit);
safepop = safepop =

View file

@ -329,7 +329,7 @@ gen_power(void)
if (opt_RES_POP) { if (opt_RES_POP) {
np = getnatp(i); 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); f = 1.0 + (((float)maxpop) / 10000.0);
} }
powbuf[i].p_power *= f; powbuf[i].p_power *= f;

View file

@ -144,8 +144,10 @@ prod(void)
if (!eff && dchr[otype].d_pkg == UPKG && if (!eff && dchr[otype].d_pkg == UPKG &&
dchr[type].d_pkg != UPKG) { dchr[type].d_pkg != UPKG) {
natp = getnatp(sect.sct_own); natp = getnatp(sect.sct_own);
civs = min(civs, max_pop(natp->nat_level[NAT_RLEV], 0)); maxpop = max_population(natp->nat_level[NAT_RLEV],
uws = min(uws, max_pop(natp->nat_level[NAT_RLEV], 0)); type, eff);
civs = min(civs, maxpop);
uws = min(uws, maxpop);
wforce = (int)(((double)civs * sect.sct_work) / 100.0 wforce = (int)(((double)civs * sect.sct_work) / 100.0
+ uws + uws
+ sect.sct_item[I_MILIT] * 2 / 5.0); + sect.sct_item[I_MILIT] * 2 / 5.0);

View file

@ -41,9 +41,9 @@
#include "common.h" #include "common.h"
int 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) { if (opt_RES_POP) {
/* research limits maximum population */ /* research limits maximum population */
@ -55,10 +55,17 @@ max_pop(float research, struct sctstr *sp)
if (opt_BIG_CITY) { if (opt_BIG_CITY) {
/* city efficiency limits maximum population */ /* city efficiency limits maximum population */
if (sp && dchr[sp->sct_type].d_pkg == UPKG) if (dchr[desig].d_pkg == UPKG)
maxpop = (int)(maxpop * ((9.0 * sp->sct_effic) / 100 + 1)); maxpop *= 1 + 9.0 * eff / 100;
if (CANT_HAPPEN(maxpop > 9999)) if (CANT_HAPPEN(maxpop > 9999))
maxpop = 9999; maxpop = 9999;
} }
return maxpop; return maxpop;
} }
int
max_pop(float research, struct sctstr *sp)
{
return max_population(research, sp->sct_type, sp->sct_effic);
}

View file

@ -655,12 +655,9 @@ void
show_sect_stats(int foo) show_sect_stats(int foo)
{ {
int x, first = 1; int x, first = 1;
struct sctstr sect;
struct natstr *natp; struct natstr *natp;
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
/* We fake this */
sect.sct_effic = 100;
for (x = 0; x <= SCT_MAXDEF; x++) { for (x = 0; x <= SCT_MAXDEF; x++) {
if (dchr[x].d_mnem == 0) if (dchr[x].d_mnem == 0)
continue; continue;
@ -669,7 +666,6 @@ show_sect_stats(int foo)
pr(" sector type mcost off def mil uw civ bar other pop\n"); pr(" sector type mcost off def mil uw civ bar other pop\n");
first = 0; first = 0;
} }
sect.sct_type = x;
pr("%c %-23s %3d %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n", 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_mnem, dchr[x].d_name,
dchr[x].d_mcst, dchr[x].d_ostr, 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_CIVIL].i_pkg[dchr[x].d_pkg],
ichr[I_BAR].i_pkg[dchr[x].d_pkg], ichr[I_BAR].i_pkg[dchr[x].d_pkg],
ichr[I_LCM].i_pkg[dchr[x].d_pkg], ichr[I_LCM].i_pkg[dchr[x].d_pkg],
max_pop(natp->nat_level[NAT_RLEV], &sect)); max_population(natp->nat_level[NAT_RLEV], x, 100));
} }
} }

View file

@ -87,7 +87,7 @@ upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
if (opt_BIG_CITY) { if (opt_BIG_CITY) {
if (!n && dchr[old_type].d_pkg == UPKG && if (!n && dchr[old_type].d_pkg == UPKG &&
dchr[*desig].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) if (vec[I_CIVIL] > maxpop)
vec[I_CIVIL] = maxpop; vec[I_CIVIL] = maxpop;
if (vec[I_UW] > maxpop) if (vec[I_UW] > maxpop)