Re: [OLC] [Dig Command]

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 09/07/00


Matthew Kuebbeler wrote:
>     case 'ne':
>     case 'NE':
>       dir = NORTHEAST;
>       break;
>     case 'nw':
>     case 'NW':
>       dir = NORTHWEST;
>       break;
>     case 'se':
>     case 'SE':
>       dir = SOUTHEAST;
>       break;
>     case 'sw':
>     case 'SW':
>       dir = SOUTHWEST;
>       break;

::mutters because someone re-invented the wheel, only he made it square
instead of round::

Well, unfortunately the snippets on Ceramic Mouse and the FTP site are
not checked for decent programming and many, even most are poorly
written and have to be fixed (and many practically re-written) to even
work anywhere except for the author's own MUD which it came out of.
Well, I'll skip the rest of the rant and get on with it...

The switch in this function is a hack, and one which only works for
stock directions.  There is a much better mechanism for getting a
direction from an arg and it is already built into the CircleMUD source,
with a little bit of modification it can work for diagonals as well.

The following is the modified do_dig from my own MUD, it will only work
if you used my directions snippet which is posted to Ceramic Mouse at
http://developer.circlemud.org/1999/08/28/0728258.shtml it also has
added checks to make sure that both the rooms are in the zone of the
builder doing the dig, plus it logs the dig, plus it fixes a memory leak
and a possible seg fault in the original dig.

ACMD(do_dig)
{
/* Only works if you have Oasis OLC */
extern void olc_add_to_save_list(int zone, byte type);

  char buf3[MAX_INPUT_LENGTH];
  int iroom = 0, rroom = 0;
  int dir = 0;
  /* struct room_data *room; */

  any_two_arg(argument, buf2, buf3);
  /* buf2 is the direction, buf3 is the room */
  iroom = atoi(buf3);
  rroom = real_room(iroom);

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

  if (rroom <= 0) {
    sprintf(buf, "There is no room with the number %d", iroom);
    send_to_char(buf, ch);
    return; }

  /*
   * Everyone but IMPLs can only edit zones they have been assigned.
   */
  if ((GET_LEVEL(ch) < LVL_IMPL) && (world[rroom].zone !=
GET_OLC_ZONE(ch) ||
       world[IN_ROOM(ch)].zone != GET_OLC_ZONE(ch))) {
    send_to_char("You do not have permission to edit this zone.\r\n",
ch);
    return;
  }

/* Main stuff */
  if ((dir = search_block(buf2, dirs, FALSE)) == -1)
    if ((dir = search_block(buf2, abbr_dirs, FALSE)) == -1) {
      sprintf(buf, "Invalid direction %s.", buf2);
      send_to_char(buf, ch);
      return;
    }
  if (!world[rroom].dir_option[rev_dir[dir]]) /* If statement to patch
up
                                                 apparent memory leak */
    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;

  if (!world[ch->in_room].dir_option[dir]) /* If statement to patch up
apparent
                                              memory leak */
    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 = rroom;

  /* Only works if you have Oasis OLC */
  olc_add_to_save_list((iroom/100), OLC_SAVE_ROOM);
  redit_save_to_disk(iroom/100);

  sprintf(buf, "You make an exit %s to room %d.\r\n", dirs[dir], iroom);
  send_to_char(buf, ch);
  sprintf(buf, "OLC: %s dug an exit %s from room %d to room %d",
GET_NAME(ch),
          dirs[dir], world[IN_ROOM(ch)].number, iroom);
  mudlog(buf, CMP, LVL_IMMORT, TRUE);
}


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/11/01 PDT