diff --git a/ai.c b/ai.c index 819ea41..258cfa9 100644 --- a/ai.c +++ b/ai.c @@ -1235,7 +1235,8 @@ int ai_bored(lifeform_t *lf, lifeform_t *master, int icanattack) { lifeform_t *who; if (lf->los[n] != lf->cell) { // not ourself who = lf->los[n]->lf; - if (who && !isdead(who) && !isunconscious(who) && cansee(lf, who)) { + + if (who && !isdead(who) && !isunconscious(who) && cansee(lf, who) && isvalidattacktarget(lf, who)) { int chance = 100; // chance that we ('lf') will attack 'who' int reachpenalty; // will usually ignore targets who we can't reach @@ -3475,7 +3476,23 @@ object_t *hasbetterweapon(lifeform_t *lf, obpile_t *op) { return NULL; } +int isvalidattacktarget(lifeform_t *lf, lifeform_t *victim) { + flag_t *f; + // lifeforms won't attack monster summoners + f = hasflagval(lf->flags, F_SUMMONEDBY, victim->id, NA, NA,NULL); + if (f) { + if (!isplayer(victim)) { + return B_FALSE; + } + } + // pets won't (intentionally) attack their masters + f = hasflagval(lf->flags, F_PETOF, victim->id, NA, NA,NULL); + if (f) { + return B_FALSE; + } + return B_TRUE; +} // returns B_TRUE if we did something int lookforobs(lifeform_t *lf) { diff --git a/ai.h b/ai.h index 8b7783a..f46738a 100644 --- a/ai.h +++ b/ai.h @@ -37,6 +37,7 @@ void clearnode(node_t *n); lifeform_t *gettargetlf(lifeform_t *lf); object_t *hasbetterarmour(lifeform_t *lf, obpile_t *op); object_t *hasbetterweapon(lifeform_t *lf, obpile_t *op); +int isvalidattacktarget(lifeform_t *lf, lifeform_t *victim); int lookforobs(lifeform_t *lf); int loseaitargets(lifeform_t *lf); void makewantedoblist(lifeform_t *lf, int *noids, enum OBTYPE *oid, int *oidcovet,int *nwantflags, enum FLAG *wantflag, int *wantflagcovet);