minor readobjnam cleanup (trunk only)

Remove some clutter from the wish handling code, mostly by taking
advantage of the fact that the wizard flag is valid even for the !WIZARD
configuration.  No change to game play.
This commit is contained in:
nethack.rankin
2010-03-01 03:27:33 +00:00
parent cbd2a516e1
commit 9f7be9c4d9
+37 -97
View File
@@ -2336,9 +2336,7 @@ struct obj *no_wish;
/* "trapped" recognized but not honored outside wizard mode */ /* "trapped" recognized but not honored outside wizard mode */
} else if(!strncmpi(bp, "trapped ",l=8)) { } else if(!strncmpi(bp, "trapped ",l=8)) {
trapped = 0; /* undo any previous "untrapped" */ trapped = 0; /* undo any previous "untrapped" */
#ifdef WIZARD
if (wizard) trapped = 1; if (wizard) trapped = 1;
#endif
} else if(!strncmpi(bp, "untrapped ",l=10)) { } else if(!strncmpi(bp, "untrapped ",l=10)) {
trapped = 2; /* not trapped */ trapped = 2; /* not trapped */
} else if(!strncmpi(bp, "greased ",l=8)) { } else if(!strncmpi(bp, "greased ",l=8)) {
@@ -2575,33 +2573,25 @@ struct obj *no_wish;
if(!BSTRCMPI(bp, p-10, "gold piece") || !BSTRCMPI(bp, p-7, "zorkmid") || if(!BSTRCMPI(bp, p-10, "gold piece") || !BSTRCMPI(bp, p-7, "zorkmid") ||
!strcmpi(bp, "gold") || !strcmpi(bp, "money") || !strcmpi(bp, "gold") || !strcmpi(bp, "money") ||
!strcmpi(bp, "coin") || *bp == GOLD_SYM) { !strcmpi(bp, "coin") || *bp == GOLD_SYM) {
if (cnt > 5000 if (cnt > 5000 && !wizard) cnt = 5000;
#ifdef WIZARD else if (cnt < 1) cnt = 1;
&& !wizard
#endif
) cnt=5000;
if (cnt < 1) cnt=1;
#ifndef GOLDOBJ #ifndef GOLDOBJ
pline("%d gold piece%s.", cnt, plur(cnt)); pline("%d gold piece%s.", cnt, plur(cnt));
u.ugold += cnt; u.ugold += (long) cnt;
context.botl=1; otmp = &zeroobj; /* readobjnam()'s return value for gold */
return (&zeroobj);
#else #else
otmp = mksobj(GOLD_PIECE, FALSE, FALSE); otmp = mksobj(GOLD_PIECE, FALSE, FALSE);
otmp->quan = cnt; otmp->quan = (long) cnt;
otmp->owt = weight(otmp); otmp->owt = weight(otmp);
context.botl=1;
return (otmp);
#endif #endif
context.botl = 1;
return otmp;
} }
/* check for single character object class code ("/" for wand, &c) */
if (strlen(bp) == 1 && if (strlen(bp) == 1 &&
(i = def_char_to_objclass(*bp)) < MAXOCLASSES && i > ILLOBJ_CLASS (i = def_char_to_objclass(*bp)) < MAXOCLASSES &&
#ifdef WIZARD i > ILLOBJ_CLASS && (i != VENOM_CLASS || wizard)) {
&& (wizard || i != VENOM_CLASS)
#else
&& i != VENOM_CLASS
#endif
) {
oclass = i; oclass = i;
goto any; goto any;
} }
@@ -2934,13 +2924,8 @@ any:
typfnd: typfnd:
if (typ) oclass = objects[typ].oc_class; if (typ) oclass = objects[typ].oc_class;
/* check for some objects that are not allowed */ /* handle some objects that are only allowed in wizard mode */
if (typ && objects[typ].oc_unique) { if (typ && !wizard) {
#ifdef WIZARD
if (wizard)
; /* allow unique objects */
else
#endif
switch (typ) { switch (typ) {
case AMULET_OF_YENDOR: case AMULET_OF_YENDOR:
typ = FAKE_AMULET_OF_YENDOR; typ = FAKE_AMULET_OF_YENDOR;
@@ -2954,32 +2939,21 @@ typfnd:
case SPE_BOOK_OF_THE_DEAD: case SPE_BOOK_OF_THE_DEAD:
typ = SPE_BLANK_PAPER; typ = SPE_BLANK_PAPER;
break; break;
case MAGIC_LAMP:
typ = OIL_LAMP;
break;
default:
/* catch any other non-wishable objects (venom) */
if (objects[typ].oc_nowish) return ((struct obj *)0);
break;
} }
} }
/* catch any other non-wishable objects */ /*
if (objects[typ].oc_nowish * Create the object, then fine-tune it.
#ifdef WIZARD */
&& !wizard otmp = typ ? mksobj(typ, TRUE, FALSE) : mkobj(oclass, FALSE);
#endif typ = otmp->otyp, oclass = otmp->oclass; /* what we actually got */
)
return((struct obj *)0);
/* convert magic lamps to regular lamps before lighting them or setting
the charges */
if (typ == MAGIC_LAMP
#ifdef WIZARD
&& !wizard
#endif
)
typ = OIL_LAMP;
if(typ) {
otmp = mksobj(typ, TRUE, FALSE);
} else {
otmp = mkobj(oclass, FALSE);
if (otmp) typ = otmp->otyp;
}
if (islit && if (islit &&
(typ == OIL_LAMP || typ == MAGIC_LAMP || typ == BRASS_LANTERN || (typ == OIL_LAMP || typ == MAGIC_LAMP || typ == BRASS_LANTERN ||
@@ -2989,16 +2963,14 @@ typfnd:
obj_extract_self(otmp); /* now release it for caller's use */ obj_extract_self(otmp); /* now release it for caller's use */
} }
if(cnt > 0 && objects[typ].oc_merge && oclass != SPBOOK_CLASS && /* if player specified a reasonable count, maybe honor it */
(cnt < rnd(6) || if (cnt > 0 && objects[typ].oc_merge &&
#ifdef WIZARD (wizard || cnt < rnd(6) ||
wizard ||
#endif
(cnt <= 7 && Is_candle(otmp)) || (cnt <= 7 && Is_candle(otmp)) ||
(cnt <= 20 && (cnt <= 20 &&
((oclass == WEAPON_CLASS && is_ammo(otmp)) ((oclass == WEAPON_CLASS && is_ammo(otmp))
|| typ == ROCK || is_missile(otmp))))) || typ == ROCK || is_missile(otmp)))))
otmp->quan = (long) cnt; otmp->quan = (long) cnt;
#ifdef WIZARD #ifdef WIZARD
if (oclass == VENOM_CLASS) otmp->spe = 1; if (oclass == VENOM_CLASS) otmp->spe = 1;
@@ -3046,15 +3018,11 @@ typfnd:
case SCR_MAIL: otmp->spe = 1; break; case SCR_MAIL: otmp->spe = 1; break;
#endif #endif
case WAN_WISHING: case WAN_WISHING:
#ifdef WIZARD
if (!wizard) { if (!wizard) {
#endif
otmp->spe = (rn2(10) ? -1 : 0); otmp->spe = (rn2(10) ? -1 : 0);
break; break;
#ifdef WIZARD
} }
/* fall through, if wizard */ /* fall through, if wizard */
#endif
default: otmp->spe = spe; default: otmp->spe = spe;
} }
@@ -3118,22 +3086,10 @@ typfnd:
curse(otmp); curse(otmp);
} else if (uncursed) { } else if (uncursed) {
otmp->blessed = 0; otmp->blessed = 0;
otmp->cursed = (Luck < 0 otmp->cursed = (Luck < 0 && !wizard);
#ifdef WIZARD
&& !wizard
#endif
);
} else if (blessed) { } else if (blessed) {
otmp->blessed = (Luck >= 0 otmp->blessed = (Luck >= 0 || wizard);
#ifdef WIZARD otmp->cursed = (Luck < 0 && !wizard);
|| wizard
#endif
);
otmp->cursed = (Luck < 0
#ifdef WIZARD
&& !wizard
#endif
);
} else if (spesgn < 0) { } else if (spesgn < 0) {
curse(otmp); curse(otmp);
} }
@@ -3151,21 +3107,13 @@ typfnd:
/* set erodeproof */ /* set erodeproof */
if (erodeproof && !eroded && !eroded2) if (erodeproof && !eroded && !eroded2)
otmp->oerodeproof = (Luck >= 0 otmp->oerodeproof = (Luck >= 0 || wizard);
#ifdef WIZARD
|| wizard
#endif
);
} }
/* set otmp->recharged */ /* set otmp->recharged */
if (oclass == WAND_CLASS) { if (oclass == WAND_CLASS) {
/* prevent wishing abuse */ /* prevent wishing abuse */
if (otmp->otyp == WAN_WISHING if (otmp->otyp == WAN_WISHING && !wizard) rechrg = 1;
#ifdef WIZARD
&& !wizard
#endif
) rechrg = 1;
otmp->recharged = (unsigned)rechrg; otmp->recharged = (unsigned)rechrg;
} }
@@ -3190,12 +3138,7 @@ typfnd:
otmp->odiluted = 1; otmp->odiluted = 1;
/* set tin variety */ /* set tin variety */
if (otmp->otyp == TIN && tvariety >= 0 && if (otmp->otyp == TIN && tvariety >= 0 && (rn2(4) || wizard))
(rn2(4)
#ifdef WIZARD
|| wizard
#endif
))
set_tin_variety(otmp, tvariety); set_tin_variety(otmp, tvariety);
if (name) { if (name) {
@@ -3216,11 +3159,8 @@ typfnd:
/* more wishing abuse: don't allow wishing for certain artifacts */ /* more wishing abuse: don't allow wishing for certain artifacts */
/* and make them pay; charge them for the wish anyway! */ /* and make them pay; charge them for the wish anyway! */
if ((is_quest_artifact(otmp) || if ((is_quest_artifact(otmp) ||
(otmp->oartifact && rn2(nartifact_exist()) > 1)) (otmp->oartifact && rn2(nartifact_exist()) > 1)) &&
#ifdef WIZARD !wizard) {
&& !wizard
#endif
) {
artifact_exists(otmp, safe_oname(otmp), FALSE); artifact_exists(otmp, safe_oname(otmp), FALSE);
obfree(otmp, (struct obj *) 0); obfree(otmp, (struct obj *) 0);
otmp = &zeroobj; otmp = &zeroobj;