[Code]Zedit New

From: Hydragon (hydragon@mag.interad.com)
Date: 01/20/97


The little glitch with Zedit New that I was encountering has continued
to baffle me.  And with the amount of requests I've received for the
code, i've decided to go ahead and post it here.  At least it works
better than stock.  Whomever creates the area must 
	1) create a room within that area, there's a lot of syserrs
		for bad command to save_internally, but it will not
		crash, not on mine anyway.
	2) zedit the new zone and add a Name to the zone, why it isn't
		loading the preset name, I don't know, that's my little
		glitch :)
	After that, you should encounter no problems.

If anyone figures that one out, please let me know.

okay, for the code:
all of this is in Zedit.c, no other files need be changed.

after all the initial voids and such:
remove :
void zedit_create_index from this top list of voids.
add (about the same location as you removed)
int get_line2(FILE * fl, char *buf);
int add_to_index(int zone, char * type);
struct zone_data *add_zone(struct zone_data * zn_table, int vzone_num);


Okay, remove the entire piece of code for create_index and zedit_new_zone
and add this where void zedit_new_zone used to be:

/*-------------------------------------------------------------------*/
/*. Create a new zone .*/

void zedit_new_zone(struct char_data *ch, int vzone_num) 
{ FILE *tempfile;
  int i, room;
  char *fname;

  if(vzone_num > 326)
  { send_to_char("326 is the highest zone allowed.\r\n", ch);
    return;
  }
  sprintf(buf1, "%s/%i.zon", ZON_PREFIX, vzone_num);
  fname = buf1;
  /*. Check zone does not exist .*/
  room = vzone_num * 100;
  for (i = 0; i <= top_of_zone_table; i++)
    if ((zone_table[i].number * 100 <= room) &&
        (zone_table[i].top >= room))
    { send_to_char("A zone already covers that area.\r\n", ch);
      return;
    }
  
  /*. Create Zone file .*/
  if(!(tempfile = fopen(fname, "w"))) {
    mudlog("SYSERR: OLC: Can't write new zone file", BRF, LVL_IMPL, TRUE);
    return;
  }
  fprintf(tempfile, "#%i\n", vzone_num);
  fprintf(tempfile, "New Zone~\n");
  fprintf(tempfile, "%i 30 2\n", (vzone_num * 100) + 99);
  fprintf(tempfile, "S\n");
  fprintf(tempfile, "$\n");
  fclose(tempfile);
    
  if(!add_to_index(vzone_num, "zon")) {
    mudlog("SYSERR: OLC: Can't add zone to index", BRF, LVL_IMPL, TRUE);
    return;  
  }  
  sprintf(buf, "OLC: Added Zone %i to zone index", vzone_num);
  mudlog(buf, BRF, LVL_IMPL, TRUE);

  zone_table = add_zone(zone_table, vzone_num);
    
  /*. Create Rooms file .*/
  sprintf(buf1, "%s/%i.wld", WLD_PREFIX, vzone_num);
  fname = buf1;
  if(!(tempfile = fopen(fname, "w")))
  { mudlog("SYSERR: OLC: Can't write new world file", BRF, LVL_IMPL, TRUE);
    return;
  }
  fprintf(tempfile, "#%i\n", vzone_num * 100);
  fprintf(tempfile, "The Begining~\n");
  fprintf(tempfile, "Not much here.\n");
  fprintf(tempfile, "~\n");
  fprintf(tempfile, "%i 0 0\n", vzone_num);
  fprintf(tempfile, "S\n");
  fprintf(tempfile, "$\n");
  fclose(tempfile);

  if(!add_to_index(vzone_num, "wld")) {
    mudlog("SYSERR: OLC: Can't write world to index", BRF, LVL_IMPL, TRUE);
    return;
  }
  sprintf(buf, "OLC: World file %i added to World Index.", vzone_num);
  mudlog(buf, BRF, LVL_IMPL, TRUE);
    
  /*. Create Mobiles file .*/
  sprintf(buf1, "%s/%i.mob", MOB_PREFIX, vzone_num);
  fname = buf1;
  if(!(tempfile = fopen(fname, "w")))   
  { mudlog("SYSERR: OLC: Can't write new mob file", BRF, LVL_IMPL, TRUE);
    return;
  }
  fprintf(tempfile, "$\n");
  fclose(tempfile);

  if(!add_to_index(vzone_num, "mob")) {
    mudlog("SYSERR: OLC: Can't write mob file to index", BRF, LVL_IMPL, TRUE);
    return;
  }
  sprintf(buf, "OLC: Mob file %i written to Mob Index.", vzone_num);  
  mudlog(buf, BRF, LVL_IMPL, TRUE);
    
  /*. Create Objects file .*/
  sprintf(buf1, "%s/%i.obj", OBJ_PREFIX, vzone_num);
  fname = buf1;
  if(!(tempfile = fopen(fname, "w")))   
  { mudlog("SYSERR: OLC: Can't write new obj file", BRF, LVL_IMPL, TRUE);
    return;
  }
  fprintf(tempfile, "$\n");
  fclose(tempfile);

  if(!add_to_index(vzone_num, "obj")) {
    mudlog("SYSERR: OLC: Can't add Object file to Index", BRF, LVL_IMPL, TRUE);
    return;
  }
  sprintf(buf, "OLC: Object file %i written to Object Index.", vzone_num);
  mudlog(buf, BRF, LVL_IMPL, TRUE);
    
  sprintf(buf, "OLC: Zone %i created by %s", vzone_num, GET_NAME(ch));
  mudlog(buf, BRF, LVL_IMPL, TRUE);
}
/*-------------------------------------------------------------------*/
struct zone_data *add_zone(struct zone_data * zn_table, int vzone_num)   
{
  struct zone_data *zone;
  int i, wrote = FALSE, last = 0, lz = -1;

  zone = zn_table;
  
  top_of_zone_table++;
    
  CREATE(zn_table, struct zone_data, top_of_zone_table);
  zn_table[top_of_zone_table].number = 32000;
  for(i = 0; i <= top_of_zone_table; i++) {
    if(!wrote && vzone_num > lz && vzone_num < zone[last].number) {
      zn_table[i].name = str_dup("New Zone");
      zn_table[i].number = vzone_num;
      zn_table[i].top = (vzone_num * 100) + 99;
      zn_table[i].lifespan = 30;
      zn_table[i].age = 0;
      zn_table[i].reset_mode = 2;
      CREATE(zn_table[i].cmd, struct reset_com, 1);
      zn_table[i].cmd[0].command = 'S';   
      wrote = TRUE;
    } else {
      zn_table[i].name = zone[last].name;
      zn_table[i].number = zone[last].number;
      zn_table[i].age = zone[last].age;
      zn_table[i].lifespan = zone[last].lifespan;
      zn_table[i].top = zone[last].top;
      zn_table[i].reset_mode = zone[last].reset_mode;
      zn_table[i].cmd = zone[last].cmd;
      lz = zone[last].number;
      last++;
    }
  }
  free(zone);
  return zn_table;
}
      
/*-------------------------------------------------------------------*/
int get_line2(FILE * fl, char *buf)
{
  char temp[256];
  int lines = 0;
      
  do {
    lines++;
    fgets(temp, 256, fl);
    if (*temp)
      temp[strlen(temp) - 1] = '\0';
  } while (!feof(fl) && (!*temp));
   
  if (feof(fl))
    return 0;
  else {
    strcpy(buf, temp);
    return lines;
  }
}

I make no claims to have written this code, I merely ported a working
portion of Obuild into a buggy piece of Oasis.

   _/  _/  _/  _/  _/_/    _/_/      _/_/     _/_/_/    _/_/   _/_/  _/
   _/  _/  _/  _/  _/ _/   _/ _/    _/  _/  _/_/   _/  _/  _/  _/ _/ _/
   _/_/_/   _/_/   _/  _/  _/_/    _/_//_/  _/         _/  _/  _/ _/ _/
   _/  _/    _/    _/  _/  _/ _/   _/   _/  _/  _/_/   _/  _/  _/  _/_/
   _/  _/    _/    _/__/   _/  _/  _/   _/   _/_/_/     _/_/   _/   _/_

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