]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/land.c
Don't use automatic supply to avoid starvation at the update
[empserver] / src / lib / update / land.c
index ece5cf05cfc91dc7a145edf54a509fd0b27b10b0..32d03a3a5c5f544cd995ad96ce3ec234d9058981 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, 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
  *  ---
  *
  *  land.c: Do production for land units
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Thomas Ruschak, 1992
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2008
  */
 
 #include <config.h>
 
+#include <math.h>
 #include "budg.h"
 #include "land.h"
 #include "lost.h"
 #include "player.h"
 #include "ship.h"
 #include "update.h"
-#include <math.h>
 
-static void landrepair(struct lndstr *, struct natstr *, int *, int);
-static void upd_land(struct lndstr *, int, struct natstr *, int *, int);
+static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
+static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
 static int feed_land(struct lndstr *, int);
 
 int
-prod_land(int etus, int natnum, int *bp, int build)
+prod_land(int etus, int natnum, struct bp *bp, int build)
                /* build = 1, maintain = 0 */
 {
     struct lndstr *lp;
@@ -59,9 +59,7 @@ prod_land(int etus, int natnum, int *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 +75,6 @@ prod_land(int etus, int natnum, int *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,15 +84,13 @@ prod_land(int etus, int natnum, int *bp, int build)
        if (player->simulation)
            np->nat_money = start_money;
     }
-    bp_disable_cachepath();
-    bp_clear_cachepath();
 
     return k;
 }
 
 static void
 upd_land(struct lndstr *lp, int etus,
-        struct natstr *np, int *bp, int build)
+        struct natstr *np, struct bp *bp, int build)
               /* build = 1, maintain = 0 */
 {
     struct lchrstr *lcp;
@@ -214,7 +200,7 @@ upd_land(struct lndstr *lp, int etus,
 }
 
 static void
-landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
+landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
 {
     int delta;
     struct sctstr *sp;
@@ -244,7 +230,7 @@ landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
     if (!player->simulation)
        avail = sp->sct_avail * 100;
     else
-       avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
+       avail = bp_get_avail(bp, sp) * 100;
 
     w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm);
     delta = roundavg((double)avail / w_p_eff);
@@ -269,7 +255,7 @@ landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
     if (!player->simulation)
        sp->sct_avail = avail / 100;
     else
-       pt_bg_nmbr(bp, sp, I_MAX + 1, avail / 100);
+       bp_put_avail(bp, sp, avail / 100);
 
     if (build < 0)
        logerror("land unit %d building %d ! \n", land->lnd_uid, build);
@@ -285,16 +271,5 @@ landrepair(struct lndstr *land, struct natstr *np, int *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);
 }