Ok lame subject but I couldn't think how to describe this in a small subject
so ya...

Ok well my problem is this, we have herbs on our game. That Druids, and
Rangers can forage the wilderness for. These herbs will cast spells on them
when they eat them. This is how I prevent from giving spells to all classes,
I find little things that fit the RP of the class to give them the spells.

My problem is since I switch to a const table to hold the herb information
I've been having a small pointer problem. So here so code to show ya the
problem.

You goto eat the herb and it does this:

   case ITEM_HERB:
    if(obj->value[3] == FALSE || obj->value[1] != HERB_EDIABLE || ((herb =
herb_id_lookup(obj->value[2])) == NULL))
    {
     if (!chance(number_range(1, 100)) || obj->value[1] != HERB_EDIABLE)
     {
      int sn;

      sn = find_spell(ch, "poison");
      obj_cast_spell(sn, obj->level, ch, ch, NULL, NULL);
      extract_obj(obj);
      return;
     }
    }
    if ((sn = spell_lookup(herb->spell)) != -1)
    {
     obj_cast_spell( sn, obj->level, ch, ch, NULL, NULL);
     break;
    }

The problem arrises with :
if ((sn = spell_lookup(herb->spell)) != -1)


because when the || ((herb = herb_id_lookup(obj->value[2])) == NULL)) did
it's little thing that function returned 0Xffffffff rather then NULL or
something usable.

K so I look at the herb_id_lookup function:

HERB_DATA *herb_id_lookup(int id)
{
 int i;

 for ( i = 0; !IS_NULLSTR(herb_list[i].name); i++)
 {
  if (herb_list[i].id == id)
   return &herb_list[i];
 }

    return NULL;
}

Nothing too wrong here, K so heres my herb_list so you can see how thats
done:

const HERB_DATA herb_list[] =
{
 { "Emerald Moss",  HERB_EDIABLE, 1, "barkskin",   SECT_FOREST},
 { "Andronis",   HERB_EDIABLE, 2, "cure poison",   SECT_FOREST},
 { "Radalis",   HERB_EDIABLE, 3, "cure light",   SECT_FOREST},
 { "Hemlock",   HERB_EDIABLE, 4, "delay poison",  SECT_MOUNTAIN},
 { "Maythen",   HERB_EDIABLE, 5, "cure silence",  SECT_FIELD},
 { "Snakeroot",  HERB_EDIABLE, 6, "cure poison",  SECT_MOUNTAIN},
 { "Ginsing",   HERB_EDIABLE, 7, "haste",    SECT_HILLS},
 { "Aloe vera",  HERB_EDIABLE, 8, "cure serious",  SECT_DESERT},
 { "Garlic",   HERB_EDIABLE, 9, "deter",   SECT_FOREST},
 { "Athelas",  HERB_EDIABLE, 10, "bless",   SECT_HILLS},
 { "Bilberry",   HERB_EDIABLE, 11, "true sight",  SECT_FIELD},
 { "Meadowsweet", HERB_EDIABLE, 12, "cure disease", SECT_SWAMP},
 { "Yucca",  HERB_EDIABLE, 13, "cancellation", SECT_DESERT},
 { "Iceland moss", HERB_EDIABLE, 14, "giant strength", SECT_MOUNTAIN},
 { "Kelp",   HERB_EDIABLE, 15, "intensify",  SECT_OCEAN},
 { "Poppy",  HERB_EDIABLE, 16, "frenzy",  SECT_HILLS},
 { "Heather",  HERB_EDIABLE, 17, "sanctuary",  SECT_HILLS},
 { NULL,   0,   0, NULL,   0}
};

So like I'm confused as to why it's not returning something valid and or
returning NULL... Also this only happens with unidentifed herbs which makes
no sence to me cause the only differance between and IDed herb and a non
IDed herb is the value[3] == TRUE:

// insert from spell_identify
 if (obj->item_type == ITEM_HERB && obj->value[3] == FALSE)
 {
       if (get_skill(ch, gsn_herblist) > 1 && number_percent() <
get_skill(ch, gsn_herblist))
       {
        check_improve(ch, gsn_herblist, TRUE, 1, SKILL_TYPE_SKILL);
        obj->value[3] = TRUE;
        if ((herb = herb_id_lookup(obj->value[2])) == NULL)
        {
         act("$p disolves into nothingness.", ch, obj, NULL, TO_CHAR);
         return;
        }
        free_string(obj->name);
        free_string(obj->short_descr);
        free_string(obj->description);

        sprintf(buf, "%s herb", herb->name);
        obj->name = str_dup(buf);

        sprintf(buf, "%s", herb->name);
        obj->short_descr = str_dup(buf);

        obj->description = str_dup("An herb lies here.");

       }
 }

So does anyone else see where my mytery problem could be, also cause I know
this will come up... Here is the GDB print out of the core:

Core was generated by `rom 5000 copyover 4'.
Program terminated with signal 11, Segmentation fault.
#0  0x080716c5 in do_eat (ch=0x411d60b8, argument=0x410b1dd9 "herb")
    at act_obj.cc:1708
1708    if ((sn = spell_lookup(herb->spell)) != -1)
arg = "herb\000\000#A¸\207ÿ¿\nÝ\020@
[EMAIL PROTECTED]@î+%\
[EMAIL PROTECTED]@\200\212ÿ¿\000\000
\000\000\000\000\000\000ø+%\b\030\000\000\000
[EMAIL PROTECTED]@àÍ\016@
[EMAIL PROTECTED]@[EMAIL PROTECTED]
[EMAIL PROTECTED]@`®\177\b
[EMAIL PROTECTED]
0\000\000\000"...
obj = (OBJ_DATA *) 0x4117e958
herb = (HERB_DATA *) 0xffffffff
sn = 112




Reply via email to