Factor out ship firing range calculation into shp_fire_range()
This commit is contained in:
parent
b3c5ba2f75
commit
ad5f8e8904
6 changed files with 16 additions and 7 deletions
|
@ -186,5 +186,6 @@ extern int m_glim(struct mchrstr *, int);
|
|||
extern int shp_dchrg(struct shpstr *);
|
||||
extern int shp_fire(struct shpstr *);
|
||||
extern int shp_torp(struct shpstr *, int);
|
||||
extern double shp_fire_range(struct shpstr *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -306,7 +306,7 @@ multifire(void)
|
|||
fshipno, fship.shp_effic);
|
||||
continue;
|
||||
}
|
||||
range = effrange(fship.shp_frnge, fship.shp_tech);
|
||||
range = shp_fire_range(&fship);
|
||||
range2 = roundrange(range);
|
||||
pr("range is %d.00 (%.2f)\n", range2, range);
|
||||
if (target == targ_sub
|
||||
|
@ -746,7 +746,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
|||
continue;
|
||||
dam += dam2;
|
||||
} else {
|
||||
erange = effrange(ship.shp_frnge, ship.shp_tech);
|
||||
erange = shp_fire_range(&ship);
|
||||
if (roundrange(erange) < ni.curdist)
|
||||
continue;
|
||||
dam2 = shp_fire(&ship);
|
||||
|
|
|
@ -241,7 +241,7 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
|
|||
{
|
||||
int range, erange, dam;
|
||||
|
||||
erange = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
|
||||
erange = roundrange(shp_fire_range(sp));
|
||||
range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y);
|
||||
if (range > erange)
|
||||
return;
|
||||
|
|
|
@ -91,7 +91,7 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
|
|||
continue;
|
||||
if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && !usesubs)
|
||||
continue;
|
||||
range = roundrange(effrange(ship.shp_frnge, ship.shp_tech));
|
||||
range = roundrange(shp_fire_range(&ship));
|
||||
if (range < ni.curdist)
|
||||
continue;
|
||||
dam = shp_fire(&ship);
|
||||
|
|
|
@ -255,6 +255,15 @@ fortrange(struct sctstr *sp)
|
|||
return rng;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return firing range for ship SP.
|
||||
*/
|
||||
double
|
||||
shp_fire_range(struct shpstr *sp)
|
||||
{
|
||||
return effrange(sp->shp_frnge, sp->shp_tech);
|
||||
}
|
||||
|
||||
int
|
||||
roundrange(double r)
|
||||
{
|
||||
|
|
|
@ -530,7 +530,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
|
|||
"Incoming torpedo sighted @ %s hits and does %d damage!\n",
|
||||
xyas(x, y, victim), dam2);
|
||||
} else {
|
||||
range = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
|
||||
range = roundrange(shp_fire_range(sp));
|
||||
if (md > range)
|
||||
continue;
|
||||
if (mission == MI_SINTERDICT)
|
||||
|
@ -835,8 +835,7 @@ oprange(struct empobj *gp, int *radius)
|
|||
|
||||
switch (gp->ef_type) {
|
||||
case EF_SHIP:
|
||||
range = ldround(effrange(((struct shpstr *)gp)->shp_frnge,
|
||||
((struct shpstr *)gp)->shp_tech), 1);
|
||||
range = ldround(shp_fire_range((struct shpstr *)gp), 1);
|
||||
break;
|
||||
case EF_LAND:
|
||||
range = ldround(effrange(((struct lndstr *)gp)->lnd_frg,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue