]> git.pond.sub.org Git - empserver/commitdiff
(lnd_fortify): Round mobility fractions up always, not just to 1.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 17 Jun 2006 08:42:23 +0000 (08:42 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 17 Jun 2006 08:42:23 +0000 (08:42 +0000)
Simplify.

(fort): Don't claim land unit can't be fortified when amount argument
is zero.

src/lib/commands/fort.c
src/lib/subs/lndsub.c

index d15ea1e5ea2c7fbc29e99d5ac29e1b18049572cb..a457fae4a88b8068b655d054a1b2029b9313c9b3 100644 (file)
@@ -82,9 +82,9 @@ fort(void)
           use all mobility down to leaving 67 left. */
        if (hard_amt < 0) {
            hard_amt = land.lnd_mobil + hard_amt;
-           if (hard_amt < 0)
-               continue;
        }
+       if (hard_amt <= 0)
+           continue;
 
        if (lnd_fortify (&land, hard_amt) <= 0) {
            pr("%s can't be fortified%s\n", prland(&land),
index fb2bd552a55a9498b51aa6b41c5022d4c86e4b8b..ee80d4629c89fbbd8f3844b2955d6b8fda8ec18a 100644 (file)
@@ -1309,48 +1309,29 @@ lnd_can_attack(struct lndstr *lp)
 
 /*
  * Increase fortification value of LP.
- * Fortification costs mobility.  Use up to HARD_AMT mobility.
+ * Fortification costs mobility.  Use up to MOB mobility.
  * Return actual fortification increase.
  */
 int
-lnd_fortify (struct lndstr *lp, int hard_amt)
+lnd_fortify(struct lndstr *lp, int mob)
 {
-    int mob_used;
-    int eng;
+    int hard_amt;
+    double mob_used, mult;
 
-    if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
+    if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
        return 0;
 
-    hard_amt = MIN(lp->lnd_mobil, hard_amt);
+    mob_used = MIN(lp->lnd_mobil, mob);
+    mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
+       ? 1.5 : 1.0;
 
-    if ((lp->lnd_harden + hard_amt) > land_mob_max)
+    hard_amt = (int)(mob_used * mult);
+    if (lp->lnd_harden + hard_amt > land_mob_max) {
        hard_amt = land_mob_max - lp->lnd_harden;
+       mob_used = ceil(hard_amt / mult);
+    }
 
-    eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
-
-    if (eng)
-       hard_amt *= 1.5;
-
-    if ((lp->lnd_harden + hard_amt) > land_mob_max)
-       hard_amt = land_mob_max - lp->lnd_harden;
-
-    /* Ok, set the mobility used */
-    mob_used = hard_amt;
-
-    /* Now, if an engineer helped, it's really only 2/3rds of
-       that */
-    if (eng)
-       mob_used /= 1.5;
-
-    /* If we increased it, but not much, we gotta take at least 1
-       mob point. */
-    if (mob_used <= 0 && hard_amt > 0)
-       mob_used = 1;
-
-    lp->lnd_mobil -= mob_used;
-    if (lp->lnd_mobil < 0)
-       lp->lnd_mobil = 0;
-
+    lp->lnd_mobil -= (int)mob_used;
     lp->lnd_harden += hard_amt;
     lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);