Re: Saved ROOMS

From: The Dark One (naxos@tiac.net)
Date: 12/15/96


*********> Room Save Snipit

By The Dark One -> Reza Nejad




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

Well I think thats it....

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