From ad5f8e8904e789cf2c2f6dc4929628cb93ae8a92 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 3 Mar 2008 20:20:39 +0100 Subject: [PATCH] Factor out ship firing range calculation into shp_fire_range() --- include/ship.h | 1 + src/lib/commands/mfir.c | 4 ++-- src/lib/commands/torp.c | 2 +- src/lib/subs/fortdef.c | 2 +- src/lib/subs/landgun.c | 9 +++++++++ src/lib/subs/mission.c | 5 ++--- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/ship.h b/include/ship.h index ea323c1f..6e5c46a3 100644 --- a/include/ship.h +++ b/include/ship.h @@ -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 diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index ca52e15a..b65e59de 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -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); diff --git a/src/lib/commands/torp.c b/src/lib/commands/torp.c index 829c719e..a33368d2 100644 --- a/src/lib/commands/torp.c +++ b/src/lib/commands/torp.c @@ -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; diff --git a/src/lib/subs/fortdef.c b/src/lib/subs/fortdef.c index 591fc0f2..5e931c77 100644 --- a/src/lib/subs/fortdef.c +++ b/src/lib/subs/fortdef.c @@ -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); diff --git a/src/lib/subs/landgun.c b/src/lib/subs/landgun.c index fbaed6c5..73210903 100644 --- a/src/lib/subs/landgun.c +++ b/src/lib/subs/landgun.c @@ -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) { diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index 1e92f77c..a889a769 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -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,