From ca6c16357f429adacc24655f07c2f8ac054d56ee Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 17 Jun 2006 08:42:23 +0000 Subject: [PATCH] (lnd_fortify): Round mobility fractions up always, not just to 1. Simplify. (fort): Don't claim land unit can't be fortified when amount argument is zero. --- src/lib/commands/fort.c | 4 ++-- src/lib/subs/lndsub.c | 45 ++++++++++++----------------------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/lib/commands/fort.c b/src/lib/commands/fort.c index d15ea1e5..a457fae4 100644 --- a/src/lib/commands/fort.c +++ b/src/lib/commands/fort.c @@ -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), diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index fb2bd552..ee80d462 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -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);