]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/land.c
Units no longer die from lack of maintenance
[empserver] / src / lib / update / land.c
index 34a749939a5cd270ad2b5bb45a102e9322636e99..09c975d5549c7d82396150fb23eea70a5b28c719 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, 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/>.
  *
  *  ---
  *
  *  ---
  *
  *  land.c: Do production for land units
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Thomas Ruschak, 1992
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2007
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
 
+#include <math.h>
 #include "budg.h"
 #include "land.h"
 #include "lost.h"
@@ -44,7 +44,6 @@
 #include "player.h"
 #include "ship.h"
 #include "update.h"
-#include <math.h>
 
 static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
 static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
@@ -59,9 +58,7 @@ prod_land(int etus, int natnum, struct bp *bp, int build)
     struct natstr *np;
     int n, k = 0;
     int start_money;
-    int lastx = 9999, lasty = 9999;
 
-    bp_enable_cachepath();
     for (n = 0; NULL != (lp = getlandp(n)); n++) {
        if (lp->lnd_own == 0)
            continue;
@@ -77,16 +74,6 @@ prod_land(int etus, int natnum, struct bp *bp, int build)
        sp = getsectp(lp->lnd_x, lp->lnd_y);
        if (sp->sct_type == SCT_SANCT)
            continue;
-       if (lastx == 9999 || lasty == 9999) {
-           lastx = lp->lnd_x;
-           lasty = lp->lnd_y;
-       }
-       if (lastx != lp->lnd_x || lasty != lp->lnd_y) {
-           /* Reset the cache */
-           bp_disable_cachepath();
-           bp_clear_cachepath();
-           bp_enable_cachepath();
-       }
        np = getnatp(lp->lnd_own);
        start_money = np->nat_money;
        upd_land(lp, etus, np, bp, build);
@@ -96,8 +83,6 @@ prod_land(int etus, int natnum, struct bp *bp, int build)
        if (player->simulation)
            np->nat_money = start_money;
     }
-    bp_disable_cachepath();
-    bp_clear_cachepath();
 
     return k;
 }
@@ -109,11 +94,8 @@ upd_land(struct lndstr *lp, int etus,
 {
     struct lchrstr *lcp;
     int pstage, ptime;
-    int n;
     int min = morale_base - (int)np->nat_level[NAT_HLEV];
-    int mult;
-    int cost;
-    int eff;
+    int n, mult, cost, eff_lost;
 
     if (!player->simulation)
        if (lp->lnd_retreat < min)
@@ -133,18 +115,14 @@ upd_land(struct lndstr *lp, int etus,
            mult *= 3;
        cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
        if (np->nat_money < cost && !player->simulation) {
-           if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) {
-               wu(0, lp->lnd_own,
-                  "%s lost to lack of maintenance\n", prland(lp));
-               makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
-                        lp->lnd_x, lp->lnd_y);
-               lp->lnd_own = 0;
-               return;
+           eff_lost = etus / 5;
+           if (lp->lnd_effic - eff_lost < LAND_MINEFF)
+               eff_lost = lp->lnd_effic - LAND_MINEFF;
+           if (eff_lost > 0) {
+               wu(0, lp->lnd_own, "%s lost %d%% to lack of maintenance\n",
+                  prland(lp), eff_lost);
+               lp->lnd_effic -= eff_lost;
            }
-           wu(0, lp->lnd_own,
-              "%s lost %d%% to lack of maintenance\n",
-              prland(lp), lp->lnd_effic - eff);
-           lp->lnd_effic = eff;
        } else {
            np->nat_money -= cost;
        }
@@ -237,8 +215,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
        /* land is ok; no repairs needed */
        return;
     }
-    if ((sp->sct_own != land->lnd_own) &&
-       (getrel(getnatp(sp->sct_own), land->lnd_own) != ALLIED))
+    if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
        return;
 
     if (!player->simulation)
@@ -285,16 +262,5 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
 static int
 feed_land(struct lndstr *lp, int etus)
 {
-    int needed;
-
-    if (opt_NOFOOD)
-       return 0;
-
-    needed = (int)ceil(food_needed(lp->lnd_item, etus));
-
-    /* scrounge */
-    if (needed > lp->lnd_item[I_FOOD])
-       resupply_commod(lp, I_FOOD);
-
     return feed_people(lp->lnd_item, etus);
 }