Re: [CODE] do_dig modifications for OasisOLC

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 01/08/01


Ron Martin wrote:
>
> Sorry.  I read that incorrectly.  I understand now.  How's this:
>
> ACMD(do_dig)
> {
>         int iroom, rroom, dir, i;
>         struct room_data * temp_room;
>
>         two_arguments(argument, buf, buf2);
>
>         if (!*buf2)

You probably would want to make this check (!buf2 || !isdigit(*buf2))
this way it will give the proper complaint if the builder types
something other than a number for the to-room.

>         {
>                 send_to_char("Format: dig <dir> <room number>\r\n", ch);
>                 return;
>         }
>
>         iroom = atoi(buf2);
>         rroom = real_room(iroom);

Move the above two lines down to the point right before where you need
them, it doesn't make a huge difference but there's no point wasting CPU
cycles on the assignments if one of the following checks is gonna cause
the function to return anyways.

>         dir = search_block(buf, dirs, FALSE);
>         if(dir == -1)
>         {
>                 send_to_char("That is not a direction.\r\n", ch);
>                 return;
>         }
>
>         if(world[ch->in_room].dir_option[dir])
>         {
>                 send_to_char("An exit already exists in that direction.\r\n", ch);
>                 return;
>         }

This is fine but you might want to consider that a builder may want to
use dig to re-route existing exits.  You can accomplish that by removing
this check (and the similar one further down) and instead putting the
opposite test in before you allocate the memory.

This is where you should move those two lines mentioned above.

>         if (rroom <= 0)

This check should be (rroom < 0).  0 is a valid rroom and the real_room
function will return -1 if the vnum is not valid.

>         {
>                 for(i = 0; i < top_of_zone_table; i++)

You already corrected this on your own, so I won't bother.

>                         if(zone_table[i].number == (iroom/100))

This is not a good way to get the zone# as it relies on zones with
exactly 100 rooms.  I think there's a macro or function or something to
do that better but I don't recall off the top of my head what it is.

>                                 break;
>
>                 if(i == top_of_zone_table)

See George Greer's earlier response about this.

<snip>

>         if(world[rroom].dir_option[rev_dir[dir]])

Again, you corrected this one yourself.

>         {
>                 send_to_char("An exit already exists from that direction.\r\n", ch);
>                 return;
>         }
>

If you want builders to be able to use dig dig to change existing exits
this is where you would put in a check like the following...

          if (!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;

And of course you would put a similar check in here.

>         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;
>
>         add_to_save_list(iroom/100, SL_WLD);

Again, not a really great way to come up with the zone#.

>         sprintf(buf, "You make an exit %s to room %d.\r\n", dirs[dir], iroom);
>         send_to_char(buf, ch);
> }

Regards, Peter

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST