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_dchrg(struct shpstr *);
|
||||||
extern int shp_fire(struct shpstr *);
|
extern int shp_fire(struct shpstr *);
|
||||||
extern int shp_torp(struct shpstr *, int);
|
extern int shp_torp(struct shpstr *, int);
|
||||||
|
extern double shp_fire_range(struct shpstr *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -306,7 +306,7 @@ multifire(void)
|
||||||
fshipno, fship.shp_effic);
|
fshipno, fship.shp_effic);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
range = effrange(fship.shp_frnge, fship.shp_tech);
|
range = shp_fire_range(&fship);
|
||||||
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
|
||||||
|
@ -746,7 +746,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
continue;
|
continue;
|
||||||
dam += dam2;
|
dam += dam2;
|
||||||
} else {
|
} else {
|
||||||
erange = effrange(ship.shp_frnge, ship.shp_tech);
|
erange = shp_fire_range(&ship);
|
||||||
if (roundrange(erange) < ni.curdist)
|
if (roundrange(erange) < ni.curdist)
|
||||||
continue;
|
continue;
|
||||||
dam2 = shp_fire(&ship);
|
dam2 = shp_fire(&ship);
|
||||||
|
|
|
@ -241,7 +241,7 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
|
||||||
{
|
{
|
||||||
int range, erange, dam;
|
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);
|
range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y);
|
||||||
if (range > erange)
|
if (range > erange)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -91,7 +91,7 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
|
||||||
continue;
|
continue;
|
||||||
if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && !usesubs)
|
if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && !usesubs)
|
||||||
continue;
|
continue;
|
||||||
range = roundrange(effrange(ship.shp_frnge, ship.shp_tech));
|
range = roundrange(shp_fire_range(&ship));
|
||||||
if (range < ni.curdist)
|
if (range < ni.curdist)
|
||||||
continue;
|
continue;
|
||||||
dam = shp_fire(&ship);
|
dam = shp_fire(&ship);
|
||||||
|
|
|
@ -255,6 +255,15 @@ fortrange(struct sctstr *sp)
|
||||||
return rng;
|
return rng;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return firing range for ship SP.
|
||||||
|
*/
|
||||||
|
double
|
||||||
|
shp_fire_range(struct shpstr *sp)
|
||||||
|
{
|
||||||
|
return effrange(sp->shp_frnge, sp->shp_tech);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
roundrange(double r)
|
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",
|
"Incoming torpedo sighted @ %s hits and does %d damage!\n",
|
||||||
xyas(x, y, victim), dam2);
|
xyas(x, y, victim), dam2);
|
||||||
} else {
|
} else {
|
||||||
range = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
|
range = roundrange(shp_fire_range(sp));
|
||||||
if (md > range)
|
if (md > range)
|
||||||
continue;
|
continue;
|
||||||
if (mission == MI_SINTERDICT)
|
if (mission == MI_SINTERDICT)
|
||||||
|
@ -835,8 +835,7 @@ oprange(struct empobj *gp, int *radius)
|
||||||
|
|
||||||
switch (gp->ef_type) {
|
switch (gp->ef_type) {
|
||||||
case EF_SHIP:
|
case EF_SHIP:
|
||||||
range = ldround(effrange(((struct shpstr *)gp)->shp_frnge,
|
range = ldround(shp_fire_range((struct shpstr *)gp), 1);
|
||||||
((struct shpstr *)gp)->shp_tech), 1);
|
|
||||||
break;
|
break;
|
||||||
case EF_LAND:
|
case EF_LAND:
|
||||||
range = ldround(effrange(((struct lndstr *)gp)->lnd_frg,
|
range = ldround(effrange(((struct lndstr *)gp)->lnd_frg,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue