]> git.pond.sub.org Git - empserver/commitdiff
(max_population): New, factored out of max_pop().
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 17 Feb 2005 21:04:08 +0000 (21:04 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 17 Feb 2005 21:04:08 +0000 (21:04 +0000)
(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
src/lib/commands/nati.c
src/lib/commands/powe.c
src/lib/commands/prod.c
src/lib/common/res_pop.c
src/lib/subs/show.c
src/lib/update/sect.c

index b084a08daea827aef2373dff76bee633e385b4a3..5caf84045cc052a51e011d6ddf27f392c8120e8d 100644 (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 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 *);
index 7f6b88b4e3235caaf933c1240a4712d48b7c9cb2..b63c3db919e655a81446f405c33a588501559710 100644 (file)
@@ -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 =
index bf8cab641138c87bebfd732672565146588d4a7d..834f718d42252f7422028a255a95bfed2a124b35 100644 (file)
@@ -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;
index f022bccdf0f6a68092911d89e5e6fd6136dd16dd..16494b39ce208aa6f2c6b31fe30dd0018a5895f5 100644 (file)
@@ -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);
index 5b3428f60f2173fb025997b694c0042c25304469..298c8ea64c0b9f64647238166aca9469a3ac5c11 100644 (file)
@@ -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);
+}
index 1f850dbab169da0812f2981d7da096315a7ba4ec..d8366c05f45dcf23bc21e1aa5dfd5066f0ed5460 100644 (file)
@@ -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], &sect));
+          max_population(natp->nat_level[NAT_RLEV], x, 100));
     }
 }
 
index ad1dd41ef79fa2ba1a0ded8f5c78aca204b53d8b..7f3de4c80901702a1697dcd1459171001fda13df 100644 (file)
@@ -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)