diff --git a/include/ship.h b/include/ship.h index 6e5c46a3..db6054d1 100644 --- a/include/ship.h +++ b/include/ship.h @@ -187,5 +187,6 @@ 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 *); +extern int shp_usable_guns(struct shpstr *); #endif diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 72e4f1f9..a0f8c629 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -523,8 +523,8 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target) if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head)) continue; - shell = gun = 0; - gun = MIN(ship.shp_item[I_GUN], ship.shp_glim); + shell = 0; + gun = shp_usable_guns(&ship); if (gun > 0) { shell = ship.shp_item[I_SHELL]; if (shell <= 0) diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index 5ea34a68..53df1daa 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -837,8 +837,8 @@ ac_shipflak(struct emp_qelem *list, coord x, coord y) rel = getrel(getnatp(ship.shp_own), plane_owner); if (rel > HOSTILE) continue; - shell = gun = 0; - gun = MIN(ship.shp_item[I_GUN], ship.shp_glim); + shell = 0; + gun = shp_usable_guns(&ship); if (gun) { shell = ship.shp_item[I_SHELL]; if (shell <= 0) { diff --git a/src/lib/subs/landgun.c b/src/lib/subs/landgun.c index 617da772..4f0c018d 100644 --- a/src/lib/subs/landgun.c +++ b/src/lib/subs/landgun.c @@ -113,8 +113,7 @@ shp_fire(struct shpstr *sp) if (sp->shp_effic < 60) return -1; - guns = sp->shp_glim; - guns = MIN(guns, sp->shp_item[I_GUN]); + guns = shp_usable_guns(sp); guns = MIN(guns, (sp->shp_item[I_MILIT] + 1) / 2); if (guns == 0) return -1; @@ -217,6 +216,15 @@ lnd_fire(struct lndstr *lp) return d; } +/* + * Return number of guns ship SP can fire. + */ +int +shp_usable_guns(struct shpstr *sp) +{ + return MIN(sp->shp_glim, sp->shp_item[I_GUN]); +} + /* * Return effective firing range for range factor RNG at tech TLEV. */ diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index 0691a58d..dd0cdee6 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -877,7 +877,7 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget) continue; /* now calculate the odds */ - gun = MIN(ship.shp_item[I_GUN], ship.shp_glim); + gun = shp_usable_guns(&ship); eff = ship.shp_effic / 100.0; teff = ship.shp_tech / (ship.shp_tech + 200.0); /* raise 4.5 for better interception -KHS */