(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:
parent
5e66e5bdee
commit
55ff194f7f
6 changed files with 27 additions and 24 deletions
|
@ -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 *);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue