Factor feels_like_helping() out of quiet_bigdef(), sd(), dd()
This commit is contained in:
parent
7374002fd7
commit
c095ad285b
3 changed files with 26 additions and 44 deletions
|
@ -437,6 +437,7 @@ extern void ef_fin_srv(void);
|
||||||
extern int sd(natid, natid, coord, coord, int, int, int);
|
extern int sd(natid, natid, coord, coord, int, int, int);
|
||||||
extern int dd(natid, natid, coord, coord, int, int);
|
extern int dd(natid, natid, coord, coord, int, int);
|
||||||
extern int shipdef(natid, natid, coord, coord);
|
extern int shipdef(natid, natid, coord, coord);
|
||||||
|
extern int feels_like_helping(natid, natid, natid);
|
||||||
/* getbit.c */
|
/* getbit.c */
|
||||||
extern int emp_getbit(int, int, unsigned char *);
|
extern int emp_getbit(int, int, unsigned char *);
|
||||||
extern void emp_setbit(int, int, unsigned char *);
|
extern void emp_setbit(int, int, unsigned char *);
|
||||||
|
|
|
@ -588,7 +588,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
int dam, dam2, rel, rel2;
|
int dam, dam2;
|
||||||
struct sctstr firing;
|
struct sctstr firing;
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
struct flist *fp;
|
struct flist *fp;
|
||||||
|
@ -598,19 +598,12 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
dam = 0;
|
dam = 0;
|
||||||
snxtitem_dist(&ni, EF_SHIP, ax, ay, 8);
|
snxtitem_dist(&ni, EF_SHIP, ax, ay, 8);
|
||||||
while (nxtitem(&ni, &ship)) {
|
while (nxtitem(&ni, &ship)) {
|
||||||
if (ship.shp_own == 0)
|
if (!feels_like_helping(ship.shp_own, own, aown))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((mchr[ship.shp_type].m_flags & M_SUB) && type != EF_SHIP)
|
if ((mchr[ship.shp_type].m_flags & M_SUB) && type != EF_SHIP)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rel = getrel(getnatp(ship.shp_own), own);
|
|
||||||
rel2 = getrel(getnatp(ship.shp_own), aown);
|
|
||||||
if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
|
|
||||||
continue;
|
|
||||||
/* Don't shoot yourself */
|
|
||||||
if (ship.shp_own == aown)
|
|
||||||
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);
|
||||||
if (roundrange(erange) < ni.curdist)
|
if (roundrange(erange) < ni.curdist)
|
||||||
|
@ -650,16 +643,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
}
|
}
|
||||||
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 (!feels_like_helping(land.lnd_own, own, aown))
|
||||||
continue;
|
|
||||||
/* Don't shoot yourself */
|
|
||||||
if (land.lnd_own == aown)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
rel = getrel(getnatp(land.lnd_own), own);
|
|
||||||
rel2 = getrel(getnatp(land.lnd_own), aown);
|
|
||||||
|
|
||||||
if ((land.lnd_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
erange = lnd_fire_range(&land);
|
erange = lnd_fire_range(&land);
|
||||||
|
@ -697,17 +681,9 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
if (!opt_NO_FORT_FIRE) {
|
if (!opt_NO_FORT_FIRE) {
|
||||||
snxtsct_dist(&ns, ax, ay, 8);
|
snxtsct_dist(&ns, ax, ay, 8);
|
||||||
while (nxtsct(&ns, &firing)) {
|
while (nxtsct(&ns, &firing)) {
|
||||||
if (firing.sct_own == 0)
|
if (!feels_like_helping(firing.sct_own, own, aown))
|
||||||
continue;
|
continue;
|
||||||
rel = getrel(getnatp(firing.sct_own), own);
|
|
||||||
rel2 = getrel(getnatp(firing.sct_own), aown);
|
|
||||||
|
|
||||||
if ((firing.sct_own != own) &&
|
|
||||||
((rel != ALLIED) || (rel2 != AT_WAR)))
|
|
||||||
continue;
|
|
||||||
/* Don't shoot yourself */
|
|
||||||
if (firing.sct_own == aown)
|
|
||||||
continue;
|
|
||||||
erange = fortrange(&firing);
|
erange = fortrange(&firing);
|
||||||
if (roundrange(erange) < ns.curdist)
|
if (roundrange(erange) < ns.curdist)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -71,7 +71,7 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
|
||||||
double eff;
|
double eff;
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
int dam, rel, rel2;
|
int dam;
|
||||||
|
|
||||||
if (own == 0)
|
if (own == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -80,15 +80,9 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
|
||||||
eff = 1.0;
|
eff = 1.0;
|
||||||
snxtitem_dist(&ni, EF_SHIP, x, y, 8);
|
snxtitem_dist(&ni, EF_SHIP, x, y, 8);
|
||||||
while (nxtitem(&ni, &ship) && eff > 0.30) {
|
while (nxtitem(&ni, &ship) && eff > 0.30) {
|
||||||
if (ship.shp_own == att)
|
if (!feels_like_helping(ship.shp_own, own, att))
|
||||||
continue;
|
|
||||||
if (ship.shp_own == 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rel = getrel(getnatp(ship.shp_own), own);
|
|
||||||
rel2 = getrel(getnatp(ship.shp_own), att);
|
|
||||||
if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
|
|
||||||
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(shp_fire_range(&ship));
|
range = roundrange(shp_fire_range(&ship));
|
||||||
|
@ -131,7 +125,7 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
|
||||||
int
|
int
|
||||||
dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
|
dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
|
||||||
{
|
{
|
||||||
int dam, rel, rel2;
|
int dam;
|
||||||
struct sctstr firing;
|
struct sctstr firing;
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
|
|
||||||
|
@ -144,13 +138,7 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
|
||||||
dam = 0;
|
dam = 0;
|
||||||
snxtsct_dist(&ns, ax, ay, 8);
|
snxtsct_dist(&ns, ax, ay, 8);
|
||||||
while (nxtsct(&ns, &firing) && dam < 80) {
|
while (nxtsct(&ns, &firing) && dam < 80) {
|
||||||
if (firing.sct_own == att)
|
if (!feels_like_helping(firing.sct_own, def_own, att))
|
||||||
continue;
|
|
||||||
if (firing.sct_own == 0)
|
|
||||||
continue;
|
|
||||||
rel = getrel(getnatp(firing.sct_own), def_own);
|
|
||||||
rel2 = getrel(getnatp(firing.sct_own), att);
|
|
||||||
if (firing.sct_own != def_own && (rel != ALLIED || rel2 != AT_WAR))
|
|
||||||
continue;
|
continue;
|
||||||
/* XXX defdef damage is additive, but ship or land unit damage isn't */
|
/* XXX defdef damage is additive, but ship or land unit damage isn't */
|
||||||
dam += sb(att, def_own, &firing, ax, ay, noisy, defending);
|
dam += sb(att, def_own, &firing, ax, ay, noisy, defending);
|
||||||
|
@ -158,6 +146,23 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
|
||||||
return dam;
|
return dam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Shall CN attempt to help FRIEND against FOE?
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
feels_like_helping(natid cn, natid friend, natid foe)
|
||||||
|
{
|
||||||
|
if (cn == 0)
|
||||||
|
return 0; /* never helps anybody */
|
||||||
|
if (cn == foe)
|
||||||
|
return 0; /* don't help anybody against self */
|
||||||
|
if (cn == friend)
|
||||||
|
return 1; /* help self against anybody else */
|
||||||
|
/* third party helps ally if at war with foe: */
|
||||||
|
return getrel(getnatp(cn), friend) == ALLIED
|
||||||
|
&& getrel(getnatp(cn), foe) == AT_WAR;
|
||||||
|
}
|
||||||
|
|
||||||
/* Shoot back
|
/* Shoot back
|
||||||
*
|
*
|
||||||
* See if the sector being fired at will defend itself.
|
* See if the sector being fired at will defend itself.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue