Re: [CODE] help with whirlpool

From: Alvoria MUD (mudguy@conan.ids.net)
Date: 12/18/96


On Wed, 18 Dec 1996, Derek L. Karnes wrote:
> Been messing with this one off and on for a while, and I think the
> problem is a flying pointer somewhere outside the function that 
> corrupts the number. 
> What I'm trying to accomplish is a simple teleport to a room within a
> given zone (46, in this case) Neither one of these works.. am I missing
> something simple, or do you think it is memory as I supposed above?
> Using gdb and printing to_room after it has been assigned usually gives
> me a number upward of 100000 (i.e garbage).

Hm... I fixed it so it works. and here is a list of things that were
wrong with your 2nd attempt, as well as comments/suggestions of mine.

1. In the for/next loop, you used vict to scan thru the room, but when it
   came around to move the char, you moved ch instead, which would be the
   whirlpool itself most of the time, and any char that tries to move or
   do any command.

Fix: Used vict as the char that gets moved, and added tmp because using
     vict->next_in_room after vict has been teleported already will ref.
     the new room the vict is in, not the whirlpool itself.

2. It's kindof pointless to use the room variable if you're only using it
in one other line after giving it a value.

Fix: Removed it, and simply changed the for statement to use ch->in_room
     instead.

3. Although this is not a bug, the reason you have been getting large
   numbers for rooms is that you have to make sure both the room VNUMs
   in the do/while loop actually exist. For testing purposes, I used
   3000 and 3060 which are the bottom and top room in my own zone #30.
   When you do real_room() on a room VNUM that doesn't exist, you get
   -1, but when you feed -1 to number(), it gets recognized as (2^32)-1
   instead, because number() uses unsigned values.

4. Just out of coding pref... I always try and put the char_from_room
   and char_to_rooms next to each other.

5. look_at_room() is just a tad faster than do_look().

6. IMHO, maybe this proc should have been assigned to a room instead,
   but I figured your intent was to have the whirlpools move around,
   so I left it that way (of course :P). But, overall the proc would
   be much simpler if it was made with being assigned to a room in mind.

Below is the corrected proc, and the original one is quoted after it.

SPECIAL(whirlpool)
{
  struct char_data *vict, *tmp;
  int spec_occured = FALSE, to_room = 0;
  struct char_data *mobile = (struct char_data *) me;         

  if(!ch) 
    return FALSE;

  for (vict = world[ch->in_room].people; vict; vict = tmp)
    {
      tmp=vict->next_in_room;
      if ((GET_LEVEL(vict) < LVL_IMMORT)&&
          (vict != mobile))
        {
          do
            {
              to_room = number(real_room(3000), real_room(3055));
            }
          while((IS_SET(world[to_room].room_flags,ROOM_PRIVATE))||
                (IS_SET(world[to_room].room_flags,ROOM_GODROOM))||
                (IS_SET(world[to_room].room_flags,ROOM_DEATH))||
                (IS_SET(world[to_room].room_flags,ROOM_NOMOB)));
          char_from_room(vict);
          char_to_room(vict, to_room);
          send_to_char("A ravaging whirlpool sucks you under!\n\r", vict);
          send_to_char("You finally surface, sputtering...\n\r", vict);
          look_at_room(vict , 0);
          spec_occured = TRUE;
        }
    }
  return(spec_occured);
}

Alvoria MUD -- "I let the cityguards test this... boy was that trippy :P."
  Address   -- telnet://conan.ids.net:4000/
  Homepage  -- http://users.ids.net/~mudguy/
  Host Site -- http://www.ids.net/

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