do_dig revisited

From: Desmond Daignault (tekdd@dtol.datatimes.com)
Date: 01/09/97


This is an update to the do_dig that I have found useful. I added the
feature to create a new room if the specified room doesn't exist.

ACMD(do_dig)
{
  /* Only works if you have Oasis OLC */
  extern void redit_save_internally(struct descriptor_data *d);
  extern void olc_add_to_save_list(int zone, byte type);
  extern const int rev_dir[];
  int real_zone(int number);

  char buf2[10];
  char buf3[10];
  char buf[80];
  int iroom = 0, rroom = 0;
  int dir = 0;
  int new = 0;
  /*  struct room_data *room; */

  two_arguments(argument, buf2, buf3);
  /* buf2 is the direction, buf3 is the room */

	iroom = atoi(buf3);
	rroom = real_room(iroom);

  if (!*buf2) {
    send_to_char("Format: dig <dir> <room number>\r\n", ch);
    return;
  } else if (!*buf3) {
    send_to_char("Format: dig <dir> <room number>\r\n", ch);
    return;
  } else if (!isdigit(*buf3)) {
    send_to_char("Format: dig <dir> <room number>\r\n", ch);
    return;
  }

  if (real_zone(iroom) == -1) {
    send_to_char("There is no zone for that number!\r\n", ch);
    return;
  }

  CREATE(ch->desc->olc, struct olc_data, 1);

  if (rroom <= 0) {
    CREATE(OLC_ROOM(ch->desc), struct room_data, 1);
    OLC_ROOM(ch->desc)->name = strdup("An unfinished room");
    OLC_ROOM(ch->desc)->description = strdup("An unfinished room\n");
    OLC_NUM(ch->desc) = iroom;
    new = 1;
  }

  /* Main stuff */
  switch (*buf2) {
    case 'n':
    case 'N':
      dir = NORTH;
      break;
    case 'e':
    case 'E':
      dir = EAST;
      break;
    case 's':
    case 'S':
      dir = SOUTH;
      break;
    case 'w':
    case 'W':
      dir = WEST;
      break;
    case 'u':
    case 'U':
      dir = UP;
      break;
    case 'd':
    case 'D':
      dir = DOWN;
      break;
  }

  if (world[ch->in_room].dir_option[dir])
    free(world[ch->in_room].dir_option[dir]);

  CREATE(world[ch->in_room].dir_option[dir], struct room_direction_data,1);

  world[ch->in_room].dir_option[dir]->general_description = NULL;
  world[ch->in_room].dir_option[dir]->keyword = NULL;
  world[ch->in_room].dir_option[dir]->to_room_vnum = iroom;

  if (!new) {
    OLC_ZNUM(ch->desc) = world[rroom].zone;
    if (world[rroom].dir_option[rev_dir[dir]])
      free (world[rroom].dir_option[rev_dir[dir]]);

    CREATE(world[rroom].dir_option[rev_dir[dir]], struct room_direction_data,1);

    world[rroom].dir_option[rev_dir[dir]]->general_description = NULL;
    world[rroom].dir_option[rev_dir[dir]]->keyword = NULL;
    world[rroom].dir_option[rev_dir[dir]]->to_room = ch->in_room;
    world[rroom].dir_option[rev_dir[dir]]->to_room_vnum = ch->in_room;

  } else {
    OLC_ZNUM(ch->desc) = real_zone(iroom);
    CREATE(OLC_ROOM(ch->desc)->dir_option[rev_dir[dir]], struct room_direction_data, 1);
    OLC_ROOM(ch->desc)->dir_option[rev_dir[dir]]->general_description = NULL;
    OLC_ROOM(ch->desc)->dir_option[rev_dir[dir]]->keyword = NULL;
    OLC_ROOM(ch->desc)->dir_option[rev_dir[dir]]->to_room = ch->in_room;
    OLC_ROOM(ch->desc)->dir_option[rev_dir[dir]]->to_room_vnum = world[ch->in_room].number;
  }

    /* Only works if you have Oasis OLC */
  if (new)
    redit_save_internally(ch->desc);

  world[ch->in_room].dir_option[dir]->to_room = real_room(iroom);

  /* save world data for destination room */
  olc_add_to_save_list((iroom/100), OLC_SAVE_ROOM);

  /* save world data for starting room */
  olc_add_to_save_list(world[ch->in_room].zone, OLC_SAVE_ROOM);

  free(OLC_ROOM(ch->desc));
  free(ch->desc->olc);
  sprintf(buf, "You make an exit %s to room %d.\r\n", buf2, iroom);
  send_to_char(buf, ch);
}


--

Dez.
_____________________________
Datatimes Text DBA Contractor
      749-2784 751-6400
_____________________________


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