[CODE] Cloak Object Spell

From: Brian Menges (bmenges@mail.arc.nasa.gov)
Date: 09/30/96


I am working on a spell that will allow people to kind of 'hide'
objects by disguising them as something else.  Right now its
pretty generic.  The only problem I am having is that it when I
try and change the description of the object it appears to
screw up the prototype of the object as well.  For example if I
cast this spell on a long sword (obj vnum 1124) to disguise it as
a dull blade every long sword that I create after that is messed
up.  It will either have no short description or will have the
short description of the dull blade. :(  I think the problem is
in the free() part of the my code.  How can I erase the current
description of the object and then set it to something else without
screwing up the memory of my mud? 

Any help would be greatly appreciated.

-Haddixx aka Brian Menges

Here is the code:

ASPELL(spell_cloak_obj)
{
  int worked = 1;
  char name[256];

  if (ch == NULL || obj == NULL)
    return;

  if( !IS_SET(GET_OBJ_EXTRA(obj), ITEM_MAGIC) ) 
  {    
    /* free old strings */
    if(obj->name)              free(obj->name);
    if(obj->description)       free(obj->description);
    if(obj->short_description) free(obj->short_description);
    strcpy(name, obj->name);

    switch( GET_OBJ_TYPE(obj) )
    {
        case ITEM_LIGHT:
           strcat(name, " lantern dirty");
           sprintf(buf1, "A small dirty lantern has been left here.");
           sprintf(buf2, "a small lantern");
	break;
        case ITEM_WAND:
           strcat(name, " wand broken");
           sprintf(buf1, "An old broken wand has been left here.");
           sprintf(buf2, "a broken wand");
	break;
        case ITEM_STAFF:
           strcat(name, " staff wooden");
           sprintf(buf1, "A plain wooden staff has been left here.");
           sprintf(buf2, "a wooden staff");
	break;
        case ITEM_WEAPON:
           strcat(name, " blade dull");
           sprintf(buf1, "A small dull blade has been left here.");
           sprintf(buf2, "a dull blade");
	break;
        case ITEM_TREASURE:
           strcat(name, " coal lump");
           sprintf(buf1, "A lump of coal lies here.");
           sprintf(buf2, "a lump of coal");
	break;
        case ITEM_ARMOR:
           strcat(name, " armor rusty");
           sprintf(buf1, "A piece of rusting armor has been left
here.");
           sprintf(buf2, "rusty armor");
	break;
        case ITEM_KEY:
           strcat(name, " key old");
           sprintf(buf1, "An old rusty key has been left here.");
           sprintf(buf2, "an old key");
	break;
        case ITEM_SHOVEL:
           strcat(name, " shovel old");
           sprintf(buf1, "An old shovel lies here.");
           sprintf(buf2, "an old shovel");
	break;
	default:
	   worked = 0;
           act("$p glows briefly but nothing seems to happen.", FALSE,
ch, obj, 0, TO_CHAR);
	break;
    }
    if(worked)
    {
      if (IS_GOOD(ch)) 
        act("$p glows blue briefly then fades to black.", FALSE, ch,
obj, 0, TO_CHAR);
      else if (IS_EVIL(ch)) 
        act("$p glows red briefly then fades to black.", FALSE, ch, obj,
0, TO_CHAR);
      else 
        act("$p glows yellow briefly then fades to black.", FALSE, ch,
obj, 0, TO_CHAR);

      SET_BIT(GET_OBJ_EXTRA(obj), ITEM_MAGIC);
      obj->name = str_dup(name);
      obj->description = str_dup(buf1);
      obj->short_description = str_dup(buf2);

     }/* end of if the spell worked */	
  }
  act("$p glows briefly but nothing seems to happen.", FALSE, ch, obj,
0, TO_CHAR);
  act("$p's magical nature protects it from your spell!", FALSE, ch,
obj, 0, TO_CHAR);

}


-- 
/ Brian M. Menges                 |  NASA Ames Research Center \
\                                 |  Mail Stop: N262-2         /
/ San Jose State University       |  Moffett Field, CA 94035   \
\ Student, Aerospace Engineering  |  Phone: (415) 604-0069     /
/ menges@mercury.engr.sjsu.edu    |  bmenges@mail.arc.nasa.gov \

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST