diff --git a/include/mcastu.h b/include/mcastu.h new file mode 100644 index 000000000..fd59871c9 --- /dev/null +++ b/include/mcastu.h @@ -0,0 +1,35 @@ + + +#define MCF_NONE 0x0000 +#define MCF_INDIRECT 0x0001 /* untargeted/indirect spell */ +#define MCF_SIGHT 0x0002 /* monster needs to see hero */ +#define MCF_HOSTILE 0x0004 /* cast by hostile monsters only */ + +#if defined(MCASTU_ENUM) +#define MONSPELL(def, flags) MCAST_##def +#elif defined(MCASTU_INIT) +#define MONSPELL(def, flags) flags +#endif + +MONSPELL(PSI_BOLT, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(OPEN_WOUNDS, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(LIGHTNING, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(FIRE_PILLAR, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(GEYSER, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(DEATH_TOUCH, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(CURE_SELF, MCF_INDIRECT), +MONSPELL(HASTE_SELF, MCF_INDIRECT), +MONSPELL(DISAPPEAR, MCF_INDIRECT), +MONSPELL(AGGRAVATION, MCF_INDIRECT|MCF_HOSTILE|MCF_SIGHT), +MONSPELL(STUN_YOU, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(WEAKEN_YOU, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(CONFUSE_YOU, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(PARALYZE, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(BLIND_YOU, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(DESTRY_ARMR, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(CURSE_ITEMS, MCF_HOSTILE|MCF_SIGHT), +MONSPELL(INSECTS, MCF_HOSTILE|MCF_INDIRECT|MCF_SIGHT), +MONSPELL(SUMMON_MONS, MCF_HOSTILE|MCF_INDIRECT|MCF_SIGHT), +MONSPELL(CLONE_WIZ, MCF_HOSTILE|MCF_INDIRECT|MCF_SIGHT), + +#undef MONSPELL diff --git a/src/mcastu.c b/src/mcastu.c index 3e32f2e4f..0d8af9d68 100644 --- a/src/mcastu.c +++ b/src/mcastu.c @@ -5,32 +5,17 @@ #include "hack.h" +#define MCASTU_ENUM enum mcast_spells { - MCAST_PSI_BOLT = 0, - MCAST_OPEN_WOUNDS, - MCAST_LIGHTNING, - MCAST_FIRE_PILLAR, - MCAST_GEYSER, - MCAST_DEATH_TOUCH, - - MCAST_CURE_SELF, - MCAST_HASTE_SELF, - MCAST_DISAPPEAR, - - MCAST_AGGRAVATION, - MCAST_STUN_YOU, - MCAST_WEAKEN_YOU, - MCAST_CONFUSE_YOU, - MCAST_PARALYZE, - MCAST_BLIND_YOU, - - MCAST_DESTRY_ARMR, - MCAST_CURSE_ITEMS, - - MCAST_INSECTS, - MCAST_SUMMON_MONS, - MCAST_CLONE_WIZ + #include "mcastu.h" }; +#undef MCASTU_ENUM + +#define MCASTU_INIT +static int mcast_flags[] = { + #include "mcastu.h" +}; +#undef MCASTU_INIT staticfn void cursetxt(struct monst *, boolean); staticfn int choose_magic_spell(struct monst *); @@ -965,18 +950,8 @@ mcast_spell(struct monst *mtmp, int dmg, int spellnum) staticfn boolean is_undirected_spell(int spellnum) { - switch (spellnum) { - case MCAST_CLONE_WIZ: - case MCAST_SUMMON_MONS: - case MCAST_AGGRAVATION: - case MCAST_DISAPPEAR: - case MCAST_HASTE_SELF: - case MCAST_CURE_SELF: - case MCAST_INSECTS: + if ((mcast_flags[spellnum] & MCF_INDIRECT) != 0) return TRUE; - default: - break; - } return FALSE; } @@ -990,25 +965,28 @@ spell_would_be_useless(struct monst *mtmp, int spellnum) * This check isn't quite right because it always uses your real position. * We really want something like "if the monster could see mux, muy". */ - boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my); + + /* spell is only cast by hostile monsters */ + if ((mcast_flags[spellnum] & MCF_HOSTILE) != 0) { + if (mtmp->mpeaceful) + return TRUE; + } + + /* spell needs the monster to see hero */ + if ((mcast_flags[spellnum] & MCF_SIGHT) != 0) { + boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my); + + if (!mcouldseeu) + return TRUE; + } switch (spellnum) { case MCAST_CLONE_WIZ: /* only the Wizard is allowed to clone himself */ if (!mtmp->iswiz || svc.context.no_of_wizards > 1) return TRUE; - if (!mcouldseeu) - return TRUE; - break; - case MCAST_SUMMON_MONS: - /* don't summon monsters if it doesn't think you're around */ - if (!mcouldseeu || mtmp->mpeaceful) - return TRUE; break; case MCAST_AGGRAVATION: - /* aggravate monsters, etc. won't be cast by peaceful monsters */ - if (!mcouldseeu || mtmp->mpeaceful) - return TRUE; /* aggravation (global wakeup) when everyone is already active */ /* if nothing needs to be awakened then this spell is useless but caster might not realize that [chance to pick it then @@ -1039,11 +1017,6 @@ spell_would_be_useless(struct monst *mtmp, int spellnum) if (mtmp->mhp == mtmp->mhpmax) return TRUE; break; - case MCAST_INSECTS: - /* summon insects/sticks to snakes won't be cast by peaceful monsters */ - if (!mcouldseeu || mtmp->mpeaceful) - return TRUE; - break; case MCAST_BLIND_YOU: if (Blinded) return TRUE; diff --git a/sys/msdos/Makefile.GCC b/sys/msdos/Makefile.GCC index bdf4391e3..17d3a8bd8 100644 --- a/sys/msdos/Makefile.GCC +++ b/sys/msdos/Makefile.GCC @@ -416,6 +416,7 @@ GLOBAL_H = $(PCCONF_H) $(INCL)/coord.h $(INCL)/global.h HACK_H = $(CONFIG_H) $(INCL)/context.h $(DUNGEON_H) \ $(DECL_H) $(DISPLAY_H) $(INCL)/sym.h \ $(INCL)/defsym.h $(INCL)/mkroom.h $(INCL)/objclass.h \ + $(INCL)/mcastu.h \ $(INCL)/trap.h $(INCL)/flag.h $(RM_H) \ $(INCL)/vision.h $(INCL)/wintype.h $(INCL)/engrave.h \ $(INCL)/rect.h $(INCL)/hack.h $(REGION_H) \ @@ -1407,7 +1408,7 @@ $(TARGETPFX)light.o: light.c $(HACK_H) $(TARGETPFX)lock.o: lock.c $(HACK_H) $(TARGETPFX)mail.o: mail.c $(HACK_H) ../include/mail.h $(TARGETPFX)makemon.o: makemon.c $(HACK_H) -$(TARGETPFX)mcastu.o: mcastu.c $(HACK_H) +$(TARGETPFX)mcastu.o: mcastu.c $(HACK_H) ../include/mcastu.h $(TARGETPFX)mdlib.o: mdlib.c $(CONFIG_H) ../include/permonst.h \ ../include/align.h ../include/monattk.h ../include/monflag.h \ ../include/monsters.h ../include/objclass.h \ diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index a6fcb6e94..861afc2d3 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -571,6 +571,7 @@ HACKINCL = align.h artifact.h artilist.h attrib.h botl.h \ color.h config.h config1.h context.h coord.h cstd.h decl.h \ defsym.h display.h dlb.h dungeon.h engrave.h extern.h flag.h \ fnamesiz.h func_tab.h global.h warnings.h hack.h lint.h mextra.h \ + mcastu.h \ micro.h mfndpos.h mkroom.h monattk.h mondata.h monflag.h monst.h \ monsters.h nhmd4.h obj.h objects.h objclass.h optlist.h patchlevel.h \ pcconf.h permonst.h prop.h rect.h region.h savefile.h selvar.h sym.h \ @@ -896,6 +897,7 @@ $(HACK_H): $(CONFIG_H) ../include/align.h ../include/artilist.h \ ../include/decl.h ../include/defsym.h ../include/display.h \ ../include/dungeon.h ../include/engrave.h ../include/flag.h \ ../include/hack.h ../include/lint.h ../include/mextra.h \ + ../include/mcastu.h \ ../include/mkroom.h ../include/monattk.h ../include/mondata.h \ ../include/monflag.h ../include/monst.h ../include/monsters.h \ ../include/nhlua.h ../include/obj.h ../include/objclass.h \ @@ -1185,7 +1187,7 @@ $(TARGETPFX)light.o: light.c $(HACK_H) $(TARGETPFX)lock.o: lock.c $(HACK_H) $(TARGETPFX)mail.o: mail.c $(HACK_H) ../include/mail.h $(TARGETPFX)makemon.o: makemon.c $(HACK_H) -$(TARGETPFX)mcastu.o: mcastu.c $(HACK_H) +$(TARGETPFX)mcastu.o: mcastu.c $(HACK_H) ../include/mcastu.h $(TARGETPFX)mdlib.o: mdlib.c $(CONFIG_H) ../include/align.h \ ../include/artilist.h ../include/attrib.h \ ../include/context.h ../include/defsym.h ../include/dlb.h \ diff --git a/sys/windows/GNUmakefile b/sys/windows/GNUmakefile index 6f282c632..d4cbafead 100644 --- a/sys/windows/GNUmakefile +++ b/sys/windows/GNUmakefile @@ -794,6 +794,7 @@ HACK_H = $(CONFIG_H) ../include/align.h ../include/artilist.h \ ../include/decl.h ../include/defsym.h ../include/display.h \ ../include/dungeon.h ../include/engrave.h ../include/flag.h \ ../include/hack.h ../include/lint.h ../include/mextra.h \ + ../include/mcastu.h \ ../include/mkroom.h ../include/monattk.h ../include/mondata.h \ ../include/monflag.h ../include/monst.h ../include/monsters.h \ ../include/nhlua.h ../include/obj.h ../include/objclass.h \ diff --git a/sys/windows/Makefile.nmake b/sys/windows/Makefile.nmake index 044fb9e70..5a549d3ef 100644 --- a/sys/windows/Makefile.nmake +++ b/sys/windows/Makefile.nmake @@ -694,6 +694,7 @@ HACKINCL = \ $(INCL)flag.h $(INCL)fnamesiz.h $(INCL)func_tab.h \ $(INCL)global.h $(INCL)warnings.h $(INCL)hack.h \ $(INCL)lint.h $(INCL)mextra.h $(INCL)micro.h \ + $(INCL)mcastu.h \ $(INCL)mfndpos.h $(INCL)mkroom.h $(INCL)monattk.h \ $(INCL)mondata.h $(INCL)monflag.h $(INCL)monst.h \ $(INCL)monsters.h $(INCL)nhmd4.h $(INCL)obj.h \ @@ -1131,6 +1132,7 @@ HACK_H = $(CONFIG_H) $(INCL)align.h $(INCL)artilist.h \ $(INCL)decl.h $(INCL)defsym.h $(INCL)display.h \ $(INCL)dungeon.h $(INCL)engrave.h $(INCL)flag.h \ $(INCL)hack.h $(INCL)lint.h $(INCL)mextra.h \ + $(INCL)mcastu.h \ $(INCL)mkroom.h $(INCL)monattk.h $(INCL)mondata.h \ $(INCL)monflag.h $(INCL)monst.h $(INCL)monsters.h \ $(INCL)nhlua.h $(INCL)obj.h $(INCL)objclass.h \ @@ -2664,7 +2666,7 @@ CTAGDEP = $(INCL)align.h $(INCL)artifact.h $(INCL)artilist.h \ $(INCL)attrib.h $(INCL)context.h $(INCL)coord.h \ $(INCL)decl.h $(INCL)dungeon.h $(INCL)engrave.h \ $(INCL)flag.h $(INCL)func_tab.h $(INCL)global.h \ - $(INCL)hack.h $(INCL)mextra.h \ + $(INCL)hack.h $(INCL)mextra.h $(INCL)mcastu.h \ $(INCL)mkroom.h $(INCL)monst.h \ $(INCL)obj.h $(INCL)objclass.h $(INCL)prop.h \ $(INCL)quest.h $(INCL)rect.h $(INCL)region.h \ @@ -2694,6 +2696,7 @@ $(UTIL)sf.tags: $(CTAGSCMD) $(CTAGDEP) $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)global.h $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)hack.h $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)mextra.h + $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)mcastu.h $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)mkroom.h $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)monst.h $(CTAGSCMD) $(CTAGSOPT) -a -f $@ $(INCL)defsym.h @@ -3269,7 +3272,7 @@ $(OTTY)light.o: light.c $(HACK_H) $(OTTY)lock.o: lock.c $(HACK_H) $(OTTY)mail.o: mail.c $(HACK_H) $(INCL)mail.h $(OTTY)makemon.o: makemon.c $(HACK_H) -$(OTTY)mcastu.o: mcastu.c $(HACK_H) +$(OTTY)mcastu.o: mcastu.c $(HACK_H) $(INCL)mcastu.h $(OTTY)mdlib.o: mdlib.c $(CONFIG_H) $(INCL)align.h \ $(INCL)artilist.h $(INCL)attrib.h \ $(INCL)context.h $(INCL)defsym.h $(INCL)dlb.h \ diff --git a/sys/windows/vs/NetHack/NetHack.vcxproj b/sys/windows/vs/NetHack/NetHack.vcxproj index 5df071e6c..72d8986b0 100644 --- a/sys/windows/vs/NetHack/NetHack.vcxproj +++ b/sys/windows/vs/NetHack/NetHack.vcxproj @@ -259,6 +259,7 @@ + diff --git a/sys/windows/vs/NetHackW/NetHackW.vcxproj b/sys/windows/vs/NetHackW/NetHackW.vcxproj index df43cdd0c..ba3b21b1e 100644 --- a/sys/windows/vs/NetHackW/NetHackW.vcxproj +++ b/sys/windows/vs/NetHackW/NetHackW.vcxproj @@ -327,6 +327,7 @@ +