Factor out ship usable gun calculation into shp_usable_gun()
This commit is contained in:
parent
ffab089c61
commit
4849600cd5
5 changed files with 16 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue