From fafbb60725fd818e96003a9a50f2dcd587e79cc6 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Sun, 17 Mar 2002 08:19:21 +0000 Subject: [PATCH] touchstone again Recent patches broke rubbing gold coins on touchstones; for the !GOLDOBJ configuration, the character's money would be lost and the program leaked memory. That problem was already present for rubbing gold on other gray stones. This also gives a gem advantage back to archeologists: they can comprehend touchstone results when the stone is uncursed rather than require it to be blessed. (I gave gnome characters that benefit too. Why gnomes and not dwarves? I don't have a reasonable answer for that....) To go along with that, make A's initial touchstone start uncursed rather than blessed, so that other characters finding them in bones won't get an immediate benefit from them for the 20% of the time that they're not cursed when saving bones. Much of this is whitespace cleanup. I reformatted use_stone() completely. --- src/apply.c | 241 ++++++++++++++++++++++++++------------------------- src/u_init.c | 35 ++++---- 2 files changed, 141 insertions(+), 135 deletions(-) diff --git a/src/apply.c b/src/apply.c index 00a9c47b6..d0ae425e8 100644 --- a/src/apply.c +++ b/src/apply.c @@ -1272,7 +1272,7 @@ int magic; /* 0=Physical, otherwise skill level */ if (wl == BOTH_SIDES) bp = makeplural(bp); #ifdef STEED if (u.usteed) - pline("%s is in no shape for jumping.", Monnam(u.usteed)); + pline("%s is in no shape for jumping.", Monnam(u.usteed)); else #endif Your("%s%s %s in no shape for jumping.", @@ -1614,17 +1614,17 @@ long timeout; silent = (timeout != monstermoves); /* happened while away */ okay_spot = get_obj_location(figurine, &cc.x, &cc.y, 0); if (figurine->where == OBJ_INVENT || - figurine->where == OBJ_MINVENT) - okay_spot = enexto(&cc, cc.x, cc.y, + figurine->where == OBJ_MINVENT) + okay_spot = enexto(&cc, cc.x, cc.y, &mons[figurine->corpsenm]); if (!okay_spot || !figurine_location_checks(figurine,&cc, TRUE)) { - /* reset the timer to try again later */ + /* reset the timer to try again later */ (void) start_timer((long)rnd(5000), TIMER_OBJECT, FIG_TRANSFORM, (genericptr_t)figurine); return; } - + cansee_spot = cansee(cc.x, cc.y); mtmp = make_familiar(figurine, cc.x, cc.y, TRUE); if (mtmp) { @@ -1650,8 +1650,8 @@ long timeout; case OBJ_MINVENT: if (cansee_spot && !silent) { - struct monst *mon; - mon = figurine->ocarry; + struct monst *mon; + mon = figurine->ocarry; /* figurine carring monster might be invisible */ if (canseemon(figurine->ocarry)) { Sprintf(carriedby, "%s pack", @@ -1689,7 +1689,7 @@ coord *cc; boolean quietly; { xchar x,y; - + x = cc->x; y = cc->y; if (!isok(x,y)) { if (!quietly) @@ -1718,7 +1718,7 @@ register struct obj *obj; { xchar x, y; coord cc; - + if(!getdir((char *)0)) { flags.move = multi = 0; return; @@ -1821,126 +1821,131 @@ reset_trapset() /* touchstones - by Ken Arnold */ STATIC_OVL void -use_stone(otmp) -struct obj *otmp; +use_stone(tstone) +struct obj *tstone; { - struct obj *obj; - char allowall[3]; - const char *color = 0; - static const char *ambiguous_scratch = "You make scratch marks on the stone."; - const char *scritch = "\"scritch, scritch\""; - unsigned material; - - allowall[0] = GOLD_CLASS; - allowall[1] = ALL_CLASSES; - allowall[2] = '\0'; - if (!(obj = getobj(allowall, "rub on the stone"))) - return; + struct obj *obj; + const char *streak_color = 0; + static const char scritch[] = "\"scritch, scritch\"", + ambiguous_scratch[] = "You make scratch marks on the stone."; + static char allowall[3] = { GOLD_CLASS, ALL_CLASSES, 0 }; +#ifndef GOLDOBJ + struct obj goldobj; +#endif - if (otmp == obj) { - You_cant("rub %s on itself.", the(xname(obj))); - return; - } - material = objects[obj->otyp].oc_material; - - if (otmp->cursed && - obj->oclass == GEM_CLASS && !is_graystone(obj) && !rn2(5)) { - pline( - (Blind ? "You feel something shatter." : - (Hallucination ? "Oh, wow, look at the pretty shards." : - "A sharp crack shatters %s %s.")), - (obj->quan == 1 ? "the" : "a"), - lcase(makesingular(let_to_name(obj->oclass, FALSE)))); - useup(obj); - return; - } + if ((obj = getobj(allowall, "rub on the stone")) == 0) + return; +#ifndef GOLDOBJ + if (obj->oclass == GOLD_CLASS) { + u.ugold += obj->quan; /* keep botl up to date */ + goldobj = *obj; + dealloc_obj(obj); + obj = &goldobj; + } +#endif - if (Blind) { - pline(scritch); - return; - } + if (obj == tstone) { + You_cant("rub %s on itself.", the(xname(obj))); + return; + } - if (Hallucination) { - pline("Oh wow, man: Fractals!"); - return; - } + if (tstone->cursed && + obj->oclass == GEM_CLASS && !is_graystone(obj) && + !obj_resists(obj, 80, 100)) { + if (Blind) + pline("You feel something shatter."); + else if (Hallucination) + pline("Oh, wow, look at the pretty shards."); + else + pline("A sharp crack shatters %s%s.", + (obj->quan > 1) ? "one of " : "", the(xname(obj))); +#ifndef GOLDOBJ + /* assert(obj != &goldobj); */ +#endif + useup(obj); + return; + } - if (material == LIQUID || material == WAX || - material == CLOTH || material == WOOD || material == GOLD) { - switch(material) { - case LIQUID: - if (!obj->known) - You("must think this is a wetstone, do you?"); - else - pline("%s a little wetter now.", Tobjnam(otmp, "are")); - break; - case WAX: - color = "waxy"; - goto see_streaks; /* okay even if not touchstone */ - /*NOTREACHED*/ - break; - case CLOTH: - pline_The("stone looks a little more polished now."); - break; - case WOOD: - color = "wooden"; - goto see_streaks; /* okay even if not touchstone */ - /*NOTREACHED*/ - break; - } + if (Blind) { + pline(scritch); + return; + } else if (Hallucination) { + pline("Oh wow, man: Fractals!"); + return; + } + + switch (obj->oclass) { + case GEM_CLASS: /* these have class-specific handling below */ + case RING_CLASS: + break; + + default: + switch (objects[obj->otyp].oc_material) { + case CLOTH: + pline_The("stone looks a little more polished now."); return; - } - if (is_flimsy(obj)) { - /* Objects passing the is_flimsy() test will not - scratch a stone. They will leave streaks on - non-touchstones and touchstones alike */ - color = c_obj_colors[objects[obj->otyp].oc_color]; - goto see_streaks; - } - - if (otmp->otyp != TOUCHSTONE) { - pline(ambiguous_scratch); + case LIQUID: + if (!obj->known) /* note: not "whetstone" */ + You("must think this is a wetstone, do you?"); + else + pline("%s a little wetter now.", Tobjnam(tstone, "are")); return; - } - - if (material == GOLD) { - color = "golden"; + case WAX: + streak_color = "waxy"; + goto see_streaks; /* okay even if not touchstone */ + case WOOD: + streak_color = "wooden"; + goto see_streaks; /* okay even if not touchstone */ + case GOLD: + streak_color = "golden"; goto see_streaks; + case SILVER: + streak_color = "silvery"; + goto see_streaks; + default: + break; } + break; /* default oclass */ + } - switch (obj->oclass) { - case GOLD_CLASS: - color = "golden"; -#ifndef GOLDOBJ - /* goldobj back to u.ugold */ - u.ugold = obj->quan; - obj->quan = 0L; - dealloc_obj(obj); - obj = (struct obj *)0; -#endif - break; - case GEM_CLASS: - if (otmp->blessed) { - makeknown(TOUCHSTONE); - makeknown(obj->otyp); - prinv((char *)0, obj, 0L); - return; - } - /* FALLTHROUGH */ - case RING_CLASS: - if (objects[obj->otyp].oc_material == GLASS) { - pline(ambiguous_scratch); /* yet not ambiguous if a known touchstone */ - return; - } - color = c_obj_colors[objects[obj->otyp].oc_color]; - break; - default: - pline(scritch); + if (is_flimsy(obj)) { + /* Objects passing the is_flimsy() test will not + scratch a stone. They will leave streaks on + non-touchstones and touchstones alike. */ + streak_color = c_obj_colors[objects[obj->otyp].oc_color]; + goto see_streaks; + } + + if (tstone->otyp != TOUCHSTONE) { + pline(ambiguous_scratch); + return; + } + + switch (obj->oclass) { + case GEM_CLASS: + if (tstone->blessed || (!tstone->cursed && + (Role_if(PM_ARCHEOLOGIST) || Race_if(PM_GNOME)))) { + makeknown(TOUCHSTONE); + makeknown(obj->otyp); + prinv((char *)0, obj, 0L); + return; + } + /* FALLTHROUGH */ + case RING_CLASS: + if (objects[obj->otyp].oc_material == GLASS) { + pline(ambiguous_scratch); /* yet not ambiguous if a known touchstone */ return; } -see_streaks: - pline("You see %s streaks on the stone.", color); + streak_color = c_obj_colors[objects[obj->otyp].oc_color]; + break; + default: + pline(scritch); return; + } + + see_streaks: + pline("You see %s streaks on the stone.", streak_color); + return; } /* Place a landmine/bear trap. Helge Hafting */ @@ -2255,7 +2260,7 @@ struct obj *obj; char kbuf[BUFSZ]; Sprintf(kbuf, "%s corpse", - an(mons[otmp->corpsenm].mname)); + an(mons[otmp->corpsenm].mname)); pline("Snatching %s is a fatal mistake.", kbuf); instapetrify(kbuf); } @@ -2635,7 +2640,7 @@ doapply() } else if (!ublindf) Blindf_on(obj); else You("are already %s.", - ublindf->otyp == TOWEL ? "covered by a towel" : + ublindf->otyp == TOWEL ? "covered by a towel" : ublindf->otyp == BLINDFOLD ? "wearing a blindfold" : "wearing lenses"); break; diff --git a/src/u_init.c b/src/u_init.c index 68d42eaa6..f3b9cfb3b 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -33,7 +33,7 @@ static struct trobj Archeologist[] = { { FOOD_RATION, 0, FOOD_CLASS, 3, 0 }, { PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, { TINNING_KIT, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, - { TOUCHSTONE, 0, GEM_CLASS, 1, 1 }, + { TOUCHSTONE, 0, GEM_CLASS, 1, 0 }, { SACK, 0, TOOL_CLASS, 1, 0 }, { 0, 0, 0, 0, 0 } }; @@ -81,7 +81,7 @@ static struct trobj Knight[] = { { 0, 0, 0, 0, 0 } }; static struct trobj Monk[] = { -#define M_BOOK 2 +#define M_BOOK 2 { LEATHER_GLOVES, 2, ARMOR_CLASS, 1, UNDEF_BLESS }, { ROBE, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, 1 }, @@ -215,10 +215,11 @@ static struct trobj Wishing[] = { }; #ifdef GOLDOBJ static struct trobj Money[] = { - { GOLD_PIECE, 0 , GOLD_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } + { GOLD_PIECE, 0 , GOLD_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; #endif + /* race-based substitutions for initial inventory; the weaker cloak for elven rangers is intentional--they shoot better */ static struct inv_sub { short race_pm, item_otyp, subs_otyp; } inv_subs[] = { @@ -275,7 +276,7 @@ static struct def_skill Skill_B[] = { { P_TWO_HANDED_SWORD, P_EXPERT }, { P_SCIMITAR, P_SKILLED }, { P_SABER, P_BASIC }, { P_CLUB, P_SKILLED }, { P_MACE, P_SKILLED }, { P_MORNING_STAR, P_SKILLED }, - { P_FLAIL, P_BASIC }, { P_HAMMER, P_EXPERT }, + { P_FLAIL, P_BASIC }, { P_HAMMER, P_EXPERT }, { P_QUARTERSTAFF, P_BASIC }, { P_SPEAR, P_SKILLED }, { P_TRIDENT, P_SKILLED }, { P_BOW, P_BASIC }, { P_ATTACK_SPELL, P_SKILLED }, @@ -388,15 +389,15 @@ static struct def_skill Skill_R[] = { static struct def_skill Skill_Ran[] = { { P_DAGGER, P_EXPERT }, { P_KNIFE, P_SKILLED }, - { P_AXE, P_SKILLED }, { P_PICK_AXE, P_BASIC }, - { P_SHORT_SWORD, P_BASIC }, { P_MORNING_STAR, P_BASIC }, - { P_FLAIL, P_SKILLED }, { P_HAMMER, P_BASIC }, + { P_AXE, P_SKILLED }, { P_PICK_AXE, P_BASIC }, + { P_SHORT_SWORD, P_BASIC }, { P_MORNING_STAR, P_BASIC }, + { P_FLAIL, P_SKILLED }, { P_HAMMER, P_BASIC }, { P_QUARTERSTAFF, P_BASIC }, { P_POLEARMS, P_SKILLED }, - { P_SPEAR, P_SKILLED }, { P_JAVELIN, P_EXPERT }, - { P_TRIDENT, P_BASIC }, { P_BOW, P_EXPERT }, - { P_SLING, P_EXPERT }, { P_CROSSBOW, P_EXPERT }, - { P_DART, P_EXPERT }, { P_SHURIKEN, P_SKILLED }, - { P_BOOMERANG, P_EXPERT }, { P_WHIP, P_BASIC }, + { P_SPEAR, P_SKILLED }, { P_JAVELIN, P_EXPERT }, + { P_TRIDENT, P_BASIC }, { P_BOW, P_EXPERT }, + { P_SLING, P_EXPERT }, { P_CROSSBOW, P_EXPERT }, + { P_DART, P_EXPERT }, { P_SHURIKEN, P_SKILLED }, + { P_BOOMERANG, P_EXPERT }, { P_WHIP, P_BASIC }, { P_HEALING_SPELL, P_BASIC }, { P_DIVINATION_SPELL, P_EXPERT }, { P_ESCAPE_SPELL, P_BASIC }, @@ -804,7 +805,7 @@ u_init() default: /* impossible */ break; } - + if (discover) ini_inv(Wishing); @@ -816,7 +817,7 @@ u_init() #ifndef GOLDOBJ u.ugold0 += hidden_gold(); /* in case sack has gold in it */ #else - if (u.umoney0) ini_inv(Money); + if (u.umoney0) ini_inv(Money); u.umoney0 += hidden_gold(); /* in case sack has gold in it */ #endif @@ -980,8 +981,8 @@ register struct trobj *trop; #ifdef GOLDOBJ if (trop->trclass == GOLD_CLASS) { - /* no "blessed" or "identified" money */ - obj->quan = u.umoney0; + /* no "blessed" or "identified" money */ + obj->quan = u.umoney0; } else { #endif obj->dknown = obj->bknown = obj->rknown = 1; -- 2.40.0