]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/land.c
Fix trailing whitespace
[empserver] / src / lib / update / land.c
index 254302af429c8589bbd13858baa533ec11fccd15..5c0fb5cf0fffbb5c50dcbef293028e1dd26ff804 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-2008, 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 "misc.h"
-#include "plague.h"
-#include "sect.h"
-#include "nat.h"
+#include "budg.h"
 #include "land.h"
-#include "ship.h"
+#include "lost.h"
 #include "news.h"
-#include "file.h"
-#include "optlist.h"
-#include "budg.h"
+#include "plague.h"
 #include "player.h"
+#include "ship.h"
 #include "update.h"
-#include "lost.h"
-#include "common.h"
-#include "subs.h"
-#include "common.h"
-#include "gen.h"
-
-int mil_dbl_pay;
 
-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;
@@ -115,7 +104,7 @@ prod_land(int etus, int natnum, int *bp, int build)
 
 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;
@@ -132,8 +121,10 @@ upd_land(struct lndstr *lp, int etus,
 
     lcp = &lchr[(int)lp->lnd_type];
     if (build == 1) {
-       if (np->nat_money >= 0)
+       if (!lp->lnd_off && np->nat_money >= 0)
            landrepair(lp, np, bp, etus);
+       if (!player->simulation)
+           lp->lnd_off = 0;
     } else {
        mult = 1;
        if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
@@ -222,16 +213,13 @@ upd_land(struct lndstr *lp, int etus,
     }
 }
 
-/*ARGSUSED*/
 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;
     struct lchrstr *lp;
-    float leftp, buildp;
-    int left, build;
-    int mil_needed, lcm_needed, hcm_needed, gun_needed, shell_needed;
+    int build;
     int avail;
     int w_p_eff;
     int mult;
@@ -249,13 +237,14 @@ landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
        /* land is ok; no repairs needed */
        return;
     }
-    if (sp->sct_own != land->lnd_own)
+    if ((sp->sct_own != land->lnd_own) &&
+       (getrel(getnatp(sp->sct_own), land->lnd_own) != ALLIED))
        return;
 
     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);
@@ -263,54 +252,13 @@ landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
        return;
     if (delta > (int)((float)etus * land_grow_scale))
        delta = (int)((float)etus * land_grow_scale);
+    if (delta > 100 - land->lnd_effic)
+       delta = 100 - land->lnd_effic;
 
-    /* delta is the max amount we can grow */
-
-    left = 100 - land->lnd_effic;
-    if (left > delta)
-       left = delta;
-
-    leftp = left / 100.0;
-
-    memset(mvec, 0, sizeof(mvec));
-    mvec[I_LCM] = lcm_needed = ldround(lp->l_lcm * leftp, 1);
-    mvec[I_HCM] = hcm_needed = ldround(lp->l_hcm * leftp, 1);
-/*
-        mvec[I_GUN] = gun_needed = ldround(lp->l_gun * leftp, 1);
-        mvec[I_MILIT] = mil_needed = ldround(lp->l_mil * leftp, 1);
-        mvec[I_SHELL] = shell_needed = ldround(lp->l_shell *leftp, 1);
- */
-    mvec[I_GUN] = gun_needed = 0;
-    mvec[I_MILIT] = mil_needed = 0;
-    mvec[I_SHELL] = shell_needed = 0;
-    get_materials(sp, bp, mvec, 0);
-
-    buildp = leftp;
-    if (mvec[I_MILIT] < mil_needed)
-       buildp = MIN(buildp, (float)mvec[I_MILIT] / (float)lp->l_mil);
-    if (mvec[I_LCM] < lcm_needed)
-       buildp = MIN(buildp, (float)mvec[I_LCM] / (float)lp->l_lcm);
-    if (mvec[I_HCM] < hcm_needed)
-       buildp = MIN(buildp, (float)mvec[I_HCM] / (float)lp->l_hcm);
-    if (mvec[I_GUN] < gun_needed)
-       buildp = MIN(buildp, (float)mvec[I_GUN] / (float)lp->l_gun);
-    if (mvec[I_SHELL] < shell_needed)
-       buildp = MIN(buildp, (float)mvec[I_SHELL] / (float)lp->l_shell);
-
-    build = ldround(buildp * 100.0, 1);
     memset(mvec, 0, sizeof(mvec));
-    mvec[I_LCM] = roundavg(lp->l_lcm * buildp);
-    mvec[I_HCM] = roundavg(lp->l_hcm * buildp);
-/*
-        mvec[I_GUN] = roundavg(lp->l_gun * buildp);
-        mvec[I_MILIT] = roundavg(lp->l_mil * buildp);
-        mvec[I_SHELL] = roundavg(lp->l_shell *buildp);
- */
-    mvec[I_GUN] = 0;
-    mvec[I_MILIT] = 0;
-    mvec[I_SHELL] = 0;
-    mil_dbl_pay += mvec[I_MILIT];
-    get_materials(sp, bp, mvec, 1);
+    mvec[I_LCM] = lp->l_lcm;
+    mvec[I_HCM] = lp->l_hcm;
+    build = get_materials(sp, bp, mvec, delta);
 
     if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
        build /= 3;
@@ -321,7 +269,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);
@@ -337,8 +285,7 @@ landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
 static int
 feed_land(struct lndstr *lp, int etus)
 {
-    int needed, give, take;
-    struct shpstr *sp;
+    int needed;
 
     if (opt_NOFOOD)
        return 0;