(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().
This commit is contained in:
Markus Armbruster 2006-06-08 20:43:13 +00:00
parent 5e66e5bdee
commit 55ff194f7f
6 changed files with 27 additions and 24 deletions

View file

@ -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 int lnd_interdict(struct emp_qelem *, coord, coord, natid);
extern void lnd_sel(struct nstr_item *, struct emp_qelem *); extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
extern int lnd_check_mines(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 double lnd_mobcost(struct lndstr *, struct sctstr *, int);
extern char *lnd_path(int, struct lndstr *, char *); extern char *lnd_path(int, struct lndstr *, char *);

View file

@ -73,7 +73,8 @@ extern int diridx(char);
extern void direrr(char *, char *, char *); extern void direrr(char *, char *, char *);
extern void pathrange(coord, coord, char *, int, struct range *); 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 #define MAX_PATH_LEN 1024

View file

@ -73,3 +73,9 @@ sector_mcost(struct sctstr *sp, int do_bonus)
return MAX(d, LND_MINMOBCOST); return MAX(d, LND_MINMOBCOST);
return MAX(d, 0.01); return MAX(d, 0.01);
} }
double
speed_factor(double effspd, int tech)
{
return 480.0 / (effspd + techfact(tech, effspd));
}

View file

@ -1442,7 +1442,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
int dtotal; int dtotal;
int new_land = 0; int new_land = 0;
double mobcost; double mobcost;
double move_cost; double pathcost;
int dist; int dist;
int radius; int radius;
int origx, origy; int origx, origy;
@ -1506,15 +1506,10 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
continue; continue;
getsect(def->x, def->y, &dsect); getsect(def->x, def->y, &dsect);
if (!BestLandPath(buf, &sect, &dsect, &move_cost, MOB_MARCH)) if (!BestLandPath(buf, &sect, &dsect, &pathcost, MOB_MARCH))
continue; continue;
mobcost = land.lnd_effic * 0.01 * lchr[(int)land.lnd_type].l_spd; mobcost = lnd_pathcost(&land, pathcost);
if (mobcost < 0.01)
mobcost = 0.01;
mobcost = 480.0 / (mobcost + techfact(land.lnd_tech, mobcost));
mobcost *= move_cost * 5.0;
if (land.lnd_mobil < mobcost) if (land.lnd_mobil < mobcost)
continue; continue;

View file

@ -631,7 +631,6 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
struct llist *llp; struct llist *llp;
struct sctstr sect; struct sctstr sect;
int mines, m, max, sshells, lshells; int mines, m, max, sshells, lshells;
double mobcost;
for (qp = land_list->q_back; qp != land_list; qp = next) { for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back; next = qp->q_back;
@ -661,11 +660,7 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
continue; continue;
} }
if (takemob) { if (takemob) {
/* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/ llp->mobil -= lnd_pathcost(&llp->land, 0.2);
mobcost = llp->land.lnd_spd;
mobcost = 480.0 / (mobcost +
techfact(llp->land.lnd_tech, mobcost));
llp->mobil -= mobcost;
llp->land.lnd_mobil = (int)llp->mobil; llp->land.lnd_mobil = (int)llp->mobil;
llp->land.lnd_harden = 0; llp->land.lnd_harden = 0;
} }
@ -994,7 +989,7 @@ lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
} }
double double
lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype) lnd_pathcost(struct lndstr *lp, double pathcost)
{ {
double effspd; double effspd;
@ -1003,13 +998,18 @@ lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
effspd *= lp->lnd_effic * 0.01; effspd *= lp->lnd_effic * 0.01;
/* /*
* The return value must be sector_mcost(...) times a factor that * The return value must be pathcost times a factor that depends
* depends only on the land unit. Anything else breaks path * only on the land unit. Anything else breaks path finding. In
* finding. In particular, you can't add or enforce a minimum * particular, you can't add or enforce a minimum cost here. Do
* cost here. Do it in sector_mcost(). * it in sector_mcost().
*/ */
return sector_mcost(sp, mobtype) * 5.0 * 480.0 return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
/ (effspd + techfact(lp->lnd_tech, effspd)); }
double
lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
{
return lnd_pathcost(lp, sector_mcost(sp, mobtype));
} }
int int

View file

@ -1058,8 +1058,8 @@ shp_missdef(struct shpstr *sp, natid victim)
double double
shp_mobcost(struct shpstr *sp) shp_mobcost(struct shpstr *sp)
{ {
double effspd = sp->shp_effic * 0.01 * sp->shp_speed; return speed_factor(sp->shp_effic * 0.01 * sp->shp_speed,
return 480.0 / (effspd + techfact(sp->shp_tech, effspd)); sp->shp_tech);
} }
/* /*