From b635160297da178fe14c70a96ed35b61dec35672 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 7 Aug 2022 22:31:41 +0300 Subject: [PATCH] Minor ranged attack tweak Make monsters with magic and gaze attacks avoid hero, just like spitters and breathers already did. Some small code cleanup related to the ranged attacks. --- include/monattk.h | 5 +++++ src/mondata.c | 17 +++-------------- src/monmove.c | 13 +++++++------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/monattk.h b/include/monattk.h index 98975e5db..04bbb74ee 100644 --- a/include/monattk.h +++ b/include/monattk.h @@ -28,6 +28,11 @@ #define AT_WEAP 254 /* uses weapon */ #define AT_MAGC 255 /* uses magic spell(s) */ +#define DISTANCE_ATTK_TYPE(atyp) ((atyp) == AT_SPIT \ + || (atyp) == AT_BREA \ + || (atyp) == AT_MAGC \ + || (atyp) == AT_GAZE) + /* Add new damage types below. * * Note that 1-10 correspond to the types of attack used in buzz(). diff --git a/src/mondata.c b/src/mondata.c index e3dcd10a2..da0f2f840 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -306,22 +306,11 @@ can_blnd( boolean ranged_attk(struct permonst* ptr) { - register int i, atyp; - long atk_mask = (1L << AT_BREA) | (1L << AT_SPIT) | (1L << AT_GAZE); + int i; - /* was: (attacktype(ptr, AT_BREA) || attacktype(ptr, AT_WEAP) - * || attacktype(ptr, AT_SPIT) || attacktype(ptr, AT_GAZE) - * || attacktype(ptr, AT_MAGC)); - * but that's too slow -dlc - */ - for (i = 0; i < NATTK; i++) { - atyp = ptr->mattk[i].aatyp; - if (atyp >= AT_WEAP) + for (i = 0; i < NATTK; i++) + if (DISTANCE_ATTK_TYPE(ptr->mattk[i].aatyp)) return TRUE; - /* assert(atyp < 32); */ - if ((atk_mask & (1L << atyp)) != 0L) - return TRUE; - } return FALSE; } diff --git a/src/monmove.c b/src/monmove.c index d12bde9aa..2a280f806 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -756,7 +756,9 @@ dochug(register struct monst* mtmp) return 0; /* Monsters can move and then shoot on same turn; our hero can't. Is that fair? */ - if (!nearby && (ranged_attk(mdat) || find_offensive(mtmp))) + if (!nearby && (ranged_attk(mdat) + || attacktype(mdat, AT_WEAP) + || find_offensive(mtmp))) break; /* engulfer/grabber checks */ if (mtmp == u.ustuck) { @@ -945,9 +947,8 @@ m_balks_at_approaching(struct monst* mtmp) || !m_canseeu(mtmp)) return FALSE; - /* has ammo+launcher or can spit */ - if (m_has_launcher_and_ammo(mtmp) - || attacktype(mtmp->data, AT_SPIT)) + /* has ammo+launcher */ + if (m_has_launcher_and_ammo(mtmp)) return TRUE; /* is using a polearm and in range */ @@ -955,8 +956,8 @@ m_balks_at_approaching(struct monst* mtmp) && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= MON_POLE_DIST) return TRUE; - /* breath attack, and hp loss or breath not used */ - if (attacktype(mtmp->data, AT_BREA) + /* can attack from distance, and hp loss or attack not used */ + if (ranged_attk(mtmp->data) && ((mtmp->mhp < (mtmp->mhpmax+1) / 3) || !mtmp->mspec_used)) return TRUE;