]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/sect.c
Make sector maintenance cost configurable
[empserver] / src / lib / update / sect.c
index f0105ac8399c4c4161e669e956198d67492257ec..9f154e2bfbb2368505ed507eb3d9387161ceec12 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  sect.c: Do production for sectors
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1996
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
@@ -79,6 +80,7 @@ upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
        *cost += work_cost;
        if (!n && IS_BIG_CITY(old_type) &&
            !IS_BIG_CITY(*desig)) {
+           // FIXME use trunc_people() and total_work()
            int maxpop = max_population(np->nat_level[NAT_RLEV], *desig, n);
            if (vec[I_CIVIL] > maxpop)
                vec[I_CIVIL] = maxpop;
@@ -137,9 +139,9 @@ enlist(short *vec, int etu, int *cost)
 
     /* Need to check treaties here */
     enlisted = 0;
-    maxmil = (vec[I_CIVIL] / 2) - vec[I_MILIT];
+    maxmil = vec[I_CIVIL] / 2 - vec[I_MILIT];
     if (maxmil > 0) {
-       enlisted = (etu * (10 + vec[I_MILIT]) * 0.05);
+       enlisted = etu * (10 + vec[I_MILIT]) * 0.05;
        if (enlisted > maxmil)
            enlisted = maxmil;
        vec[I_CIVIL] -= enlisted;
@@ -257,14 +259,14 @@ decay_fallout(struct sctstr *sp, int etus)
  * Produce for a specific nation
  */
 void
-produce_sect(int natnum, int etu, int *bp, long p_sect[][2])
+produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
 {
     struct sctstr *sp;
     struct natstr *np;
     short buf[I_MAX + 1];
     short *vec;
     int work, cost, ecost, pcost, sctwork;
-    int n, desig, maxpop, neweff, amount;
+    int n, desig, neweff, amount;
 
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
        if (sp->sct_type == SCT_WATER)
@@ -276,13 +278,6 @@ produce_sect(int natnum, int etu, int *bp, long p_sect[][2])
 
        np = getnatp(natnum);
 
-       if ((sp->sct_type == SCT_CAPIT) && (sp->sct_effic > 60)) {
-           p_sect[SCT_CAPIT][0]++;
-           p_sect[SCT_CAPIT][1] += etu;
-           if (!player->simulation)
-               np->nat_money -= etu;
-       }
-
        if (player->simulation) {
            /* work on a copy, which will be discarded */
            memcpy(buf, sp->sct_item, sizeof(buf));
@@ -290,35 +285,28 @@ produce_sect(int natnum, int etu, int *bp, long p_sect[][2])
        } else
            vec = sp->sct_item;
 
-       /* If everybody is dead, the sector reverts to unowned. 
-          * This is also checked at the end of the production in
-          * they all starved or were plagued off.
+       /* If everybody is dead, the sector reverts to unowned.
+        * This is also checked at the end of the production in
+        * they all starved or were plagued off.
         */
        if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 &&
-           !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) {
-           makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
-           sp->sct_own = 0;
-           sp->sct_oldown = 0;
+           !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) {
+           if (!player->simulation) {
+               makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
+               sp->sct_own = 0;
+               sp->sct_oldown = 0;
+           }
            continue;
        }
 
        sp->sct_updated = 1;
        work = 0;
 
-       /* do_feed trys to supply.  So, we need to enable cacheing
-          here */
-       bp_enable_cachepath();
-
-       sctwork = do_feed(sp, np, vec, &work, bp, etu);
+       sctwork = do_feed(sp, np, vec, &work, etu);
+       bp_put_items(bp, sp, vec);
 
-       bp_disable_cachepath();
-       bp_clear_cachepath();
-
-       if (sp->sct_off || np->nat_money < 0) {
-           if (!player->simulation)
-               sp->sct_off = 0;
+       if (sp->sct_off || np->nat_money < 0)
            continue;
-       }
 
        neweff = sp->sct_effic;
        amount = 0;
@@ -326,12 +314,19 @@ produce_sect(int natnum, int etu, int *bp, long p_sect[][2])
 
        desig = sp->sct_type;
 
+       if (dchr[desig].d_maint) {
+           cost = etu * dchr[desig].d_maint;
+           p_sect[SCT_MAINT][0]++;
+           p_sect[SCT_MAINT][1] += cost;
+           if (!player->simulation)
+               np->nat_money -= cost;
+       }
+
        if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
-           np->nat_money > 0) {
+           np->nat_money >= 0) {
            neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
                                  &cost);
-           pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]);
-           pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]);
+           bp_put_items(bp, sp, vec);
            p_sect[SCT_EFFIC][0]++;
            p_sect[SCT_EFFIC][1] += cost;
            if (!player->simulation) {
@@ -347,6 +342,7 @@ produce_sect(int natnum, int etu, int *bp, long p_sect[][2])
            p_sect[desig][1] += ecost;
            if (!player->simulation)
                np->nat_money -= ecost;
+           bp_put_items(bp, sp, vec);
        }
 
        /*
@@ -354,20 +350,16 @@ produce_sect(int natnum, int etu, int *bp, long p_sect[][2])
         */
 
        if (neweff >= 60) {
-           if (np->nat_money > 0 && dchr[desig].d_prd >= 0)
+           if (np->nat_money >= 0 && dchr[desig].d_prd >= 0)
                work -= produce(np, sp, vec, work, desig, neweff,
                                &pcost, &amount);
+           bp_put_items(bp, sp, vec);
        }
 
-       pt_bg_nmbr(bp, sp, I_MAX + 1, work);
+       bp_put_avail(bp, sp, work);
        p_sect[desig][0] += amount;
        p_sect[desig][1] += pcost;
        if (!player->simulation) {
-           maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
-           if (vec[I_CIVIL] > maxpop)
-               vec[I_CIVIL] = maxpop;
-           if (vec[I_UW] > maxpop)
-               vec[I_UW] = maxpop;
            sp->sct_avail = work;
            np->nat_money -= pcost;
        }