Simplify quiet_bigdef()
Move common part of submarine and surface ship return fire out of the conditional. Use ni.curdist instead of recomputing the range.
This commit is contained in:
parent
3c7ea15195
commit
4babf726f0
1 changed files with 10 additions and 19 deletions
|
@ -695,7 +695,6 @@ static int
|
||||||
quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
coord ax, coord ay, int *nfiring)
|
coord ax, coord ay, int *nfiring)
|
||||||
{
|
{
|
||||||
int range;
|
|
||||||
double erange;
|
double erange;
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
|
@ -726,8 +725,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
continue;
|
continue;
|
||||||
if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
|
if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
|
||||||
erange = torprange(&ship);
|
erange = torprange(&ship);
|
||||||
range = mapdist(ship.shp_x, ship.shp_y, ax, ay);
|
if (roundrange(erange) < ni.curdist)
|
||||||
if (range > roundrange(erange))
|
|
||||||
continue;
|
continue;
|
||||||
if (!line_of_sight(NULL, ship.shp_x, ship.shp_y, ax, ay))
|
if (!line_of_sight(NULL, ship.shp_x, ship.shp_y, ax, ay))
|
||||||
continue;
|
continue;
|
||||||
|
@ -735,15 +733,8 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
/* no putship(&ship) because ammo is charged in use_ammo() */
|
/* no putship(&ship) because ammo is charged in use_ammo() */
|
||||||
if (dam2 < 0)
|
if (dam2 < 0)
|
||||||
continue;
|
continue;
|
||||||
(*nfiring)++;
|
if (!chance(shp_torp_hitchance(&ship, ni.curdist)))
|
||||||
fp = malloc(sizeof(struct flist));
|
dam2 = 0;
|
||||||
memset(fp, 0, sizeof(struct flist));
|
|
||||||
fp->type = targ_ship;
|
|
||||||
fp->uid = ship.shp_uid;
|
|
||||||
add_to_fired_queue(&fp->queue, list);
|
|
||||||
if (!chance(shp_torp_hitchance(&ship, range)))
|
|
||||||
continue;
|
|
||||||
dam += dam2;
|
|
||||||
} else {
|
} else {
|
||||||
erange = shp_fire_range(&ship);
|
erange = shp_fire_range(&ship);
|
||||||
if (roundrange(erange) < ni.curdist)
|
if (roundrange(erange) < ni.curdist)
|
||||||
|
@ -752,16 +743,16 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
/* no putship(&ship) because ammo is charged in use_ammo() */
|
/* no putship(&ship) because ammo is charged in use_ammo() */
|
||||||
if (dam2 < 0)
|
if (dam2 < 0)
|
||||||
continue;
|
continue;
|
||||||
|
nreport(ship.shp_own, N_FIRE_BACK, player->cnum, 1);
|
||||||
|
}
|
||||||
(*nfiring)++;
|
(*nfiring)++;
|
||||||
fp = malloc(sizeof(struct flist));
|
fp = malloc(sizeof(struct flist));
|
||||||
memset(fp, 0, sizeof(struct flist));
|
memset(fp, 0, sizeof(struct flist));
|
||||||
fp->type = targ_ship;
|
fp->type = targ_ship;
|
||||||
fp->uid = ship.shp_uid;
|
fp->uid = ship.shp_uid;
|
||||||
add_to_fired_queue(&fp->queue, list);
|
add_to_fired_queue(&fp->queue, list);
|
||||||
nreport(ship.shp_own, N_FIRE_BACK, player->cnum, 1);
|
|
||||||
dam += dam2;
|
dam += dam2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
snxtitem_dist(&ni, EF_LAND, ax, ay, 8);
|
snxtitem_dist(&ni, EF_LAND, ax, ay, 8);
|
||||||
while (nxtitem(&ni, &land)) {
|
while (nxtitem(&ni, &land)) {
|
||||||
if (land.lnd_own == 0)
|
if (land.lnd_own == 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue