From 55ff194f7f1e0b11f5af654228ee9efb55ff87f5 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 8 Jun 2006 20:43:13 +0000 Subject: [PATCH] (lnd_pathcost): New, factored out of lnd_mobcost(). (att_reacting_units): Use it. Fixes overcharging of inefficient units. Broken when Empire3 changed land unit mobility use not to depend on efficiency, except for supply units. (lnd_sweep): Use it. No functional change. (speed_factor): New, factored out of lnd_pathcost() and shp_mobcost(). --- include/land.h | 1 + include/path.h | 3 ++- src/lib/common/move.c | 6 ++++++ src/lib/subs/attsub.c | 11 +++-------- src/lib/subs/lndsub.c | 26 +++++++++++++------------- src/lib/subs/shpsub.c | 4 ++-- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/land.h b/include/land.h index 3a761686f..3dc5fcf55 100644 --- a/include/land.h +++ b/include/land.h @@ -200,6 +200,7 @@ extern void lnd_sweep(struct emp_qelem *, int, int, natid); extern int lnd_interdict(struct emp_qelem *, coord, coord, natid); extern void lnd_sel(struct nstr_item *, struct emp_qelem *); extern int lnd_check_mines(struct emp_qelem *); +extern double lnd_pathcost(struct lndstr *, double); extern double lnd_mobcost(struct lndstr *, struct sctstr *, int); extern char *lnd_path(int, struct lndstr *, char *); diff --git a/include/path.h b/include/path.h index 0ef6e364d..57db93996 100644 --- a/include/path.h +++ b/include/path.h @@ -73,7 +73,8 @@ extern int diridx(char); extern void direrr(char *, char *, char *); extern void pathrange(coord, coord, char *, int, struct range *); -extern double sector_mcost(struct sctstr *sp, int do_bonus); +extern double sector_mcost(struct sctstr *, int); +extern double speed_factor(double, int); #define MAX_PATH_LEN 1024 diff --git a/src/lib/common/move.c b/src/lib/common/move.c index eddc07806..093b5cb48 100644 --- a/src/lib/common/move.c +++ b/src/lib/common/move.c @@ -73,3 +73,9 @@ sector_mcost(struct sctstr *sp, int do_bonus) return MAX(d, LND_MINMOBCOST); return MAX(d, 0.01); } + +double +speed_factor(double effspd, int tech) +{ + return 480.0 / (effspd + techfact(tech, effspd)); +} diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 0394f96be..e4dff0609 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -1442,7 +1442,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy, int dtotal; int new_land = 0; double mobcost; - double move_cost; + double pathcost; int dist; int radius; int origx, origy; @@ -1506,15 +1506,10 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy, continue; getsect(def->x, def->y, &dsect); - if (!BestLandPath(buf, §, &dsect, &move_cost, MOB_MARCH)) + if (!BestLandPath(buf, §, &dsect, &pathcost, MOB_MARCH)) continue; - mobcost = land.lnd_effic * 0.01 * lchr[(int)land.lnd_type].l_spd; - if (mobcost < 0.01) - mobcost = 0.01; - mobcost = 480.0 / (mobcost + techfact(land.lnd_tech, mobcost)); - mobcost *= move_cost * 5.0; - + mobcost = lnd_pathcost(&land, pathcost); if (land.lnd_mobil < mobcost) continue; diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 787ad15a7..ae5ca04b4 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -631,7 +631,6 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob, struct llist *llp; struct sctstr sect; int mines, m, max, sshells, lshells; - double mobcost; for (qp = land_list->q_back; qp != land_list; qp = next) { next = qp->q_back; @@ -661,11 +660,7 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob, continue; } if (takemob) { -/* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/ - mobcost = llp->land.lnd_spd; - mobcost = 480.0 / (mobcost + - techfact(llp->land.lnd_tech, mobcost)); - llp->mobil -= mobcost; + llp->mobil -= lnd_pathcost(&llp->land, 0.2); llp->land.lnd_mobil = (int)llp->mobil; llp->land.lnd_harden = 0; } @@ -994,7 +989,7 @@ lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp) } double -lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype) +lnd_pathcost(struct lndstr *lp, double pathcost) { double effspd; @@ -1003,13 +998,18 @@ lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype) effspd *= lp->lnd_effic * 0.01; /* - * The return value must be sector_mcost(...) times a factor that - * depends only on the land unit. Anything else breaks path - * finding. In particular, you can't add or enforce a minimum - * cost here. Do it in sector_mcost(). + * The return value must be pathcost times a factor that depends + * only on the land unit. Anything else breaks path finding. In + * particular, you can't add or enforce a minimum cost here. Do + * it in sector_mcost(). */ - return sector_mcost(sp, mobtype) * 5.0 * 480.0 - / (effspd + techfact(lp->lnd_tech, effspd)); + return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech); +} + +double +lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype) +{ + return lnd_pathcost(lp, sector_mcost(sp, mobtype)); } int diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index b6600a12e..77f33d734 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -1058,8 +1058,8 @@ shp_missdef(struct shpstr *sp, natid victim) double shp_mobcost(struct shpstr *sp) { - double effspd = sp->shp_effic * 0.01 * sp->shp_speed; - return 480.0 / (effspd + techfact(sp->shp_tech, effspd)); + return speed_factor(sp->shp_effic * 0.01 * sp->shp_speed, + sp->shp_tech); } /* -- 2.43.0