]> git.pond.sub.org Git - empserver/commitdiff
update budget produce: Count loaded civilians for TECH_POP
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Jun 2016 11:21:35 +0000 (13:21 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:08:30 +0000 (20:08 +0200)
When option TECH_POP is enabled, the cost of tech increases when
civilian population exceeds 50000.  Only civilians in old-owned
sectors count.  This differs from education and happiness, where
civilians loaded on ships and land units count, too.

The update counts population for TECH_POP with count_pop().  This is
an extra pass over all sectors.

produce also uses count_pop(), once per tech center examined.
Wasteful.

budget avoids count_pop(): it uses tax()'s civilian count.  More
efficient, but the difference to the update is ugly.

Change TECH_POP to use the same civilian count as education and
happiness, i.e. count civilians on ships and land units, too.

This count is available in nat_budget[] in time for produce(): it's
computed by tax() and by ship and land unit maintenance.  So use it
there.  This takes care of the update and budget.  produce doesn't run
enough update code to do the same.  Keep calling count_pop() there.
Update it to match the update, and give it internal linkage.
Duplicating update's workings there is ugly, so mark it FIXME.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/prototypes.h
include/update.h
src/lib/commands/budg.c
src/lib/commands/prod.c
src/lib/update/main.c
src/lib/update/produce.c

index 79b96ce639f571f48a810be572c1c78ee514841a..2e4e9506a8c393e551776513699fd8558f707ed8 100644 (file)
@@ -59,7 +59,6 @@ extern int edit_sect_i(struct sctstr *, char *, int);
 extern int load_comm_ok(struct sctstr *, natid, i_type, int);
 extern void gift(natid, natid, void *, char *);
 extern int display_mark(i_type, int);
-extern int count_pop(int);
 extern int line_of_sight(char **rad, int ax, int ay, int bx, int by);
 extern void plane_sona(struct emp_qelem *, int, int, struct shiplist **);
 extern char *prsub(struct shpstr *);
index 1d93a05164eb0e6c5241470cf7b30d15ed614e6f..edb9bd79c5720129ea88be7f37c62f4f3fb57fa3 100644 (file)
@@ -73,7 +73,6 @@ struct budget {
 
 /* main.c */
 extern struct budget nat_budget[MAXNOC];
-extern int tpops[MAXNOC];
 /* nat.c */
 extern float levels[MAXNOC][4];
 
index 63003faee3d93828d82d098dfa2bc363eca8539d..10f0433107420e8d5c012a4e11f4cd77bbe90832 100644 (file)
@@ -163,7 +163,6 @@ calc_all(void)
                bank_income(sp, etu);
        }
     }
-    tpops[player->cnum] = budget->oldowned_civs;
     upd_slmilcosts(etu, player->cnum);
     pay_reserve(np, etu);
 
index 86cd78479e66b02fc13dc7fdc4d874558b9fc563..22ff9b7d9e0d70166663de02c725ca5171f2c8e6 100644 (file)
 #include <math.h>
 #include "commands.h"
 #include "item.h"
+#include "land.h"
 #include "optlist.h"
 #include "product.h"
+#include "ship.h"
 #include "update.h"
 
 static void prprod(struct sctstr *, double, double, char,
                   double, double, double, char[], int[], int[], int);
 
-int
-count_pop(int n)
+static int
+count_pop(void)
 {
+    /* FIXME don't duplicate the update's workings, use its code */
     int i;
     int pop = 0;
-    struct sctstr *sp;
+    struct sctstr *sectp;
+    struct shpstr *sp;
+    struct lndstr *lp;
+
+    for (i = 0; (sectp = getsectid(i)); i++) {
+       if (sectp->sct_own == player->cnum) {
+           if (sectp->sct_own == sectp->sct_oldown)
+               pop += sectp->sct_item[I_CIVIL];
+       }
+    }
 
-    for (i = 0; NULL != (sp = getsectid(i)); i++) {
-       if (sp->sct_own != n)
-           continue;
-       if (sp->sct_oldown != n)
-           continue;
-       pop += sp->sct_item[I_CIVIL];
+    for (i = 0; (sp = getshipp(i)); i++) {
+       if (sp->shp_own == player->cnum)
+           pop += sp->shp_item[I_CIVIL];
+    }
+
+    for (i = 0; (lp = getlandp(i)); i++) {
+       if (lp->lnd_own == player->cnum)
+           pop += lp->lnd_item[I_CIVIL];
     }
+
     return pop;
 }
 
@@ -70,7 +85,7 @@ prod(void)
     struct pchrstr *pp;
     double p_e;
     double prodeff;
-    int totpop;
+    int totpop = -1;
     double cost;
     int i;
     int nsect;
@@ -155,7 +170,8 @@ prod(void)
        cost = take * pp->p_cost;
        if (opt_TECH_POP) {
            if (pp->p_level == NAT_TLEV) {
-               totpop = count_pop(sect.sct_own);
+               if (totpop < 0)
+                   totpop = count_pop();
                if (totpop > 50000)
                    cost *= totpop / 50000.0;
            }
index 643b9d5117c697e0660420556ce491b45e57af47..cb1cf2957f5a5ec4226cfbcb082c096ff219d511 100644 (file)
@@ -47,7 +47,6 @@
 #include "update.h"
 
 struct budget nat_budget[MAXNOC];
-int tpops[MAXNOC];
 
 void
 update_main(void)
@@ -87,7 +86,6 @@ update_main(void)
        if (!(np = getnatp(n)))
            continue;
        nat_budget[n].start_money = nat_budget[n].money = np->nat_money;
-       tpops[n] = count_pop(n);
     }
 
     logerror("preparing sectors...");
index 817be09523836322cc59ed2db516c897ca8bc123..2ecf467a9866aa176b67fac0a560f6b71303b901 100644 (file)
@@ -68,8 +68,8 @@ produce(struct natstr *np, struct sctstr *sp)
     cost = product->p_cost * output / prodeff;
     if (opt_TECH_POP) {
        if (product->p_level == NAT_TLEV) {
-           if (tpops[sp->sct_own] > 50000)
-               cost *= tpops[sp->sct_own] / 50000.0;
+           if (budget->oldowned_civs > 50000)
+               cost *= budget->oldowned_civs / 50000.0;
        }
     }