]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/sect.c
Remove option TREATIES
[empserver] / src / lib / update / sect.c
index 6b310a1b3869f9d3065ef849800ad0650cf58f95..e324b279167a2030a5945ea5337a0990ca923172 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2014, 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/>.
  *
  *  ---
  *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1996
+ *     Markus Armbruster, 2004-2013
  */
 
 #include <config.h>
 
 #include "budg.h"
+#include "chance.h"
 #include "item.h"
 #include "land.h"
 #include "lost.h"
 #include "path.h"
 #include "player.h"
-#include "product.h"
 #include "ship.h"
 #include "update.h"
 
@@ -77,8 +77,7 @@ 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)
@@ -136,7 +135,6 @@ enlist(short *vec, int etu, int *cost)
     int maxmil;
     int enlisted;
 
-    /* Need to check treaties here */
     enlisted = 0;
     maxmil = vec[I_CIVIL] / 2 - vec[I_MILIT];
     if (maxmil > 0) {
@@ -153,14 +151,14 @@ 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;
 
     for (n = I_NONE + 1; n <= I_MAX; n++) {
-       melt = roundavg(vec[n] * etus * (long)fallout
+       melt = roundavg(vec[n] * etus * (double)fallout
                        / (1000.0 * ichr[n].i_melt_denom));
        if (melt > vec[n])
            melt = vec[n];
@@ -199,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)
@@ -216,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);
     }
 }
 
@@ -258,7 +256,7 @@ decay_fallout(struct sctstr *sp, int etus)
  * Produce for a specific nation
  */
 void
-produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
+produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2])
 {
     struct sctstr *sp;
     struct natstr *np;
@@ -277,13 +275,6 @@ produce_sect(int natnum, int etu, struct bp *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));
@@ -296,7 +287,7 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
         * 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)) {
+           !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;
@@ -320,6 +311,14 @@ produce_sect(int natnum, int etu, struct bp *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) {
            neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,