Room Saving [by Reza Nejad]
Snippet Posted Wednesday, August 12th @ 11:36:12 PM, by George Greer in the Rooms dept.
Added Jan 16, 1997. Click the link below to read it or download it.

From: The Dark One (Reza Nejad) <naxos@tiac.net>
Subject: Room Save Snippit

make a "save" directory in lib

----->in structs.h

add  #define ROOM_SAVE

(1 << 21) (or whatever the next number is)

if you use OasicOLC change num_room_flags one higher


------>Stick This in house.c


/*****************************************************************
******************ROOM SAVE STUFF*********************************
******************************************************************/



int save_get_filename(int i, char *filename)
{
  if (i < 0)
    return 0;

  sprintf(filename, "save/%d.save", i);
  return 1;
}


int save_load(int i)
{
 FILE *fll;
 char fname[MAX_STRING_LENGTH];
 struct obj_file_elem object;

  if (!save_get_filename(i, fname))
    return 0;
  if (!(fll = fopen(fname, "r+b"))) {
    return 0;
  }

  while (!feof(fll)) {
    fread(&object, sizeof(struct obj_file_elem), 1, fll);
    if (ferror(fll)) {
      perror("Reading save file: save_load.");
      fclose(fll);
      return 0;
    }
    if (!feof(fll))
      obj_to_room(Obj_from_store(object), i);
  }

  fclose(fll);

  return 1;

}

void save_boot(void)
{
 extern int top_of_world;
 int i;

 for (i=0; i <= top_of_world; i++)
  {
   if (IS_SET(ROOM_FLAGS(i), ROOM_SAVE))
   {
   save_load(i);
   }
  }
 }


int save_save(struct obj_data * obj, FILE * fll)
{
  struct obj_data *tmp;
  int result;

  if (obj) {
    save_save(obj->contains, fll);
    save_save(obj->next_content, fll);
    result = Obj_to_store(obj, fll);
    if (!result)
      return 0;

    for (tmp = obj->in_obj; tmp; tmp = tmp->in_obj)
      GET_OBJ_WEIGHT(tmp) -= GET_OBJ_WEIGHT(obj);
  }
  return 1;
}


void save_restore_weight(struct obj_data * obj)
{
  if (obj) {
    save_restore_weight(obj->contains);
    save_restore_weight(obj->next_content);
    if (obj->in_obj)
      GET_OBJ_WEIGHT(obj->in_obj) += GET_OBJ_WEIGHT(obj);
  }
}


void save_saved(int i)
{
  char buf[MAX_STRING_LENGTH];
  FILE *fll;

  if (i == -1)
    return;

   sprintf(buf, "save/%d.save", i);
   fopen(buf, "wb");
   fclose(fll);

   fll = fopen(buf, "wb");

   save_save(world[i].contents, fll);

  fclose(fll);
  save_restore_weight(world[i].contents);


}

/****************************************************************
*****************************************************************
*****************************************************************/


------>Add this to house.h

void    save_boot(void);
void    save_saved(int vnum);

-----> In db.c

in void_boot_db

add

  log("Loading Saved Rooms.");
  save_boot();

anywhere you like inside of the boot routines (I sugjest affter the house
loading)


------> In heartbeat() or do_save() or do_reboot() anywhere you find nice

   for(i=0;i <= top_of_world; i++) {
    if(IS_SET(ROOM_FLAGS(i), ROOM_SAVE))
     save_saved(i);
   }

*Note be sure to define "int i" and "extern int top_of_world" at the
 top of the function

---------->End


<< Roomlink (Another) [by Angus Mezick] | Reply | View as text | Flattened | Rounds - Combat Initiative [by Daniel Koepke] >>

 


Related Links
  download
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.