[LONG] saving object instances

From: Jason Stortz (JI-Stortz@WIU.EDU)
Date: 07/23/00

Dear Peers,

I am back again with more questions concerning saving objects with unique
descriptions.  I would first like to extend my thanks to PjD who spotted
the error for me last time.  I can't believe I missed it. =) Sometimes you
just need a fresh pair of eyes.

So, to bring you up to date, this is what I have: I can now save
short_description, description(seen in room when object is on ground), and
name.  I have a restring function which enables me to hold an object in my
inventory and redo that objects short_description, description or name.

That's all well and fine.

Okay, Scenario 1: I load an object using load obj 300 lets say.  And it's a
sword, great.  Now, I type in:

 restring obj sword short a HUGE sword.

Okay, I check my inventory and sure enough, instead of seeing "a sword"
like I saw originally, I see "a HUGE sword."  Perfect eh? =(  Not so...

Scenario 2: I create another sword after restringing the first.  Instead of
the message "you create a sword" like I am expecting, I get "you create a
HUGE sword."  Well, not good at all.  From this I deduce that perhaps the
restring function is changing a template of the object instead of
the "instance" of it?

So, I guess what I am asking about here is a concept.  CircleMUD loads in
the objects when you use the load command, or when a character logs in.
But theoretically how does this happen?  Hmm...are there really
no "individual" objects?  Sorry guys, I'm having problems getting what I
want you to understand into words here.  See, I want to be able to type
in "load obj 300" five times lets say, then use "restring obj sword short
HUGE sword" and "restring obj 2.sword short HUGE sword" etc, to change each
of the five or six objects into unique items, but I am struggling to find
out how to do this.  I've combed over some stuff here, but am getting lost
and need a little redirection.

Any brainstorming is welcome.

Here is the code I used in objsave.c that is relevant:
struct obj_data *Obj_from_store(struct obj_file_elem object, int *location)
  struct obj_data *obj;
  int j;
  *location = 0;
  if (real_object(object.item_number) >= 0) {
    obj = read_object(object.item_number, VIRTUAL);
    *location = object.location;
    GET_OBJ_VAL(obj, 0) = object.value[0];
    GET_OBJ_VAL(obj, 1) = object.value[1];
    GET_OBJ_VAL(obj, 2) = object.value[2];
    GET_OBJ_VAL(obj, 3) = object.value[3];
    GET_OBJ_VAL(obj, 4) = object.value[4];
    GET_OBJ_VAL(obj, 5) = object.value[5];
    GET_OBJ_VAL(obj, 6) = object.value[6];
    GET_OBJ_VAL(obj, 7) = object.value[7];
    GET_OBJ_VAL(obj, 8) = object.value[8];
    GET_OBJ_VAL(obj, 9) = object.value[9];
    GET_OBJ_EXTRA(obj) = object.extra_flags;
    GET_OBJ_WEIGHT(obj) = object.weight;
    GET_OBJ_TIMER(obj) = object.timer;
    obj->obj_flags.bitvector = object.bitvector;

    for (j = 0; j < MAX_OBJ_AFFECT; j++)
      obj->affected[j] = object.affected[j];
 /* etc, etc..*/
int Obj_to_store(struct obj_data * obj, FILE * fl, int location)
  int j;
  struct obj_file_elem object;
  object.item_number = GET_OBJ_VNUM(obj);
  object.location = location;
  object.value[0] = GET_OBJ_VAL(obj, 0);
  object.value[1] = GET_OBJ_VAL(obj, 1);
  object.value[2] = GET_OBJ_VAL(obj, 2);
  object.value[3] = GET_OBJ_VAL(obj, 3);
  object.value[4] = GET_OBJ_VAL(obj, 4);
  object.value[5] = GET_OBJ_VAL(obj, 5);
  object.value[6] = GET_OBJ_VAL(obj, 6);
  object.value[7] = GET_OBJ_VAL(obj, 7);
  object.value[8] = GET_OBJ_VAL(obj, 8);
  object.value[9] = GET_OBJ_VAL(obj, 9);

  object.extra_flags = GET_OBJ_EXTRA(obj);
  object.weight = GET_OBJ_WEIGHT(obj);
  object.timer = GET_OBJ_TIMER(obj);
  object.bitvector = obj->obj_flags.bitvector;
  for (j = 0; j < MAX_OBJ_AFFECT; j++)
    object.affected[j] = obj->affected[j];

  if (fwrite(&object, sizeof(struct obj_file_elem), 1, fl) < 1) {
    perror("SYSERR: error writing object in Obj_to_store");
    return (0);
  return (1);

All the restring function uses is this basically, where arg1, arg2, and
info are passed in.  Arg1 is the name of the object, arg2 is the field to
edit, and info is the new stuff to place into the field.
  }else if(!str_cmp(arg2,"long")){
  }else if(!str_cmp(arg2,"name")){
  send_to_char("No such object around.\r\n",ch);

And here is my obj_file_elem that was used earlier in the code from
PjD will notice I know have allocated space for name, description, and
short_description.  Again, thanks! =)
struct obj_file_elem {
   obj_vnum item_number;

   sh_int location;
   int value[10];
   char name[512];
   char description[MAX_STRING_LENGTH];
   char short_description[256];
   int /*bitvector_t*/ extra_flags;
   int weight;
   int timer;
   long /*bitvector_t*/ bitvector;
   struct obj_affected_type affected[MAX_OBJ_AFFECT];

Madman Clause:
All code included in this message is COMPLETELY free for use.  Take it,
copy it, mess it up, whatever.  I require no credit in any form, you may
claim what you like as your own.  I donít care.  I also have no
responsibility if you do so choose to copy anything here. =)

Thanks Everyone,

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |

This archive was generated by hypermail 2b30 : 04/10/01 PDT