[code] Restringing objects, stop asking! :)

From: Ebon Mists (mud@quake.cloudnet.com)
Date: 10/25/96


Ok, because I have gotten so sick and tired of people asking how to restring
objects without fucking up the prototypes, here's my function for it that I
wrote like 6 months ago and have been too lazy to post.

First, in structs.h add in somewhere:

#define OBJ_SDESC	0  /* An objects short desc: 'a long sword' */
#define OBJ_DESC	1  /* Room descript: 'A long sword lies here.' */
#define OBJ_NAME	2  /* It's keywords: 'sword long steel' */
#define	OBJ_ACTDESC	3  /* It's actdesc, useful for notes and paper */

Ok then add this to the prototypes at the beginning of utils.h:

bool rename_obj(struct obj_data *obj, char *rename_string, int descr);

Then add this to the end of utils.h:

bool rename_obj(struct obj_data *obj, char *rename_string, int descr)
{
  int i;

  switch (descr) {
  case OBJ_SDESC:
    if ((i = GET_OBJ_RNUM(obj)) > -1) {
      if (obj->short_description && obj->short_description != find_obj(i)->short_description)
	free(obj->short_description);
    }
    else if (obj->short_description)
      free(obj->short_description);
    obj->short_description = str_dup(rename_string);
    return 1;
    break;
  case OBJ_DESC:
    if ((i = GET_OBJ_RNUM(obj)) > -1) {
      if (obj->description && obj->description != find_obj(i)->description)
	free(obj->description);
    }
    else if (obj->description)
      free(obj->description);
    obj->description = str_dup(rename_string);
    return 1;
    break;
  case OBJ_NAME:
    if ((i = GET_OBJ_RNUM(obj)) > -1) {
      if (obj->name && obj->name != find_obj(i)->name)
	free(obj->name);
    }
    else if (obj->name)
      free(obj->name);
    obj->name = str_dup(rename_string);
    return 1;
    break;
  case OBJ_ACTDESC:
    if ((i = GET_OBJ_RNUM(obj)) > -1) {
      if (obj->action_description && obj->action_description != find_obj(i)->action_description)
	free(obj->action_description);
    }
    else if (obj->action_description)
      free(obj->action_description);
    obj->action_description = str_dup(rename_string);
    return 1;
    break;
  default:
    sprintf(buf, "ERROR: Invalid object name pointer passed to rename_obj().");
    mudlog(buf, CMP, LVL_IMPL, TRUE);
    return 0;
    break;
  }
}


Now to rename a steel longsword fully into a bucket of KFC, you'd call:

rename_obj(obj, "a bucket of KFC", OBJ_SDESC);
rename_obj(obj, "bucket KFC", OBJ_NAME);
rename_obj(obj, "A steaming and yummy bucket of KFC lies here.", OBJ_DESC);

Now you can restring objects into whatever you want. Add this to the
snippets page, add it to the ftp site, whatever. Just try and give me a
little credit somewhere. :)

And if you use it, send me an email just so I know if people out there are
actually using my code. :)

Hades of Ebon Mists

Ps. I *BELIEVE* the find_obj() function will work correctly... I removed the
use of RNUMS from my mud, and edited the find_obj function so it will still
work correctly, but that was eons ago. If someone finds that this code does
NOT work/compile correctly, let me know, the problem probably lies in the
find_obj function then.


+-----------------------------------------------------------+
| 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