Factor out land unit firing range calculation into lnd_fire_range()

This commit is contained in:
Markus Armbruster 2008-03-03 20:24:52 +01:00
parent ad5f8e8904
commit 76830b5b98
5 changed files with 15 additions and 6 deletions

View file

@ -168,6 +168,7 @@ extern int l_dam(struct lchrstr *, int);
extern int l_aaf(struct lchrstr *, int); extern int l_aaf(struct lchrstr *, int);
extern int lnd_fire(struct lndstr *); extern int lnd_fire(struct lndstr *);
extern double lnd_fire_range(struct lndstr *);
/* src/lib/subs/lndsub.c */ /* src/lib/subs/lndsub.c */
extern void lnd_sweep(struct emp_qelem *, int, int, natid); extern void lnd_sweep(struct emp_qelem *, int, int, natid);

View file

@ -362,7 +362,7 @@ multifire(void)
continue; continue;
} }
range = effrange(fland.lnd_frg, fland.lnd_tech); range = lnd_fire_range(&fland);
range2 = roundrange(range); range2 = roundrange(range);
pr("range is %d.00 (%.2f)\n", range2, range); pr("range is %d.00 (%.2f)\n", range2, range);
if (target == targ_sub) { if (target == targ_sub) {
@ -777,7 +777,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
if ((land.lnd_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR))) if ((land.lnd_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
continue; continue;
erange = effrange(land.lnd_frg, land.lnd_tech); erange = lnd_fire_range(&land);
if (roundrange(erange) < ni.curdist) if (roundrange(erange) < ni.curdist)
continue; continue;

View file

@ -264,6 +264,15 @@ shp_fire_range(struct shpstr *sp)
return effrange(sp->shp_frnge, sp->shp_tech); return effrange(sp->shp_frnge, sp->shp_tech);
} }
/*
* Return firing range for land unit SP.
*/
double
lnd_fire_range(struct lndstr *lp)
{
return effrange(lp->lnd_frg, lp->lnd_tech);
}
int int
roundrange(double r) roundrange(double r)
{ {

View file

@ -1137,7 +1137,7 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
/* are we in range? */ /* are we in range? */
dist = mapdist(land.lnd_x, land.lnd_y, x, y); dist = mapdist(land.lnd_x, land.lnd_y, x, y);
range = roundrange(effrange(land.lnd_frg, land.lnd_tech)); range = roundrange(lnd_fire_range(&land));
if (dist > range) if (dist > range)
continue; continue;

View file

@ -437,7 +437,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
(md > land_max_interdiction_range)) (md > land_max_interdiction_range))
continue; continue;
range = roundrange(effrange(lp->lnd_frg, lp->lnd_tech)); range = roundrange(lnd_fire_range(lp));
if (md > range) if (md > range)
continue; continue;
@ -838,8 +838,7 @@ oprange(struct empobj *gp, int *radius)
range = ldround(shp_fire_range((struct shpstr *)gp), 1); range = ldround(shp_fire_range((struct shpstr *)gp), 1);
break; break;
case EF_LAND: case EF_LAND:
range = ldround(effrange(((struct lndstr *)gp)->lnd_frg, range = ldround(lnd_fire_range((struct lndstr *)gp), 1);
((struct lndstr *)gp)->lnd_tech), 1);
break; break;
case EF_PLANE: case EF_PLANE:
/* missiles go one way, so we can use all the range */ /* missiles go one way, so we can use all the range */