ACMD(do_dig)
{
	char buf[80];
	int iroom = IN_ROOM(ch), rroom = 0;
	int dir = 0;
	int i, zone = (GET_ROOM_VNUM(iroom) / 100) * 100;
	struct room_data *new_room;
	bool found = FALSE;

	/* A couple function defines to shut up the warnings. */
	zone_rnum real_zone_by_thing(room_vnum vznum);
	room_rnum add_room(struct room_data *room);

	one_argument(argument, buf);

	if(!*buf) {
		send_to_char(ch, "usage: Dig [direction]\r\n");
		return;
	}

	/*
	 * This needs changed for the new lower/upper zone method, but I can get by
	 * just fine with this.
	 */
	for(i = 0; i < 100; i++) {
		if(real_room(zone + i) < 0) {
			found = TRUE;
			break;
		}
	}

	if(!found) {
		send_to_char(ch, "No more rooms in this zone.  Grovel to an imp for another one.\r\n");
		return;
	}

	/* Ok, now zone+i = first available room vnum.  Get the direction to dig. */

	/* Main stuff */

	if((dir = find_dir(buf)) < 0) {
		send_to_char(ch, "That's not a direction.\r\n");
		return;
	}


	if(world[iroom].dir_option[dir]) {
		if(world[iroom].dir_option[dir]->to_room != NOWHERE) {
			send_to_char(ch, "There's already an exit in that direction.\r\n");
			return;
		}
	}

	CREATE(new_room, struct room_data, 1);
	new_room->name = str_dup("A freshly dug room.");
	new_room->description = str_dup("You are in a freshly dug room.\r\n");
	new_room->number = zone + i;
	new_room->zone = real_zone_by_thing(zone + i);

	if((rroom = add_room(new_room)) < 0) {
		send_to_char(ch, "Something screwed up.  New room couldn't be created.\r\n");
		free(new_room);
		return;
	}

	send_to_char(ch, "New room created %s to %d(%d) with exit %s\r\n", dirs[dir], zone + i, rroom, dirs[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 = IN_ROOM(ch);

	CREATE(world[IN_ROOM(ch)].dir_option[dir], struct room_direction_data, 1);
	world[IN_ROOM(ch)].dir_option[dir]->general_description = NULL;
	world[IN_ROOM(ch)].dir_option[dir]->keyword = NULL;
	world[IN_ROOM(ch)].dir_option[dir]->to_room = rroom;
}

