]> granicus.if.org Git - nethack/commitdiff
selling health food (trunk only)
authornethack.rankin <nethack.rankin>
Sun, 6 Mar 2005 06:42:41 +0000 (06:42 +0000)
committernethack.rankin <nethack.rankin>
Sun, 6 Mar 2005 06:42:41 +0000 (06:42 +0000)
     I didn't remember a new shop type of "health food store" being added.
While trying to test some shop changes, it sure threw me for a loop when
a shopkeeper who sold lots of food refused to buy any.  This patch teaches
such shks to buy vegetarian food.  (No fixes entry included since the
relevant code hasn't been released yet.)

     Shouldn't such shops sometimes carry tins and eggs in their initial
stock?  They currently don't because those items fail the material==VEGGY
test.  Adding eggs would be easy; tins are messier since you can't decide
whether they're vegetarian until after they've been created.

src/shknam.c

index 20ae230dd91aa0604a075f730f89aa93227b676b..77996e924c6c39a0c909d27d891aa5ddb5607115 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)shknam.c   3.5     2003/01/09      */
+/*     SCCS Id: @(#)shknam.c   3.5     2005/03/05      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -559,11 +559,25 @@ struct obj *obj;
     int i, shp_indx = ESHK(shkp)->shoptype - SHOPBASE;
     const struct shclass *shp = &shtypes[shp_indx];
 
-    if (shp->symb == RANDOM_CLASS) return TRUE;
-    else for (i = 0; i < SIZE(shtypes[0].iprobs) && shp->iprobs[i].iprob; i++)
-               if (shp->iprobs[i].itype < 0 ?
+    if (shp->symb == RANDOM_CLASS)
+       return TRUE;
+    for (i = 0; i < SIZE(shtypes[0].iprobs) && shp->iprobs[i].iprob; i++) {
+       /* pseudo-class needs special handling */
+       if (shp->iprobs[i].itype == VEGETARIAN_CLASS) {
+           if ((obj->otyp == TIN || obj->otyp == CORPSE) &&
+                   ((obj->corpsenm >= LOW_PM &&
+                       vegetarian(&mons[obj->corpsenm])) ||
+                    (obj->otyp == TIN && obj->spe == 1)))      /* spinach */
+               return TRUE;
+           if (obj->oclass == FOOD_CLASS &&
+                   (objects[obj->otyp].oc_material == VEGGY ||
+                       obj->otyp == EGG))
+               return TRUE;
+       } else if ((shp->iprobs[i].itype < 0) ?
                        shp->iprobs[i].itype == - obj->otyp :
-                       shp->iprobs[i].itype == obj->oclass) return TRUE;
+                       shp->iprobs[i].itype == obj->oclass)
+           return TRUE;
+    }
     /* not found */
     return FALSE;
 }