]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/sect.c
Clean up superfluous includes
[empserver] / src / lib / update / sect.c
index ea7238b28da9d38477d77b0e57562db88b7623e6..116d79464e23eb17b320a4f6166c60efe198328d 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *  ---
  *
  *  sect.c: Do production for sectors
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1996
+ *     Markus Armbruster, 2004-2010
  */
 
 #include <config.h>
@@ -40,7 +40,6 @@
 #include "lost.h"
 #include "path.h"
 #include "player.h"
-#include "product.h"
 #include "ship.h"
 #include "update.h"
 
@@ -77,8 +76,8 @@ upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
        }
        neweff = n;
        *cost += work_cost;
-       if (!n && IS_BIG_CITY(old_type) &&
-           !IS_BIG_CITY(*desig)) {
+       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 +136,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;
@@ -152,8 +151,8 @@ enlist(short *vec, int etu, int *cost)
 /* Fallout is calculated here. */
 
 static void
-meltitems(int etus, int fallout, int own, short *vec, int type, int x, int y,
-         int uid)
+meltitems(int etus, int fallout, int own, short *vec,
+         int type, int x, int y, int uid)
 {
     i_type n;
     int melt;
@@ -198,15 +197,15 @@ do_fallout(struct sctstr *sp, int etus)
        return;
     if (etus > 24)
        etus = 24;
-    meltitems(etus, sp->sct_fallout, sp->sct_own, sp->sct_item, EF_SECTOR,
-             sp->sct_x, sp->sct_y, 0);
+    meltitems(etus, sp->sct_fallout, sp->sct_own, sp->sct_item,
+             EF_SECTOR, sp->sct_x, sp->sct_y, 0);
     for (i = 0; NULL != (lp = getlandp(i)); i++) {
        if (!lp->lnd_own)
            continue;
        if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y)
            continue;
-       meltitems(etus, sp->sct_fallout, lp->lnd_own, lp->lnd_item, EF_LAND,
-                 lp->lnd_x, lp->lnd_y, lp->lnd_uid);
+       meltitems(etus, sp->sct_fallout, lp->lnd_own, lp->lnd_item,
+                 EF_LAND, lp->lnd_x, lp->lnd_y, lp->lnd_uid);
     }
     for (i = 0; NULL != (spp = getshipp(i)); i++) {
        if (!spp->shp_own)
@@ -215,8 +214,8 @@ do_fallout(struct sctstr *sp, int etus)
            continue;
        if (mchr[(int)spp->shp_type].m_flags & M_SUB)
            continue;
-       meltitems(etus, sp->sct_fallout, spp->shp_own, spp->shp_item, EF_SHIP,
-                 spp->shp_x, spp->shp_y, spp->shp_uid);
+       meltitems(etus, sp->sct_fallout, spp->shp_own, spp->shp_item,
+                 EF_SHIP, spp->shp_x, spp->shp_y, spp->shp_uid);
     }
 }
 
@@ -257,14 +256,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 +275,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,29 +282,25 @@ 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);
-
-       bp_disable_cachepath();
-       bp_clear_cachepath();
+       sctwork = do_feed(sp, np, vec, &work, etu);
+       bp_put_items(bp, sp, vec);
 
        if (sp->sct_off || np->nat_money < 0)
            continue;
@@ -323,12 +311,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) {
@@ -344,6 +339,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);
        }
 
        /*
@@ -351,20 +347,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;
        }