/* SCCS Id: @(#)artifact.h 3.4 1995/05/31 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ package jnethack; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; public class artifact { //~ Static fields/initializers ----------------------------------------------------------------- public static long SPFX_NONE = 0x0000000L; /* no special effects, just a bonus */ public static long SPFX_NOGEN = 0x0000001L; /* item is special, bequeathed by gods */ public static long SPFX_RESTR = 0x0000002L; /* item is restricted - can't be named */ public static long SPFX_INTEL = 0x0000004L; /* item is self-willed - intelligent */ public static long SPFX_SPEAK = 0x0000008L; /* item can speak (not implemented) */ public static long SPFX_SEEK = 0x0000010L; /* item helps you search for things */ public static long SPFX_WARN = 0x0000020L; /* item warns you of danger */ public static long SPFX_ATTK = 0x0000040L; /* item has a special attack (attk) */ public static long SPFX_DEFN = 0x0000080L; /* item has a special defence (defn) */ public static long SPFX_DRLI = 0x0000100L; /* drains a level from monsters */ public static long SPFX_SEARCH = 0x0000200L; /* helps searching */ public static long SPFX_BEHEAD = 0x0000400L; /* beheads monsters */ public static long SPFX_HALRES = 0x0000800L; /* blocks hallucinations */ public static long SPFX_ESP = 0x0001000L; /* ESP (like amulet of ESP) */ public static long SPFX_STLTH = 0x0002000L; /* Stealth */ public static long SPFX_REGEN = 0x0004000L; /* Regeneration */ public static long SPFX_EREGEN = 0x0008000L; /* Energy Regeneration */ public static long SPFX_HSPDAM = 0x0010000L; /* 1/2 spell damage (on player) in combat */ public static long SPFX_HPHDAM = 0x0020000L; /* 1/2 physical damage (on player) in combat */ public static long SPFX_TCTRL = 0x0040000L; /* Teleportation Control */ public static long SPFX_LUCK = 0x0080000L; /* Increase Luck (like Luckstone) */ public static long SPFX_DMONS = 0x0100000L; /* attack bonus on one monster type */ public static long SPFX_DCLAS = 0x0200000L; /* attack bonus on monsters w/ symbol mtype */ public static long SPFX_DFLAG1 = 0x0400000L; /* attack bonus on monsters w/ mflags1 flag */ public static long SPFX_DFLAG2 = 0x0800000L; /* attack bonus on monsters w/ mflags2 flag */ public static long SPFX_DALIGN = 0x1000000L; /* attack bonus on non-aligned monsters */ public static long SPFX_DBONUS = 0x1F00000L; /* attack bonus mask */ public static long SPFX_XRAY = 0x2000000L; /* gives X-RAY vision to player */ public static long SPFX_REFLECT = 0x4000000L; /* Reflection */ /* invoked properties with special powers */ public static long TAMING = (prop.LAST_PROP + 1); public static long HEALING = (prop.LAST_PROP + 2); public static long ENERGY_BOOST = (prop.LAST_PROP + 3); public static long UNTRAP = (prop.LAST_PROP + 4); public static long CHARGE_OBJ = (prop.LAST_PROP + 5); public static long LEV_TELE = (prop.LAST_PROP + 6); public static long CREATE_PORTAL = (prop.LAST_PROP + 7); public static long ENLIGHTENING = (prop.LAST_PROP + 8); public static long CREATE_AMMO = (prop.LAST_PROP + 9); //~ Instance fields ---------------------------------------------------------------------------- String name; attack attk; attack cary; attack defn; byte alignment; /* alignment of bequeathing gods */ char inv_prop; /* property obtained by invoking artifact */ long cost; /* price when sold to hero (default 100 x base cost) */ long cspfx; /* special effect just from carrying obj */ long mtype; /* monster type, symbol, or flag */ long spfx; /* special effect from wielding/wearing */ short otyp; short race; /* character race associated with */ short role; /* character role associated with */ private static artifact A(String nam,short typ,long s1,long s2,long mt,attack atk,attack dfn,attack cry,char inv, byte al,short cl,short rac,long cost) { artifact a = new artifact(); a.otyp = typ; a.name = nam; a.spfx = s1; a.cspfx = s2; a.mtype = mt; a.attk = atk; a.defn = dfn; a.cary = cry; a.inv_prop = inv; a.alignment = al; a.role = cl; a.race = rac; a.cost = cost; return a; } private static final attack NO_ATTK = new attack(0,0,0,0); /* no attack */ private static final attack NO_DFNS = NO_ATTK; /* no defense */ private static final attack NO_CARY = NO_ATTK; /* no carry effects */ private static attack DFNS(char c) { return new attack(0,c,0,0);} private static attack CARY(char c) { return new attack(0,c,0,0);} private static attack PHYS(char a, char b) {return new attack(0,AD_PHYS,a,b);} /* physical */ private static attack DRLI(char a, char b) {return new attack(0,AD_DRLI,a,b);} /* life drain */ private static attack COLD(char a, char b) {return new attack(0,AD_COLD,a,b);} private static attack FIRE(char a, char b) {return new attack(0,AD_FIRE,a,b);} private static attack ELEC(char a, char b) {return new attack(0,AD_ELEC,a,b);} /* electrical shock */ private static attack STUN(char a, char b) {return new attack(0,AD_STUN,a,b);} /* magical attack */ static final artifact []artilist ; static final String []artifact_names; static{ /* Artifact cost rationale: * 1. The more useful the artifact, the better its cost. * 2. Quest artifacts are highly valued. * 3. Chaotic artifacts are inflated due to scarcity (and balance). */ artilist = new artifact[]{ /* dummy element #0, so that all interesting indices are non-zero */ A("", STRANGE_OBJECT, 0, 0, 0, NO_ATTK, NO_DFNS, NO_CARY, 0, A_NONE, NON_PM, NON_PM, 0L ), A("Excalibur", LONG_SWORD, (SPFX_NOGEN|SPFX_RESTR|SPFX_SEEK|SPFX_DEFN|SPFX_INTEL|SPFX_SEARCH),0,0, PHYS(5,10), DRLI(0,0), NO_CARY, 0, A_LAWFUL, PM_KNIGHT, NON_PM, 4000L ), /* * Stormbringer only has a 2 because it can drain a level, * providing 8 more. */ A("Stormbringer", RUNESWORD, (SPFX_RESTR|SPFX_ATTK|SPFX_DEFN|SPFX_INTEL|SPFX_DRLI), 0, 0, DRLI(5,2), DRLI(0,0), NO_CARY, 0, A_CHAOTIC, NON_PM, NON_PM, 8000L ), /* * Mjollnir will return to the hand of the wielder when thrown * if the wielder is a Valkyrie wearing Gauntlets of Power. */ A("Mjollnir", WAR_HAMMER, /* Mjo:llnir */ (SPFX_RESTR|SPFX_ATTK), 0, 0, ELEC(5,24), NO_DFNS, NO_CARY, 0, A_NEUTRAL, PM_VALKYRIE, NON_PM, 4000L ), A("Cleaver", BATTLE_AXE, SPFX_RESTR, 0, 0, PHYS(3,6), NO_DFNS, NO_CARY, 0, A_NEUTRAL, PM_BARBARIAN, NON_PM, 1500L ), A("Grimtooth", ORCISH_DAGGER, SPFX_RESTR, 0, 0, PHYS(2,6), NO_DFNS, NO_CARY, 0, A_CHAOTIC, NON_PM, PM_ORC, 300L ), /* * Orcrist and Sting have same alignment as elves. */ A("Orcrist", ELVEN_BROADSWORD, SPFX_DFLAG2, 0, M2_ORC, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_CHAOTIC, NON_PM, PM_ELF, 2000L ), /* * The combination of SPFX_WARN and M2_something on an artifact * will trigger EWarn_of_mon for all monsters that have the appropriate * M2_something flags. In Sting's case it will trigger EWarn_of_mon * for M2_ORC monsters. */ A("Sting", ELVEN_DAGGER, (SPFX_WARN|SPFX_DFLAG2), 0, M2_ORC, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_CHAOTIC, NON_PM, PM_ELF, 800L ), /* * Magicbane is a bit different! Its magic fanfare * unbalances victims in addition to doing some damage. */ A("Magicbane", ATHAME, (SPFX_RESTR|SPFX_ATTK|SPFX_DEFN), 0, 0, STUN(3,4), DFNS(AD_MAGM), NO_CARY, 0, A_NEUTRAL, PM_WIZARD, NON_PM, 3500L ), A("Frost Brand", LONG_SWORD, (SPFX_RESTR|SPFX_ATTK|SPFX_DEFN), 0, 0, COLD(5,0), COLD(0,0), NO_CARY, 0, A_NONE, NON_PM, NON_PM, 3000L ), A("Fire Brand", LONG_SWORD, (SPFX_RESTR|SPFX_ATTK|SPFX_DEFN), 0, 0, FIRE(5,0), FIRE(0,0), NO_CARY, 0, A_NONE, NON_PM, NON_PM, 3000L ), A("Dragonbane", BROADSWORD, (SPFX_RESTR|SPFX_DCLAS), 0, S_DRAGON, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_NONE, NON_PM, NON_PM, 500L ), A("Demonbane", LONG_SWORD, (SPFX_RESTR|SPFX_DFLAG2), 0, M2_DEMON, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_LAWFUL, NON_PM, NON_PM, 2500L ), A("Werebane", SILVER_SABER, (SPFX_RESTR|SPFX_DFLAG2), 0, M2_WERE, PHYS(5,0), DFNS(AD_WERE), NO_CARY, 0, A_NONE, NON_PM, NON_PM, 1500L ), A("Grayswandir", SILVER_SABER, (SPFX_RESTR|SPFX_HALRES), 0, 0, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_LAWFUL, NON_PM, NON_PM, 8000L ), A("Giantslayer", LONG_SWORD, (SPFX_RESTR|SPFX_DFLAG2), 0, M2_GIANT, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_NEUTRAL, NON_PM, NON_PM, 200L ), A("Ogresmasher", WAR_HAMMER, (SPFX_RESTR|SPFX_DCLAS), 0, S_OGRE, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_NONE, NON_PM, NON_PM, 200L ), A("Trollsbane", MORNING_STAR, (SPFX_RESTR|SPFX_DCLAS), 0, S_TROLL, PHYS(5,0), NO_DFNS, NO_CARY, 0, A_NONE, NON_PM, NON_PM, 200L ), /* * Two problems: 1) doesn't let trolls regenerate heads, * 2) doesn't give unusual message for 2-headed monsters (but * allowing those at all causes more problems than worth the effort). */ A("Vorpal Blade", LONG_SWORD, (SPFX_RESTR|SPFX_BEHEAD), 0, 0, PHYS(5,1), NO_DFNS, NO_CARY, 0, A_NEUTRAL, NON_PM, NON_PM, 4000L ), /* * Ah, never shall I forget the cry, * or the shriek that shrieked he, * As I gnashed my teeth, and from my sheath * I drew my Snickersnee! * --Koko, Lord high executioner of Titipu * (From Sir W.S. Gilbert's "The Mikado") */ A("Snickersnee", KATANA, SPFX_RESTR, 0, 0, PHYS(0,8), NO_DFNS, NO_CARY, 0, A_LAWFUL, PM_SAMURAI, NON_PM, 1200L ), A("Sunsword", LONG_SWORD, (SPFX_RESTR|SPFX_DFLAG2), 0, M2_UNDEAD, PHYS(5,0), DFNS(AD_BLND), NO_CARY, 0, A_LAWFUL, NON_PM, NON_PM, 1500L ), /* * The artifacts for the quest dungeon, all self-willed. */ A("The Orb of Detection", CRYSTAL_BALL, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL), (SPFX_ESP|SPFX_HSPDAM), 0, NO_ATTK, NO_DFNS, CARY(AD_MAGM), INVIS, A_LAWFUL, PM_ARCHEOLOGIST, NON_PM, 2500L ), A("The Heart of Ahriman", LUCKSTONE, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL), SPFX_STLTH, 0, /* this stone does double damage if used as a projectile weapon */ PHYS(5,0), NO_DFNS, NO_CARY, LEVITATION, A_NEUTRAL, PM_BARBARIAN, NON_PM, 2500L ), A("The Sceptre of Might", MACE, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_DALIGN), 0, 0, PHYS(5,0), NO_DFNS, CARY(AD_MAGM), CONFLICT, A_LAWFUL, PM_CAVEMAN, NON_PM, 2500L ), //#if 0 /* OBSOLETE */ //A("The Palantir of Westernesse", CRYSTAL_BALL, // (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL), // (SPFX_ESP|SPFX_REGEN|SPFX_HSPDAM), 0, // NO_ATTK, NO_DFNS, NO_CARY, // TAMING, A_CHAOTIC, NON_PM , PM_ELF, 8000L ), //#endif A("The Staff of Aesculapius", QUARTERSTAFF, (SPFX_NOGEN|SPFX_RESTR|SPFX_ATTK|SPFX_INTEL|SPFX_DRLI|SPFX_REGEN), 0,0, DRLI(0,0), DRLI(0,0), NO_CARY, HEALING, A_NEUTRAL, PM_HEALER, NON_PM, 5000L ), A("The Magic Mirror of Merlin", MIRROR, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_SPEAK), SPFX_ESP, 0, NO_ATTK, NO_DFNS, CARY(AD_MAGM), 0, A_LAWFUL, PM_KNIGHT, NON_PM, 1500L ), A("The Eyes of the Overworld", LENSES, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_XRAY), 0, 0, NO_ATTK, NO_DFNS, CARY(AD_MAGM), ENLIGHTENING, A_NEUTRAL, PM_MONK, NON_PM, 2500L ), A("The Mitre of Holiness", HELM_OF_BRILLIANCE, (SPFX_NOGEN|SPFX_RESTR|SPFX_DFLAG2|SPFX_INTEL), 0, M2_UNDEAD, NO_ATTK, NO_DFNS, CARY(AD_FIRE), ENERGY_BOOST, A_LAWFUL, PM_PRIEST, NON_PM, 2000L ), A("The Longbow of Diana", BOW, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_REFLECT), SPFX_ESP, 0, PHYS(5,0), NO_DFNS, NO_CARY, CREATE_AMMO, A_CHAOTIC, PM_RANGER, NON_PM, 4000L ), A("The Master Key of Thievery", SKELETON_KEY, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_SPEAK), (SPFX_WARN|SPFX_TCTRL|SPFX_HPHDAM), 0, NO_ATTK, NO_DFNS, NO_CARY, UNTRAP, A_CHAOTIC, PM_ROGUE, NON_PM, 3500L ), A("The Tsurugi of Muramasa", TSURUGI, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_BEHEAD|SPFX_LUCK), 0, 0, PHYS(0,8), NO_DFNS, NO_CARY, 0, A_LAWFUL, PM_SAMURAI, NON_PM, 4500L ), //#ifdef TOURIST A("The Platinum Yendorian Express Card", CREDIT_CARD, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_DEFN), (SPFX_ESP|SPFX_HSPDAM), 0, NO_ATTK, NO_DFNS, CARY(AD_MAGM), CHARGE_OBJ, A_NEUTRAL, PM_TOURIST, NON_PM, 7000L ), //#endif A("The Orb of Fate", CRYSTAL_BALL, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL|SPFX_LUCK), (SPFX_WARN|SPFX_HSPDAM|SPFX_HPHDAM), 0, NO_ATTK, NO_DFNS, NO_CARY, LEV_TELE, A_NEUTRAL, PM_VALKYRIE, NON_PM, 3500L ), A("The Eye of the Aethiopica", AMULET_OF_ESP, (SPFX_NOGEN|SPFX_RESTR|SPFX_INTEL), (SPFX_EREGEN|SPFX_HSPDAM), 0, NO_ATTK, NO_DFNS, CARY(AD_MAGM), CREATE_PORTAL, A_NEUTRAL, PM_WIZARD, NON_PM, 4000L ), /* * terminator; otyp must be zero */ A(0, 0, 0, 0, 0, NO_ATTK, NO_DFNS, NO_CARY, 0, A_NONE, NON_PM, NON_PM, 0L )}; //initialize name list artifact_names = new String[artilist.length]; for(int count=0;count < artilist.length;count++) { artifact_names[count] = artilist[count].name; } } /* * Note: both artilist[] and artiexist[] have a dummy element #0, * so loops over them should normally start at #1. The primary * exception is the save & restore code, which doesn't care about * the contents, just the total size. */ public static artifact get_artifact(obj o) { return (((o)&&(o).oartifact) ? artilist[(int) (o).oartifact] : null); } /* The amount added to the victim's total hit points to insure that the victim will be killed even after damage bonus/penalty adjustments. Most such penalties are small, and 200 is plenty; the exception is half physical damage. 3.3.1 and previous versions tried to use a very large number to account for this case; now, we just compute the fatal damage by adding it to 2 times the total hit points instead of 1 time. Note: this will still break if they have more than about half the number of hit points that will fit in a 15 bit integer. */ static final int FATAL_DAMAGE_MODIFIER =200; static int spec_dbon_applies; /* flags including which artifacts have already been created */ static boolean []artiexist = new boolean[1+obj.NROFARTIFACTS+1]; /* and a discovery list for them (no dummy first entry here) */ static char []artidisco = new char[obj.NROFARTIFACTS]; /* handle some special cases; must be called after u_init() */ static void hack_artifacts() { artifact art; int alignmnt = aligns[flags.initalign].value; /* Fix up the alignments of "gift" artifacts */ for (art = artilist+1; art.otyp; art++) { if (art.role == Role_switch && art.alignment != align.A_NONE) { art.alignment = alignmnt; } } /* Excalibur can be used by any lawful character, not just knights */ if (!Role_if(PM_KNIGHT)) { artilist[ART_EXCALIBUR].role = role.NON_PM; } /* Fix up the quest artifact */ if (urole.questarti) { artilist[urole.questarti].alignment = alignmnt; artilist[urole.questarti].role = Role_switch; } return; } /* zero out the artifact existence list */ static void init_artifacts() { Arrays.fill(artiexist,false); Arrays.fill(artidisco,'\u0000'); hack_artifacts(); } static void save_artifacts(ObjectOutputStream fd) { try { fd.writeObject(artiexist); fd.writeObject(artidisco); } catch (IOException ex) { Logger.getLogger(artifact.class.getName()).log(Level.SEVERE, null, ex); } } static void restore_artifacts(ObjectInputStream fd) { try { artiexist = (boolean[]) fd.readObject(); artidisco = (char[]) fd.readObject(); hack_artifacts(); /* redo non-saved special cases */ } catch (IOException ex) { Logger.getLogger(artifact.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(artifact.class.getName()).log(Level.SEVERE, null, ex); } } static String artiname(int artinum) { if (artinum <= 0 || artinum > obj.NROFARTIFACTS) { return ""; } return(artilist[artinum].name); } /* Make an artifact. If a specific alignment is specified, then an object of the appropriate alignment is created from scratch, or 0 is returned if none is available. (If at least one aligned artifact has already been given, then unaligned ones also become eligible for this.) If no alignment is given, then 'otmp' is converted into an artifact of matching type, or returned as-is if that's not possible. For the 2nd case, caller should use ``obj = mk_artifact(obj, A_NONE);'' for the 1st, ``obj = mk_artifact((struct obj *)0, some_alignment);''. */ static artifact mk_artifact(obj otmp, aligntyp alignment) /* existing object; ignored if alignment specified */ /* target alignment, or A_NONE */ { artifact a; int n, m, count; boolean by_align = (alignment != align.A_NONE); short o_typ = (by_align || otmp == null) ? 0 : otmp.otyp; boolean unique = !by_align && (otmp != null) && objclass.objects[o_typ].oc_unique; short [] eligible = new short[obj.NROFARTIFACTS]; /* gather eligible artifacts */ for (n = 0, count = 0, a = artilist[count], m = 1; a.otyp != 0; count++, m++) if ((!by_align ? a.otyp == o_typ : (a.alignment == alignment || (a.alignment == align.A_NONE && decl.u.ugifts > 0))) && (((a.spfx & SPFX_NOGEN) == 0) || unique) && !artiexist[m]) { if (by_align && a.race != role.NON_PM && race_hostile(monst.mons[a.race])) continue; /* skip enemies' equipment */ else if (by_align && you.Role_if(a.role)) break make_artif; /* 'a' points to the desired one */ else eligible[n++] = m; } if (n>0) { /* found at least one candidate */ m = eligible[rn2(n)]; /* [0..n-1] */ a = artilist[m]; /* make an appropriate object if necessary, then christen it */ make_artif: if (by_align) otmp = mksobj((int)a.otyp, TRUE, FALSE); otmp = oname(otmp, a.name); otmp.oartifact = m; artiexist[m] = TRUE; } else { /* nothing appropriate could be found; return the original object */ if (by_align) otmp = 0; /* (there was no original object) */ } return otmp; } /* * Returns the full name (with articles and correct capitalization) of an * artifact named "name" if one exists, or NULL, it not. * The given name must be rather close to the real name for it to match. * The object type of the artifact is returned in otyp if the return value * is non-NULL. */ const char* artifact_name(name, otyp) const char *name; short *otyp; { register const struct artifact *a; register const char *aname; if(!strncmpi(name, "the ", 4)) name += 4; for (a = artilist+1; a.otyp; a++) { aname = a.name; if(!strncmpi(aname, "the ", 4)) aname += 4; if(!strcmpi(name, aname)) { *otyp = a.otyp; return a.name; } } return (char *)0; } boolean exist_artifact(otyp, name) register int otyp; register const char *name; { register const struct artifact *a; register boolean *arex; if (otyp && *name) for (a = artilist+1,arex = artiexist+1; a.otyp; a++,arex++) if ((int) a.otyp == otyp && !strcmp(a.name, name)) return *arex; return FALSE; } void artifact_exists(otmp, name, mod) register struct obj *otmp; register const char *name; register boolean mod; { register const struct artifact *a; if (otmp && *name) for (a = artilist+1; a.otyp; a++) if (a.otyp == otmp.otyp && !strcmp(a.name, name)) { register int m = a - artilist; otmp.oartifact = (char)(mod ? m : 0); otmp.age = 0; if(otmp.otyp == RIN_INCREASE_DAMAGE) otmp.spe = 0; artiexist[m] = mod; break; } return; } int nartifact_exist() { int a = 0; int n = SIZE(artiexist); while(n > 1) if(artiexist[--n]) a++; return a; } #endif /* OVLB */ #ifdef OVL0 boolean spec_ability(otmp, abil) struct obj *otmp; unsigned long abil; { const struct artifact *arti = get_artifact(otmp); return((boolean)(arti && (arti.spfx & abil))); } /* used so that callers don't need to known about SPFX_ codes */ boolean confers_luck(obj) struct obj *obj; { /* might as well check for this too */ if (obj.otyp == LUCKSTONE) return TRUE; return (obj.oartifact && spec_ability(obj, SPFX_LUCK)); } /* used to check whether a monster is getting reflection from an artifact */ boolean arti_reflects(obj) struct obj *obj; { const struct artifact *arti = get_artifact(obj); if (arti) { /* while being worn */ if ((obj.owornmask & ~W_ART) && (arti.spfx & SPFX_REFLECT)) return TRUE; /* just being carried */ if (arti.cspfx & SPFX_REFLECT) return TRUE; } return FALSE; } #endif /* OVL0 */ #ifdef OVLB boolean restrict_name(otmp, name) /* returns 1 if name is restricted for otmp.otyp */ register struct obj *otmp; register const char *name; { register const struct artifact *a; register const char *aname; if (!*name) return FALSE; if (!strncmpi(name, "the ", 4)) name += 4; /* Since almost every artifact is SPFX_RESTR, it doesn't cost us much to do the string comparison before the spfx check. Bug fix: don't name multiple elven daggers "Sting". */ for (a = artilist+1; a.otyp; a++) { if (a.otyp != otmp.otyp) continue; aname = a.name; if (!strncmpi(aname, "the ", 4)) aname += 4; if (!strcmp(aname, name)) return ((boolean)((a.spfx & (SPFX_NOGEN|SPFX_RESTR)) != 0 || otmp.quan > 1L)); } return FALSE; } static boolean attacks(adtyp, otmp) register int adtyp; register struct obj *otmp; { register const struct artifact *weap; if ((weap = get_artifact(otmp)) != 0) return((boolean)(weap.attk.adtyp == adtyp)); return FALSE; } boolean defends(adtyp, otmp) register int adtyp; register struct obj *otmp; { register const struct artifact *weap; if ((weap = get_artifact(otmp)) != 0) return((boolean)(weap.defn.adtyp == adtyp)); return FALSE; } /* used for monsters */ boolean protects(adtyp, otmp) int adtyp; struct obj *otmp; { register const struct artifact *weap; if ((weap = get_artifact(otmp)) != 0) return (boolean)(weap.cary.adtyp == adtyp); return FALSE; } /* * a potential artifact has just been worn/wielded/picked-up or * unworn/unwielded/dropped. Pickup/drop only set/reset the W_ART mask. */ void set_artifact_intrinsic(otmp,on,wp_mask) register struct obj *otmp; boolean on; long wp_mask; { long *mask = 0; register const struct artifact *oart = get_artifact(otmp); uchar dtyp; long spfx; if (!oart) return; /* effects from the defn field */ dtyp = (wp_mask != W_ART) ? oart.defn.adtyp : oart.cary.adtyp; if (dtyp == AD_FIRE) mask = &EFire_resistance; else if (dtyp == AD_COLD) mask = &ECold_resistance; else if (dtyp == AD_ELEC) mask = &EShock_resistance; else if (dtyp == AD_MAGM) mask = &EAntimagic; else if (dtyp == AD_DISN) mask = &EDisint_resistance; else if (dtyp == AD_DRST) mask = &EPoison_resistance; if (mask && wp_mask == W_ART && !on) { /* find out if some other artifact also confers this intrinsic */ /* if so, leave the mask alone */ register struct obj* obj; for(obj = invent; obj; obj = obj.nobj) if(obj != otmp && obj.oartifact) { register const struct artifact *art = get_artifact(obj); if(art.cary.adtyp == dtyp) { mask = (long *) 0; break; } } } if (mask) { if (on) *mask |= wp_mask; else *mask &= ~wp_mask; } /* intrinsics from the spfx field; there could be more than one */ spfx = (wp_mask != W_ART) ? oart.spfx : oart.cspfx; if(spfx && wp_mask == W_ART && !on) { /* don't change any spfx also conferred by other artifacts */ register struct obj* obj; for(obj = invent; obj; obj = obj.nobj) if(obj != otmp && obj.oartifact) { register const struct artifact *art = get_artifact(obj); spfx &= ~art.cspfx; } } if (spfx & SPFX_SEARCH) { if(on) ESearching |= wp_mask; else ESearching &= ~wp_mask; } if (spfx & SPFX_HALRES) { /* make_hallucinated must (re)set the mask itself to get * the display right */ /* restoring needed because this is the only artifact intrinsic * that can print a message--need to guard against being printed * when restoring a game */ (void) make_hallucinated((long)!on, restoring ? FALSE : TRUE, wp_mask); } if (spfx & SPFX_ESP) { if(on) ETelepat |= wp_mask; else ETelepat &= ~wp_mask; see_monsters(); } if (spfx & SPFX_STLTH) { if (on) EStealth |= wp_mask; else EStealth &= ~wp_mask; } if (spfx & SPFX_REGEN) { if (on) ERegeneration |= wp_mask; else ERegeneration &= ~wp_mask; } if (spfx & SPFX_TCTRL) { if (on) ETeleport_control |= wp_mask; else ETeleport_control &= ~wp_mask; } if (spfx & SPFX_WARN) { if (spec_m2(otmp)) { if (on) { EWarn_of_mon |= wp_mask; flags.warntype |= spec_m2(otmp); } else { EWarn_of_mon &= ~wp_mask; flags.warntype &= ~spec_m2(otmp); } see_monsters(); } else { if (on) EWarning |= wp_mask; else EWarning &= ~wp_mask; } } if (spfx & SPFX_EREGEN) { if (on) EEnergy_regeneration |= wp_mask; else EEnergy_regeneration &= ~wp_mask; } if (spfx & SPFX_HSPDAM) { if (on) EHalf_spell_damage |= wp_mask; else EHalf_spell_damage &= ~wp_mask; } if (spfx & SPFX_HPHDAM) { if (on) EHalf_physical_damage |= wp_mask; else EHalf_physical_damage &= ~wp_mask; } if (spfx & SPFX_XRAY) { /* this assumes that no one else is using xray_range */ if (on) u.xray_range = 3; else u.xray_range = -1; vision_full_recalc = 1; } if ((spfx & SPFX_REFLECT) && (wp_mask & W_WEP)) { if (on) EReflecting |= wp_mask; else EReflecting &= ~wp_mask; } if(wp_mask == W_ART && !on && oart.inv_prop) { /* might have to turn off invoked power too */ if (oart.inv_prop <= LAST_PROP && (u.uprops[oart.inv_prop].extrinsic & W_ARTI)) (void) arti_invoke(otmp); } } /* * creature (usually player) tries to touch (pick up or wield) an artifact obj. * Returns 0 if the object refuses to be touched. * This routine does not change any object chains. * Ignores such things as gauntlets, assuming the artifact is not * fooled by such trappings. */ int touch_artifact(obj,mon) struct obj *obj; struct monst *mon; { register const struct artifact *oart = get_artifact(obj); boolean badclass, badalign, self_willed, yours; if(!oart) return 1; yours = (mon == &youmonst); /* all quest artifacts are self-willed; it this ever changes, `badclass' will have to be extended to explicitly include quest artifacts */ self_willed = ((oart.spfx & SPFX_INTEL) != 0); if (yours) { badclass = self_willed && ((oart.role != NON_PM && !Role_if(oart.role)) || (oart.race != NON_PM && !Race_if(oart.race))); badalign = (oart.spfx & SPFX_RESTR) && oart.alignment != A_NONE && (oart.alignment != u.ualign.type || u.ualign.record < 0); } else if (!is_covetous(mon.data) && !is_mplayer(mon.data)) { badclass = self_willed && oart.role != NON_PM && oart != &artilist[ART_EXCALIBUR]; badalign = (oart.spfx & SPFX_RESTR) && oart.alignment != A_NONE && (oart.alignment != sgn(mon.data.maligntyp)); } else { /* an M3_WANTSxxx monster or a fake player */ /* special monsters trying to take the Amulet, invocation tools or quest item can touch anything except for `spec_applies' artifacts */ badclass = badalign = FALSE; } /* weapons which attack specific categories of monsters are bad for them even if their alignments happen to match */ if (!badalign && (oart.spfx & SPFX_DBONUS) != 0) { struct artifact tmp; tmp = *oart; tmp.spfx &= SPFX_DBONUS; badalign = !!spec_applies(&tmp, mon); } if (((badclass || badalign) && self_willed) || (badalign && (!yours || !rn2(4)))) { int dmg; char buf[BUFSZ]; if (!yours) return 0; You("are blasted by %s power!", s_suffix(the(xname(obj)))); dmg = d((Antimagic ? 2 : 4), (self_willed ? 10 : 4)); Sprintf(buf, "touching %s", oart.name); losehp(dmg, buf, KILLED_BY); exercise(A_WIS, FALSE); } /* can pick it up unless you're totally non-synch'd with the artifact */ if (badclass && badalign && self_willed) { if (yours) pline("%s your grasp!", Tobjnam(obj, "evade")); return 0; } return 1; } #endif /* OVLB */ #ifdef OVL1 /* decide whether an artifact's special attacks apply against mtmp */ static int spec_applies(weap, mtmp) register const struct artifact *weap; struct monst *mtmp; { struct permonst *ptr; boolean yours; if(!(weap.spfx & (SPFX_DBONUS | SPFX_ATTK))) return(weap.attk.adtyp == AD_PHYS); yours = (mtmp == &youmonst); ptr = mtmp.data; if (weap.spfx & SPFX_DMONS) { return (ptr == &mons[(int)weap.mtype]); } else if (weap.spfx & SPFX_DCLAS) { return (weap.mtype == (unsigned long)ptr.mlet); } else if (weap.spfx & SPFX_DFLAG1) { return ((ptr.mflags1 & weap.mtype) != 0L); } else if (weap.spfx & SPFX_DFLAG2) { return ((ptr.mflags2 & weap.mtype) || (yours && ((!Upolyd && (urace.selfmask & weap.mtype)) || ((weap.mtype & M2_WERE) && u.ulycn >= LOW_PM)))); } else if (weap.spfx & SPFX_DALIGN) { return yours ? (u.ualign.type != weap.alignment) : (ptr.maligntyp == A_NONE || sgn(ptr.maligntyp) != weap.alignment); } else if (weap.spfx & SPFX_ATTK) { struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp)); if (defending_weapon && defending_weapon.oartifact && defends((int)weap.attk.adtyp, defending_weapon)) return FALSE; switch(weap.attk.adtyp) { case AD_FIRE: return !(yours ? Fire_resistance : resists_fire(mtmp)); case AD_COLD: return !(yours ? Cold_resistance : resists_cold(mtmp)); case AD_ELEC: return !(yours ? Shock_resistance : resists_elec(mtmp)); case AD_MAGM: case AD_STUN: return !(yours ? Antimagic : (rn2(100) < ptr.mr)); case AD_DRST: return !(yours ? Poison_resistance : resists_poison(mtmp)); case AD_DRLI: return !(yours ? Drain_resistance : resists_drli(mtmp)); case AD_STON: return !(yours ? Stone_resistance : resists_ston(mtmp)); default: impossible("Weird weapon special attack."); } } return(0); } /* return the M2 flags of monster that an artifact's special attacks apply against */ long spec_m2(otmp) struct obj *otmp; { register const struct artifact *artifact = get_artifact(otmp); if (artifact) return artifact.mtype; return 0L; } /* special attack bonus */ int spec_abon(otmp, mon) struct obj *otmp; struct monst *mon; { register const struct artifact *weap = get_artifact(otmp); /* no need for an extra check for `NO_ATTK' because this will always return 0 for any artifact which has that attribute */ if (weap && weap.attk.damn && spec_applies(weap, mon)) return rnd((int)weap.attk.damn); return 0; } /* special damage bonus */ int spec_dbon(otmp, mon, tmp) struct obj *otmp; struct monst *mon; int tmp; { register const struct artifact *weap = get_artifact(otmp); if (!weap || (weap.attk.adtyp == AD_PHYS && /* check for `NO_ATTK' */ weap.attk.damn == 0 && weap.attk.damd == 0)) spec_dbon_applies = FALSE; else spec_dbon_applies = spec_applies(weap, mon); if (spec_dbon_applies) return weap.attk.damd ? rnd((int)weap.attk.damd) : max(tmp,1); return 0; } /* add identified artifact to discoveries list */ void discover_artifact(m) char m; { int i; /* look for this artifact in the discoveries list; if we hit an empty slot then it's not present, so add it */ for (i = 0; i < NROFARTIFACTS; i++) if (artidisco[i] == 0 || artidisco[i] == m) { artidisco[i] = m; return; } /* there is one slot per artifact, so we should never reach the end without either finding the artifact or an empty slot... */ impossible("couldn't discover artifact (%d)", (int)m); } /* used to decide whether an artifact has been fully identified */ boolean undiscovered_artifact(m) char m; { int i; /* look for this artifact in the discoveries list; if we hit an empty slot then it's undiscovered */ for (i = 0; i < NROFARTIFACTS; i++) if (artidisco[i] == m) return FALSE; else if (artidisco[i] == 0) break; return TRUE; } /* display a list of discovered artifacts; return their count */ int disp_artifact_discoveries(tmpwin) winid tmpwin; /* supplied by dodiscover() */ { int i, m, otyp; char buf[BUFSZ]; for (i = 0; i < NROFARTIFACTS; i++) { if (artidisco[i] == 0) break; /* empty slot implies end of list */ if (i == 0) putstr(tmpwin, iflags.menu_headings, "Artifacts"); m = artidisco[i]; otyp = artilist[m].otyp; Sprintf(buf, " %s [%s %s]", artiname(m), align_str(artilist[m].alignment), simple_typename(otyp)); putstr(tmpwin, 0, buf); } return i; } #endif /* OVL1 */ #ifdef OVLB /* * Magicbane's intrinsic magic is incompatible with normal * enchantment magic. Thus, its effects have a negative * dependence on spe. Against low mr victims, it typically * does "double athame" damage, 2d4. Occasionally, it will * cast unbalancing magic which effectively averages out to * 4d4 damage (3d4 against high mr victims), for spe = 0. * * Prior to 3.4.1, the cancel (aka purge) effect always * included the scare effect too; now it's one or the other. * Likewise, the stun effect won't be combined with either * of those two; it will be chosen separately or possibly * used as a fallback when scare or cancel fails. * * [Historical note: a change to artifact_hit() for 3.4.0 * unintentionally made all of Magicbane's special effects * be blocked if the defender successfully saved against a * stun attack. As of 3.4.1, those effects can occur but * will be slightly less likely than they were in 3.3.x.] */ #define MB_MAX_DIEROLL 8 /* rolls above this aren't magical */ static const char * const mb_verb[2][4] = { { "probe", "stun", "scare", "cancel" }, { "prod", "amaze", "tickle", "purge" }, }; #define MB_INDEX_PROBE 0 #define MB_INDEX_STUN 1 #define MB_INDEX_SCARE 2 #define MB_INDEX_CANCEL 3 /* called when someone is being hit by Magicbane */ static boolean Mb_hit(magr, mdef, mb, dmgptr, dieroll, vis, hittee) struct monst *magr, *mdef; /* attacker and defender */ struct obj *mb; /* Magicbane */ int *dmgptr; /* extra damage target will suffer */ int dieroll; /* d20 that has already scored a hit */ boolean vis; /* whether the action can be seen */ char *hittee; /* target's name: "you" or mon_nam(mdef) */ { struct permonst *old_uasmon; const char *verb; boolean youattack = (magr == &youmonst), youdefend = (mdef == &youmonst), resisted = FALSE, do_stun, do_confuse, result; int attack_indx, scare_dieroll = MB_MAX_DIEROLL / 2; result = FALSE; /* no message given yet */ /* the most severe effects are less likely at higher enchantment */ if (mb.spe >= 3) scare_dieroll /= (1 << (mb.spe / 3)); /* if target successfully resisted the artifact damage bonus, reduce overall likelihood of the assorted special effects */ if (!spec_dbon_applies) dieroll += 1; /* might stun even when attempting a more severe effect, but in that case it will only happen if the other effect fails; extra damage will apply regardless; 3.4.1: sometimes might just probe even when it hasn't been enchanted */ do_stun = (max(mb.spe,0) < rn2(spec_dbon_applies ? 11 : 7)); /* the special effects also boost physical damage; increments are generally cumulative, but since the stun effect is based on a different criterium its damage might not be included; the base damage is either 1d4 (athame) or 2d4 (athame+spec_dbon) depending on target's resistance check against AD_STUN (handled by caller) [note that a successful save against AD_STUN doesn't actually prevent the target from ending up stunned] */ attack_indx = MB_INDEX_PROBE; *dmgptr += rnd(4); /* (2..3)d4 */ if (do_stun) { attack_indx = MB_INDEX_STUN; *dmgptr += rnd(4); /* (3..4)d4 */ } if (dieroll <= scare_dieroll) { attack_indx = MB_INDEX_SCARE; *dmgptr += rnd(4); /* (3..5)d4 */ } if (dieroll <= (scare_dieroll / 2)) { attack_indx = MB_INDEX_CANCEL; *dmgptr += rnd(4); /* (4..6)d4 */ } /* give the hit message prior to inflicting the effects */ verb = mb_verb[!!Hallucination][attack_indx]; if (youattack || youdefend || vis) { result = TRUE; pline_The("magic-absorbing blade %s %s!", vtense((const char *)0, verb), hittee); /* assume probing has some sort of noticeable feedback even if it is being done by one monster to another */ if (attack_indx == MB_INDEX_PROBE && !canspotmon(mdef)) map_invisible(mdef.mx, mdef.my); } /* now perform special effects */ switch (attack_indx) { case MB_INDEX_CANCEL: old_uasmon = youmonst.data; /* No mdef.mcan check: even a cancelled monster can be polymorphed * into a golem, and the "cancel" effect acts as if some magical * energy remains in spellcasting defenders to be absorbed later. */ if (!cancel_monst(mdef, mb, youattack, FALSE, FALSE)) { resisted = TRUE; } else { do_stun = FALSE; if (youdefend) { if (youmonst.data != old_uasmon) *dmgptr = 0; /* rehumanized, so no more damage */ if (u.uenmax > 0) { You("lose magical energy!"); u.uenmax--; if (u.uen > 0) u.uen--; flags.botl = 1; } } else { if (mdef.data == &mons[PM_CLAY_GOLEM]) mdef.mhp = 1; /* cancelled clay golems will die */ if (youattack && attacktype(mdef.data, AT_MAGC)) { You("absorb magical energy!"); u.uenmax++; u.uen++; flags.botl = 1; } } } break; case MB_INDEX_SCARE: if (youdefend) { if (Antimagic) { resisted = TRUE; } else { nomul(-3); nomovemsg = ""; if (magr && magr == u.ustuck && sticks(youmonst.data)) { u.ustuck = (struct monst *)0; You("release %s!", mon_nam(magr)); } } } else { if (rn2(2) && resist(mdef, WEAPON_CLASS, 0, NOTELL)) resisted = TRUE; else monflee(mdef, 3, FALSE, (mdef.mhp > *dmgptr)); } if (!resisted) do_stun = FALSE; break; case MB_INDEX_STUN: do_stun = TRUE; /* (this is redundant...) */ break; case MB_INDEX_PROBE: if (youattack && (mb.spe == 0 || !rn2(3 * abs(mb.spe)))) { pline_The("%s is insightful.", verb); /* pre-damage status */ probe_monster(mdef); } break; } /* stun if that was selected and a worse effect didn't occur */ if (do_stun) { if (youdefend) make_stunned((HStun + 3), FALSE); else mdef.mstun = 1; /* avoid extra stun message below if we used mb_verb["stun"] above */ if (attack_indx == MB_INDEX_STUN) do_stun = FALSE; } /* lastly, all this magic can be confusing... */ do_confuse = !rn2(12); if (do_confuse) { if (youdefend) make_confused(HConfusion + 4, FALSE); else mdef.mconf = 1; } if (youattack || youdefend || vis) { (void) upstart(hittee); /* capitalize */ if (resisted) { pline("%s %s!", hittee, vtense(hittee, "resist")); shieldeff(youdefend ? u.ux : mdef.mx, youdefend ? u.uy : mdef.my); } if ((do_stun || do_confuse) && flags.verbose) { char buf[BUFSZ]; buf[0] = '\0'; if (do_stun) Strcat(buf, "stunned"); if (do_stun && do_confuse) Strcat(buf, " and "); if (do_confuse) Strcat(buf, "confused"); pline("%s %s %s%c", hittee, vtense(hittee, "are"), buf, (do_stun && do_confuse) ? '!' : '.'); } } return result; } /* Function used when someone attacks someone else with an artifact * weapon. Only adds the special (artifact) damage, and returns a 1 if it * did something special (in which case the caller won't print the normal * hit message). This should be called once upon every artifact attack; * dmgval() no longer takes artifact bonuses into account. Possible * extension: change the killer so that when an orc kills you with * Stormbringer it's "killed by Stormbringer" instead of "killed by an orc". */ boolean artifact_hit(magr, mdef, otmp, dmgptr, dieroll) struct monst *magr, *mdef; struct obj *otmp; int *dmgptr; int dieroll; /* needed for Magicbane and vorpal blades */ { boolean youattack = (magr == &youmonst); boolean youdefend = (mdef == &youmonst); boolean vis = (!youattack && magr && cansee(magr.mx, magr.my)) || (!youdefend && cansee(mdef.mx, mdef.my)) || (youattack && u.uswallow && mdef == u.ustuck && !Blind); boolean realizes_damage; const char *wepdesc; static const char you[] = "you"; char hittee[BUFSZ]; Strcpy(hittee, youdefend ? you : mon_nam(mdef)); /* The following takes care of most of the damage, but not all-- * the exception being for level draining, which is specially * handled. Messages are done in this function, however. */ *dmgptr += spec_dbon(otmp, mdef, *dmgptr); if (youattack && youdefend) { impossible("attacking yourself with weapon?"); return FALSE; } realizes_damage = (youdefend || vis || /* feel the effect even if not seen */ (youattack && mdef == u.ustuck)); /* the four basic attacks: fire, cold, shock and missiles */ if (attacks(AD_FIRE, otmp)) { if (realizes_damage) pline_The("fiery blade %s %s%c", !spec_dbon_applies ? "hits" : (mdef.data == &mons[PM_WATER_ELEMENTAL]) ? "vaporizes part of" : "burns", hittee, !spec_dbon_applies ? '.' : '!'); if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); if (!rn2(4)) (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); if (!rn2(7)) (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); if (youdefend && Slimed) burn_away_slime(); return realizes_damage; } if (attacks(AD_COLD, otmp)) { if (realizes_damage) pline_The("ice-cold blade %s %s%c", !spec_dbon_applies ? "hits" : "freezes", hittee, !spec_dbon_applies ? '.' : '!'); if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); return realizes_damage; } if (attacks(AD_ELEC, otmp)) { if (realizes_damage) pline_The("massive hammer hits%s %s%c", !spec_dbon_applies ? "" : "! Lightning strikes", hittee, !spec_dbon_applies ? '.' : '!'); if (!rn2(5)) (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); if (!rn2(5)) (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC); return realizes_damage; } if (attacks(AD_MAGM, otmp)) { if (realizes_damage) pline_The("imaginary widget hits%s %s%c", !spec_dbon_applies ? "" : "! A hail of magic missiles strikes", hittee, !spec_dbon_applies ? '.' : '!'); return realizes_damage; } if (attacks(AD_STUN, otmp) && dieroll <= MB_MAX_DIEROLL) { /* Magicbane's special attacks (possibly modifies hittee[]) */ return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee); } if (!spec_dbon_applies) { /* since damage bonus didn't apply, nothing more to do; no further attacks have side-effects on inventory */ return FALSE; } /* We really want "on a natural 20" but Nethack does it in */ /* reverse from AD&D. */ if (spec_ability(otmp, SPFX_BEHEAD)) { if (otmp.oartifact == ART_TSURUGI_OF_MURAMASA && dieroll == 1) { wepdesc = "The razor-sharp blade"; /* not really beheading, but so close, why add another SPFX */ if (youattack && u.uswallow && mdef == u.ustuck) { You("slice %s wide open!", mon_nam(mdef)); *dmgptr = 2 * mdef.mhp + FATAL_DAMAGE_MODIFIER; return TRUE; } if (!youdefend) { /* allow normal cutworm() call to add extra damage */ if(notonhead) return FALSE; if (bigmonst(mdef.data)) { if (youattack) You("slice deeply into %s!", mon_nam(mdef)); else if (vis) pline("%s cuts deeply into %s!", Monnam(magr), hittee); *dmgptr *= 2; return TRUE; } *dmgptr = 2 * mdef.mhp + FATAL_DAMAGE_MODIFIER; pline("%s cuts %s in half!", wepdesc, mon_nam(mdef)); otmp.dknown = TRUE; return TRUE; } else { if (bigmonst(youmonst.data)) { pline("%s cuts deeply into you!", magr ? Monnam(magr) : wepdesc); *dmgptr *= 2; return TRUE; } /* Players with negative AC's take less damage instead * of just not getting hit. We must add a large enough * value to the damage so that this reduction in * damage does not prevent death. */ *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; pline("%s cuts you in half!", wepdesc); otmp.dknown = TRUE; return TRUE; } } else if (otmp.oartifact == ART_VORPAL_BLADE && (dieroll == 1 || mdef.data == &mons[PM_JABBERWOCK])) { static const char * const behead_msg[2] = { "%s beheads %s!", "%s decapitates %s!" }; if (youattack && u.uswallow && mdef == u.ustuck) return FALSE; wepdesc = artilist[ART_VORPAL_BLADE].name; if (!youdefend) { if (!has_head(mdef.data) || notonhead || u.uswallow) { if (youattack) pline("Somehow, you miss %s wildly.", mon_nam(mdef)); else if (vis) pline("Somehow, %s misses wildly.", mon_nam(magr)); *dmgptr = 0; return ((boolean)(youattack || vis)); } if (noncorporeal(mdef.data) || amorphous(mdef.data)) { pline("%s slices through %s %s.", wepdesc, s_suffix(mon_nam(mdef)), mbodypart(mdef,NECK)); return TRUE; } *dmgptr = 2 * mdef.mhp + FATAL_DAMAGE_MODIFIER; pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, mon_nam(mdef)); otmp.dknown = TRUE; return TRUE; } else { if (!has_head(youmonst.data)) { pline("Somehow, %s misses you wildly.", magr ? mon_nam(magr) : wepdesc); *dmgptr = 0; return TRUE; } if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) { pline("%s slices through your %s.", wepdesc, body_part(NECK)); return TRUE; } *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, "you"); otmp.dknown = TRUE; /* Should amulets fall off? */ return TRUE; } } } if (spec_ability(otmp, SPFX_DRLI)) { if (!youdefend) { if (vis) { if(otmp.oartifact == ART_STORMBRINGER) pline_The("%s blade draws the life from %s!", hcolor(NH_BLACK), mon_nam(mdef)); else pline("%s draws the life from %s!", The(distant_name(otmp, xname)), mon_nam(mdef)); } if (mdef.m_lev == 0) { *dmgptr = 2 * mdef.mhp + FATAL_DAMAGE_MODIFIER; } else { int drain = rnd(8); *dmgptr += drain; mdef.mhpmax -= drain; mdef.m_lev--; drain /= 2; if (drain) healup(drain, 0, FALSE, FALSE); } return vis; } else { /* youdefend */ int oldhpmax = u.uhpmax; if (Blind) You_feel("an %s drain your life!", otmp.oartifact == ART_STORMBRINGER ? "unholy blade" : "object"); else if (otmp.oartifact == ART_STORMBRINGER) pline_The("%s blade drains your life!", hcolor(NH_BLACK)); else pline("%s drains your life!", The(distant_name(otmp, xname))); losexp("life drainage"); if (magr && magr.mhp < magr.mhpmax) { magr.mhp += (oldhpmax - u.uhpmax)/2; if (magr.mhp > magr.mhpmax) magr.mhp = magr.mhpmax; } return TRUE; } } return FALSE; } static NEARDATA const char recharge_type[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; static NEARDATA const char invoke_types[] = { ALL_CLASSES, 0 }; /* #invoke: an "ugly check" filters out most objects */ int doinvoke() { register struct obj *obj; obj = getobj(invoke_types, "invoke"); if (!obj) return 0; if (obj.oartifact && !touch_artifact(obj, &youmonst)) return 1; return arti_invoke(obj); } static int arti_invoke(obj) register struct obj *obj; { register const struct artifact *oart = get_artifact(obj); if(!oart || !oart.inv_prop) { if(obj.otyp == CRYSTAL_BALL) use_crystal_ball(obj); else pline(nothing_happens); return 1; } if(oart.inv_prop > LAST_PROP) { /* It's a special power, not "just" a property */ if(obj.age > monstermoves) { /* the artifact is tired :-) */ You_feel("that %s %s ignoring you.", the(xname(obj)), otense(obj, "are")); /* and just got more so; patience is essential... */ obj.age += (long) d(3,10); return 1; } obj.age = monstermoves + rnz(100); switch(oart.inv_prop) { case TAMING: { struct obj pseudo; pseudo = zeroobj; /* neither cursed nor blessed */ pseudo.otyp = SCR_TAMING; (void) seffects(&pseudo); break; } case HEALING: { int healamt = (u.uhpmax + 1 - u.uhp) / 2; long creamed = (long)u.ucreamed; if (Upolyd) healamt = (u.mhmax + 1 - u.mh) / 2; if (healamt || Sick || Slimed || Blinded > creamed) You_feel("better."); else goto nothing_special; if (healamt > 0) { if (Upolyd) u.mh += healamt; else u.uhp += healamt; } if(Sick) make_sick(0L,(char *)0,FALSE,SICK_ALL); if(Slimed) Slimed = 0L; if (Blinded > creamed) make_blinded(creamed, FALSE); flags.botl = 1; break; } case ENERGY_BOOST: { int epboost = (u.uenmax + 1 - u.uen) / 2; if (epboost > 120) epboost = 120; /* arbitrary */ else if (epboost < 12) epboost = u.uenmax - u.uen; if(epboost) { You_feel("re-energized."); u.uen += epboost; flags.botl = 1; } else goto nothing_special; break; } case UNTRAP: { if(!untrap(TRUE)) { obj.age = 0; /* don't charge for changing their mind */ return 0; } break; } case CHARGE_OBJ: { struct obj *otmp = getobj(recharge_type, "charge"); boolean b_effect; if (!otmp) { obj.age = 0; return 0; } b_effect = obj.blessed && (Role_switch == oart.role || !oart.role); recharge(otmp, b_effect ? 1 : obj.cursed ? -1 : 0); update_inventory(); break; } case LEV_TELE: level_tele(); break; case CREATE_PORTAL: { int i, num_ok_dungeons, last_ok_dungeon = 0; d_level newlev; extern int n_dgns; /* from dungeon.c */ winid tmpwin = create_nhwindow(NHW_MENU); anything any; any.a_void = 0; /* set all bits to zero */ start_menu(tmpwin); /* use index+1 (cant use 0) as identifier */ for (i = num_ok_dungeons = 0; i < n_dgns; i++) { if (!dungeons[i].dunlev_ureached) continue; any.a_int = i+1; add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, dungeons[i].dname, MENU_UNSELECTED); num_ok_dungeons++; last_ok_dungeon = i; } end_menu(tmpwin, "Open a portal to which dungeon?"); if (num_ok_dungeons > 1) { /* more than one entry; display menu for choices */ menu_item *selected; int n; n = select_menu(tmpwin, PICK_ONE, &selected); if (n <= 0) { destroy_nhwindow(tmpwin); goto nothing_special; } i = selected[0].item.a_int - 1; free((genericptr_t)selected); } else i = last_ok_dungeon; /* also first & only OK dungeon */ destroy_nhwindow(tmpwin); /* * i is now index into dungeon structure for the new dungeon. * Find the closest level in the given dungeon, open * a use-once portal to that dungeon and go there. * The closest level is either the entry or dunlev_ureached. */ newlev.dnum = i; if(dungeons[i].depth_start >= depth(&u.uz)) newlev.dlevel = dungeons[i].entry_lev; else newlev.dlevel = dungeons[i].dunlev_ureached; if(u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev) || newlev.dnum == u.uz.dnum) { You_feel("very disoriented for a moment."); } else { if(!Blind) You("are surrounded by a shimmering sphere!"); else You_feel("weightless for a moment."); goto_level(&newlev, FALSE, FALSE, FALSE); } break; } case ENLIGHTENING: enlightenment(0); break; case CREATE_AMMO: { struct obj *otmp = mksobj(ARROW, TRUE, FALSE); if (!otmp) goto nothing_special; otmp.blessed = obj.blessed; otmp.cursed = obj.cursed; otmp.bknown = obj.bknown; if (obj.blessed) { if (otmp.spe < 0) otmp.spe = 0; otmp.quan += rnd(10); } else if (obj.cursed) { if (otmp.spe > 0) otmp.spe = 0; } else otmp.quan += rnd(5); otmp.owt = weight(otmp); otmp = hold_another_object(otmp, "Suddenly %s out.", aobjnam(otmp, "fall"), (const char *)0); break; } } } else { long eprop = (u.uprops[oart.inv_prop].extrinsic ^= W_ARTI), iprop = u.uprops[oart.inv_prop].intrinsic; boolean on = (eprop & W_ARTI) != 0; /* true if invoked prop just set */ if(on && obj.age > monstermoves) { /* the artifact is tired :-) */ u.uprops[oart.inv_prop].extrinsic ^= W_ARTI; You_feel("that %s %s ignoring you.", the(xname(obj)), otense(obj, "are")); /* can't just keep repeatedly trying */ obj.age += (long) d(3,10); return 1; } else if(!on) { /* when turning off property, determine downtime */ /* arbitrary for now until we can tune this -dlc */ obj.age = monstermoves + rnz(100); } if ((eprop & ~W_ARTI) || iprop) { nothing_special: /* you had the property from some other source too */ if (carried(obj)) You_feel("a surge of power, but nothing seems to happen."); return 1; } switch(oart.inv_prop) { case CONFLICT: if(on) You_feel("like a rabble-rouser."); else You_feel("the tension decrease around you."); break; case LEVITATION: if(on) { float_up(); spoteffects(FALSE); } else (void) float_down(I_SPECIAL|TIMEOUT, W_ARTI); break; case INVIS: if (BInvis || Blind) goto nothing_special; newsym(u.ux, u.uy); if (on) Your("body takes on a %s transparency...", Hallucination ? "normal" : "strange"); else Your("body seems to unfade..."); break; } } return 1; } /* WAC return TRUE if artifact is always lit */ boolean artifact_light(obj) struct obj *obj; { return (get_artifact(obj) && obj.oartifact == ART_SUNSWORD); } /* KMH -- Talking artifacts are finally implemented */ void arti_speak(obj) struct obj *obj; { register const struct artifact *oart = get_artifact(obj); const char *line; char buf[BUFSZ]; /* Is this a speaking artifact? */ if (!oart || !(oart.spfx & SPFX_SPEAK)) return; line = getrumor(bcsign(obj), buf, TRUE); if (!*line) line = "NetHack rumors file closed for renovation."; pline("%s:", Tobjnam(obj, "whisper")); verbalize("%s", line); return; } boolean artifact_has_invprop(otmp, inv_prop) struct obj *otmp; uchar inv_prop; { const struct artifact *arti = get_artifact(otmp); return((boolean)(arti && (arti.inv_prop == inv_prop))); } /* Return the price sold to the hero of a given artifact or unique item */ long arti_cost(otmp) struct obj *otmp; { if (!otmp.oartifact) return ((long)objects[otmp.otyp].oc_cost); else if (artilist[(int) otmp.oartifact].cost) return (artilist[(int) otmp.oartifact].cost); else return (100L * (long)objects[otmp.otyp].oc_cost); } } ----- Classpath: --------------------------------------------- bootPath: C:\Java\JDK6\jre\lib\alt-rt.jar;C:\Java\JDK6\jre\lib\endorsed\saaj-impl.jar;C:\Java\JDK6\jre\lib\endorsed\webservices-api.jar;C:\Java\JDK6\jre\lib\resources.jar;C:\Java\JDK6\jre\lib\rt.jar;C:\Java\JDK6\jre\lib\sunrsasign.jar;C:\Java\JDK6\jre\lib\jsse.jar;C:\Java\JDK6\jre\lib\jce.jar;C:\Java\JDK6\jre\lib\charsets.jar;C:\Java\JDK6\jre\classes;C:\Java\JDK6\jre\lib\ext\dnsns.jar;C:\Java\JDK6\jre\lib\ext\localedata.jar;C:\Java\JDK6\jre\lib\ext\sunjce_provider.jar;C:\Java\JDK6\jre\lib\ext\sunmscapi.jar;C:\Java\JDK6\jre\lib\ext\sunpkcs11.jar classPath: sourcePath: C:\Documents and Settings\mlambert\Desktop\Amusements\Nethack\JNethack\src ----- Original exception --------------------------------------------- java.lang.NullPointerException at com.sun.tools.javac.comp.Flow.checkInit(Flow.java:401) at com.sun.tools.javac.comp.Flow.visitIdent(Flow.java:1274) at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:1683) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.tree.TreeScanner.visitIndexed(TreeScanner.java:246) at com.sun.tools.javac.tree.JCTree$JCArrayAccess.accept(JCTree.java:1624) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow.scanExpr(Flow.java:519) at com.sun.tools.javac.comp.Flow.visitAssign(Flow.java:1213) at com.sun.tools.javac.tree.JCTree$JCAssign.accept(JCTree.java:1444) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:171) at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1145) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:503) at com.sun.tools.javac.comp.Flow.scanStats(Flow.java:511) at com.sun.tools.javac.comp.Flow.visitBlock(Flow.java:771) at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:768) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:503) at com.sun.tools.javac.comp.Flow.scanDef(Flow.java:489) at com.sun.tools.javac.comp.Flow.visitClassDef(Flow.java:637) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:587) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:1346) at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1179) at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1142) at com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:457) at com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:436) at org.netbeans.modules.java.source.parsing.JavacParser.moveToPhase(JavacParser.java:543) at org.netbeans.modules.java.source.parsing.JavacParser.getResult(JavacParser.java:393) at org.netbeans.modules.java.source.parsing.JavacParser.getResult(JavacParser.java:148) at org.netbeans.modules.parsing.impl.SourceCache.getResult(SourceCache.java:209) at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:655) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)