- Monsters summoned by other monsters should never attack their summoner.

This commit is contained in:
Rob Pearce 2016-06-01 21:17:06 +10:00
parent 5135352e2a
commit 2ed1f07968
2 changed files with 19 additions and 1 deletions

19
ai.c
View File

@ -1235,7 +1235,8 @@ int ai_bored(lifeform_t *lf, lifeform_t *master, int icanattack) {
lifeform_t *who; lifeform_t *who;
if (lf->los[n] != lf->cell) { // not ourself if (lf->los[n] != lf->cell) { // not ourself
who = lf->los[n]->lf; 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 chance = 100; // chance that we ('lf') will attack 'who'
int reachpenalty; int reachpenalty;
// will usually ignore targets who we can't reach // will usually ignore targets who we can't reach
@ -3475,7 +3476,23 @@ object_t *hasbetterweapon(lifeform_t *lf, obpile_t *op) {
return NULL; 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 // returns B_TRUE if we did something
int lookforobs(lifeform_t *lf) { int lookforobs(lifeform_t *lf) {

1
ai.h
View File

@ -37,6 +37,7 @@ void clearnode(node_t *n);
lifeform_t *gettargetlf(lifeform_t *lf); lifeform_t *gettargetlf(lifeform_t *lf);
object_t *hasbetterarmour(lifeform_t *lf, obpile_t *op); object_t *hasbetterarmour(lifeform_t *lf, obpile_t *op);
object_t *hasbetterweapon(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 lookforobs(lifeform_t *lf);
int loseaitargets(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); void makewantedoblist(lifeform_t *lf, int *noids, enum OBTYPE *oid, int *oidcovet,int *nwantflags, enum FLAG *wantflag, int *wantflagcovet);