MCPcopy Create free account
hub / github.com/NetHack/NetHack / spell_would_be_useless

Function spell_would_be_useless

src/mcastu.c:908–985  ·  view source on GitHub ↗

Some spells are useless under some circumstances. */

Source from the content-addressed store, hash-verified

906
907/* Some spells are useless under some circumstances. */
908staticfn boolean
909spell_would_be_useless(struct monst *mtmp, int spellnum)
910{
911 /* Some spells don't require the player to really be there and can be cast
912 * by the monster when you're invisible, yet still shouldn't be cast when
913 * the monster doesn't even think you're there.
914 * This check isn't quite right because it always uses your real position.
915 * We really want something like "if the monster could see mux, muy".
916 */
917
918 /* spell is only cast by hostile monsters */
919 if ((mcast_data[spellnum].flags & MCF_HOSTILE) != 0) {
920 if (mtmp->mpeaceful)
921 return TRUE;
922 }
923
924 /* spell needs the monster to see hero */
925 if ((mcast_data[spellnum].flags & MCF_SIGHT) != 0) {
926 boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my);
927
928 if (!mcouldseeu)
929 return TRUE;
930 }
931
932 switch (spellnum) {
933 case MCAST_DEATH_TOUCH:
934 if ((Antimagic || Hallucination) && !rn2(2))
935 return TRUE;
936 break;
937 case MCAST_GEYSER:
938 if (!rn2(5))
939 return TRUE;
940 break;
941 case MCAST_CLONE_WIZ:
942 /* only the Wizard is allowed to clone himself */
943 if (!mtmp->iswiz || svc.context.no_of_wizards > 1)
944 return TRUE;
945 break;
946 case MCAST_AGGRAVATION:
947 /* aggravation (global wakeup) when everyone is already active */
948 /* if nothing needs to be awakened then this spell is useless
949 but caster might not realize that [chance to pick it then
950 must be very small otherwise caller's many retry attempts
951 will eventually end up picking it too often] */
952 if (!has_aggravatables(mtmp))
953 return rn2(100) ? TRUE : FALSE;
954 break;
955 case MCAST_HASTE_SELF:
956 /* haste self when already fast */
957 if (mtmp->permspeed == MFAST)
958 return TRUE;
959 break;
960 case MCAST_DISAPPEAR:
961 /* invisibility when already invisible */
962 if (mtmp->minvis || mtmp->invis_blkd)
963 return TRUE;
964 /* peaceful monster won't cast invisibility if you can't see
965 invisible,

Callers 2

choose_monster_spellFunction · 0.85
castmuFunction · 0.85

Calls 2

rn2Function · 0.85
has_aggravatablesFunction · 0.85

Tested by

no test coverage detected